build: OpenBSD compatibility

This commit is contained in:
mintsuki 2021-07-26 18:27:05 +02:00
parent af03050db3
commit 9d68787fe1
4 changed files with 20 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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