Makefile - multiple recipes calling one, with variables - only the first gets run

user1456632 :

I have set up my makefile like below, to minimize code duplication

The recipes are a set of blocks that set a variable, and then run the sleeper_agent recipe. They work great when called individually as make xlsx_sleeper for example.

But when I call all_sleepers, only the first one (xlsx_sleeper) gets compiled.

I have tried declaring them as phony (.PHONY: all_sleepers xlsx_sleeper docx_sleeper pptx_sleeper pdf_sleeper png_sleeper), which changes nothing

and adding a .FORCE rule to the sleeper_agent rule, which results in no such file or directory:

.FORCE:
sleeper_agent: .FORCE [...]

Here is my makefile:

all_sleepers: xlsx_sleeper docx_sleeper pptx_sleeper png_sleeper pdf_sleeper

sleeper_agent: $(OBJ)/sleeper_agent.o $(OBJ)/identities.o
    windres icons/$(ext)/resource.rc -O coff -o obj/$(ext).res
    $(CC) -o $(BIN)/sleeper_$(ext).exe $^ $(OBJ)/$(ext).res $(CFLAGS) $(LIBS)

xlsx_sleeper: ext=xlsx
xlsx_sleeper: sleeper_agent

docx_sleeper: ext=docx
docx_sleeper: sleeper_agent

pptx_sleeper: ext=pptx
pptx_sleeper: sleeper_agent

png_sleeper: ext=png
png_sleeper: sleeper_agent

pdf_sleeper: ext=pdf
pdf_sleeper: sleeper_agent
Renaud Pacalet :

Your problem is that make does not see any reason why it should rebuild the sleeper_agent target several times. You should probably stick to the make philosophy:

  1. Try to have real files as targets ($(BIN)/sleeper_xlsx.exe).
  2. Use phony (non-file) targets only:
    • To give symbolic names to other targets or groups of targets (all_sleepers, xlsx_sleeper, ...)
    • For rules that don't produce files (clean, help...)
  3. Declare phony targets as such (.PHONY: ...)

Example using static pattern rules, automatic variables and the patsubst make function:

SLEEPER  := xlsx docx pptx png pdf
EXE      := $(patsubst %,$(BIN)/sleeper_%.exe,$(SLEEPER))
SHORT    := $(patsubst %,%_sleeper,$(SLEEPER))

.PHONY: all_sleepers $(SHORT) clean_sleepers

all_sleepers: $(EXE)

$(SHORT): %_sleeper: $(BIN)/sleeper_%.exe

$(EXE): $(BIN)/sleeper_%.exe: $(OBJ)/sleeper_agent.o $(OBJ)/identities.o
    windres icons/$*/resource.rc -O coff -o obj/$*.res
    $(CC) -o $@ $^ $(OBJ)/$*.res $(CFLAGS) $(LIBS)

clean_sleepers:
    rm -f $(EXE)

And then you should be able to run:

make all_sleepers

to build them all or:

make xlsx_sleeper

to build only one of them. EXE is the list of real executable files and a static pattern rule explains how to build them. In its recipe the $* automatic variable expands as the string matching the % wildcard. SHORT is the list of xxxx_sleeper shortcuts and another static pattern rule explains for each of them to which real executable it corresponds. all_sleepers and the xxxx_sleeper shortcuts (plus the clean_sleepers I added as example) are properly declared as phony because there are no such real files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling multiple functions only if one gets executed with out any errors

From Dev

one hot encoding only factor variables in R recipes

From Dev

One Makefile run for multiple directories

From Dev

Makefile target multiple sources but only one target

From Dev

Calling multiple functions with code within fails to call both, only calls the first one

From Dev

Is that only an error with calling gets?

From Dev

Run a function only the first time when AngularJS gets loaded

From Dev

Realm object gets `invalidated` before write, only on first run

From Dev

If statement - Four variables, only run if one true

From Dev

Linq query and multiple where clauses with OR only first condition gets evaluated

From Dev

only getting SMTPServerDisconnected: please run connect() first when calling on server

From Dev

Multiple forms and submit buttons, but only one gets submitted?

From Dev

Multiple iFrames, only the first one loads

From Dev

Multiple Runtime Permissions - Only Requesting First One

From Dev

multiple if but only runs the first one? javascript

From Dev

makefile: multiple automatic variables

From Dev

Date in Makefile recipes

From Dev

When calling one of my functions in Node.js the program first calls emitHookFactory and gets stuck in an infinite loop

From Dev

Makefile for calling make with multiple targets

From Dev

Multiple compilers in one Makefile

From Dev

Multiple setState flutter only updating with the first one only

From Dev

calling GetAsync multiple times only executes one time

From Dev

Angularjs - Calling only one of many subcontrollers/ multiple controllers

From Dev

Force Chef to run recipes multiple times with different attributes

From Dev

How can I run two makefile targets such that the second uses the first's variables?

From Dev

Run all the commands in the code instead of only the first one in Alloy

From Dev

Makefile only creating first file

From Dev

Calling tf.session.run gets slower

From Dev

Grunt task containing multiple spawn tasks will only run the first task

Related Related

  1. 1

    Calling multiple functions only if one gets executed with out any errors

  2. 2

    one hot encoding only factor variables in R recipes

  3. 3

    One Makefile run for multiple directories

  4. 4

    Makefile target multiple sources but only one target

  5. 5

    Calling multiple functions with code within fails to call both, only calls the first one

  6. 6

    Is that only an error with calling gets?

  7. 7

    Run a function only the first time when AngularJS gets loaded

  8. 8

    Realm object gets `invalidated` before write, only on first run

  9. 9

    If statement - Four variables, only run if one true

  10. 10

    Linq query and multiple where clauses with OR only first condition gets evaluated

  11. 11

    only getting SMTPServerDisconnected: please run connect() first when calling on server

  12. 12

    Multiple forms and submit buttons, but only one gets submitted?

  13. 13

    Multiple iFrames, only the first one loads

  14. 14

    Multiple Runtime Permissions - Only Requesting First One

  15. 15

    multiple if but only runs the first one? javascript

  16. 16

    makefile: multiple automatic variables

  17. 17

    Date in Makefile recipes

  18. 18

    When calling one of my functions in Node.js the program first calls emitHookFactory and gets stuck in an infinite loop

  19. 19

    Makefile for calling make with multiple targets

  20. 20

    Multiple compilers in one Makefile

  21. 21

    Multiple setState flutter only updating with the first one only

  22. 22

    calling GetAsync multiple times only executes one time

  23. 23

    Angularjs - Calling only one of many subcontrollers/ multiple controllers

  24. 24

    Force Chef to run recipes multiple times with different attributes

  25. 25

    How can I run two makefile targets such that the second uses the first's variables?

  26. 26

    Run all the commands in the code instead of only the first one in Alloy

  27. 27

    Makefile only creating first file

  28. 28

    Calling tf.session.run gets slower

  29. 29

    Grunt task containing multiple spawn tasks will only run the first task

HotTag

Archive