Search code examples
makefileautoconfautomake

Order-only prerequisite inside automake file


I wonder if it is possible add an order-only prerequisite in a Makefile.am

pkglibexec_PROGRAMS = atarget
EXTRA_atarget_PREREQUISITE = | target_prereq_1 target_prereq_2         # <=pseudo code

So that the generated Makefile would apply those prerequisities.

As a workaround I currently use the generated code for the target from Makefile copied into Makefile.am It looks this way:

pkglibexec_PROGRAMS = atarget
...
atarget_gen_program: some_source.cl
    cat $^ > $@

cl_generate: atarget_gen_program
    xxd -i $< > cl_gen_header.h
    @rm -f $<

cl_header:
    sed -i "1 s|^|/*awesome commentary*/|" cl_gen_header.h

...
$(pkglibexec_PROGRAMS)$(EXEEXT): | cl_generate cl_header $(atarget_OBJECTS) $(atarget_DEPENDENCIES) $(EXTRA_atarget_DEPENDENCIES) 
    @rm -f atarget$(EXEEXT)
    $(AM_V_CCLD)$(LINK) $(atarget_OBJECTS) $(atarget_LDADD) $(LIBS)

This seems to be working, yet there is perhaps not related problem, hence if I run make in multiple-job mode (i.e. make -j 4) the prerequisites at my case are not ,coupled' in a job and cl_generate does not seem to be ,on time' when cl_header target is already triggered, resulting in an error within sed command in the latter target.

I would be appreciate even if anybody proves the concept is entirely wrong and enlighten the stuff for me. Thanks a lot.


Solution

  • I recommend you do not do it that way.

    You can write any standard makefile text in automake files: they are just makefiles, with a bunch of boilerplate added for you afterwards.

    So, you can just write this as a standard make rule to define the order-only targets you don't need to add them into the extra prerequisites variable:

    atarget: | target_prereq_1 target_prereq_2