From 9332a9f4e16756da8ba9e3d1db1ff5c7df457330 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 2 Feb 2022 16:24:13 +0100 Subject: [PATCH] build: Misc improvements --- GNUmakefile.in | 4 ++-- README.md | 2 +- autogen.sh | 4 +--- configure.ac | 44 ++++++++++++++++++++++++++++++++------------ stage23/GNUmakefile | 2 +- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index cf779ad6..b299f081 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -70,7 +70,7 @@ export LIMINE_OBJDUMP LIMINE_READELF ?= @LIMINE_READELF@ export LIMINE_READELF -override USING_CLANG := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_CC) --version | grep clang >/dev/null && echo 1) +override USING_CLANG := @using_clang@ export USING_CLANG override STAGE1_FILES := $(shell find '$(call SHESCAPE,$(SRCDIR))/stage1' -type f -name '*.asm') @@ -141,7 +141,7 @@ limine-bios: stage23-bios decompressor .PHONY: limine-eltorito-efi limine-eltorito-efi: mkdir -p '$(call SHESCAPE,$(BINDIR))' - dd if=/dev/zero of='$(call SHESCAPE,$(BINDIR))/limine-eltorito-efi.bin' bs=512 count=2880 + dd if=/dev/zero of='$(call SHESCAPE,$(BINDIR))/limine-eltorito-efi.bin' bs=512 count=2880 2>/dev/null ( mformat -i '$(call SHESCAPE,$(BINDIR))/limine-eltorito-efi.bin' -f 1440 :: && \ mmd -D s -i '$(call SHESCAPE,$(BINDIR))/limine-eltorito-efi.bin' ::/EFI && \ mmd -D s -i '$(call SHESCAPE,$(BINDIR))/limine-eltorito-efi.bin' ::/EFI/BOOT && \ diff --git a/README.md b/README.md index 42dcfb95..43958516 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 (remember to re-run `./configure` after building the toolchain). +later (remember to `make clean` and 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++`. diff --git a/autogen.sh b/autogen.sh index 9b97e3cf..65a41b76 100755 --- a/autogen.sh +++ b/autogen.sh @@ -9,15 +9,13 @@ test -z "$srcdir" && srcdir=. cd "$srcdir" -build_aux="build-aux" - [ -d stivale ] || git clone https://github.com/stivale/stivale.git [ -d reduced-gnu-efi ] || git clone https://github.com/limine-bootloader/reduced-gnu-efi.git automake_libdir="$(automake --print-libdir)" mkdir -p build-aux -cp "${automake_libdir}/install-sh" "${build_aux}" +cp "${automake_libdir}/install-sh" build-aux autoconf diff --git a/configure.ac b/configure.ac index 3d2abc73..680101b3 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,10 @@ test "x$TOOLCHAIN" = "x" && TOOLCHAIN='limine' AC_ARG_VAR(LIMINE_CC, [C compiler command for Limine [default: $TOOLCHAIN-gcc]]) +AC_DEFUN([CC_ERROR_MSG], [ + AC_MSG_ERROR([no suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install x86_64 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 @@ -66,15 +70,31 @@ else 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]) + CC_ERROR_MSG fi fi fi +if ! $LIMINE_CC --version >/dev/null 2>&1; then + CC_ERROR_MSG +fi + +if $LIMINE_CC --version | grep clang >/dev/null 2>&1; then + AC_SUBST(using_clang, 1) +elif $LIMINE_CC --version | grep 'Free Software Foundation' >/dev/null 2>&1; then + AC_SUBST(using_clang, 0) +else + CC_ERROR_MSG +fi + +if ! $LIMINE_CC -dumpmachine >/dev/null 2>&1; then + CC_ERROR_MSG +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 LIMINE_CC found, run $srcdir/make_toolchain.sh or install x86_64 GCC/Clang]) + CC_ERROR_MSG fi fi @@ -83,19 +103,19 @@ AC_DEFUN([GET_BINUTILS_PROG], [ 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 + if ! test "x$LIMINE_$1_0" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null 2>&1; 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 + if ! test "x$LIMINE_$1_1" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null 2>&1; 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 + if ! test "x$LIMINE_$1_2" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null 2>&1; 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 + if ! test "x$LIMINE_$1_3" = "xyes" || ! $LIMINE_$1 --version | grep 'GNU Binutils' >/dev/null 2>&1; then AC_MSG_ERROR([no suitable LIMINE_$1 found, run $srcdir/make_toolchain.sh or install GNU binutils]) fi fi @@ -103,12 +123,12 @@ AC_DEFUN([GET_BINUTILS_PROG], [ fi ]) -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) +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' diff --git a/stage23/GNUmakefile b/stage23/GNUmakefile index 7280593a..89fef8c7 100644 --- a/stage23/GNUmakefile +++ b/stage23/GNUmakefile @@ -213,7 +213,7 @@ $(call MKESCAPE,$(BUILDDIR))/stage2.bin.gz: $(call MKESCAPE,$(BUILDDIR))/stage2. gzip -n -9 < '$(call SHESCAPE,$<)' > '$(call SHESCAPE,$@)' $(call MKESCAPE,$(BUILDDIR))/stage2.bin: $(call MKESCAPE,$(BUILDDIR))/limine.sys - dd if='$(call SHESCAPE,$<)' bs=$$(( 0x$$("$(LIMINE_READELF)" -S '$(call SHESCAPE,$(BUILDDIR))/limine.elf' | grep .stage3.text | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of='$(call SHESCAPE,$@)' + dd if='$(call SHESCAPE,$<)' bs=$$(( 0x$$("$(LIMINE_READELF)" -S '$(call SHESCAPE,$(BUILDDIR))/limine.elf' | $(GREP) .stage3.text | $(SED) 's/^.*] //' | $(AWK) '{print $$3}' | $(SED) 's/^0*//') - 0x8000 )) count=1 of='$(call SHESCAPE,$@)' 2>/dev/null $(call MKESCAPE,$(BUILDDIR))/stage2.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_stage2only.elf cd '$(call SHESCAPE,$(BUILDDIR))' && \