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 enhancements #152

Merged
merged 5 commits into from
Sep 4, 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
3 changes: 3 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ CXXFLAGS += -D__CPU_$(call uppercase,$(TARGET_SUBFAMILY))
# generic CFLAGS/LDFLAGS
LDFLAGS += -L$(PREFIX_A)

# make PROJECT_PATH the first search dir to allow project customizations/monkey-patching
CFLAGS := -I$(PROJECT_PATH) $(CFLAGS)

# add multilib directory to library search path
SYSROOT := $(shell $(CC) $(CFLAGS) -print-sysroot)
MULTILIB_DIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
Expand Down
20 changes: 10 additions & 10 deletions Makefile.host
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
# %LICENSE%
#

CROSS ?=
CROSS :=
nalajcie marked this conversation as resolved.
Show resolved Hide resolved

CC = $(CROSS)gcc
CXX = $(CROSS)g++
CC := $(CROSS)gcc
CXX := $(CROSS)g++

OLVL ?= -O2
CFLAGS += $(OLVL)
CFLAGS += -Wall -Wstrict-prototypes -g -fomit-frame-pointer -ffunction-sections -fdata-sections

AR = $(CROSS)ar
AR := $(CROSS)ar
ARFLAGS = -r

LD = $(CROSS)gcc
LD := $(CROSS)gcc
LDFLAGS += -Wl,--gc-sections
LDFLAGS_PREFIX := -Wl,

OBJCOPY = $(CROSS)objcopy
OBJDUMP = $(CROSS)objdump
STRIP = $(CROSS)strip
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
STRIP := $(CROSS)strip

# Sanitizers
ifneq ($(NOSAN), 1)
CFLAGS += -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
CFLAGS += -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
endif

# install unstripped binaries in rootfs
Expand Down
8 changes: 0 additions & 8 deletions build-core-armv7a7-imx6ull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,3 @@ fi

b_log "Building posixsrv"
make -C "phoenix-rtos-posixsrv" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psdisk" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psu" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/syspagen" "$PREFIX_BOOT"
5 changes: 0 additions & 5 deletions build-core-armv7a9-zynq7000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@ make -C "phoenix-rtos-utils" all install

b_log "Building posixsrv"
make -C "phoenix-rtos-posixsrv" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
6 changes: 0 additions & 6 deletions build-core-armv7m7-imxrt105x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,3 @@ make -C "phoenix-rtos-lwip" all install

#b_log "Building posixsrv"
#make -C "phoenix-rtos-posixsrv" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psu" "$PREFIX_BOOT"
6 changes: 0 additions & 6 deletions build-core-armv7m7-imxrt106x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,3 @@ fi

#b_log "Building posixsrv"
#make -C "phoenix-rtos-posixsrv" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psu" "$PREFIX_BOOT"
6 changes: 0 additions & 6 deletions build-core-armv7m7-imxrt117x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,3 @@ fi

#b_log "Building posixsrv"
#make -C "phoenix-rtos-posixsrv" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psu" "$PREFIX_BOOT"
6 changes: 0 additions & 6 deletions build-core-host-generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ make -C "phoenix-rtos-filesystems" all

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

b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psdisk" "$PREFIX_BOOT"
cp "$PREFIX_BUILD_HOST/prog.stripped/psu" "$PREFIX_BOOT"
8 changes: 0 additions & 8 deletions build-core-riscv64-generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@ make -C "phoenix-rtos-devices" all install

b_log "Building coreutils"
make -C "phoenix-rtos-utils" all install

b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old all
cp "$PREFIX_BUILD_HOST/prog.stripped/syspagen" "$PREFIX_BOOT"

#FIXME: tests should not always be built as a part of CORE
b_log "Building phoenix-rtos-tests"
make -C "phoenix-rtos-tests" all
5 changes: 0 additions & 5 deletions build-core-sparcv8leon3-gr716.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@ make -C "phoenix-rtos-devices" all install

b_log "Building coreutils"
make -C "phoenix-rtos-utils" all install

# FIXME: compile host tools using host-generic-pc target?
b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" -f Makefile.old $CLEAN all
cp "$PREFIX_BUILD_HOST/prog.stripped/phoenixd" "$PREFIX_BOOT"
10 changes: 10 additions & 0 deletions build-host-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Shell script for building Phoenix-RTOS firmware
#
# Builder for Phoenix-RTOS host utils

b_log "Building host corelibs"
make -C "phoenix-rtos-corelibs" libptable

b_log "Building hostutils"
make -C "phoenix-rtos-hostutils" all
44 changes: 35 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#

set -e
ORIG_ENV="$(env)"

# Colon-separated list of dirs to overlay the default rootFS.
# It can be overwritten by build.project scripts.
ROOTFS_OVERLAYS=""

. ./phoenix-rtos-build/build.subr
. ./build.project
source ./phoenix-rtos-build/build.subr
nalajcie marked this conversation as resolved.
Show resolved Hide resolved
source ./build.project
nalajcie marked this conversation as resolved.
Show resolved Hide resolved

PREFIX_PROJECT="$(pwd)"

Expand All @@ -25,8 +26,10 @@ if [ -z "$PROJECT_PATH" ]; then
exit 1;
fi

_TARGET_FOR_HOST_BUILD="host-generic-pc"

PREFIX_BUILD="$PREFIX_PROJECT/_build/$TARGET"
PREFIX_BUILD_HOST="$PREFIX_PROJECT/_build/host-generic-pc"
PREFIX_BUILD_HOST="$PREFIX_PROJECT/_build/$_TARGET_FOR_HOST_BUILD"
PREFIX_FS="$PREFIX_PROJECT/_fs/$TARGET"
PREFIX_BOOT="$PREFIX_PROJECT/_boot/$TARGET"

Expand All @@ -48,13 +51,12 @@ CC=${CROSS}gcc
AS=${CROSS}as
LD=${CROSS}ld
AR=${CROSS}ar
OBJCPY=${CROSS}objcopy

MAKEFLAGS="--no-print-directory -j 9"

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 CLEAN MAKEFLAGS DEVICE_FLAGS PLO_SCRIPT_DIR
PREFIX_H PREFIX_ROOTFS CROSS CFLAGS CXXFLAGS LDFLAGS CC LD AR AS MAKEFLAGS DEVICE_FLAGS PLO_SCRIPT_DIR

# 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 All @@ -69,12 +71,14 @@ export EXPORT_CFLAGS EXPORT_LDFLAGS
#
if [ $# -lt 1 ]; then
echo "Build options should be specified!"
echo "Usage: build.sh [clean] [all] [fs] [core] [test] [ports] [project] [image]";
echo "Usage: build.sh [clean] [all] [host] [fs] [core] [test] [ports] [project] [image]";
exit 1;
fi

B_CLEAN="n"
B_FS="n"
B_CORE="n"
B_HOST="n"
B_PORTS="n"
B_PROJECT="n"
B_IMAGE="n"
Expand All @@ -88,11 +92,13 @@ for arg in "${ARGS[@]}"; do
case "$arg"
in
clean)
CLEAN="clean";;
B_CLEAN="y";;
fs)
B_FS="y";;
core)
B_CORE="y";;
host)
B_HOST="y";;
test|tests)
B_TEST="y";;
ports)
Expand All @@ -102,7 +108,7 @@ for arg in "${ARGS[@]}"; do
image)
B_IMAGE="y";;
all)
B_FS="y"; B_CORE="y"; B_PORTS="y"; B_PROJECT="y"; B_IMAGE="y";;
B_FS="y"; B_CORE="y"; B_HOST="y"; B_PORTS="y"; B_PROJECT="y"; B_IMAGE="y";;
*)
echo "Unknown build option: \"$arg\"."
exit 1;;
Expand All @@ -112,7 +118,7 @@ done
#
# Clean if requested
#
if [ -n "$CLEAN" ]; then
if [ "$B_CLEAN" = "y" ]; then
b_log "Cleaning build dirs"
rm -rf "$PREFIX_BUILD" "$PREFIX_BUILD_HOST"
rm -rf "$PREFIX_FS"
Expand Down Expand Up @@ -164,6 +170,26 @@ if [ "${B_FS}" = "y" ] && [ -d "${PREFIX_ROOTSKEL}" ]; then
install -m 664 "${PREFIX_BUILD}/git-version" "$PREFIX_FS/root/etc"
fi

