For those unfamiliar with IDL (interface description language), it abstracts data description for use across platforms (java, c, c++, etc). My project has dependencies Foo.c, Foo.h, FooHelper.c, and FooHelper.h which are generated from Foo.idl. How do I run an arbitrary command when Foo.idl changes, but still include Foo.c, FooHelper.c, in the build process?
My current attempts add a rule to the Makefile.am — the hope is that the rule is copied over to the generated Makefile.
I have tried:
Foo.idl : Foo.idl
${the_generate_command}
and then added Foo.idl to my_program_SOURCES but it doesn’t run the_generate_command when building.
I have had success generating from the IDL with
Foo.c Foo.h FooHelper.h FooHelper.c : Foo.idl
${the_generate_command}
But it won’t add Foo.c, FooHelper.c to the compile process, so they’re never built, just generated by the_generate_command!
All the code (including the idl) is in $PROJECT_DIR/src.
rq’s answer is almost correct, but misses a couple of subtleties. Try this:
The additional rules to “generate”
Foo.h,FooHelper.handFooHelper.cfromFoo.censure that parallel builds won’t try and run$(THE_GENERATE_COMMAND)twice. It is an idiom detailed in the Automake manual which will work for parallel builds. There is still a little fragility here: if the user removes (say)FooHelper.handFooHelper.cand starts a parallel make, it may run the$(MAKE) $(AM_MAKEFLAGS) $<recovery part of the rule multiple times in parallel. As the manual says, this race can only going to happen if the user manually mutilates the build tree, and even then it’s nothing amake clean; makecannot fix.The
BUILT_SOURCESline ensures thatFoo.c,Foo.h,FooHelper.handFooHelper.care built before trying to buildmyprogram(see this section of the Automake manual to see why just adding them tomyprog_SOURCESis insufficient). TheEXTRA_DISTvariable ensures that the.idlfile will be captured bymake dist(reference).MAINTAINERCLEANFILESspecifies additional files to delete when runningmake maintainer-clean; this is to comply with the GNU Makefile Standards. See also the variable’s description in the Automake manual.