开发者

Automake: dependency on build result

I use automake and autoc开发者_Go百科onf.

In the subdirectory src/ the Makefile.am contains

bin_PROGRAMS = hello
hello_SOURCES = hello.c

After building hello I want to run a tool (some analyzer/optimizer installed on the system) on the binary to modify it (e.g. strip) or generate statistics (e.g. dwarves, pahole ...). For this purpose the Makefile.am in the top-level-directory contains

tool:
         tool src/hello

When building hello with make and executing make tool everything is fine. The problem occurs when the user runs make tool without building the binary. How can I enforce building the bin_PROGRAMS (which may be a list) or just the hello binary as dependency of the target tool?

Neither

tool: bin_PROGRAMS
         tool src/hello

nor

tool: src/hello
         tool src/hello

work.


A Makefile target named 'tool' is supposed to create a file named 'tool'. Since 'tool' already exists, Make assumes that it does not need to run the command again (I'm simplifying, but only a little).

A construct like this should work:

tool_output: tool src/hello
    tool src/hello > tool_output

Also, in general I believe you cannot use bin_PROGRAMS or any other Automake variable (assigned with =) as a dependency, but I could be wrong.


You want:

tool: $(bin_PROGRAMS)

But you'll have the same problem as if you specify src/hello explicitly. (Namely, the top level Makefile doesn't know how to build hello in src.) You'd probably be better off doing something like:

tool:
        cd src && $(MAKE) $(AM_MAKEFLAGS) tool

in the top level and put the actual rule in src/Makefile.am, where you can list the dependency. But that's a pretty bad idea, too. Probably the best thing to do is use an all-local rule and put something like:

all-local:
        tool hello

in src/Makefile.am. This will ensure that tool is run whenever you run make with no arguments, but it will not update the output when hello is rebuilt. If that is acceptable, then this is a reasonable solution. Another option is to do:

tool-output: hello
        tool hello

in src/Makefile.am and list tool-output in noinst_DATA in src/Makefile.am.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