Skip to content
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
62 changes: 52 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -849,21 +849,61 @@ rt-darwin-x86_64: embcc embar
# EmbLinkOS is a backend, not a second library: same sources, one different
# file at the bottom. It needs that OS's ABI headers, so it is opt-in.
# make libc-emblinkos EMBLINKOS=$HOME/EmbLinkOs
# make libc-emblinkos EMBLINKOS=... EMBLINKOS_ARCH=aarch64
# x86_64's goes to build/libc/emblinkos, aarch64's to emblinkos-aarch64.
EMBLINKOS ?= $(HOME)/EmbLinkOs
EMBLINKOS_ARCH ?= x86_64
ELOS_SUFFIX = $(if $(filter aarch64,$(EMBLINKOS_ARCH)),-aarch64,)
ELOS_LIBC = $(BUILD)/libc/emblinkos$(ELOS_SUFFIX)
ELOS_LIBCXX = $(BUILD)/libcxx/emblinkos$(ELOS_SUFFIX)
# --unwind-tables: every function gets its .eh_frame, as GCC gives every
# x86-64 function by default. The unwinder needs its own frames' (without
# them a throw's walk ends where it starts, in _Unwind_RaiseException), and a
# throw from a C++ callback passes through C frames -- qsort's, bsearch's.
ELOS_CC = ./embcc --target=$(EMBLINKOS_ARCH)-elf --unwind-tables

