build: Misc portability improvements

This commit is contained in:
mintsuki 2022-01-22 03:10:25 +01:00
parent b1a7c0d19f
commit c28e3a6f7f
6 changed files with 94 additions and 24 deletions

View File

@ -51,26 +51,62 @@ 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 := ld.bfd
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
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
export LIMINE_LD
@ -101,16 +137,36 @@ ifneq ($(MAKECMDGOALS), install)
ifneq ($(MAKECMDGOALS), install-data)
ifneq ($(MAKECMDGOALS), install-strip)
override USING_GNU_LD := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_LD) --version | grep Binutils >/dev/null && echo 1)
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_OBJCOPY := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_OBJCOPY) --version | grep Binutils >/dev/null && echo 1)
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")
@ -132,7 +188,7 @@ ifeq ($(USING_CLANG), 1)
override LIMINE_CC := $(ORIG_LIMINE_CC)
endif
override STAGE1_FILES := $(shell find -L '$(call SHESCAPE,$(SRCDIR))/stage1' -type f -name '*.asm')
override STAGE1_FILES := $(shell find '$(call SHESCAPE,$(SRCDIR))/stage1' -type f -name '*.asm')
.PHONY: all
all: limine-uefi limine-bios

View File

@ -72,7 +72,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, you can skip to
the next paragraph in order to use the system's toolchain instead.
The toolchain's build process depends on the following packages: `GNU make`,
The toolchain's build process depends on the following packages: `GNU make`, `GNU tar`,
`curl`, `gzip`, `bzip2`, `gcc/clang`, `g++/clang++`.
Building the toolchain can be accomplished by running:
@ -91,8 +91,8 @@ paragraph, or `gcc` or `llvm/clang` must also be installed, alongside
### Configure
If checking out from the repository, run `./autogen.sh`, else, if using a
release tarball, run `./configure` directly.
If checking out from the repository, run `./autogen.sh` (GNU autoconf required),
else, if using a release tarball, run `./configure` directly.
Both `./autogen.sh` and `./configure` take arguments and environment variables;
for more information on these, run `./configure --help`.
@ -119,7 +119,7 @@ release directory just fine. This step will only install them to a `share` and
To install Limine, run:
```bash
make install
make install # (or gmake where applicable)
```
## How to use

View File

@ -2,7 +2,9 @@
set -ex
srcdir="$(realpath $(dirname "$0"))"
origdir="$(pwd -P)"
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
cd "$srcdir"
@ -12,6 +14,8 @@ cd "$srcdir"
autoconf
cd "$origdir"
if test -z "$NOCONFIGURE"; then
exec "$srcdir"/configure "$@"
fi

View File

@ -47,8 +47,8 @@ override INTERNAL_LDFLAGS := \
-static \
-Tlinker.ld
override C_FILES := $(shell find -L ./ -type f -name '*.c')
override ASM_FILES := $(shell find -L ./ -type f -name '*.asm')
override C_FILES := $(shell find ./ -type f -name '*.c')
override ASM_FILES := $(shell find ./ -type f -name '*.asm')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
override HEADER_DEPS := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.d))

View File

@ -2,7 +2,7 @@
set -ex
srcdir="$(realpath $(dirname "$0"))"
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
cd "$srcdir"
@ -17,6 +17,12 @@ else
export MAKE=make
fi
if command -v gtar; then
export TAR=gtar
else
export TAR=tar
fi
export CFLAGS="-O2 -pipe"
unset CC
@ -30,9 +36,9 @@ if [ "$(uname)" = "OpenBSD" ]; then
fi
mkdir -p toolchain && cd toolchain
PREFIX="$(pwd)"
PREFIX="$(pwd -P)"
export MAKEFLAGS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)"
export MAKEFLAGS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || psrinfo -tc 2>/dev/null || echo 1)"
export PATH="$PREFIX/bin:$PATH"
@ -47,8 +53,8 @@ rm -rf build
mkdir build
cd build
tar -zxf ../binutils-$BINUTILSVERSION.tar.gz
tar -zxf ../gcc-$GCCVERSION.tar.gz
$TAR -zxf ../binutils-$BINUTILSVERSION.tar.gz
$TAR -zxf ../gcc-$GCCVERSION.tar.gz
mkdir build-binutils
cd build-binutils
@ -58,7 +64,11 @@ $MAKE install
cd ..
cd gcc-$GCCVERSION
contrib/download_prerequisites
sed 's|http://gcc.gnu|https://gcc.gnu|g' < contrib/download_prerequisites > dp.sed
mv dp.sed contrib/download_prerequisites
chmod +x contrib/download_prerequisites
rm dp.sed
contrib/download_prerequisites --no-verify
cd ..
mkdir build-gcc
cd build-gcc

View File

@ -2,7 +2,7 @@ TARGET ?=
BUILDDIR ?=
USING_CLANG ?= 0
override SRCDIR := $(shell pwd)
override SRCDIR := $(shell pwd -P)
override SPACE := $(subst ,, )
@ -150,22 +150,22 @@ endif
.PHONY: all clean
override C_FILES := $(shell find -L ./ -type f -name '*.c')
override C_FILES := $(shell find ./ -type f -name '*.c')
ifeq ($(TARGET), bios)
override ASM32_FILES := $(shell find -L ./ -type f -name '*.asm32')
override ASMB_FILES := $(shell find -L ./ -type f -name '*.asmb')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm32')
override ASMB_FILES := $(shell find ./ -type f -name '*.asmb')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM32_FILES:.asm32=.o) $(ASMB_FILES:.asmb=.o) $(C_FILES:.c=.o))
endif
ifeq ($(TARGET), uefi64)
override ASM64_FILES := $(shell find -L ./ -type f -name '*.asm64')
override ASM64U_FILES := $(shell find -L ./ -type f -name '*.asm64u')
override ASM64_FILES := $(shell find ./ -type f -name '*.asm64')
override ASM64U_FILES := $(shell find ./ -type f -name '*.asm64u')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM64_FILES:.asm64=.o) $(ASM64U_FILES:.asm64u=.o) $(C_FILES:.c=.o))
endif
ifeq ($(TARGET), uefi32)
override ASM32_FILES := $(shell find -L ./ -type f -name '*.asm32')
override ASM32U_FILES := $(shell find -L ./ -type f -name '*.asm32u')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm32')
override ASM32U_FILES := $(shell find ./ -type f -name '*.asm32u')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(ASM32_FILES:.asm32=.o) $(ASM32U_FILES:.asm32u=.o) $(C_FILES:.c=.o))
endif