build: Improve toolchain detection
diff --git a/README.md b/README.md
index ca62e9db..61b8cf43 100644
--- a/README.md
+++ b/README.md
@@ -72,8 +72,9 @@ The toolchain's build process depends on the following packages: `GNU make`,
Building the toolchain can be accomplished by running:
```bash
-./make_toolchain.sh
+TARGET=<target architecture> ./make_toolchain.sh
```
+where `<target architecture>` is something like `i686` or `x86_64`.
### Prerequisites
diff --git a/common/GNUmakefile b/common/GNUmakefile
index 8bae057b..7af01bce 100644
--- a/common/GNUmakefile
+++ b/common/GNUmakefile
@@ -25,18 +25,6 @@ else
$(error Invalid target)
endif
-ifeq ($(USING_CLANG), 1)
-ifeq ($(TARGET), bios)
-override LIMINE_CC += --target=i686-elf
-endif
-ifeq ($(TARGET), uefi-x86-64)
-override LIMINE_CC += --target=x86_64-elf
-endif
-ifeq ($(TARGET), uefi-ia32)
-override LIMINE_CC += --target=i686-elf
-endif
-endif
-
COM_OUTPUT ?= false
E9_OUTPUT ?= false
diff --git a/configure.ac b/configure.ac
index 8edab0c1..4ca0fe2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,8 +66,8 @@ else
(
mkdir -p "$BUILDDIR/toolchain-files"
cd "$BUILDDIR/toolchain-files"
- ARCHITECTURE=i686 "$SRCDIR/toolchain-detect/configure" || exit 1
- )
+ ARCHITECTURE=i686 "$SRCDIR/toolchain-detect/configure"
+ ) || exit 1
BUILD_BIOS="limine-bios"
fi
@@ -109,8 +109,8 @@ else
(
mkdir -p "$BUILDDIR/toolchain-files"
cd "$BUILDDIR/toolchain-files"
- ARCHITECTURE=i686 "$SRCDIR/toolchain-detect/configure" || exit 1
- )
+ ARCHITECTURE=i686 "$SRCDIR/toolchain-detect/configure"
+ ) || exit 1
BUILD_UEFI_IA32="limine-uefi-ia32"
fi
@@ -128,8 +128,8 @@ else
(
mkdir -p "$BUILDDIR/toolchain-files"
cd "$BUILDDIR/toolchain-files"
- ARCHITECTURE=x86_64 "$SRCDIR/toolchain-detect/configure" || exit 1
- )
+ ARCHITECTURE=x86_64 "$SRCDIR/toolchain-detect/configure"
+ ) || exit 1
BUILD_UEFI_X86_64="limine-uefi-x86-64"
fi
diff --git a/decompressor/GNUmakefile b/decompressor/GNUmakefile
index c8cccd25..ff753ec5 100644
--- a/decompressor/GNUmakefile
+++ b/decompressor/GNUmakefile
@@ -12,10 +12,6 @@ ifeq ($(call MKESCAPE,$(BUILDDIR)), )
$(error BUILDDIR not specified)
endif
-ifeq ($(USING_CLANG), 1)
-override LIMINE_CC += --target=i686-elf
-endif
-
override INTERNAL_CFLAGS := \
$(WERROR) \
-m32 \
@@ -87,7 +83,3 @@ $(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -f elf32 -o '$(call SHESCAPE,$@)'
-
-.PHONY: clean
-clean:
- rm -rf '$(call SHESCAPE,$(BUILDDIR))'
diff --git a/toolchain-detect/configure.ac b/toolchain-detect/configure.ac
index 296ca17e..60388367 100644
--- a/toolchain-detect/configure.ac
+++ b/toolchain-detect/configure.ac
@@ -12,6 +12,8 @@ AC_PROG_GREP
if test "x$TOOLCHAIN" = "x"; then
TOOLCHAIN=$ARCHITECTURE-elf
+else
+ ENFORCE_TOOLCHAIN=yes
fi
AC_SUBST(TOOLCHAIN, $TOOLCHAIN)
@@ -33,6 +35,9 @@ else
fi
AC_CHECK_PROG([LIMINE_CC_1], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_1" = "xyes"; then
+ if test "x$ENFORCE_TOOLCHAIN" = "xyes"; then
+ CC_ERROR_MSG
+ fi
LIMINE_CC="$TOOLCHAIN-cc"
AC_CHECK_PROG([LIMINE_CC_2], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_2" = "xyes"; then
@@ -59,13 +64,22 @@ if ! $LIMINE_CC --version >/dev/null 2>&1; then
fi
if $LIMINE_CC --version | $GREP clang >/dev/null 2>&1; then
- AC_SUBST(USING_CLANG, 1)
+ LIMINE_CC="$LIMINE_CC --target=$ARCHITECTURE-elf"
elif $LIMINE_CC --version | $GREP 'Free Software Foundation' >/dev/null 2>&1; then
- AC_SUBST(USING_CLANG, 0)
+ true
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=${#ARCHITECTURE} count=1 2>/dev/null)"
+if ! test "x$CC_MACHINE" = "x$ARCHITECTURE"; then
+ CC_ERROR_MSG
+fi
+
AC_DEFUN([GET_BINUTILS_PROG], [
if ! test "x$LIMINE_$1" = "x"; then
AC_CHECK_PROG([LIMINE_$1_0], [$LIMINE_$1], [yes])
@@ -80,6 +94,9 @@ AC_DEFUN([GET_BINUTILS_PROG], [
fi
AC_CHECK_PROG([LIMINE_$1_1], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_1" = "xyes"; then
+ if test "x$ENFORCE_TOOLCHAIN" = "xyes"; then
+ AC_MSG_ERROR([LIMINE_$1 ($LIMINE_$1) not found])
+ fi
if test '$2' = 'ld'; then
LIMINE_$1='ld.lld'
else
diff --git a/toolchain-detect/toolchain.mk.in b/toolchain-detect/toolchain.mk.in
index 1455df4a..af772b99 100644
--- a/toolchain-detect/toolchain.mk.in
+++ b/toolchain-detect/toolchain.mk.in
@@ -1,5 +1,3 @@
-override USING_CLANG := @USING_CLANG@
-export USING_CLANG
override TOOLCHAIN := @TOOLCHAIN@
export TOOLCHAIN
override LIMINE_CC := @LIMINE_CC@
