:: commit 9d68787fe1a2421dca823676ac113fb2cf514a73

mintsuki <mintsuki@protonmail.com> — 2021-07-26 16:27

parents: af03050db3

build: OpenBSD compatibility

diff --git a/Makefile b/Makefile
index d4c45a15..4582a686 100644
--- a/Makefile
+++ b/Makefile
@@ -13,15 +13,19 @@ ifeq ($(shell export "PATH=$(PATH)"; command -v $(TOOLCHAIN_CC) ; ), )
 TOOLCHAIN_CC := cc
 endif
 
+CC_MACHINE := $(shell export "PATH=$(PATH)"; $(TOOLCHAIN_CC) -dumpmachine | dd bs=6 count=1 2>/dev/null)
+
 ifneq ($(MAKECMDGOALS), toolchain)
 ifneq ($(MAKECMDGOALS), distclean)
 ifneq ($(MAKECMDGOALS), distclean2)
-ifneq ($(shell export "PATH=$(PATH)"; $(TOOLCHAIN_CC) -dumpmachine | head -c 6), x86_64)
+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")
 endif
 endif
 endif
 endif
+endif
 
 STAGE1_FILES := $(shell find -L ./stage1 -type f -name '*.asm' | sort)
 
diff --git a/README.md b/README.md
index f4acddc7..0148c352 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ 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`, `gcc/clang`, `g++/clang++`.
+`curl`, `gzip`, `bzip2`, `gcc/clang`, `g++/clang++`.
 
 Building the toolchain can be accomplished by running:
 ```bash
diff --git a/aux/make_toolchain.sh b/aux/make_toolchain.sh
index 4376cd7c..cf8a5f6a 100755
--- a/aux/make_toolchain.sh
+++ b/aux/make_toolchain.sh
@@ -8,6 +8,13 @@ GCCVERSION=11.1.0
 
 CFLAGS="-O2 -pipe"
 
+if [ "$(uname)" = "OpenBSD" ]; then
+    # OpenBSD has an awfully ancient GCC which fails to build our toolchain.
+    # Force clang/clang++.
+    export CC="clang"
+    export CXX="clang++"
+fi
+
 mkdir -p "$1" && cd "$1"
 PREFIX="$(pwd)"
 
@@ -26,8 +33,8 @@ rm -rf build
 mkdir build
 cd build
 
-tar -xf ../binutils-$BINUTILSVERSION.tar.gz
-tar -xf ../gcc-$GCCVERSION.tar.gz
+tar -zxf ../binutils-$BINUTILSVERSION.tar.gz
+tar -zxf ../gcc-$GCCVERSION.tar.gz
 
 mkdir build-binutils
 cd build-binutils
diff --git a/stage23/gensyms.sh b/stage23/gensyms.sh
index e91a7014..f7bc1f02 100755
--- a/stage23/gensyms.sh
+++ b/stage23/gensyms.sh
@@ -8,7 +8,7 @@ TMP2=$(mktemp)
 TMP3=$(mktemp)
 TMP4=$(mktemp)
 
-$1 -t "$2" | sed '/[[:<:]]d[[:>:]]/d' | sort > "$TMP1"
+$1 -t "$2" | ( sed '/[[:<:]]d[[:>:]]/d' 2>/dev/null || sed '/\bd\b/d' ) | sort > "$TMP1"
 grep "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
 grep "\.text" < "$TMP1" | awk 'NF{ print $NF }' > "$TMP3"
 
@@ -17,11 +17,13 @@ echo "global $3_map" >> "$TMP4"
 echo "$3_map:" >> "$TMP4"
 
 if [ "$4" = "32" ]; then
-    paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dd 0x/g;s/$/", 0/g;s/\$/\ndb "/g' >> "$TMP4"
+    paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dd 0x/g;s/$/", 0/g;s/\$/\
+db "/g' >> "$TMP4"
     echo "dd 0xffffffff" >> "$TMP4"
     nasm -f elf32 "$TMP4" -o $3.map.o
 elif [ "$4" = "64" ]; then
-    paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dq 0x/g;s/$/", 0/g;s/\$/\ndb "/g' >> "$TMP4"
+    paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dq 0x/g;s/$/", 0/g;s/\$/\
+db "/g' >> "$TMP4"
     echo "dq 0xffffffffffffffff" >> "$TMP4"
     nasm -f elf64 "$TMP4" -o $3.map.o
 fi
tab: 248 wrap: offon