build: Add toolchain-detect

This commit is contained in:
mintsuki 2022-06-15 07:16:41 +02:00
parent 0c084e37d5
commit 7404cb467e
9 changed files with 188 additions and 128 deletions

4
.gitignore vendored
View File

@ -22,6 +22,10 @@
/.vscode
/test_image
!/common/font.bin
/toolchain-detect/configure
/toolchain-detect/configure.ac.save
/toolchain-detect/*~
/toolchain-detect/autom4te.cache
/configure
/configure.ac.save
/build-aux

View File

@ -76,9 +76,6 @@ export LIMINE_READELF
override LIMINE_VERSION := @PACKAGE_VERSION@
override USING_CLANG := @USING_CLANG@
export USING_CLANG
override STAGE1_FILES := $(shell find '$(call SHESCAPE,$(SRCDIR))/stage1' -type f -name '*.asm')
.PHONY: all
@ -211,38 +208,62 @@ distclean: clean
.PHONY: maintainer-clean
maintainer-clean: distclean
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf freestanding_headers limine-efi configure build-aux *'~' autom4te.cache *.tar.xz *.tar.gz
cd '$(call SHESCAPE,$(SRCDIR))'/toolchain-detect && rm -rf configure *'~' autom4te.cache
.PHONY: common-uefi-x86-64
common-uefi-x86-64:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all TARGET=uefi-x86-64 BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64'
mkdir -p '$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64'
cd '$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64' && \
TARGET=uefi-x86-64 '$(call SHESCAPE,$(SRCDIR))'/toolchain-detect/configure
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all \
TOOLCHAIN_FILE='$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64/toolchain.mk' \
TARGET=uefi-x86-64 \
BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64'
.PHONY: common-uefi-x86-64-clean
common-uefi-x86-64-clean:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' clean TARGET=uefi-x86-64 BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64'
rm -rf '$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64'
.PHONY: common-uefi-ia32
common-uefi-ia32:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all TARGET=uefi-ia32 BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32'
mkdir -p '$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32'
cd '$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32' && \
TARGET=uefi-ia32 '$(call SHESCAPE,$(SRCDIR))'/toolchain-detect/configure
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all \
TOOLCHAIN_FILE='$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32/toolchain.mk' \
TARGET=uefi-ia32 \
BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32'
.PHONY: common-uefi-ia32-clean
common-uefi-ia32-clean:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' clean TARGET=uefi-ia32 BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32'
rm -rf '$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32'
.PHONY: common-bios
common-bios:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all TARGET=bios BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-bios'
mkdir -p '$(call SHESCAPE,$(BUILDDIR))/common-bios'
cd '$(call SHESCAPE,$(BUILDDIR))/common-bios' && \
TARGET=bios '$(call SHESCAPE,$(SRCDIR))'/toolchain-detect/configure
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' all \
TOOLCHAIN_FILE='$(call SHESCAPE,$(BUILDDIR))/common-bios/toolchain.mk' \
TARGET=bios \
BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-bios'
.PHONY: common-bios-clean
common-bios-clean:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/common' clean TARGET=bios BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/common-bios'
rm -rf '$(call SHESCAPE,$(BUILDDIR))/common-bios'
.PHONY: decompressor
decompressor:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/decompressor' all BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/decompressor-build'
mkdir -p '$(call SHESCAPE,$(BUILDDIR))/decompressor-build'
cd '$(call SHESCAPE,$(BUILDDIR))/decompressor-build' && \
TARGET=bios '$(call SHESCAPE,$(SRCDIR))'/toolchain-detect/configure
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/decompressor' all \
TOOLCHAIN_FILE='$(call SHESCAPE,$(BUILDDIR))/common-bios/toolchain.mk' \
BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/decompressor-build'
.PHONY: decompressor-clean
decompressor-clean:
$(MAKE) -C '$(call SHESCAPE,$(SRCDIR))/decompressor' clean BUILDDIR='$(call SHESCAPE,$(BUILDDIR))/decompressor-build'
rm -rf '$(call SHESCAPE,$(BUILDDIR))/decompressor-build'
.PHONY: test-clean
test-clean:

View File

@ -16,3 +16,4 @@ mkdir -p build-aux
cp "${automake_libdir}/install-sh" build-aux
autoconf
( cd toolchain-detect && autoconf )

View File

@ -1,6 +1,7 @@
include $(TOOLCHAIN_FILE)
TARGET ?=
BUILDDIR ?=
USING_CLANG ?= 0
override SRCDIR := $(shell pwd -P)
@ -150,7 +151,7 @@ override INTERNAL_LDFLAGS += \
-ztext
endif
.PHONY: all clean
.PHONY: all
override C_FILES := $(shell find ./ -type f -name '*.c')
ifeq ($(TARGET), bios)
@ -442,6 +443,3 @@ $(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_uefi_ia32
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf32 -o '$(call SHESCAPE,$@)'
endif
clean:
rm -rf '$(call SHESCAPE,$(BUILDDIR))'

View File

@ -137,103 +137,14 @@ fi
AC_SUBST(BUILD_CD_EFI, [$BUILD_CD_EFI])
AC_ARG_VAR(TOOLCHAIN, [Alternative toolchain prefix (or 'llvm') [default: limine]])
test "x$TOOLCHAIN" = "x" && TOOLCHAIN='limine'
AC_ARG_VAR(TOOLCHAIN, [alternative toolchain prefix (or 'llvm')])
AC_ARG_VAR(LIMINE_CC, [C compiler command for Limine])
AC_DEFUN([CC_ERROR_MSG], [
AC_MSG_ERROR([no suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install the appropriate 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
if test "$TOOLCHAIN" = 'llvm'; then
LIMINE_CC='clang'
else
LIMINE_CC="$TOOLCHAIN-gcc"
fi
AC_CHECK_PROG([LIMINE_CC_1], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_1" = "xyes"; then
LIMINE_CC="$TOOLCHAIN-cc"
AC_CHECK_PROG([LIMINE_CC_2], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_2" = "xyes"; then
LIMINE_CC="gcc"
AC_CHECK_PROG([LIMINE_CC_3], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_3" = "xyes"; then
LIMINE_CC="clang"
AC_CHECK_PROG([LIMINE_CC_4], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_4" = "xyes"; then
LIMINE_CC="cc"
AC_CHECK_PROG([LIMINE_CC_5], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_5" = "xyes"; then
CC_ERROR_MSG
fi
fi
fi
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
AC_DEFUN([GET_BINUTILS_PROG], [
AC_ARG_VAR(LIMINE_$1, [$3 command for Limine])
if ! test "x$LIMINE_$1" = "x"; then
AC_CHECK_PROG([LIMINE_$1_0], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_0" = "xyes"; then
AC_MSG_ERROR([LIMINE_$1 ($LIMINE_$1) not found])
fi
else
if test "$TOOLCHAIN" = 'llvm' && test '$2' = 'ld'; then
LIMINE_$1='ld.lld'
else
LIMINE_$1="$TOOLCHAIN-$2"
fi
AC_CHECK_PROG([LIMINE_$1_1], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_1" = "xyes"; then
LIMINE_$1='g$2'
AC_CHECK_PROG([LIMINE_$1_2], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_2" = "xyes"; then
LIMINE_$1='$2'
AC_CHECK_PROG([LIMINE_$1_3], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_3" = "xyes"; then
if test '$2' = 'ld'; then
LIMINE_$1='ld.lld'
else
LIMINE_$1='llvm-$2'
fi
AC_CHECK_PROG([LIMINE_$1_4], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_4" = "xyes"; then
AC_MSG_ERROR([no suitable LIMINE_$1 found, run $srcdir/make_toolchain.sh or install the appropriate LLVM/GNU binutils])
fi
fi
fi
fi
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)
AC_ARG_VAR(LIMINE_LD, [linker command for Limine])
AC_ARG_VAR(LIMINE_AR, [archiver command for Limine])
AC_ARG_VAR(LIMINE_AS, [assembler command for Limine])
AC_ARG_VAR(LIMINE_OBJCOPY, [objcopy command for Limine])
AC_ARG_VAR(LIMINE_OBJDUMP, [objdump command for Limine])
AC_ARG_VAR(LIMINE_READELF, [readelf command for 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'

View File

@ -1,5 +1,6 @@
include $(TOOLCHAIN_FILE)
BUILDDIR ?=
USING_CLANG ?= 0
override SPACE := $(subst ,, )

View File

@ -7,10 +7,15 @@ test -z "$srcdir" && srcdir=.
cd "$srcdir"
TARGET=x86_64-elf
if [ -z "$TARGET" ]; then
set +x
echo "TARGET not specified"
exit 1
fi
TARGET=$TARGET-elf
BINUTILSVERSION=2.38
GCCVERSION=12.1.0
NASMVERSION=2.15.05
if command -v gmake; then
export MAKE=gmake
@ -49,9 +54,6 @@ fi
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
curl -o gcc-$GCCVERSION.tar.gz https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
fi
if [ ! -f nasm-$NASMVERSION.tar.gz ]; then
curl -o nasm-$NASMVERSION.tar.gz https://limine-bootloader.org/files/misc/nasm-$NASMVERSION.tar.gz
fi
rm -rf build
mkdir build
@ -59,11 +61,10 @@ cd build
$TAR -zxf ../binutils-$BINUTILSVERSION.tar.gz
$TAR -zxf ../gcc-$GCCVERSION.tar.gz
$TAR -zxf ../nasm-$NASMVERSION.tar.gz
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --program-prefix=limine- --with-sysroot --disable-nls --disable-werror --enable-targets=x86_64-elf,x86_64-pe
../binutils-$BINUTILSVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
$MAKE
$MAKE install
cd ..
@ -76,16 +77,9 @@ chmod +x contrib/download_prerequisites
cd ..
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --program-prefix=limine- --disable-nls --enable-languages=c --without-headers
../gcc-$GCCVERSION/configure CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
$MAKE all-gcc
$MAKE all-target-libgcc
$MAKE install-gcc
$MAKE install-target-libgcc
cd ..
mkdir build-nasm
cd build-nasm
../nasm-$NASMVERSION/configure --prefix="$PREFIX"
MAKEFLAGS="" $MAKE
MAKEFLAGS="" $MAKE install
cd ..

View File

@ -0,0 +1,112 @@
AC_INIT([Limine], m4_esyscmd([../version.sh]), [https://github.com/limine-bootloader/limine/issues], [limine], [https://limine-bootloader.org/])
AC_PREREQ(2.69)
case "$TARGET" in
uefi-x86-64)
ARCHITECTURE=x86_64
;;
uefi-ia32|bios)
ARCHITECTURE=i686
;;
*)
AC_MSG_ERROR([invalid target])
;;
esac
if test "x$TOOLCHAIN" = "x"; then
TOOLCHAIN=$ARCHITECTURE-elf
fi
AC_SUBST(TOOLCHAIN, $TOOLCHAIN)
AC_DEFUN([CC_ERROR_MSG], [
AC_MSG_ERROR([no suitable LIMINE_CC found, run $srcdir/make_toolchain.sh or install the appropriate 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
if test "$TOOLCHAIN" = 'llvm'; then
LIMINE_CC='clang'
else
LIMINE_CC="$TOOLCHAIN-gcc"
fi
AC_CHECK_PROG([LIMINE_CC_1], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_1" = "xyes"; then
LIMINE_CC="$TOOLCHAIN-cc"
AC_CHECK_PROG([LIMINE_CC_2], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_2" = "xyes"; then
LIMINE_CC="clang"
AC_CHECK_PROG([LIMINE_CC_3], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_3" = "xyes"; then
LIMINE_CC="gcc"
AC_CHECK_PROG([LIMINE_CC_4], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_4" = "xyes"; then
LIMINE_CC="cc"
AC_CHECK_PROG([LIMINE_CC_5], [$LIMINE_CC], [yes])
if ! test "x$LIMINE_CC_5" = "xyes"; then
CC_ERROR_MSG
fi
fi
fi
fi
fi
fi
AC_SUBST(LIMINE_CC, $LIMINE_CC)
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
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"; then
AC_MSG_ERROR([LIMINE_$1 ($LIMINE_$1) not found])
fi
else
if test "$TOOLCHAIN" = 'llvm' && test '$2' = 'ld'; then
LIMINE_$1='ld.lld'
else
LIMINE_$1="$TOOLCHAIN-$2"
fi
AC_CHECK_PROG([LIMINE_$1_1], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_1" = "xyes"; then
if test '$2' = 'ld'; then
LIMINE_$1='ld.lld'
else
LIMINE_$1='llvm-$2'
fi
AC_CHECK_PROG([LIMINE_$1_2], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_2" = "xyes"; then
LIMINE_$1='$2'
AC_CHECK_PROG([LIMINE_$1_3], [$LIMINE_$1], [yes])
if ! test "x$LIMINE_$1_3" = "xyes"; then
AC_MSG_ERROR([no suitable LIMINE_$1 found, run $srcdir/make_toolchain.sh or install the appropriate LLVM/GNU binutils])
fi
fi
fi
fi
AC_SUBST(LIMINE_$1, $LIMINE_$1)
])
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_CONFIG_FILES(toolchain.mk)
AC_OUTPUT

View File

@ -0,0 +1,18 @@
override USING_CLANG := @USING_CLANG@
export USING_CLANG
override TOOLCHAIN := @TOOLCHAIN@
export TOOLCHAIN
override LIMINE_CC := @LIMINE_CC@
export LIMINE_CC
override LIMINE_LD := @LIMINE_LD@
export LIMINE_LD
override LIMINE_AR := @LIMINE_AR@
export LIMINE_AR
override LIMINE_AS := @LIMINE_AS@
export LIMINE_AS
override LIMINE_OBJCOPY := @LIMINE_OBJCOPY@
export LIMINE_OBJCOPY
override LIMINE_OBJDUMP := @LIMINE_OBJDUMP@
export LIMINE_OBJDUMP
override LIMINE_READELF := @LIMINE_READELF@
export LIMINE_READELF