Welcome to little lamb

Code » comain » commit 41441cd

Put object & dependency files into obj/

author Olivier Brunel
2023-02-06 10:04:48 UTC
committer Olivier Brunel
2023-02-06 10:04:48 UTC
parent 091378621d06d371a495ba10471c63b9ac341ef3

Put object & dependency files into obj/

common.mk +11 -6
mkdirobj +5 -0

diff --git a/common.mk b/common.mk
index 176de90..77c8ef7 100644
--- a/common.mk
+++ b/common.mk
@@ -17,9 +17,9 @@ LDFLAGS_SHARED   = -shared -Wl,--hash-style=gnu
 
 SRCS  = $(wildcard src/*.c src/*/*.c)
 ASMS  = $(wildcard src/*.S src/*/*.S)
-OBJS  = $(SRCS:.c=.o) $(ASMS:.S=.o)
-OBJS += $(SRCS:.c=.lo)
-DEPS  = $(SRCS:.c=.d) $(ASMS:.S=.d)
+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)
 BINS  =
 LIBS  =
 SHARED_LIBS = $(patsubst %,lib%.so,$(LIBS))
@@ -31,13 +31,16 @@ DATA =
 # to be removed upon `make clean`
 CLEAN = $(BINS) $(STATIC_LIBS) $(SHARED_LIBS) $(OBJS) $(DEPS)
 
-%.o: %.c Makefile common.mk config.mk project.mk
+obj: comain
+	$(_DIR) comain/mkdirobj
+
+obj/%.o: src/%.c Makefile common.mk config.mk project.mk | obj
 	$(_CC) $(COMMON_CPPFLAGS) $(CPPFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(<:src/%.c=%)) $(CFLAGS) -o $@ -c $<
 
-%.o: %.S Makefile common.mk config.mk project.mk
+obj/%.o: src/%.S Makefile common.mk config.mk project.mk | obj
 	$(_CC) $(COMMON_CPPFLAGS) $(CPPFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(<:src/%.c=%)) $(CFLAGS) -o $@ -c $<
 
-%.lo: %.c Makefile common.mk config.mk project.mk
+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 $<
 
 lib%.a:
@@ -115,6 +118,7 @@ install: install-bins install-libs install-docs install-data
 
 clean:
 	$(_CLEAN) rm -f $(CLEAN)
+	@rm -rf obj
 
 cleandeps:
 	$(_CLEAN) rm -f $(BUILD_DEPS)
@@ -126,6 +130,7 @@ distclean: clean cleandeps
 repoclean: distclean
 	$(_CLEAN) rm -f configure common.mk
 
+_DIR = $(if $(V),,$(call say," DIR  ")$@;)
 _CP = $(if $(V),,$(call say,"  CP  ")$@;)
 _CC = $(if $(V),$(CC),$(call say,"  CC  ")$@;$(CC))
 _AR = $(if $(V),,$(call say,"  AR  ")$@;)
diff --git a/mkdirobj b/mkdirobj
new file mode 100755
index 0000000..6fe3bbb
--- /dev/null
+++ b/mkdirobj
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+find src -type d -printf '%P\n' | while read -r dir; do
+    if test ! -e "obj/$dir"; then mkdir "obj/$dir"; fi
+done