#
# Build host tools
#
if [ "${B_HOST}" = "y" ]; then
if [ "$TARGET" != "$_TARGET_FOR_HOST_BUILD" ]; then
# if not already building for host - re-exec with clean env
(env "$ORIG_ENV" TARGET=$_TARGET_FOR_HOST_BUILD ./phoenix-rtos-build/build.sh host)
else
source ./phoenix-rtos-build/build-host-tools.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Not following: ./phoenix-rtos-build/build-host-tools.sh: openBinaryFile: does not exist (No such file or directory) SC1091

fi
fi

# always install hostutils if they are present
b_log "Installing hostutils"
HOSTUTILS=(metaelf phoenixd psdisk psu syspagen)
for tool in "${HOSTUTILS[@]}"; do
toolfile="$PREFIX_BUILD_HOST/prog.stripped/$tool"
[ -e "$toolfile" ] && cp -a "$toolfile" "$PREFIX_BOOT"
anglov marked this conversation as resolved.
Show resolved Hide resolved
done

#
# Build core part
#
Expand Down
3 changes: 3 additions & 0 deletions makes/binary.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# - LOCAL_CFLAGS - additional CFLAGS for current component compilation
# - LOCAL_CXXFLAGS - additional CXXFLAGS for current component compilation
# - LOCAL_LDFLAGS - additional LDFLAGS for current component linking
# - LOCAL_LDLIBS - additional LDLIBS for current component linking
# - LOCAL_INSTALL_PATH - custom rootfs dir for the binary to be installed (if not provided - DEFAULT_INSTALL_PATH)

# Global variables (not reset by this script):
Expand Down Expand Up @@ -51,6 +52,7 @@ $(OBJS.$(NAME)): | $(DEPS)
$(OBJS.$(NAME)): CFLAGS:=-I"$(ABS_HEADERS_DIR)" $(CFLAGS) $(LOCAL_CFLAGS)
$(OBJS.$(NAME)): CXXFLAGS:=-I"$(ABS_HEADERS_DIR)" $(CXXFLAGS) $(LOCAL_CXXFLAGS)
$(PREFIX_PROG)$(NAME): LDFLAGS:=$(LDFLAGS) $(LOCAL_LDFLAGS)
$(PREFIX_PROG)$(NAME): LDLIBS:=$(LOCAL_LDLIBS) $(LDLIBS)

# dynamically generated dependencies (file-to-file dependencies)
DEPS.$(NAME) := $(patsubst %,$(PREFIX_O)%.d,$(SRCS))
Expand Down Expand Up @@ -122,4 +124,5 @@ LIBS :=
LOCAL_CFLAGS :=
LOCAL_CXXFLAGS :=
LOCAL_LDFLAGS :=
LOCAL_LDLIBS :=
LOCAL_INSTALL_PATH :=
3 changes: 2 additions & 1 deletion makes/static-lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ endif

# binary.mk clears all variables it uses so we should expect that they are not set here. Leaving them set would
# influence next binary.mk call leading to unexpected errors
ifneq ($(DEP_LIB)$(LIBS)$(LOCAL_LDFLAGS)$(LOCAL_INSTALL_PATH),)
ifneq ($(DEP_LIB)$(LIBS)$(LOCAL_LDFLAGS)$(LOCAL_LDLIBS)$(LOCAL_INSTALL_PATH),)
$(warning $(NAME): DEP_LIB=$(DEP_LIB))
$(warning $(NAME): LIBS=$(LIBS))
$(warning $(NAME): LOCAL_LDFLAGS=$(LOCAL_LDFLAGS))
$(warning $(NAME): LOCAL_LDLIBS=$(LOCAL_LDLIBS))
$(warning $(NAME): LOCAL_INSTALL_PATH=$(LOCAL_INSTALL_PATH))
$(error $(NAME): static-lib.mk invoked with args reserved for binary.mk)
endif
Expand Down
Loading