Build: add support for building on OpenBSD

This requires gcc8 from ports to build the Toolchain.
This commit is contained in:
joshua stein 2020-01-01 20:06:14 -06:00 committed by Andreas Kling
parent d61131945d
commit 5e430e4eb4
Notes: sideshowbarker 2024-07-19 10:25:04 +09:00
7 changed files with 81 additions and 26 deletions

View file

@ -40,6 +40,13 @@ Notes:
- osxfuse, e2fsprogs, m4, autoconf, automake, libtool and `BuildFuseExt2.sh` are needed if you want to build the root filesystem disk image natively on macOS. This allows mounting an EXT2 fs and also installs commands like `mke2fs` that are not available on stock macOS. - osxfuse, e2fsprogs, m4, autoconf, automake, libtool and `BuildFuseExt2.sh` are needed if you want to build the root filesystem disk image natively on macOS. This allows mounting an EXT2 fs and also installs commands like `mke2fs` that are not available on stock macOS.
- If you install some commercial EXT2 macOS fs handler instead of osxfuse and fuse-ext2, you will need to `brew install e2fsprogs` to obtain `mke2fs` anyway. - If you install some commercial EXT2 macOS fs handler instead of osxfuse and fuse-ext2, you will need to `brew install e2fsprogs` to obtain `mke2fs` anyway.
### OpenBSD prerequisites
```
pkg_add bash gmp gcc git flock gmake sudo
```
When building with `make`, `gmake` must be used. The `makeall.sh` script will do this automatically when building on OpenBSD.
### Build ### Build
Go into the `Toolchain/` directory and run the **BuildIt.sh** script. Go into the `Toolchain/` directory and run the **BuildIt.sh** script.

View file

