0

This question builds upon How to generate a source file when building using autotools

I want to do something like

<generated-c-files>: input.txt generator
    ./generator input.txt      # produces <generated-c-files>

The earlier question answers this scenario when the generated c file(s) have fixed name(s) known a priori. However, I have a variable number of files with variable names being generated, depending on the contents of input.txt. What is a good way to do it with autotools?

I am using wildcards to pick up all generated files, which are being placed in a single build folder. However, this requires me to make twice, where the first make fails to link. This seems to be because the wildcard is evaluated before generator is executed. I would like to do it with one successful make and, preferably, not use wildcards.

Community
  • 1
  • 1
  • Do the generated files have a common patternt or anything? – Etan Reisner Aug 02 '13 at 15:42
  • If the output files differ from the inputs in extension only, then a suffix rule can be used. General pattern rules are a GNU extension. – Jack Kelly Aug 03 '13 at 07:20
  • You cannot use a pattern or suffix rule if the target files do not exist, and the list of preqrequisite files is not known. For instance, suppose you don't know what C sources make up the C program. If the .o files all exist from a previous build, then you can infer that the program is made up of all the .o's, and for each .o you can infer that the corresponding .c is a prerequisite. However, when the .o files do not exist (clean (re-)build), oops! – Kaz Oct 24 '13 at 06:20

1 Answers1

0

I would say that since the responsibility for parsing input.txt is encapsulated within generator, it is generator which can tell you what files are to be generated. It should have some options for that, so you can do stuff like, for instance:

GENERATED_C_FILES := $(shell ./generator --list-output-files input.txt)

# We don't list generator as a prerequisite here because it has to exist
# for the above to work.

$(GENERATED_C_FILES): input.txt
    ./generator input.txt

There are hacks that can be done to get make to detect that generator is missing, rebuild it, and re-run itself. But, more simply and clearly, maybe the generator build-time utility can be produced at ./configure time, so that it can be relied upon to be there at make time.

Kaz
  • 55,781
  • 9
  • 100
  • 149