build: Even more portability improvements

This commit is contained in:
mintsuki 2022-01-21 02:57:31 +01:00
parent 64467c06d8
commit a25129b8c1
4 changed files with 42 additions and 37 deletions

View File

@ -16,8 +16,6 @@ NASMESCAPE = $(subst ','"'$(COMMA) \"'\"$(COMMA) '"',$(1))
override PATH := $(BUILDDIR)/toolchain/bin:$(PATH)
export PATH
override NCPUS := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
override LIMINE_VERSION := @limine_version@
export LIMINE_VERSION
@ -82,7 +80,7 @@ export LIMINE_OBJCOPY
export LIMINE_OBJDUMP
export LIMINE_READELF
override USING_CLANG := $(shell $(LIMINE_CC) --version | grep clang >/dev/null && echo 1)
override USING_CLANG := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_CC) --version | grep clang >/dev/null && echo 1)
export USING_CLANG
ifeq ($(USING_CLANG), 1)
@ -92,26 +90,25 @@ endif
override CC_MACHINE := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_CC) -dumpmachine | dd bs=6 count=1 2>/dev/null)
ifneq ($(MAKECMDGOALS), toolchain)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), distclean)
ifneq ($(MAKECMDGOALS), maintainer-clean)
ifneq ($(MAKECMDGOALS), uninstall)
ifneq ($(MAKECMDGOALS), dist)
override USING_GNU_LD := $(shell $(LIMINE_LD) --version | grep Binutils >/dev/null && echo 1)
override USING_GNU_LD := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_LD) --version | grep 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 $(LIMINE_OBJCOPY) --version | grep Binutils >/dev/null && echo 1)
override USING_GNU_OBJCOPY := $(shell PATH='$(call SHESCAPE,$(PATH))' $(LIMINE_OBJCOPY) --version | grep Binutils >/dev/null && echo 1)
ifneq ($(USING_GNU_OBJCOPY), 1)
$(error The specified LIMINE_OBJCOPY ($(LIMINE_OBJCOPY)) is not GNU objcopy)
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")
$(error No suitable x86_64 C compiler found, please install an x86_64 C toolchain or run "./make_toolchain.sh")
endif
endif
@ -120,7 +117,6 @@ endif
endif
endif
endif
endif
ifeq ($(USING_CLANG), 1)
override LIMINE_CC := $(ORIG_LIMINE_CC)
@ -278,10 +274,6 @@ test-clean:
$(MAKE) -C test clean
rm -rf test_image test.hdd test.iso
.PHONY: toolchain
toolchain:
MAKE="$(MAKE)" '$(call SHESCAPE,$(SRCDIR))'/build-aux/make_toolchain.sh '$(call SHESCAPE,$(BUILDDIR))'/toolchain -j$(NCPUS)
ovmf-x64:
mkdir -p ovmf-x64
cd ovmf-x64 && curl -o OVMF-X64.zip https://efi.akeo.ie/OVMF/OVMF-X64.zip && 7z x OVMF-X64.zip

View File

@ -66,6 +66,29 @@ release.
*These steps are not necessary if cloning a binary release. If so, skip to*
*"Installing Limine binaries".*
### Building the toolchain
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`,
`curl`, `gzip`, `bzip2`, `gcc/clang`, `g++/clang++`.
Building the toolchain can be accomplished by running:
```bash
./make_toolchain.sh
```
### Prerequisites
In order to build Limine, the following packages have to be installed:
`GNU make`, `nasm`, `mtools` (optional, necessary to build
`limine-eltorito-efi.bin`).
Furthermore, either the toolchain must have been built in the previous
paragraph, or `gcc` or `llvm/clang` must also be installed, alongside
`GNU binutils`.
### Configure
If checking out from the repository, run `./autogen.sh`, else, if using a
@ -78,30 +101,9 @@ Limine supports both in-tree and out-of-tree builds. Simply run the configure
script from the directory you wish to execute the build in. The following `make`
commands are supposed to be ran inside the build directory.
### Building the toolchain
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`,
`curl`, `gzip`, `bzip2`, `gcc/clang`, `g++/clang++`.
Building the toolchain can be accomplished by running:
```bash
make toolchain # (or gmake where applicable)
```
### Building Limine
In order to build Limine, the following packages have to be installed:
`GNU make`, `nasm`, `mtools` (optional, necessary to build
`limine-eltorito-efi.bin`).
Furthermore, either the toolchain must have been built in the previous
paragraph, or `gcc` or `llvm/clang` must also be installed, alongside
`GNU binutils`.
Then, to build Limine, run:
To build Limine, run:
```bash
make # (or gmake where applicable)
```

View File

@ -2,10 +2,21 @@
set -ex
srcdir="$(realpath $(dirname "$0"))"
test -z "$srcdir" && srcdir=.
cd "$srcdir"
TARGET=x86_64-elf
BINUTILSVERSION=2.37
GCCVERSION=11.2.0
if command -v gmake; then
export MAKE=gmake
else
export MAKE=make
fi
export CFLAGS="-O2 -pipe"
unset CC
@ -18,10 +29,10 @@ if [ "$(uname)" = "OpenBSD" ]; then
export CXX="clang++"
fi
mkdir -p "$1" && cd "$1"
mkdir -p toolchain && cd toolchain
PREFIX="$(pwd)"
export MAKEFLAGS="$2"
export MAKEFLAGS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)"
export PATH="$PREFIX/bin:$PATH"

View File

@ -7,7 +7,7 @@ export LC_ALL=C
TMP0=$(mktemp)
cat >"$TMP0" <<EOF
#!/bin/sh
#! /bin/sh
set -e