build: Misc improvements
diff --git a/GNUmakefile.in b/GNUmakefile.in
index 50b5c46e..cf779ad6 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -1,10 +1,10 @@
PREFIX ?= @prefix@
DESTDIR ?=
-BUILDDIR ?= @abs_builddir@
+override BUILDDIR := @abs_builddir@
override BINDIR := $(BUILDDIR)/bin
-SRCDIR ?= @abs_srcdir@
+override SRCDIR := @abs_srcdir@
override SPACE := $(subst ,, )
override COMMA := ,
@@ -13,7 +13,7 @@ MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
NASMESCAPE = $(subst ','"'$(COMMA) \"'\"$(COMMA) '"',$(1))
-override PATH := $(BUILDDIR)/toolchain/bin:$(PATH)
+override PATH := $(BUILDDIR)/toolchain/bin:/usr/local/bin:$(PATH)
export PATH
override LIMINE_VERSION := @limine_version@
@@ -36,6 +36,15 @@ export HOST_CC
INSTALL ?= @INSTALL@
export INSTALL
+GREP ?= @GREP@
+export GREP
+
+SED ?= @SED@
+export SED
+
+AWK ?= @AWK@
+export AWK
+
CFLAGS ?= @CFLAGS@
export CFLAGS
diff --git a/README.md b/README.md
index d19678da..42dcfb95 100644
--- a/README.md
+++ b/README.md
@@ -73,7 +73,7 @@ This step can take a long time, but it will ensure that the toolchain will work
with Limine. If on an x86_64 host, with GCC or Clang installed, it is possible
that the host toolchain will suffice. You can skip to the next paragraph in order
to use the system's toolchain instead. If that fails, you can still come back here
-later.
+later (remember to re-run `./configure` after building the toolchain).
The toolchain's build process depends on the following packages: `GNU make`, `GNU tar`,
`curl`, `gzip`, `bzip2`, `gcc/clang`, `g++/clang++`.
@@ -86,7 +86,7 @@ Building the toolchain can be accomplished by running:
### Prerequisites
In order to build Limine, the following packages have to be installed:
-`GNU make`, `nasm`, `mtools` (optional, necessary to build
+`GNU make`, `gzip`, `nasm`, `mtools` (optional, necessary to build
`limine-eltorito-efi.bin`).
Furthermore, either the toolchain must have been built in the previous
paragraph, or `gcc` or `llvm/clang` must also be installed, alongside
diff --git a/configure.ac b/configure.ac
index 45633219..3d2abc73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ AC_PREREQ(2.69)
AC_CONFIG_AUX_DIR([build-aux])
TOOLCHAIN_DIR="$(pwd -P)/toolchain/bin"
-PATH="$TOOLCHAIN_DIR$PATH_SEPARATOR$PATH"
+PATH="$TOOLCHAIN_DIR$PATH_SEPARATOR/usr/local/bin$PATH_SEPARATOR$PATH"
export PATH
test "x$CFLAGS" = "x" && CFLAGS='-g -O2 -pipe -Wall -Wextra'
@@ -22,10 +22,28 @@ if test "$werror_state" = "yes"; then
fi
AC_PROG_INSTALL
+AC_PROG_GREP
+AC_PROG_SED
+AC_PROG_AWK
+
+AC_CHECK_PROG([FIND_FOUND], [find], [yes])
+if ! test "x$FIND_FOUND" = "xyes"; then
+ AC_MSG_ERROR([find not found, please install find before configuring])
+fi
AC_CHECK_PROG([NASM_FOUND], [nasm], [yes])
if ! test "x$NASM_FOUND" = "xyes"; then
- AC_MSG_ERROR([NASM not found, please install NASM before configuring.])
+ AC_MSG_ERROR([nasm not found, please install nasm before configuring])
+fi
+
+AC_CHECK_PROG([GZIP_FOUND], [gzip], [yes])
+if ! test "x$GZIP_FOUND" = "xyes"; then
+ AC_MSG_ERROR([gzip not found, please install gzip before configuring])
+fi
+
+AC_CHECK_PROG([MTOOLS_FOUND], [mcopy], [yes])
+if ! test "x$MTOOLS_FOUND" = "xyes"; then
+ AC_MSG_WARN([mtools not found, install mtools to build limine-eltorito-efi.bin])
fi
AC_ARG_VAR(HOST_CC, [C compiler for the build host [default: $CC]])
@@ -34,62 +52,69 @@ test "x$HOST_CC" = "x" && HOST_CC="$CC"
AC_ARG_VAR(TOOLCHAIN, [Alternative toolchain prefix [default: limine]])
test "x$TOOLCHAIN" = "x" && TOOLCHAIN='limine'
-AC_ARG_VAR(LIMINE_CFLAGS, [C flags for Limine [default: -O3 -pipe -Wall -Wextra]])
-test "x$LIMINE_CFLAGS" = "x" && LIMINE_CFLAGS='-O3 -pipe -Wall -Wextra'
-
-AC_ARG_VAR(LIMINE_LDFLAGS, [Linker flags for Limine [default: ]])
-test "x$LIMINE_LDFLAGS" = "x" && LIMINE_LDFLAGS=' '
-
AC_ARG_VAR(LIMINE_CC, [C compiler command for Limine [default: $TOOLCHAIN-gcc]])
-test "x$LIMINE_CC" = "x" && LIMINE_CC="$TOOLCHAIN-gcc"
-
-AC_PATH_PROG([LIMINE_CC_1], [$LIMINE_CC], [no])
-if test "x$LIMINE_CC_1" = "xno"; then
- LIMINE_CC="$CC"
- AC_PATH_PROG([LIMINE_CC_2], [$LIMINE_CC], [no])
- if test "x$LIMINE_CC_2" = "xno"; then
- AC_MSG_ERROR([No suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install GCC/Clang.])
+
+if ! test "x$LIMINE_CC" = "x"; then
+ AC_CHECK_PROG([LIMINE_CC_0], [$LIMINE_CC], [yes])
+ if ! test "x$LIMINE_CC_0" = "xyes"; then
+ AC_MSG_ERROR([LIMINE_CC ($LIMINE_CC) not found])
+ fi
+else
+ LIMINE_CC="$TOOLCHAIN-gcc"
+ AC_CHECK_PROG([LIMINE_CC_1], [$LIMINE_CC], [yes])
+ if ! test "x$LIMINE_CC_1" = "xyes"; then
+ LIMINE_CC="$CC"
+ AC_CHECK_PROG([LIMINE_CC_2], [$LIMINE_CC], [yes])
+ if ! test "x$LIMINE_CC_2" = "xyes"; then
+ AC_MSG_ERROR([no suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install x86_64 GCC/Clang])
+ fi
fi
fi
CC_MACHINE="$($LIMINE_CC -dumpmachine | dd bs=6 count=1 2>/dev/null)"
if ! test "x$CC_MACHINE" = "xx86_64"; then
if ! test "x$CC_MACHINE" = "xamd64-"; then
- AC_MSG_ERROR([No suitable x86_64 C compiler found, please install x86_64 capable GCC/clang or run $srcdir/make_toolchain.sh])
+ AC_MSG_ERROR([no suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install x86_64 GCC/Clang])
fi
fi
-AC_DEFUN([GET_TOOLCHAIN_PROG], [
- AC_ARG_VAR(LIMINE_$1, [$3 command for Limine [$TOOLCHAIN-$2]])
- test "x$LIMINE_$1" = "x" && LIMINE_$1="$TOOLCHAIN-$2"
-
- AC_PATH_PROG([LIMINE_$1_1], [$LIMINE_$1], [no])
- if test "x$LIMINE_$1_1" = "xno"; then
- LIMINE_$1='g$2'
- AC_PATH_PROG([LIMINE_$1_2], [$LIMINE_$1], [no])
- if test "x$LIMINE_$1_2" = "xno"; then
- LIMINE_$1='$2'
- AC_PATH_PROG([LIMINE_$1_3], [$LIMINE_$1], [no], [/usr/local/bin])
- if test "x$LIMINE_$1_3" = "xno"; then
- AC_PATH_PROG([LIMINE_$1_4], [$LIMINE_$1], [no])
- if test "x$LIMINE_$1_4" = "xno"; then
- AC_MSG_ERROR([No suitable LIMINE_$1 found, run $srcdir/make_toolchain.sh or install GNU binutils.])
+AC_DEFUN([GET_BINUTILS_PROG], [
+ AC_ARG_VAR(LIMINE_$1, [$3 command for Limine [default: $TOOLCHAIN-$2]])
+
+ if ! test "x$LIMINE_$1" = "x"; then
+ AC_CHECK_PROG([LIMINE_$1_0], [$LIMINE_$1], [yes])
+ if ! test "x$LIMINE_$1_0" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null; then
+ AC_MSG_ERROR([LIMINE_$1 ($LIMINE_$1) is not a suitable $3])
+ fi
+ else
+ LIMINE_$1="$TOOLCHAIN-$2"
+ AC_CHECK_PROG([LIMINE_$1_1], [$LIMINE_$1], [yes])
+ if ! test "x$LIMINE_$1_1" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null; then
+ LIMINE_$1='g$2'
+ AC_CHECK_PROG([LIMINE_$1_2], [$LIMINE_$1], [yes])
+ if ! test "x$LIMINE_$1_2" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null; then
+ LIMINE_$1='$2'
+ AC_CHECK_PROG([LIMINE_$1_3], [$LIMINE_$1], [yes])
+ if ! test "x$LIMINE_$1_3" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null; then
+ AC_MSG_ERROR([no suitable LIMINE_$1 found, run $srcdir/make_toolchain.sh or install GNU binutils])
fi
fi
fi
fi
-
- if ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null; then
- AC_MSG_ERROR([LIMINE_$1 ($LIMINE_$1) is not from GNU binutils. Run $srcdir/make_toolchain.sh or install GNU binutils.])
- fi
])
-GET_TOOLCHAIN_PROG(LD, ld, Linker)
-GET_TOOLCHAIN_PROG(AR, ar, Archiver)
-GET_TOOLCHAIN_PROG(AS, as, Assembler)
-GET_TOOLCHAIN_PROG(OBJCOPY, objcopy, Objcopy)
-GET_TOOLCHAIN_PROG(OBJDUMP, objdump, Objdump)
-GET_TOOLCHAIN_PROG(READELF, readelf, Readelf)
+GET_BINUTILS_PROG(LD, ld, Linker)
+GET_BINUTILS_PROG(AR, ar, Archiver)
+GET_BINUTILS_PROG(AS, as, Assembler)
+GET_BINUTILS_PROG(OBJCOPY, objcopy, Objcopy)
+GET_BINUTILS_PROG(OBJDUMP, objdump, Objdump)
+GET_BINUTILS_PROG(READELF, readelf, Readelf)
+
+AC_ARG_VAR(LIMINE_CFLAGS, [C flags for Limine [default: -O3 -pipe -Wall -Wextra]])
+test "x$LIMINE_CFLAGS" = "x" && LIMINE_CFLAGS='-O3 -pipe -Wall -Wextra'
+
+AC_ARG_VAR(LIMINE_LDFLAGS, [Linker flags for Limine [default: ]])
+test "x$LIMINE_LDFLAGS" = "x" && LIMINE_LDFLAGS=' '
AC_SUBST(limine_version, m4_esyscmd([./version.sh]))
diff --git a/stage23/GNUmakefile b/stage23/GNUmakefile
index 2c430252..7280593a 100644
--- a/stage23/GNUmakefile
+++ b/stage23/GNUmakefile
@@ -36,8 +36,8 @@ override LIMINE_CC += --target=i686-elf
endif
endif
-COM_OUTPUT = false
-E9_OUTPUT = false
+COM_OUTPUT ?= false
+E9_OUTPUT ?= false
override S2CFLAGS := $(LIMINE_CFLAGS) -Os
@@ -217,11 +217,11 @@ $(call MKESCAPE,$(BUILDDIR))/stage2.bin: $(call MKESCAPE,$(BUILDDIR))/limine.sys
$(call MKESCAPE,$(BUILDDIR))/stage2.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_stage2only.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
- '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' "$(LIMINE_OBJDUMP)" '$(call SHESCAPE,$<)' stage2 32
+ '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' stage2 32
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
- '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' "$(LIMINE_OBJDUMP)" '$(call SHESCAPE,$<)' full 32
+ '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32
$(call MKESCAPE,$(BUILDDIR))/limine.sys: $(call MKESCAPE,$(BUILDDIR))/limine.elf
$(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
@@ -257,7 +257,7 @@ ifeq ($(TARGET), uefi64)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_efi_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
- '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' "$(LIMINE_OBJDUMP)" '$(call SHESCAPE,$<)' full 64
+ '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 64
$(call MKESCAPE,$(BUILDDIR))/BOOTX64.EFI: $(call MKESCAPE,$(BUILDDIR))/limine_efi.elf
$(LIMINE_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc -j .sbat --target efi-app-x86_64 '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
@@ -292,7 +292,7 @@ ifeq ($(TARGET), uefi32)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_efi_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
- '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' "$(LIMINE_OBJDUMP)" '$(call SHESCAPE,$<)' full 32
+ '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32
$(call MKESCAPE,$(BUILDDIR))/BOOTIA32.EFI: $(call MKESCAPE,$(BUILDDIR))/limine_efi.elf
$(LIMINE_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc -j .sbat --target efi-app-ia32 '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
diff --git a/stage23/gensyms.sh b/stage23/gensyms.sh
index 49ba8a95..047522cd 100755
--- a/stage23/gensyms.sh
+++ b/stage23/gensyms.sh
@@ -2,7 +2,8 @@
set -e
-export LC_ALL=C
+LC_ALL=C
+export LC_ALL
TMP0=$(mktemp)
@@ -25,24 +26,24 @@ TMP2=$(mktemp)
TMP3=$(mktemp)
TMP4=$(mktemp)
-$1 -t "$2" | ( sed '/[[:<:]]d[[:>:]]/d' 2>/dev/null || sed '/\bd\b/d' ) | sort > "$TMP1"
-grep "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
-grep "\.text" < "$TMP1" | awk 'NF{ print $NF }' > "$TMP3"
+"$LIMINE_OBJDUMP" -t "$1" | ( "$SED" '/[[:<:]]d[[:>:]]/d' 2>/dev/null || "$SED" '/\bd\b/d' ) | sort > "$TMP1"
+"$GREP" "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
+"$GREP" "\.text" < "$TMP1" | "$AWK" 'NF{ print $NF }' > "$TMP3"
-echo "section .$3_map" > "$TMP4"
-echo "global $3_map" >> "$TMP4"
-echo "$3_map:" >> "$TMP4"
+echo "section .$2_map" > "$TMP4"
+echo "global $2_map" >> "$TMP4"
+echo "$2_map:" >> "$TMP4"
-if [ "$4" = "32" ]; then
- paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dd 0x/g;s/$/", 0/g;s/\$/\
+if [ "$3" = "32" ]; then
+ paste -d'$' "$TMP2" "$TMP3" | "$SED" 's/^/dd 0x/g;s/$/", 0/g;s/\$/\
db "/g' >> "$TMP4"
echo "dd 0xffffffff" >> "$TMP4"
- nasm -f elf32 "$TMP4" -o $3.map.o
-elif [ "$4" = "64" ]; then
- paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dq 0x/g;s/$/", 0/g;s/\$/\
+ nasm -f elf32 "$TMP4" -o $2.map.o
+elif [ "$3" = "64" ]; then
+ paste -d'$' "$TMP2" "$TMP3" | "$SED" 's/^/dq 0x/g;s/$/", 0/g;s/\$/\
db "/g' >> "$TMP4"
echo "dq 0xffffffffffffffff" >> "$TMP4"
- nasm -f elf64 "$TMP4" -o $3.map.o
+ nasm -f elf64 "$TMP4" -o $2.map.o
fi
rm "$TMP1" "$TMP2" "$TMP3" "$TMP4"
