Welcome to little lamb

Code » comain » commit 0c59daa

common.mk: Fix missing dependencies for .lo

author Olivier Brunel
2023-03-21 09:59:17 UTC
committer Olivier Brunel
2023-03-21 21:21:02 UTC
parent 7d0e8f335968f3bf25a8071aa68d3be5fa1c56d5

common.mk: Fix missing dependencies for .lo

Specifically, because gcc /replaces/ the suffix to .d (instead of adding
it, as the doc says) it would always create foobar.d, thusly creating it
for the .lo file, then overwriting it for the .o file.

So instead we use proper names (foobar.o.d & foobar.lo.d) and rename the
dependency file post-compilation.

common.mk +4 -1

diff --git a/common.mk b/common.mk
index a2dfae2..45780a8 100644
--- a/common.mk
+++ b/common.mk
@@ -19,7 +19,7 @@ SRCS  = $(wildcard src/*.c src/*/*.c)
 ASMS  = $(wildcard src/*.S src/*/*.S)
 OBJS  = $(SRCS:src/%.c=obj/%.o) $(ASMS:src/%.S=obj/%.o)
 OBJS += $(SRCS:src/%.c=obj/%.lo)
-DEPS  = $(SRCS:src/%.c=obj/%.d) $(ASMS:src/%.S=obj/%.d)
+DEPS  = $(OBJS:%=%.d)
 BINS  =
 LIBS  =
 TOOLS =
@@ -37,12 +37,15 @@ obj: comain
 
 obj/%.o: src/%.c Makefile common.mk config.mk project.mk | obj
 	$(_CC) $(COMMON_CPPFLAGS) $(CPPFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(<:src/%.c=%)) $(CFLAGS) -o $@ -c $<
+	@mv $(@:%.o=%.d) $(@:%.o=%.o.d)
 
 obj/%.o: src/%.S Makefile common.mk config.mk project.mk | obj
 	$(_CC) $(COMMON_CPPFLAGS) $(CPPFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(<:src/%.c=%)) $(CFLAGS) -o $@ -c $<
+	@mv $(@:%.o=%.d) $(@:%.o=%.o.d)
 
 obj/%.lo: src/%.c Makefile common.mk config.mk project.mk | obj
 	$(_CC) $(COMMON_CPPFLAGS) $(CPPFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(<:src/%.c=%)) $(CFLAGS) $(CFLAGS_SHARED) -o $@ -c $<
+	@mv $(@:%.lo=%.d) $(@:%.lo=%.lo.d)
 
 lib%.a:
 	$(_AR) $(AR) rc $@ $^