From 3285a49dd871d54c1ec13076173ad617443baae1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 25 Jun 2011 13:20:37 -0400 Subject: 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 Signed-off-by: Artem Bityutskiy --- common.mk | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'common.mk') 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)/.$(