diff --git a/Makefile.common b/Makefile.common index e530f5f3..ff01f4f5 100644 --- a/Makefile.common +++ b/Makefile.common @@ -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) diff --git a/Makefile.host b/Makefile.host index 5f3d76a9..7ca0bbe7 100644 --- a/Makefile.host +++ b/Makefile.host @@ -6,30 +6,30 @@ # %LICENSE% # -CROSS ?= +CROSS := -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 diff --git a/build-core-armv7a7-imx6ull.sh b/build-core-armv7a7-imx6ull.sh index 8b853af1..5cba0279 100755 --- a/build-core-armv7a7-imx6ull.sh +++ b/build-core-armv7a7-imx6ull.sh @@ -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" diff --git a/build-core-armv7a9-zynq7000.sh b/build-core-armv7a9-zynq7000.sh index c09a3df6..2c8a76f1 100755 --- a/build-core-armv7a9-zynq7000.sh +++ b/build-core-armv7a9-zynq7000.sh @@ -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" diff --git a/build-core-armv7m7-imxrt105x.sh b/build-core-armv7m7-imxrt105x.sh index 7871dedc..80069b34 100755 --- a/build-core-armv7m7-imxrt105x.sh +++ b/build-core-armv7m7-imxrt105x.sh @@ -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" diff --git a/build-core-armv7m7-imxrt106x.sh b/build-core-armv7m7-imxrt106x.sh index 1afe1a01..035080dd 100755 --- a/build-core-armv7m7-imxrt106x.sh +++ b/build-core-armv7m7-imxrt106x.sh @@ -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" diff --git a/build-core-armv7m7-imxrt117x.sh b/build-core-armv7m7-imxrt117x.sh index 7c175e6a..06c2c19f 100755 --- a/build-core-armv7m7-imxrt117x.sh +++ b/build-core-armv7m7-imxrt117x.sh @@ -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" diff --git a/build-core-host-generic.sh b/build-core-host-generic.sh index e00aee8d..27684386 100755 --- a/build-core-host-generic.sh +++ b/build-core-host-generic.sh @@ -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" diff --git a/build-core-riscv64-generic.sh b/build-core-riscv64-generic.sh index d284b58a..4d2da63e 100755 --- a/build-core-riscv64-generic.sh +++ b/build-core-riscv64-generic.sh @@ -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 diff --git a/build-core-sparcv8leon3-gr716.sh b/build-core-sparcv8leon3-gr716.sh index 4c9d414f..691be369 100755 --- a/build-core-sparcv8leon3-gr716.sh +++ b/build-core-sparcv8leon3-gr716.sh @@ -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" diff --git a/build-host-tools.sh b/build-host-tools.sh new file mode 100644 index 00000000..945b5db2 --- /dev/null +++ b/build-host-tools.sh @@ -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 diff --git a/build.sh b/build.sh index 1807556f..1a480ac8 100755 --- a/build.sh +++ b/build.sh @@ -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 +source ./build.project PREFIX_PROJECT="$(pwd)" @@ -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" @@ -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)" @@ -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" @@ -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) @@ -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;; @@ -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" @@ -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 + 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" +done + # # Build core part # diff --git a/makes/binary.mk b/makes/binary.mk index 5d68f7e0..cf4e389c 100644 --- a/makes/binary.mk +++ b/makes/binary.mk @@ -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): @@ -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)) @@ -122,4 +124,5 @@ LIBS := LOCAL_CFLAGS := LOCAL_CXXFLAGS := LOCAL_LDFLAGS := +LOCAL_LDLIBS := LOCAL_INSTALL_PATH := diff --git a/makes/static-lib.mk b/makes/static-lib.mk index 123622b9..f8c6d7e8 100644 --- a/makes/static-lib.mk +++ b/makes/static-lib.mk @@ -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