build: Even more portability improvements
diff --git a/GNUmakefile.in b/GNUmakefile.in
index a0cce647..521e63e2 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -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
diff --git a/README.md b/README.md
index 24c5863e..45821d42 100644
--- a/README.md
+++ b/README.md
@@ -66,18 +66,6 @@ release.
*These steps are not necessary if cloning a binary release. If so, skip to*
*"Installing Limine binaries".*
-### Configure
-
-If checking out from the repository, run `./autogen.sh`, 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`.
-
-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
@@ -89,10 +77,10 @@ The toolchain's build process depends on the following packages: `GNU make`,
Building the toolchain can be accomplished by running:
```bash
-make toolchain # (or gmake where applicable)
+./make_toolchain.sh
```
-### Building Limine
+### Prerequisites
In order to build Limine, the following packages have to be installed:
`GNU make`, `nasm`, `mtools` (optional, necessary to build
@@ -101,7 +89,21 @@ 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:
+### Configure
+
+If checking out from the repository, run `./autogen.sh`, 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`.
+
+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 Limine
+
+To build Limine, run:
```bash
make # (or gmake where applicable)
```
diff --git a/build-aux/make_toolchain.sh b/build-aux/make_toolchain.sh
index fe8ac96b..d686b651 100755
--- a/build-aux/make_toolchain.sh
+++ b/build-aux/make_toolchain.sh
@@ -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"
diff --git a/stage23/gensyms.sh b/stage23/gensyms.sh
index 797399a6..49ba8a95 100755
--- a/stage23/gensyms.sh
+++ b/stage23/gensyms.sh
@@ -7,7 +7,7 @@ export LC_ALL=C
TMP0=$(mktemp)
cat >"$TMP0" <<EOF
-#!/bin/sh
+#! /bin/sh
set -e
