aboutsummaryrefslogtreecommitdiff
path: root/common.mk
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-06-25 13:20:37 -0400
committerArtem Bityutskiy <dedekind1@gmail.com>2011-06-27 09:07:07 +0300
commit3285a49dd871d54c1ec13076173ad617443baae1 (patch)
tree6b0962b6ec8437ffd54f03846f454943ea8bc443 /common.mk
parent966122b0bbb175e9d8cc9876bb455e12c1d70eb9 (diff)
rewrite build system to avoid recursion
The ubi-utils/src/ subdir is tossed as it just complicates things for no real gain. The dictionary.h header is relocated to the ubi-utils/include/ since other headers in there need it. The top level clean is replaced with a `find -delete` on objects, so it might prune more than necessary, but many projects now do this sort of thing and no one complained there. A "mkdep" helper generates the actual rule, and the variables are used with "foreach" to expand these automatically. The tests subdir is updated only to reflect the ubi-utils source move. Otherwise, it is left untouched as making that non-recursive isn't really worth the effort. While we're gutting things, also through in kbuild style output while building to make things more legible. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Diffstat (limited to 'common.mk')
-rw-r--r--common.mk48
1 files changed, 31 insertions, 17 deletions
diff --git a/common.mk b/common.mk
index 0f3d447..d0e207d 100644
--- a/common.mk
+++ b/common.mk
@@ -39,34 +39,48 @@ override BUILDDIR := $(patsubst %/,%,$(BUILDDIR))
override TARGETS := $(addprefix $(BUILDDIR)/,$(TARGETS))
-SUBDIRS_ALL = $(patsubst %,subdirs_%_all,$(SUBDIRS))
-SUBDIRS_CLEAN = $(patsubst %,subdirs_%_clean,$(SUBDIRS))
-SUBDIRS_INSTALL = $(patsubst %,subdirs_%_install,$(SUBDIRS))
+ifeq ($(V),1)
+XECHO = @:
+XPRINTF = @:
+Q =
+else
+XECHO = @echo
+XPRINTF = @printf
+Q = @
+endif
+define BECHO
+$(XPRINTF) ' %-7s %s\n' "$1" "$(subst $(BUILDDIR)/,,$@)"
+endef
-all:: $(TARGETS) $(SUBDIRS_ALL)
+all:: $(TARGETS)
-clean:: $(SUBDIRS_CLEAN)
+clean::
rm -f $(BUILDDIR)/*.o $(TARGETS) $(BUILDDIR)/.*.c.dep
-install:: $(TARGETS) $(SUBDIRS_INSTALL)
+install:: $(TARGETS)
-%: %.o $(LDDEPS) $(LDDEPS_$(notdir $@))
- $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
+define _mkdep
+$(BUILDDIR)/$1$2: $(addprefix $(BUILDDIR)/$1,$(obj-$2) $3) $(addprefix $(BUILDDIR)/,$4)
+endef
+define mkdep
+$(call _mkdep,$1,$2,$3 $2.o,$4 lib/libmtd.a)
+endef
+
+%: %.o $(LDDEPS)
+ $(call BECHO,LD)
+ $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
$(BUILDDIR)/%.a:
- $(AR) crv $@ $^
- $(RANLIB) $@
+ $(call BECHO,AR)
+ $(Q)$(AR) cr $@ $^
+ $(Q)$(RANLIB) $@
$(BUILDDIR)/%.o: %.c
ifneq ($(BUILDDIR),$(CURDIR))
- mkdir -p $(dir $@)
+ $(Q)mkdir -p $(dir $@)
endif
- $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -g -Wp,-MD,$(BUILDDIR)/.$(<F).dep
-
-subdirs_%:
- d=$(patsubst subdirs_%,%,$@); \
- t=`echo $$d | sed s:.*_::` d=`echo $$d | sed s:_.*::`; \
- $(MAKE) BUILDDIR=$(BUILDDIR)/$$d -C $$d $$t
+ $(call BECHO,CC)
+ $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -g -Wp,-MD,$(BUILDDIR)/.$(<F).dep
.SUFFIXES: