Reputation: 189
I have a Makefile.am
that looks something like this:
bin_PROGRAMS = prog
AM_CFLAGS = $(prog_CFLAGS)
prog_SOURCES = \
data.h \
src1.c \
src2.c \
...
src30.c
The data.h
file is sometimes updated by a update_data.pl
perl script depending on certain conditions. I tried adding this to the end of Makefile.am
:
.PHONY: data.h
data.h:
perl update_data.pl
but the script never runs. I'm sure I'm missing something simple, but I just can't figure it out.
Upvotes: 0
Views: 305
Reputation: 189
This is how I finally got it to work. Using $(shell)
may not be the best way, but it works.
bin_PROGRAMS = prog
AM_CFLAGS = $(prog_CFLAGS)
update_data := $(shell ./update_data.pl > /dev/tty)
prog_SOURCES = \
data.h \
src1.c \
src2.c \
...
src30.c
Upvotes: 0
Reputation: 37747
I am doing something similar for updating a header file with a few defines depending on the current git branch, HEAD commit, tree dirty state.
There might be a few uncaught corner cases, but it works for me. May it give you some inspiration.
CLEANFILES += git-info.h
BUILT_SOURCES += git-info.h.stamp
git-info.h.stamp:
echo "#ifndef GIT_INFO_H" > git-info.h.new
echo "#define GIT_INFO_H" >> git-info.h.new
echo "..." >> git-info.h.new
echo "#endif" >> git-info.h.new
if test -f git-info.h && cmp git-info.h.new git-info.h; then :; \
else cat git-info.h.new > git-info.h; fi; \
rm -f git-info.h.new
Notes:
The stamp file is never created, and thus this rule will always be executed on "make all" (not on "make my-program", though).
git-info.h
is only ever touched if it has actually changed. This
avoids rebuilds caused just by an updated timestamp of git-info.h
without any changes to the content.
To reduce the rebuild effort when git-info.h
has changed, I
only include the generated git-info.h
header from a single
regular C my_program_SOURCES
source file git-info.c
which
then defines a few global char foo[] = FOO;
symbols which
will then be linked to the final executable.
The git-info.o
file will automatically depend on git-info.h
,
which will cause a rebuild when the header has changed.
Upvotes: 0
Reputation: 3240
Since you already have a data.h
file, and it doesn't depend on anything, make
thinks there's nothing to do to update it.
There's not really a good way to tell make
to always recreate the file. You can have it depend on the update_data.pl
file, if you want to regenerate it when you update the script. Or you can have it depend on the data file (as well as the script) if it's parsing and converting a data file.
But if your build is not hermetic, and the content depends on something make
can't know about, there's no good way to solve your problem.
Upvotes: 1