From 5e430e4eb4cc00bf7a7c4a047ef15e7bc737d32a Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 1 Jan 2020 20:06:14 -0600 Subject: [PATCH] Build: add support for building on OpenBSD This requires gcc8 from ports to build the Toolchain. --- Documentation/BuildInstructions.md | 7 ++++ Kernel/build-image-qemu.sh | 17 ++++++++-- Kernel/build-root-filesystem.sh | 8 +++-- Kernel/makeall.sh | 14 +++++--- Libraries/LibC/limits.h | 2 ++ Makefile.common | 5 +++ Toolchain/BuildIt.sh | 54 +++++++++++++++++++++--------- 7 files changed, 81 insertions(+), 26 deletions(-) diff --git a/Documentation/BuildInstructions.md b/Documentation/BuildInstructions.md index 9c7cdd24d1f..dd1d8cac395 100644 --- a/Documentation/BuildInstructions.md +++ b/Documentation/BuildInstructions.md @@ -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. - 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 Go into the `Toolchain/` directory and run the **BuildIt.sh** script. diff --git a/Kernel/build-image-qemu.sh b/Kernel/build-image-qemu.sh index 760b75da60b..41b9e357101 100755 --- a/Kernel/build-image-qemu.sh +++ b/Kernel/build-image-qemu.sh @@ -10,7 +10,7 @@ die() { if [ "$(id -u)" != 0 ]; then die "this script needs to run as root" fi -if [ "$(uname)" = "Darwin" ]; then +if [ "$(uname -s)" = "Darwin" ]; then export PATH="/usr/local/opt/e2fsprogs/bin:$PATH" export PATH="/usr/local/opt/e2fsprogs/sbin:$PATH" fi @@ -20,13 +20,21 @@ chown "$build_user":"$build_group" _disk_image || die "couldn't adjust permissio echo "done" 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" printf "mounting filesystem... " 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" +elif [ "$(uname -s)" = "OpenBSD" ]; then + mount -t ext2fs /dev/${VND}i mnt/ || die "couldn't mount filesystem" else mount _disk_image mnt/ || die "couldn't mount filesystem" fi @@ -37,6 +45,9 @@ cleanup() { printf "unmounting filesystem... " umount mnt || ( sleep 1 && sync && umount mnt ) rm -rf mnt + if [ "$(uname -s)" = "OpenBSD" ]; then + vnconfig -u $VND + fi echo "done" fi } diff --git a/Kernel/build-root-filesystem.sh b/Kernel/build-root-filesystem.sh index b5dceb740fb..f0c607f6da2 100755 --- a/Kernel/build-root-filesystem.sh +++ b/Kernel/build-root-filesystem.sh @@ -77,10 +77,12 @@ echo "done" printf "installing userland... " -if [ "$(uname)" != "Darwin" ]; then -find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \; +if [ "$(uname -s)" = "Darwin" ]; then + 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 -find ../Userland/ -type f -perm +111 -exec cp {} mnt/bin/ \; + find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \; fi chmod 4755 mnt/bin/su chmod 4755 mnt/bin/ping diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index e5292555044..5eec01557c5 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -12,8 +12,14 @@ export build_group sudo id -make -C ../ clean && \ - make -C ../ && \ - make -C ../ test && \ - make -C ../ install && +MAKE=make + +if [ "$(uname -s)" = "OpenBSD" ]; then + MAKE=gmake +fi + +$MAKE -C ../ clean && \ + $MAKE -C ../ && \ + $MAKE -C ../ test && \ + $MAKE -C ../ install && sudo -E PATH="$PATH" ./build-image-qemu.sh diff --git a/Libraries/LibC/limits.h b/Libraries/LibC/limits.h index d89f7228eeb..eb8d8565420 100644 --- a/Libraries/LibC/limits.h +++ b/Libraries/LibC/limits.h @@ -2,7 +2,9 @@ #include +#ifndef PAGE_SIZE #define PAGE_SIZE 4096 +#endif #define PATH_MAX 4096 #if !defined MAXPATHLEN && defined PATH_MAX diff --git a/Makefile.common b/Makefile.common index 27c7afb4c46..44d4092a83a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -23,6 +23,11 @@ INCLUDE_FLAGS += \ VERBOSE = 0 ifneq ($(USE_HOST_CXX),) + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),OpenBSD) + HOST_CXX ?= clang++ + endif + ifeq '' '$(findstring clang++,$(CXX))' C_WARNING_FLAGS += -Wno-unknown-warning-option CXX_WARNING_FLAGS += -Wno-unknown-warning-option diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index 46177fc020a..66b66c76b8a 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # This file will need to be run in bash, for now. @@ -12,6 +12,20 @@ TARGET="$ARCH-pc-serenity" PREFIX="$DIR/Local" 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 SYSROOT is "$SYSROOT" @@ -30,7 +44,7 @@ GCC_PKG="${GCC_NAME}.tar.gz" GCC_BASE_URL="http://ftp.gnu.org/gnu/gcc" pushd "$DIR/Tarballs" - md5="$(md5sum $BINUTILS_PKG | cut -f1 -d' ')" + md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')" echo "bu md5='$md5'" if [ ! -e $BINUTILS_PKG ] || [ "$md5" != ${BINUTILS_MD5SUM} ] ; then rm -f $BINUTILS_PKG @@ -39,7 +53,7 @@ pushd "$DIR/Tarballs" echo "Skipped downloading binutils" fi - md5="$(md5sum ${GCC_PKG} | cut -f1 -d' ')" + md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')" echo "gc md5='$md5'" if [ ! -e $GCC_PKG ] || [ "$md5" != ${GCC_MD5SUM} ] ; then rm -f $GCC_PKG @@ -50,7 +64,7 @@ pushd "$DIR/Tarballs" if [ ! -d ${BINUTILS_NAME} ]; then echo "Extracting binutils..." - tar -xf ${BINUTILS_PKG} + tar -xzf ${BINUTILS_PKG} pushd ${BINUTILS_NAME} git init >/dev/null @@ -64,7 +78,7 @@ pushd "$DIR/Tarballs" if [ ! -d $GCC_NAME ]; then echo "Extracting gcc..." - tar -xf $GCC_PKG + tar -xzf $GCC_PKG pushd $GCC_NAME git init >/dev/null @@ -90,7 +104,7 @@ mkdir -p "$DIR/Build/binutils" mkdir -p "$DIR/Build/gcc" if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$(nproc) + MAKEJOBS=$($NPROC) fi pushd "$DIR/Build/" @@ -106,16 +120,20 @@ pushd "$DIR/Build/" # under macOS generated makefiles are not resolving the "intl" # dependency properly to allow linking its own copy of # libintl when building with --enable-shared. - make -j "$MAKEJOBS" || true + "$MAKE" -j "$MAKEJOBS" || true pushd intl - make all-yes + "$MAKE" all-yes popd fi - make -j "$MAKEJOBS" || exit 1 - make install || exit 1 + "$MAKE" -j "$MAKEJOBS" || exit 1 + "$MAKE" install || exit 1 popd 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" \ --target="$TARGET" \ --with-sysroot="$SYSROOT" \ @@ -125,18 +143,22 @@ pushd "$DIR/Build/" --enable-languages=c,c++ || exit 1 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" - make install-gcc install-target-libgcc || exit 1 + "$MAKE" install-gcc install-target-libgcc || exit 1 echo "XXX serenity libc and libm" - ( cd "$DIR/../Libraries/LibC/" && make clean && make && make install ) - ( cd "$DIR/../Libraries/LibM/" && make clean && make && make install ) + ( cd "$DIR/../Libraries/LibC/" && "$MAKE" clean && "$MAKE" && "$MAKE" install ) + ( cd "$DIR/../Libraries/LibM/" && "$MAKE" clean && "$MAKE" && "$MAKE" install ) echo "XXX build libstdc++" - make all-target-libstdc++-v3 || exit 1 + "$MAKE" all-target-libstdc++-v3 || exit 1 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