Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: introduce per-project sysroot #159

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ PREFIX_ROOTFS ?= $(PREFIX_FS)/root/
# Check TARGET, set TARGET_SUFF and include target building options
include $(MAKES_PATH)/include-target.mk

# setup tools
# setup tools and sysroot
include $(MAKES_PATH)/setup-tools.mk
include $(MAKES_PATH)/setup-sysroot.mk

# add utility functions
include $(MAKES_PATH)/funcs.mk
Expand Down Expand Up @@ -97,12 +98,6 @@ ifneq ($(PROJECT_PATH),)
CXXFLAGS := -I$(PROJECT_PATH) $(CXXFLAGS)
endif

# add multilib directory to library search path
SYSROOT := $(shell $(CC) $(CFLAGS) -print-sysroot)
MULTILIB_DIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
LIBC_INSTALL_DIR := $(SYSROOT)/lib/$(MULTILIB_DIR)
LDFLAGS += -L$(LIBC_INSTALL_DIR)

# remove local dev path from macros
CFLAGS += -fmacro-prefix-map=$(dir $(TOPDIR))=
CXXFLAGS += -fmacro-prefix-map=$(dir $(TOPDIR))=
Expand Down
11 changes: 7 additions & 4 deletions build-core-armv7a7-imx6ull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all install
Expand Down
11 changes: 7 additions & 4 deletions build-core-armv7a9-zynq7000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building unity"
make -C "phoenix-rtos-tests" unity
Expand Down
11 changes: 7 additions & 4 deletions build-core-armv7m4-stm32l4x6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all install
Expand Down
11 changes: 7 additions & 4 deletions build-core-armv7m7-imxrt105x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all
Expand Down
10 changes: 8 additions & 2 deletions build-core-armv7m7-imxrt106x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building libphoenix"
make -C "libphoenix" all install
Expand Down
12 changes: 8 additions & 4 deletions build-core-armv7m7-imxrt117x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all

b_log "Building libphoenix"
make -C "libphoenix" all install
make -C "phoenix-rtos-kernel" all

if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all
Expand Down
11 changes: 7 additions & 4 deletions build-core-ia32-generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all install
Expand Down
11 changes: 6 additions & 5 deletions build-core-riscv64-generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
make -C "phoenix-rtos-kernel" all

KERNEL_MAKECMDGOALS="install-headers"
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all

b_log "Building libphoenix"
make -C "libphoenix" all install
b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all install
Expand Down
11 changes: 7 additions & 4 deletions build-core-sparcv8leon3-gr716.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
set -e

b_log "Building phoenix-rtos-kernel"
KERNEL_MAKECMDGOALS="install-headers"
make -C "phoenix-rtos-kernel" $KERNEL_MAKECMDGOALS all
make -C "phoenix-rtos-kernel" all

b_log "Building libphoenix"
make -C "libphoenix" all install
if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
make -C "phoenix-rtos-kernel" install-headers

b_log "Building libphoenix"
make -C "libphoenix" all install
fi

b_log "Building phoenix-rtos-corelibs"
make -C "phoenix-rtos-corelibs" all
Expand Down
24 changes: 23 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ROOTFS_OVERLAYS=""

source ./phoenix-rtos-build/build.subr
source ./build.project

Check warning on line 20 in build.sh

View workflow job for this annotation

GitHub Actions / call-lint / shellcheck-pr

