Reputation: 2484
I'm porting a home-baked makefile
setup into the autotools suite. I've run into a problem for which I haven't yet found a suitable answer. It may be that I'm just not using the correct terms in my searches. Being a complete neophyte to autotools, I probably just don't know enough of the jargon.
The problem: our build process has a dependency for a header file which is generated from a csv file. (I don't know why. It is what it is.) In our old system, we did something like this:
.PHONY: all
all : header.csv.h $(objects)
header.csv.h:
python prebuild.py
# remainder for building objects and the file lib.a
Finding this link to extend default rules, I've added this to my Makefile.am
noninst_LIBRARIES = libstuff.a
# .. Additional CXXFLAGS and CPPFLAGS, and listing the sources
all-local: header.csv.h
header.csv.h:
python prebuild.py
The remade Makefile
s still didn't work. Inspection of the generated Makefile
for this part of the library showed this:
# lots of stuff preceeding
all: all-am
all-am: Makefile $(LIBRARIES) all-local
all-local: header.csv.h
# the rest as above
Right there in all-am:
is the problem. The $(LIBRARIES)
dependencies are listed first and are therefore being built first. Some further reading on the extending link above shows this is to be expected: no way to guaranteeing the order. It's simple enough to "fix": move all-local
to precede $(LIBRARIES)
. However, this only fixes it once. I must guarantee this is always built first.
Can I add things to the configure
script to be executed during the configuration process? What's the right way to handle something like this?
Upvotes: 0
Views: 444
Reputation: 283684
You're not supposed to write rules which depend on the order things are listed in the Makefile. There's no reason to have this rule at all (I understand it's a direct translation of your old Makefile -- which was also wrong):
all-local: header.csv.h
because header.csv.h
is not a build product that needs to appear at the end of the make process. Instead you need
somesourcefile.o : header.csv.h
reflecting the true fact, that building somesourcefile.o requires the header file to exist, because somesourcefile.cpp includes it. If it is included in multiple places, you might need multiple of these rules.
When you specify dependencies correctly, make
will calculate the dependency graph, and build things in the correct order.
Also, this rule
header.csv.h:
python prebuild.py
should almost certainly be
header.csv.h : header.csv prebuild.py
python prebuild.py
to make sure it gets rebuilt when either the source data or the translation rules change, and not when they don't.
Upvotes: 1