@ -10,7 +10,7 @@ die() {
if [ "$(id -u)" != 0 ]; then if [ "$(id -u)" != 0 ]; then
die "this script needs to run as root" die "this script needs to run as root"
fi fi
if [ "$(uname)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
export PATH="/usr/local/opt/e2fsprogs/bin:$PATH" export PATH="/usr/local/opt/e2fsprogs/bin:$PATH"
export PATH="/usr/local/opt/e2fsprogs/sbin:$PATH" export PATH="/usr/local/opt/e2fsprogs/sbin:$PATH"
fi fi
@ -20,13 +20,21 @@ chown "$build_user":"$build_group" _disk_image || die "couldn't adjust permissio
echo "done" echo "done"
printf "creating new filesystem... " printf "creating new filesystem... "
mke2fs -q -I 128 _disk_image || die "couldn't create filesystem" if [ "$(uname -s)" = "OpenBSD" ]; then
VND=`vnconfig _disk_image`
(echo "e 0"; echo 83; echo n; echo 0; echo "*"; echo "quit") | fdisk -e $VND
mkfs.ext2 -I 128 -F /dev/${VND}i || die "couldn't create filesystem"
else
mke2fs -q -I 128 _disk_image || die "couldn't create filesystem"
fi
echo "done" echo "done"
printf "mounting filesystem... " printf "mounting filesystem... "
mkdir -p mnt mkdir -p mnt
if [ "$(uname)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
fuse-ext2 _disk_image mnt -o rw+,allow_other,uid=501,gid=20 || die "couldn't mount filesystem" fuse-ext2 _disk_image mnt -o rw+,allow_other,uid=501,gid=20 || die "couldn't mount filesystem"
elif [ "$(uname -s)" = "OpenBSD" ]; then
mount -t ext2fs /dev/${VND}i mnt/ || die "couldn't mount filesystem"
else else
mount _disk_image mnt/ || die "couldn't mount filesystem" mount _disk_image mnt/ || die "couldn't mount filesystem"
fi fi
@ -37,6 +45,9 @@ cleanup() {
printf "unmounting filesystem... " printf "unmounting filesystem... "
umount mnt || ( sleep 1 && sync && umount mnt ) umount mnt || ( sleep 1 && sync && umount mnt )
rm -rf mnt rm -rf mnt
if [ "$(uname -s)" = "OpenBSD" ]; then
vnconfig -u $VND
fi
echo "done" echo "done"
fi fi
} }

View file

@ -77,10 +77,12 @@ echo "done"
printf "installing userland... " printf "installing userland... "
if [ "$(uname)" != "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \; find ../Userland/ -type f -perm +111 -exec cp {} mnt/bin/ \;
elif [ "$(uname -s)" = "OpenBSD" ]; then
find ../Userland/ -type f -perm -555 -exec cp {} mnt/bin/ \;
else else
find ../Userland/ -type f -perm +111 -exec cp {} mnt/bin/ \; find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \;
fi fi
chmod 4755 mnt/bin/su chmod 4755 mnt/bin/su
chmod 4755 mnt/bin/ping chmod 4755 mnt/bin/ping

View file

@ -12,8 +12,14 @@ export build_group
sudo id sudo id
make -C ../ clean && \ MAKE=make
make -C ../ && \
make -C ../ test && \ if [ "$(uname -s)" = "OpenBSD" ]; then
make -C ../ install && MAKE=gmake
fi
$MAKE -C ../ clean && \
$MAKE -C ../ && \
$MAKE -C ../ test && \
$MAKE -C ../ install &&
sudo -E PATH="$PATH" ./build-image-qemu.sh sudo -E PATH="$PATH" ./build-image-qemu.sh

View file

@ -2,7 +2,9 @@
#include <bits/stdint.h> #include <bits/stdint.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
#endif
#define PATH_MAX 4096 #define PATH_MAX 4096
#if !defined MAXPATHLEN && defined PATH_MAX #if !defined MAXPATHLEN && defined PATH_MAX

View file

@ -23,6 +23,11 @@ INCLUDE_FLAGS += \
VERBOSE = 0 VERBOSE = 0
ifneq ($(USE_HOST_CXX),) ifneq ($(USE_HOST_CXX),)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
HOST_CXX ?= clang++
endif
ifeq '' '$(findstring clang++,$(CXX))' ifeq '' '$(findstring clang++,$(CXX))'
C_WARNING_FLAGS += -Wno-unknown-warning-option C_WARNING_FLAGS += -Wno-unknown-warning-option
CXX_WARNING_FLAGS += -Wno-unknown-warning-option CXX_WARNING_FLAGS += -Wno-unknown-warning-option

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
set -e set -e
# This file will need to be run in bash, for now. # This file will need to be run in bash, for now.
@ -12,6 +12,20 @@ TARGET="$ARCH-pc-serenity"
PREFIX="$DIR/Local" PREFIX="$DIR/Local"
SYSROOT="$DIR/../Root" SYSROOT="$DIR/../Root"
MAKE=make
MD5SUM=md5sum
NPROC=nproc
if [ `uname -s` = "OpenBSD" ]; then
MAKE=gmake
MD5SUM="md5 -q"
NPROC="sysctl -n hw.ncpuonline"
export CC=egcc
export CXX=eg++
export with_gmp=/usr/local
export LDFLAGS=-Wl,-z,notext
fi
echo PREFIX is "$PREFIX" echo PREFIX is "$PREFIX"
echo SYSROOT is "$SYSROOT" echo SYSROOT is "$SYSROOT"
@ -30,7 +44,7 @@ GCC_PKG="${GCC_NAME}.tar.gz"
GCC_BASE_URL="http://ftp.gnu.org/gnu/gcc" GCC_BASE_URL="http://ftp.gnu.org/gnu/gcc"
pushd "$DIR/Tarballs" pushd "$DIR/Tarballs"
md5="$(md5sum $BINUTILS_PKG | cut -f1 -d' ')" md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')"
echo "bu md5='$md5'" echo "bu md5='$md5'"
if [ ! -e $BINUTILS_PKG ] || [ "$md5" != ${BINUTILS_MD5SUM} ] ; then if [ ! -e $BINUTILS_PKG ] || [ "$md5" != ${BINUTILS_MD5SUM} ] ; then
rm -f $BINUTILS_PKG rm -f $BINUTILS_PKG
@ -39,7 +53,7 @@ pushd "$DIR/Tarballs"
echo "Skipped downloading binutils" echo "Skipped downloading binutils"
fi fi
md5="$(md5sum ${GCC_PKG} | cut -f1 -d' ')" md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')"
echo "gc md5='$md5'" echo "gc md5='$md5'"
if [ ! -e $GCC_PKG ] || [ "$md5" != ${GCC_MD5SUM} ] ; then if [ ! -e $GCC_PKG ] || [ "$md5" != ${GCC_MD5SUM} ] ; then
rm -f $GCC_PKG rm -f $GCC_PKG
@ -50,7 +64,7 @@ pushd "$DIR/Tarballs"
if [ ! -d ${BINUTILS_NAME} ]; then if [ ! -d ${BINUTILS_NAME} ]; then
echo "Extracting binutils..." echo "Extracting binutils..."
tar -xf ${BINUTILS_PKG} tar -xzf ${BINUTILS_PKG}
pushd ${BINUTILS_NAME} pushd ${BINUTILS_NAME}
git init >/dev/null git init >/dev/null
@ -64,7 +78,7 @@ pushd "$DIR/Tarballs"
if [ ! -d $GCC_NAME ]; then if [ ! -d $GCC_NAME ]; then
echo "Extracting gcc..." echo "Extracting gcc..."
tar -xf $GCC_PKG tar -xzf $GCC_PKG
pushd $GCC_NAME pushd $GCC_NAME
git init >/dev/null git init >/dev/null
@ -90,7 +104,7 @@ mkdir -p "$DIR/Build/binutils"
mkdir -p "$DIR/Build/gcc" mkdir -p "$DIR/Build/gcc"
if [ -z "$MAKEJOBS" ]; then if [ -z "$MAKEJOBS" ]; then
MAKEJOBS=$(nproc) MAKEJOBS=$($NPROC)
fi fi
pushd "$DIR/Build/" pushd "$DIR/Build/"
@ -106,16 +120,20 @@ pushd "$DIR/Build/"
# under macOS generated makefiles are not resolving the "intl" # under macOS generated makefiles are not resolving the "intl"
# dependency properly to allow linking its own copy of # dependency properly to allow linking its own copy of
# libintl when building with --enable-shared. # libintl when building with --enable-shared.
make -j "$MAKEJOBS" || true "$MAKE" -j "$MAKEJOBS" || true
pushd intl pushd intl
make all-yes "$MAKE" all-yes
popd popd
fi fi
make -j "$MAKEJOBS" || exit 1 "$MAKE" -j "$MAKEJOBS" || exit 1
make install || exit 1 "$MAKE" install || exit 1
popd popd
pushd gcc pushd gcc
if [ `uname -s` = "OpenBSD" ]; then
perl -pi -e 's/-no-pie/-nopie/g' "$DIR"/Tarballs/gcc-9.2.0/gcc/configure
fi
"$DIR"/Tarballs/gcc-9.2.0/configure --prefix="$PREFIX" \ "$DIR"/Tarballs/gcc-9.2.0/configure --prefix="$PREFIX" \
--target="$TARGET" \ --target="$TARGET" \
--with-sysroot="$SYSROOT" \ --with-sysroot="$SYSROOT" \
@ -125,18 +143,22 @@ pushd "$DIR/Build/"
--enable-languages=c,c++ || exit 1 --enable-languages=c,c++ || exit 1
echo "XXX build gcc and libgcc" echo "XXX build gcc and libgcc"
make -j "$MAKEJOBS" all-gcc all-target-libgcc || exit 1 "$MAKE" -j "$MAKEJOBS" all-gcc all-target-libgcc || exit 1
echo "XXX install gcc and libgcc" echo "XXX install gcc and libgcc"
make install-gcc install-target-libgcc || exit 1 "$MAKE" install-gcc install-target-libgcc || exit 1
echo "XXX serenity libc and libm" echo "XXX serenity libc and libm"
( cd "$DIR/../Libraries/LibC/" && make clean && make && make install ) ( cd "$DIR/../Libraries/LibC/" && "$MAKE" clean && "$MAKE" && "$MAKE" install )
( cd "$DIR/../Libraries/LibM/" && make clean && make && make install ) ( cd "$DIR/../Libraries/LibM/" && "$MAKE" clean && "$MAKE" && "$MAKE" install )
echo "XXX build libstdc++" echo "XXX build libstdc++"
make all-target-libstdc++-v3 || exit 1 "$MAKE" all-target-libstdc++-v3 || exit 1
echo "XXX install libstdc++" echo "XXX install libstdc++"
make install-target-libstdc++-v3 || exit 1 "$MAKE" install-target-libstdc++-v3 || exit 1
if [ `uname -s` = "OpenBSD" ]; then
cd "$DIR"/Local/libexec/gcc/i686-pc-serenity/9.2.0 && ln -sf liblto_plugin.so.0.0 liblto_plugin.so
fi
popd popd
popd popd