build: Move program detection logic to configure script

This commit is contained in:
mintsuki 2022-01-31 11:46:19 +01:00
parent ac865be1a1
commit e4bd2cfdbf
5 changed files with 82 additions and 169 deletions

View File

@ -74,7 +74,7 @@ jobs:
run: cp LICENSE.md build/bin/
- name: Copy install-sh to bin
run: cp install-sh build/bin/
run: cp build-aux/install-sh build/bin/
- name: Push binaries to binary branch
run: |

3
.gitignore vendored
View File

@ -23,7 +23,8 @@ stivale
test_image
!stage23/font.bin
configure
install-sh
configure.ac.save
build-aux
*~
config.status
config.log

View File

@ -31,6 +31,7 @@ endif
export CC
HOST_CC ?= @HOST_CC@
export HOST_CC
INSTALL ?= @INSTALL@
export INSTALL
@ -39,165 +40,30 @@ CFLAGS ?= @CFLAGS@
export CFLAGS
LIMINE_CFLAGS ?= @LIMINE_CFLAGS@
LIMINE_LDFLAGS ?= @LIMINE_LDFLAGS@
export LIMINE_CFLAGS
LIMINE_LDFLAGS ?= @LIMINE_LDFLAGS@
export LIMINE_LDFLAGS
TOOLCHAIN ?= @TOOLCHAIN@
export TOOLCHAIN
LIMINE_CC ?= @LIMINE_CC@
LIMINE_LD ?= @LIMINE_LD@
LIMINE_AR ?= @LIMINE_AR@
LIMINE_AS ?= @LIMINE_AS@
LIMINE_OBJCOPY ?= @LIMINE_OBJCOPY@
LIMINE_OBJDUMP ?= @LIMINE_OBJDUMP@
LIMINE_READELF ?= @LIMINE_READELF@
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_CC) ; ), )
override LIMINE_CC := $(CC)
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_LD) ; ), )
override LIMINE_LD := gld
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_LD) ; ), )
override LIMINE_LD := /usr/local/bin/ld
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_LD) ; ), )
override LIMINE_LD := ld
endif
endif
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AR) ; ), )
override LIMINE_AR := gar
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AR) ; ), )
override LIMINE_AR := /usr/local/bin/ar
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AR) ; ), )
override LIMINE_AR := ar
endif
endif
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AS) ; ), )
override LIMINE_AS := gas
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AS) ; ), )
override LIMINE_AS := /usr/local/bin/as
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_AS) ; ), )
override LIMINE_AS := as
endif
endif
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJCOPY) ; ), )
override LIMINE_OBJCOPY := gobjcopy
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJCOPY) ; ), )
override LIMINE_OBJCOPY := /usr/local/bin/objcopy
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJCOPY) ; ), )
override LIMINE_OBJCOPY := objcopy
endif
endif
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJDUMP) ; ), )
override LIMINE_OBJDUMP := gobjdump
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJDUMP) ; ), )
override LIMINE_OBJDUMP := /usr/local/bin/objdump
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_OBJDUMP) ; ), )
override LIMINE_OBJDUMP := objdump
endif
endif
endif
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_READELF) ; ), )
override LIMINE_READELF := greadelf
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_READELF) ; ), )
override LIMINE_READELF := /usr/local/bin/readelf
ifeq ($(shell PATH='$(call SHESCAPE,$(PATH))' command -v $(LIMINE_READELF) ; ), )
override LIMINE_READELF := readelf
endif
endif
endif
export LIMINE_CC
LIMINE_LD ?= @LIMINE_LD@
export LIMINE_LD
LIMINE_AR ?= @LIMINE_AR@
export LIMINE_AR
LIMINE_AS ?= @LIMINE_AS@
export LIMINE_AS
LIMINE_OBJCOPY ?= @LIMINE_OBJCOPY@
export LIMINE_OBJCOPY
LIMINE_OBJDUMP ?= @LIMINE_OBJDUMP@
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)
export USING_CLANG
ifeq ($(USING_CLANG), 1)
override ORIG_LIMINE_CC := $(LIMINE_CC)
override LIMINE_CC += --target=x86_64-elf
endif
override CC_MACHINE := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_CC) -dumpmachine | dd bs=6 count=1 2>/dev/null)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), distclean)
ifneq ($(MAKECMDGOALS), maintainer-clean)
ifneq ($(MAKECMDGOALS), uninstall)
ifneq ($(MAKECMDGOALS), dist)
ifneq ($(MAKECMDGOALS), limine-install)
ifneq ($(MAKECMDGOALS), limine-hdd.h)
ifneq ($(MAKECMDGOALS), limine-eltorito-efi)
ifneq ($(MAKECMDGOALS), install)
ifneq ($(MAKECMDGOALS), install-data)
ifneq ($(MAKECMDGOALS), install-strip)
override USING_GNU_LD := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_LD) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_LD), 1)
$(error The specified LIMINE_LD linker ($(LIMINE_LD)) is not the GNU linker)
endif
override USING_GNU_AR := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_AR) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_AR), 1)
$(error The specified LIMINE_AR archiver ($(LIMINE_AR)) is not the GNU archiver)
endif
override USING_GNU_AS := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_AS) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_AS), 1)
$(error The specified LIMINE_AS assembler ($(LIMINE_AS)) is not the GNU assembler)
endif
override USING_GNU_OBJCOPY := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_OBJCOPY) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_OBJCOPY), 1)
$(error The specified LIMINE_OBJCOPY ($(LIMINE_OBJCOPY)) is not GNU objcopy)
endif
override USING_GNU_OBJDUMP := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_OBJDUMP) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_OBJDUMP), 1)
$(error The specified LIMINE_OBJDUMP ($(LIMINE_OBJDUMP)) is not GNU objdump)
endif
override USING_GNU_READELF := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_READELF) --version | grep 'GNU Binutils' >/dev/null && echo 1)
ifneq ($(USING_GNU_READELF), 1)
$(error The specified LIMINE_READELF ($(LIMINE_READELF)) is not GNU readelf)
endif
ifneq ($(CC_MACHINE), x86_64)
ifneq ($(CC_MACHINE), amd64-)
$(error No suitable x86_64 C compiler found, please install an x86_64 C toolchain or run "./make_toolchain.sh")
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
ifeq ($(USING_CLANG), 1)
override LIMINE_CC := $(ORIG_LIMINE_CC)
endif
override STAGE1_FILES := $(shell find '$(call SHESCAPE,$(SRCDIR))/stage1' -type f -name '*.asm')
.PHONY: all
@ -308,7 +174,6 @@ dist:
cp -r '$(call SHESCAPE,$(SRCDIR))'/.git '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)"/
cd '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)" && git checkout .
cd '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)" && NOCONFIGURE=yes ./autogen.sh
cp '$(call SHESCAPE,$(SRCDIR))'/install-sh '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)"/
rm -rf '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)/reduced-gnu-efi/.git"
rm -rf '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)/stivale/.git"
rm -rf '$(call SHESCAPE,$(BUILDDIR))'/"limine-$(LIMINE_VERSION)/.git"
@ -324,7 +189,7 @@ distclean: clean
.PHONY: maintainer-clean
maintainer-clean: distclean
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf stivale reduced-gnu-efi configure install-sh *'~' autom4te.cache *.tar.xz *.tar.gz
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf stivale reduced-gnu-efi configure build-aux *'~' autom4te.cache *.tar.xz *.tar.gz
.PHONY: stage23-uefi64
stage23-uefi64: $(call MKESCAPE,$(SRCDIR))/stivale

