From b078354aa1a2e24c827307764521e9666670eb11 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 10 Dec 2014 19:16:03 -0800 Subject: Throwing away old dependency system. * Makefile (DEPGEN): New macro variable. (OPT_OBJS, DBG_OBJS): Define with := assignment. (OBJS): New variable. (dbg/%.o, opt/*.o): Use -MMD and -MT options of gcc to generate dependencies. Also use DEPGEN macro to rewrite each dependency makefile's rule into a DEP_ variable assignment. (DEP_INSTANTIATE): New macro variable. (include dep.mk): Removed, replaced by eval hack that includes all the .d files and instantiates the rule from the DEP_ variable in each one. (opt/lex.yy.o, dbg/lex.yy.o): We need to hard code the dependency of these on y.tab.h, to force that header to generate. (DEP_opt/lex.yy.o, DEP_dbg/lex.yy.o): New variables, related to above. (depend): Target removed. * dep.mk: File removed. * depend.txr: File removed. --- Makefile | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index cc9d32df..56169677 100644 --- a/Makefile +++ b/Makefile @@ -58,8 +58,9 @@ MPI_OBJS := $(addprefix mpi-$(mpi_version)/,$(MPI_OBJ_BASE)) OBJS += $(MPI_OBJS) -DBG_OBJS = $(call ADD_CONF,dbg,$(OBJS) $(OBJS-y)) -OPT_OBJS = $(call ADD_CONF,opt,$(OBJS) $(OBJS-y)) +DBG_OBJS := $(call ADD_CONF,dbg,$(OBJS) $(OBJS-y)) +OPT_OBJS := $(call ADD_CONF,opt,$(OBJS) $(OBJS-y)) +OBJS := $(DBG_OBJS) $(OPT_OBJS) TXR := ./$(PROG) @@ -75,16 +76,23 @@ ABBREV = $(if $(VERBOSE),\ @printf "%s %s -> %s\n" $(1) "$(filter-out $(DEP_$@),$^)" $@) ABBREV3 = $(if $(VERBOSE),@:,@printf "%s %s -> %s\n" $(1) "$(3)" $(2)) +define DEPGEN +$(V)sed -e '1s/^/DEP_/' -e '1s/: [^ ]\+/ :=/' < $(1) > $(1:.d=.v) +endef + dbg/%.o: %.c $(call ABBREV,CC) $(V)mkdir -p $(dir $@) - $(V)$(CC) $(CFLAGS) -c -o $@ $< + $(V)$(CC) -MMD -MT $@ $(CFLAGS) -c -o $@ $< + $(call DEPGEN,${@:.o=.d}) opt/%.o: %.c $(call ABBREV,CC) $(V)mkdir -p $(dir $@) - $(V)$(CC) $(OPT_FLAGS) $(CFLAGS) -c -o $@ $< + $(V)$(CC) -MMD -MT $@ $(OPT_FLAGS) $(CFLAGS) -c -o $@ $< + $(call DEPGEN,${@:.o=.d}) +# The following pattern rule is used for test targets built by configure %.o: %.c $(call ABBREV,CC,$<) $(V)$(CC) $(OPT_FLAGS) $(CFLAGS) -c -o $@ $< @@ -102,9 +110,18 @@ $(PROG)-dbg: $(DBG_OBJS) VPATH := $(top_srcdir) --include $(top_srcdir)/dep.mk +# Pull in dependencies +-include $(OBJS:.o=.d) $(OBJS:.o=.v) -lex.yy.c: parser.l config.make +opt/lex.yy.o: y.tab.h +dbg/lex.yy.o: y.tab.h +DEP_opt/lex.yy.o += y.tab.h +DEP_dbg/lex.yy.o += y.tab.h + +$(eval $(foreach dep,$(OPT_OBJS:.o=.d) $(DBG_OBJS:.o=.d),\ + $(call DEP_INSTANTIATE,$(dep)))) + +lex.yy.c: parser.l $(call ABBREV,LEX) $(V)rm -f $@ $(V)$(LEX) $(LEX_DBG_FLAGS) $< @@ -148,10 +165,6 @@ distclean: clean rm -f config.h config.make config.log rm -rf mpi-$(mpi_version) -.PHONY: depend -depend: - txr $(top_srcdir)/depend.txr $(OPT_OBJS) $(DBG_OBJS) > $(top_srcdir)/dep.mk - TESTS_TMP := txr.test.out TESTS_OUT := $(addprefix tst/,\ $(patsubst %.txr,%.out,\ -- cgit v1.2.3