aboutsummaryrefslogtreecommitdiff
path: root/rules.mk
diff options
context:
space:
mode:
Diffstat (limited to 'rules.mk')
-rw-r--r--rules.mk26
1 files changed, 22 insertions, 4 deletions
diff --git a/rules.mk b/rules.mk
index a802d0d..05994ab 100644
--- a/rules.mk
+++ b/rules.mk
@@ -1,7 +1,8 @@
# generate objects from sources
-# args 1: target.SRCS
+# arg 1: target.SRCS
+# arg 2: object suffix prefix
# returns: target.OBJS
-objects = $(foreach f,$($1),$(addsuffix _${ARCH}.o,$(basename $f)))
+objects = $(foreach f,$($1),$(addsuffix $2.o,$(basename $f)))
# generate depends from .S .c .cpp sources
# args 1: target.SRCS
@@ -18,7 +19,7 @@ all: targets
# - generate target.a that depends on target.OBJS
# - add target.a to TARGETS
$(foreach V,$(filter %.SRCS, ${.VARIABLES}),\
- $(eval $(V:%.SRCS=%.OBJS) := $(call objects,$V)) \
+ $(eval $(V:%.SRCS=%.OBJS) := $(call objects,$V,_${ARCH})) \
$(eval TARGET.OBJS += $(V:%.SRCS=%.OBJS)) \
$(eval $(V:%.SRCS=%.DEPS) := $(call depends,$V)) \
$(eval include $($(V:%.SRCS=%.DEPS))) \
@@ -27,6 +28,17 @@ $(foreach V,$(filter %.SRCS, ${.VARIABLES}),\
$(eval TARGETS += $(V:%.SRCS=%.a)) \
)
+# for each target in HOSTTARGETBIN
+# - generate target.OBJS from target.SRCS
+# - generate target.DEPS from target.SRCS
+# - include target.DEPS
+# - generate target.exe depending on target.OBJS
+$(foreach T,${HOSTTARGETBIN},\
+ $(eval $T.OBJS := $(call objects,$T.SRC,) ) \
+ $(eval $T.DEPS := $(call depends,$T.SRC) ) \
+ $(eval $T: ${$T.OBJS}; @echo ' LD HOST $T'; ${HOST_CC} ${HOST_LDFLAGS} -o $T ${$T.OBJS} ) \
+)
+
TESTS.DEPS = $(foreach F,${TESTS},$(addsuffix .d,$F))
include ${TESTS.DEPS}
@@ -36,6 +48,7 @@ debug:
@echo " DEPS: ${TARGET.DEPS}"
@echo "tests : ${TESTS}"
@echo " DEPS: ${TESTS.DEPS}"
+ @echo "HOSTTARGETBIN: ${HOSTTARGETBIN}"
%.info:
@echo "Target: $(basename $@)"
@@ -63,7 +76,7 @@ ${ARCH}_CXXFLAGS += -I../lib/libk -Drestrict=__restrict__
%.d: %.cc
@${HOST_CXX} ${HOST_CXXFLAGS} -M -MT $(<:.cc=_${ARCH}.o) $< -MF $@
-# Suffix rules
+# Target suffix rules
%.a:
@echo ' AR $@'
@${${ARCH}_AR} ${${ARCH}_ARFLAGS} $@ $(filter %.o,$^)
@@ -90,6 +103,11 @@ ${ARCH}_CXXFLAGS += -I../lib/libk -Drestrict=__restrict__
@echo -n ' B2b '
@b2sum $@ | cut -d' ' -f1
+# Host suffix rules
+%.o: %.c
+ @echo ' CC HOST $<'
+ @${HOST_CC} ${HOST_CFLAGS} -c -o $@ $<
+
# test rules
tst/%: tst/%.cc
@echo ' CXX TEST $@'