View File

@ -9,10 +9,16 @@ 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 --add-missing --copy || true
automake_libdir="$(automake --print-libdir)"
mkdir -p build-aux
cp "${automake_libdir}/install-sh" "${build_aux}"
autoconf
cd "$origdir"

View File

@ -2,9 +2,14 @@ AC_INIT([Limine], m4_esyscmd([./version.sh]), [https://github.com/limine-bootloa
AC_PREREQ(2.69)
AC_SUBST(limine_version, m4_esyscmd([./version.sh]))
AC_CONFIG_AUX_DIR([build-aux])
TOOLCHAIN_DIR="$(pwd -P)/toolchain/bin"
PATH="$TOOLCHAIN_DIR$PATH_SEPARATOR$PATH"
export PATH
test "x$CFLAGS" = "x" && CFLAGS='-g -O2 -pipe -Wall -Wextra'
AC_PROG_CC
werror_state="no"
AC_ARG_ENABLE([werror],
@ -16,41 +21,77 @@ if test "$werror_state" = "yes"; then
CFLAGS="$CFLAGS -Werror"
fi
AC_PROG_CC
AC_PROG_INSTALL
AC_ARG_VAR(HOST_CC, [C compiler for the build host [$(CC)]])
test "x$HOST_CC" = "x" && HOST_CC='$(CC)'
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.])
fi
AC_ARG_VAR(TOOLCHAIN, [Alternative toolchain prefix [limine]])
AC_ARG_VAR(HOST_CC, [C compiler for the build host [default: $CC]])
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 [-O3 -pipe -Wall -Wextra]])
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 [ ]])
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 [$(TOOLCHAIN)-gcc]])
test "x$LIMINE_CC" = "x" && LIMINE_CC='$(TOOLCHAIN)-gcc'
AC_ARG_VAR(LIMINE_CC, [C compiler command for Limine [default: $TOOLCHAIN-gcc]])
test "x$LIMINE_CC" = "x" && LIMINE_CC="$TOOLCHAIN-gcc"
AC_ARG_VAR(LIMINE_LD, [Linker command for Limine [$(TOOLCHAIN)-ld]])
test "x$LIMINE_LD" = "x" && LIMINE_LD='$(TOOLCHAIN)-ld'
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.])
fi
fi
AC_ARG_VAR(LIMINE_AR, [Archiver command for Limine [$(TOOLCHAIN)-ar]])
test "x$LIMINE_AR" = "x" && LIMINE_AR='$(TOOLCHAIN)-ar'
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])
fi
fi
AC_ARG_VAR(LIMINE_AS, [Assembler command for Limine [$(TOOLCHAIN)-as]])
test "x$LIMINE_AS" = "x" && LIMINE_AS='$(TOOLCHAIN)-as'
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_ARG_VAR(LIMINE_OBJCOPY, [Objcopy command for Limine [$(TOOLCHAIN)-objcopy]])
test "x$LIMINE_OBJCOPY" = "x" && LIMINE_OBJCOPY='$(TOOLCHAIN)-objcopy'
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.])
fi
fi
fi
fi
AC_ARG_VAR(LIMINE_OBJDUMP, [Objdump command for Limine [$(TOOLCHAIN)-objdump]])
test "x$LIMINE_OBJDUMP" = "x" && LIMINE_OBJDUMP='$(TOOLCHAIN)-objdump'
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
])
AC_ARG_VAR(LIMINE_READELF, [Readelf command for Limine [$(TOOLCHAIN)-readelf]])
test "x$LIMINE_READELF" = "x" && LIMINE_READELF='$(TOOLCHAIN)-readelf'
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)
AC_SUBST(limine_version, m4_esyscmd([./version.sh]))
AC_PREFIX_DEFAULT(/usr/local)