diff options
author | aqua <aqua@iserlohn-fortress.net> | 2023-03-19 21:34:20 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2023-03-20 20:10:02 +0200 |
commit | 5e42e0ee0abbebd5f447c0c4f608be544236c452 (patch) | |
tree | 9cfb3455b48b95fcd9637b8e15802b61419f46fd | |
parent | Build tests using HOSTTARGETBIN (diff) | |
download | kernel-5e42e0ee0abbebd5f447c0c4f608be544236c452.tar.xz |
Place compiled objects and dependencies in build/
- generate dependencies during compile rather than explicitly
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | rules.mk | 72 |
2 files changed, 34 insertions, 43 deletions
@@ -1,13 +1,10 @@ lib/musl* -build* -*.d -*.o +build *.a *.elf *.iso isodir src/conf.h .config.old -test_* doc include/ @@ -2,13 +2,13 @@ # arg 1: target.SRCS # arg 2: object suffix prefix # returns: target.OBJS -objects = $(foreach f,$($1),$(addsuffix $2.o,$(basename $f))) +objects = $(foreach f,$($1),$(addprefix build/,$(addsuffix $2.o,$(basename $f)))) # generate depends from .S .c .cpp sources # arg 1: target.SRCS # arg 2: dependency suffix prefix # returns: target.DEPS -depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addsuffix $2.d,$(basename $f))) +depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addprefix build/,$(addsuffix $2.d,$(basename $f)))) # default target .DEFAULT_GOAL := all @@ -16,19 +16,19 @@ depends = $(foreach f,$(filter %.S %.c %.cpp,$($1)),$(addsuffix $2.d,$(basename # TARGETBIN: binaries using the target architecture $(foreach T,${TARGETBIN},\ - $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \ - $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \ - $(eval include $($T.DEPS) ) \ - $(eval $T.elf: ${$T.OBJS} ) \ + $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \ + $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \ + $(eval -include $($T.DEPS) ) \ + $(eval $T.elf: ${$T.OBJS} ) \ $(eval DEFAULT_TARGETS += $T.elf) \ ) # TARGETLIB: static libraries using the target architecture $(foreach T,${TARGETLIB},\ - $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \ - $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \ - $(eval include $($T.DEPS) ) \ - $(eval $T.a: ${$T.OBJS} ) \ + $(eval $T.OBJS += $(call objects,$T.SRCS,_${ARCH}) ) \ + $(eval $T.DEPS += $(call depends,$T.SRCS,_${ARCH}) ) \ + $(eval -include $($T.DEPS) ) \ + $(eval $T.a: ${$T.OBJS} ) \ $(eval DEFAULT_TARGETS += $T.a) \ ) @@ -36,7 +36,7 @@ $(foreach T,${TARGETLIB},\ $(foreach T,${HOSTTARGETBIN},\ $(eval $T.OBJS += $(call objects,$T.SRCS,) ) \ $(eval $T.DEPS += $(call depends,$T.SRCS,) ) \ - $(eval include $($T.DEPS) ) \ + $(eval -include $($T.DEPS) ) \ $(eval $T: ${$T.OBJS}; @echo ' HOST LD $T'; ${HOST_CXX} ${HOST_LDFLAGS} -o $T ${$T.OBJS} ) \ $(eval DEFAULT_TARGETS += $T) \ ) @@ -65,51 +65,45 @@ ${ARCH}_CFLAGS += -I../lib/libk \ -Werror=implicit-function-declaration ${ARCH}_CXXFLAGS += -I../lib/libk -Drestrict=__restrict__ -# Target depndency rules -%_${ARCH}.d: %.S - @${${ARCH}_CC} ${${ARCH}_CFLAGS} -M -MT $(<:.S=_${ARCH}.o) $< -MF $@ - -%_${ARCH}.d: %.c - @${${ARCH}_CC} ${${ARCH}_CFLAGS} -M -MT $(<:.c=_${ARCH}.o) $< -MF $@ - -# Host dependency rules -%.d: %.c - @${HOST_CC} ${HOST_CFLAGS} -M -MT $(<:.c=.o) $< -MF $@ - -%.d: %.cc - @${HOST_CXX} ${HOST_CXXFLAGS} -M -MT $(<:.cc=) $< -MF $@ - # Target suffix rules +# -MD output makefile dependency rule +# -MT target change the target of the rule +# -MF file write the dependencies to file %.a: - @echo ' AR $@' + @echo ' AR $@' @${${ARCH}_AR} ${${ARCH}_ARFLAGS} $@ $(filter %.o,$^) -%_${ARCH}.o: %.s - @echo ' AS $<' +build/%_${ARCH}.o: %.s + @echo ' AS $<' + @mkdir -p $(dir $@) @${${ARCH}_AS} ${${ARCH}_ASFLAGS} -c -o $@ $< -%_${ARCH}.o: %.S - @echo ' CC $<' - @${${ARCH}_CC} ${${ARCH}_CFLAGS} -c -o $@ $< +build/%_${ARCH}.o: %.S + @echo ' CC $<' + @mkdir -p $(dir $@) + @${${ARCH}_CC} ${${ARCH}_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $< -%_${ARCH}.o: %.c - @echo ' CC $<' - @${${ARCH}_CC} ${${ARCH}_CFLAGS} -c -o $@ $< +build/%_${ARCH}.o: %.c + @echo ' CC $<' + @mkdir -p $(dir $@) + @${${ARCH}_CC} ${${ARCH}_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $< %.elf: - @echo ' LD $@' + @echo ' LD $@' @${${ARCH}_LD} ${${ARCH}_LDFLAGS} -o $@ $^ @echo -n ' B2b ' @b2sum $@ | cut -d' ' -f1 # Host suffix rules -%.o: %.c +build/%.o: %.c @echo ' HOST CC $<' - @${HOST_CC} ${HOST_CFLAGS} -c -o $@ $< + @mkdir -p $(dir $@) + @${HOST_CC} ${HOST_CFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $< -%.o: %.cc +build/%.o: %.cc @echo ' HOST CXX $<' - @${HOST_CXX} ${HOST_CXXFLAGS} -c -o $@ $< + @mkdir -p $(dir $@) + @${HOST_CXX} ${HOST_CXXFLAGS} -MD -MT $@ -MF $(@:.o=.d) -c -o $@ $< .PHONY: test test.quiet valgrind valgrind.quiet clean.base FORCE test: ${TESTS} |