[shellcheck] reported by reviewdog 🐶 Not following: ./build.project: openBinaryFile: does not exist (No such file or directory) [SC1091](https://github.com/koalaman/shellcheck/wiki/SC1091) Raw Output: ./build.sh:20:8:info:Not following: ./build.project: openBinaryFile: does not exist (No such file or directory) [SC1091](https://github.com/koalaman/shellcheck/wiki/SC1091)

PREFIX_PROJECT="$(pwd)"

Expand All @@ -39,12 +39,24 @@

PREFIX_A="$PREFIX_BUILD/lib/"
PREFIX_H="$PREFIX_BUILD/include/"
PREFIX_SYSROOT="" # empty by default (use toolchain sysroot)

PLO_SCRIPT_DIR="$PREFIX_BUILD/plo-scripts"

PREFIX_ROOTFS="$PREFIX_FS/root/"
: "${PREFIX_ROOTSKEL:="$PREFIX_PROJECT/_fs/root-skel/"}"


# LIBPHOENIX_DEVEL_MODE:
# - if enabled (y): use project-specific sysroot (PREFIX_SYSROOT) and install kernel headers + compile/install libphoenix
# - if disabled (n or not set): use toolchain sysroot, don't install kernel headers, don't compile libphoenix
#TODO: change default value to 'n' when the toolchain-supplied sysroot will be stable enough
: "${LIBPHOENIX_DEVEL_MODE:=y}"

if [ "$LIBPHOENIX_DEVEL_MODE" = "y" ]; then
PREFIX_SYSROOT="$PREFIX_BUILD/sysroot"
fi

# Default project's overlay directory, it does not have to exist.
ROOTFS_OVERLAYS="$PROJECT_PATH/rootfs-overlay:${ROOTFS_OVERLAYS}"

Expand All @@ -57,7 +69,8 @@

export TARGET TARGET_FAMILY TARGET_SUBFAMILY TARGET_PROJECT PROJECT_PATH PREFIX_PROJECT PREFIX_BUILD\
PREFIX_BUILD_HOST PREFIX_FS PREFIX_BOOT PREFIX_PROG PREFIX_PROG_STRIPPED PREFIX_A\
PREFIX_H PREFIX_ROOTFS CROSS CFLAGS CXXFLAGS LDFLAGS CC LD AR AS MAKEFLAGS DEVICE_FLAGS PLO_SCRIPT_DIR
PREFIX_H PREFIX_ROOTFS CROSS CFLAGS CXXFLAGS LDFLAGS CC LD AR AS MAKEFLAGS DEVICE_FLAGS PLO_SCRIPT_DIR\
PREFIX_SYSROOT LIBPHOENIX_DEVEL_MODE

# export flags for ports - call make only after all necessary env variables are already set
EXPORT_CFLAGS="$(make -f phoenix-rtos-build/Makefile.common export-cflags)"
Expand Down Expand Up @@ -133,6 +146,15 @@
mkdir -p "$PREFIX_BUILD_HOST"
mkdir -p "$PREFIX_BOOT"
mkdir -p "$PREFIX_PROG" "$PREFIX_PROG_STRIPPED"

if [ -n "$PREFIX_SYSROOT" ]; then
mkdir -p "$PREFIX_SYSROOT" "$PREFIX_SYSROOT/include" "$PREFIX_SYSROOT/usr"

# libc includes needs to be accessible by ${SYSROOT}/usr/local/include for C++ headers to work
(cd "$PREFIX_SYSROOT/usr" && ln -sfn . local)
# see sysroot-setup.mk for next steps in sysroot setup
fi

if declare -f "b_prepare" > /dev/null; then
b_prepare
fi
Expand Down
46 changes: 46 additions & 0 deletions makes/setup-sysroot.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# setting up toolchain sysroot
# WARN: these compiler options were carefully crafted, think twice before changing them!
#
# C++ includes and include-fixed are problematic as they are using #include_next
# we need to copy them into our sysroot in special paths to ensure they will be searched in order:
# c++ -> include-fixed -> libc include -> other toolchain paths
#
# gcc options helpful in development: -H (include tree) -v (include paths to be searched)
# echo "#warning toolchain include" >> $($CC -print-sysroot)/usr/include/stdint.h

# use stamp file to setup sysroot only once regardless of the component being built
_SYSROOT_STAMPFILE := $(PREFIX_BUILD)/.stamp_sysroot


ifneq ($(PREFIX_SYSROOT),)
# basic sysroot define, compile-time hardcoded toolchain paths would still be searched (see gcc/cppdefaults.c)
SYSROOT_OPTS := --sysroot="$(PREFIX_SYSROOT)/"

# shouldn't be necessary but without it - we're linking against toolchain crt0.o
SYSROOT_OPTS += -B$(PREFIX_SYSROOT)/lib/

# magically rearranges toolchain paths that sysroot libc subdir would be searched first :)
SYSROOT_OPTS += -iprefix "$(PREFIX_SYSROOT)/"

CFLAGS += $(SYSROOT_OPTS)
CXXFLAGS += $(SYSROOT_OPTS)

# WARN: assuming there are no multilib c++ headers
$(_SYSROOT_STAMPFILE):
@mkdir -p $(PREFIX_SYSROOT)/include
$(SIL)cp -a "$$($(CC) -print-sysroot)/include/c++" "$(PREFIX_SYSROOT)/include/"
$(SIL)cp -a $(shell $(CC) -E -Wp,-v -x c /dev/null 2>&1 | awk '!/ignoring/ && /include-fixed/ {print $0}') "$(PREFIX_SYSROOT)"
@touch $@

else
$(_SYSROOT_STAMPFILE):
@mkdir -p $(PREFIX_BUILD)
@touch $@
endif

prepare_sysroot: $(_SYSROOT_STAMPFILE)

# make it an order rule for any build/install target
all: | prepare_sysroot
install: | prepare_sysroot
install-%: | prepare_sysroot
4 changes: 4 additions & 0 deletions target/host.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ CXXFLAGS := $(CFLAGS)
# install unstripped binaries in rootfs
# (cruicial for tests binaries with debug info for meaningful sanitizers info)
ROOTFS_INSTALL_UNSTRIPPED := y

# don't use sysroot on host
LIBPHOENIX_DEVEL_MODE := n
PREFIX_SYSROOT :=
Loading