I would like use automake to process/modify the binaries before they are installed. For example, I would like to extract the symbols from the binary into a separate file and location (like this). Another example is to collect the md5sums of critical assets for publishing a report.
This is a simplified (but representative) Makefile.am that I have:
abc_PROGRAMS = foo
foo_SOURCES = foo.cpp
pqr_PROGRAMS = bar
bar_SOURCES = bar.cpp
ALL_SYMS := $(PROGRAMS:%=%.sym)
sym_DATA = $(ALL_SYMS)
# A convenient target such as "make foo.sym" will trigger this rule:
$(ALL_SYMS): %.sym : %
...
objcopy --preserve-dates --only-keep-debug $< $@
objcopy --preserve-dates --strip-all --add-gnu-debuglink=$@ $<
...
I have tried a few ways to hook in my script in during install, but with limited success.
One potential way is using install-exec-local:
install-exec-local: $(ALL_SYMS)
The problem with install-exec-local is that when I use: "make install -j", the install-exec-local target runs in parallel with the install, so binaries foo and bar get installed into at their respective destination dirs, even while they are being were being modified by the %.sym rule, thereby potentiall messing up the installed files. However this solution works if -j is not used. I would like if I can leverage the advantages of using -j.
Another potential way is using install-exec-hook:
install-exec-hook: $(ALL_SYMS)
The problem with install-exec-hook is that the programs foo and bar are already installed before I get a chance to modify them using the %.sym rule. Besides foo and bar get installed at different locations, I don't have a generic way to get their destination locations while writing a suitable install-exec-hook rule.
Another potential way is to define STRIP_PROGRAM or something equivalent, but that does not work really well, because i think it won't work with the "make install" target, but only with "make install-strip -j". I have not gone this path, because our build scripts use "make install -j".
Another way is to do it is by creating build rules that run during build time rather than install time. But this one is really cumbersome, that it creates many files in the build directory and I would like to avoid it. Also new people in the project while adding new programs can easily bypass these finely tuned elaborate arrangements.
abc_PROGRAMS = foo foo : foo.tmp foo.sym : foo noinst_PROGRAMS = foo.tmp foo_tmp_SOURCES = foo.cpp pqr_PROGRAMS = bar bar : bar.tmp bar.sym : bar noinst_PROGRAMS += bar.tmp bar_tmp_SOURCES = bar.cpp sym_DATA = foo.sym bar.sym foo bar: % : %.tmp ... cp $@ $< objcopy --only-keep-debug $@ $@.sym objcopy --strip-all --add-gnu-debuglink=$@.sym $@
I would have loved if automake provided a hook which ran before a program is installed, or just after a program is built.
The stackoverflow.com community is really making a difference to the quality of solutions that are available on the internet. I am sure someone must have faced a problem similar to mine. I am awaiting good solutions or industry best practices on this issue. Lastly, I apologize for not being able to make the question much more brief or easier to understand.