help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

only run submake if that submake needs to be run?


From: David Wuertele
Subject: only run submake if that submake needs to be run?
Date: Mon, 09 Aug 2004 16:23:40 -0700
User-agent: Gnus/5.090018 (Oort Gnus v0.18) Emacs/21.2 (gnu/linux)

I have a large project that is made up of many small projects.
The small projects are very similar to each other --- each submake
looks something like this:

  PROGRAM := my_program_name
  EXTRA_CFLAGS += -DTHISFLAG -DTHATFLAG

  -include ../Rules.mk

Not only does the Rules.mk file have syntax for taking the above
information and turning it into compilation rules, but it also has a
rule for printing out what the submakes targets are and what are all
the files that they could possibly depend upon:

  report-installtargets:
        @echo $(INSTALL_TARGETS)
  report-sourcefiles:
        @echo $(EVERY_SOURCEFILE)

So the big project makefile can discover whether a specific component
needs to be remade, like this:

  define COMPONENT_template
    $(shell make -s -C $(1) $(SUBMAKEARGS) report-installtargets): $(shell make 
-s -C $(1) $(SUBMAKEARGS) report-sourcefiles); make -C $(1) $(SUBMAKEARGS)
  endef

  $(foreach component,$(SYSTEM_COMPONENTS),$(eval $(call 
COMPONENT_template,$(component))))

The problem with this is that it is too coarse-grained:  the submake
gets run if ANY of the source files are newer than ANY of the target
files, even if those particular source files aren't used in the making
of those particular target files.

So the submake often gets run even when unnecessary.  This is not a
severe problem, just an annoyance that I'd like to avoid.

If I could get the submake to output a set of dependencies, something
like this:

  # make -C subdir123 tell-me-your-dependencies
  /path/to/program1: ./subdir123/program1.c ./subdir123/program1-another.c ; 
make -C subdir123
  /path/to/program2: ./subdir123/program2.c ; make -C subdir123
  /path/to/program3: ./subdir123/program3.c ./subdir123/program3-another.c ; 
make -C subdir123
  # make -C subdir456 tell-me-your-dependencies
  /path/to/program4: ./subdir456/program4.c ./subdir456/program4-another.c ; 
make -C subdir456
  /path/to/program5: ./subdir456/program4.c ./subdir456/program5.c 
./subdir456/program6.c ; make -C subdir456
  /path/to/program6: ./subdir456/program6.c ./subdir456/program6-another.c ; 
make -C subdir456
  # 

Then I could use that output to make a finer grained project makefile:

  SYSTEM_COMPONENTS := subdir123 subdir456

  define COMPONENT_template
    $(shell make -C $(1) $(SUBMAKEARGS) tell-me-your-dependencies)
  endef

  $(foreach component,$(SYSTEM_COMPONENTS),$(eval $(call 
COMPONENT_template,$(component))))

This would then only run the submake if one of the origin files were
newer.

Is there any way to acheive this goal with GNU Make 3.80?

Thanks,
Dave





reply via email to

[Prev in Thread] Current Thread [Next in Thread]