libc-emblinkos: embcc embar
@[ -f "$(EMBLINKOS)/user/lib/embk.h" ] || { \
echo "libc-emblinkos: no $(EMBLINKOS)/user/lib/embk.h"; \
echo " set EMBLINKOS=/path/to/EmbLinkOs"; exit 1; }
@mkdir -p $(BUILD)/libc/emblinkos
@for f in $(LIBC_SRCS_PORTABLE) lib/libc/os/emblinkos/backend.c; do \
o=$(BUILD)/libc/emblinkos/$$(echo $$f | tr / _ | sed 's/\.c$$/.o/'); \
./embcc -c -O2 $(LIBC_INC) -I$(EMBLINKOS)/user/lib $$f -o $$o || exit 1; \
@case "$(EMBLINKOS_ARCH)" in x86_64|aarch64) ;; *) \
echo "libc-emblinkos: EMBLINKOS_ARCH is x86_64 or aarch64"; exit 1;; esac
@mkdir -p $(ELOS_LIBC)
@for f in $(LIBC_SRCS_PORTABLE) lib/libc/os/posix-names.c \
lib/libc/os/emblinkos/backend.c; do \
o=$(ELOS_LIBC)/$$(echo $$f | tr / _ | sed 's/\.c$$/.o/'); \
$(ELOS_CC) -c -O2 $(LIBC_INC) -I$(EMBLINKOS)/user/lib $$f -o $$o || exit 1; \
done
@rm -f $(BUILD)/libc/emblinkos/libc.a
@$${EMBCC_X86_AR:-./embar} rcs $(BUILD)/libc/emblinkos/libc.a \
$(BUILD)/libc/emblinkos/*.o
@echo "libc: $(BUILD)/libc/emblinkos/libc.a"
@rm -f $(ELOS_LIBC)/libc.a $(ELOS_LIBC)/libm.a
@$${EMBCC_X86_AR:-./embar} rcs $(ELOS_LIBC)/libc.a $(ELOS_LIBC)/*.o
@# libm.a holds nothing: the math is in libc.a, as glibc's is, and an
@# empty one beside it keeps a program's -lm from finding another libc's
@printf '' > $(ELOS_LIBC)/libm-empty.c
@$(ELOS_CC) -c $(ELOS_LIBC)/libm-empty.c -o $(ELOS_LIBC)/libm-empty.o.x
@$${EMBCC_X86_AR:-./embar} rcs $(ELOS_LIBC)/libm.a $(ELOS_LIBC)/libm-empty.o.x
@# librt.a: the compiler runtime, with the unwinder C++'s exceptions
@# need -- its programs have no other (lib/rt/unwind.c says why)
@for f in $(RT_SRCS); do \
o=$(ELOS_LIBC)/rt_$$(basename $$f .c).o.x; \
$(ELOS_CC) -c -O2 -D__EMBCC_RT_UNWIND $$f -o $$o || exit 1; \
done
@rm -f $(ELOS_LIBC)/librt.a
@$${EMBCC_X86_AR:-./embar} rcs $(ELOS_LIBC)/librt.a $(ELOS_LIBC)/rt_*.o.x
@echo "libc: $(ELOS_LIBC)/libc.a (+ an empty libm.a, and librt.a)"

# C++ on EmbLinkOS: lib/libcxx over this C library, compiled by EmbCC.
# make libcxx-emblinkos EMBLINKOS=$HOME/EmbLinkOs [EMBLINKOS_ARCH=aarch64]
libcxx-emblinkos: embcc embar
@[ -f "$(EMBLINKOS)/user/lib/embk.h" ] || { \
echo "libcxx-emblinkos: no $(EMBLINKOS)/user/lib/embk.h"; exit 1; }
@mkdir -p $(ELOS_LIBCXX)
@for f in $(LIBCXX_SRCS); do \
o=$(ELOS_LIBCXX)/$$(basename $$f .cc).o; \
$(ELOS_CC) -c -O2 -x c++ $(LIBCXX_INC) -I$(EMBLINKOS)/user/lib $$f -o $$o || exit 1; \
done
@rm -f $(ELOS_LIBCXX)/libcxx.a
@$${EMBCC_X86_AR:-./embar} rcs $(ELOS_LIBCXX)/libcxx.a $(ELOS_LIBCXX)/*.o
@echo "libcxx: $(ELOS_LIBCXX)/libcxx.a"

# Linux, which is the first target this library reaches with NO other C
# library underneath it: lib/libc/os/linux/backend.c issues syscalls, so
Expand All @@ -875,7 +915,9 @@ libc-emblinkos: embcc embar
# exactly once in an image, and a definition that arrives by archive
# member is a definition that arrives by accident.
# make libc-linux-x86_64 / make libc-linux-aarch64
LIBC_SRCS_LINUX := $(LIBC_SRCS_PORTABLE) lib/libc/os/linux/backend.c \
LIBC_SRCS_LINUX := $(LIBC_SRCS_PORTABLE) lib/libc/os/posix-names.c \
lib/libc/os/linux/backend.c \
lib/libc/os/linux/posix.c \
lib/libc/os/linux/thread.c lib/libc/os/linux/tls.c

# lib/rt -- the COMPILER runtime, which is a different library from the C
Expand Down Expand Up @@ -1230,7 +1272,7 @@ distclean: clean
rm -f config.mk

.PHONY: all check test test-arm64 test-libstdcxx site libc libc-x86_64 libc-aarch64 \
libc-emblinkos libc-linux libc-linux-x86_64 libc-linux-aarch64 \
libc-emblinkos libcxx-emblinkos libc-linux libc-linux-x86_64 libc-linux-aarch64 \
libcxx libcxx-x86_64 libcxx-aarch64 \
libcxx-linux-x86_64 libcxx-linux-aarch64 libcxx-embedded \
install install-files uninstall libc-linux-all clean distclean
2 changes: 1 addition & 1 deletion build.ebm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ output: /data/build/out/embcc/platform_platform_common.o

name: platform_platform_posix.o
kind: compile
inputs: /data/src/embcc/platform/platform_posix.c /data/src/embcc/platform/platform.h /data/apps/embcc/include/stddef.h /system/abi/include/stdio.h /system/abi/include/_ansi.h /system/abi/include/newlib.h /system/abi/include/_newlib_version.h /system/abi/include/sys/config.h /system/abi/include/machine/ieeefp.h /system/abi/include/sys/features.h /system/abi/include/sys/cdefs.h /system/abi/include/machine/_default_types.h /data/apps/embcc/include/stdarg.h /system/abi/include/sys/reent.h /system/abi/include/sys/_types.h /system/abi/include/machine/_types.h /system/abi/include/sys/lock.h /system/abi/include/sys/stdio.h /system/abi/include/stdlib.h /system/abi/include/machine/stdlib.h /system/abi/include/alloca.h /data/apps/embcc/include/string.h /data/src/embcc/driver/util.h /system/abi/include/dirent.h /system/abi/include/sys/dirent.h /system/abi/include/unistd.h /system/abi/include/sys/unistd.h /system/abi/include/sys/types.h /system/abi/include/sys/_stdint.h /system/abi/include/sys/_pthreadtypes.h /system/abi/include/sys/sched.h /system/abi/include/sys/_timespec.h /system/abi/include/machine/types.h /system/abi/include/pthread.h
inputs: /data/src/embcc/platform/platform_posix.c /data/src/embcc/platform/platform.h /data/apps/embcc/include/stddef.h /system/abi/include/stdio.h /system/abi/include/_ansi.h /system/abi/include/newlib.h /system/abi/include/_newlib_version.h /system/abi/include/sys/config.h /system/abi/include/machine/ieeefp.h /system/abi/include/sys/features.h /system/abi/include/sys/cdefs.h /system/abi/include/machine/_default_types.h /data/apps/embcc/include/stdarg.h /system/abi/include/sys/reent.h /system/abi/include/sys/_types.h /system/abi/include/machine/_types.h /system/abi/include/sys/lock.h /system/abi/include/sys/stdio.h /system/abi/include/stdlib.h /system/abi/include/machine/stdlib.h /system/abi/include/alloca.h /data/apps/embcc/include/string.h /data/src/embcc/driver/util.h /system/abi/include/dirent.h /system/abi/include/sys/dirent.h /system/abi/include/unistd.h /system/abi/include/sys/unistd.h /system/abi/include/sys/types.h /system/abi/include/sys/_stdint.h /system/abi/include/sys/_pthreadtypes.h /system/abi/include/sys/sched.h /system/abi/include/sys/_timespec.h /system/abi/include/machine/types.h /system/abi/include/sys/stat.h /system/abi/include/time.h /system/abi/include/machine/time.h /system/abi/include/sys/timespec.h /system/abi/include/sys/_locale.h /system/abi/include/pthread.h
args: /data/apps/embcc/embcc.elf -c -I/data/apps/embcc/include -I/system/abi/include /data/src/embcc/platform/platform_posix.c -o /data/build/out/embcc/platform_platform_posix.o
output: /data/build/out/embcc/platform_platform_posix.o

Expand Down
Loading
Loading