views:

456

answers:

2

As part of the build I'm processing DocBook file that produces multiple HTML files (one file per chapter).

I want to postprocess those HTML files and copy them elsewhere. Those files depend on DocBook source, but I cannot know filenames in advance (filenames depend on DocBook source too).

I've got rule that sort-of works if the files are generated already:

www/manual/%.html: build/manual/%.html
   postprocess "$<" "$@"

but I don't know how to tell make to generate them, if they aren't there yet. If I just add rule for www/manual/index.html, only that file gets postprocessed, not all of them.

I suppose I need makedepend for DocBook or perhaps some nifty wildcard trick. What's the solution for this?

A: 

Are you trying to write a rule like "If there are no files at all in the manual directory then run the foo command to generate them"?

One easy possibility (a hack, given that I don't know advanced makefile usage and don't propose to invest time learning it unecessarily) would be for that specified foo command to not only create filenames that you don't know in advance, but also to create one (perhaps empty) file whose filename you do know in advance, and which you can then use as your marker for whether or not the rule has been run.

ChrisW
I've tried that - added rule for index.html, which can be expected, but that doesn't trigger postprocessing of other files, only the explicitly named one.
porneL
I thought you need two rules: 1) a rule for generation or pre-processing, which you were asking about; and 2) a rule for post-processing, which you have already, which uses wildcards, and which post-processes all the files in the directory. I was suggesting that the rule for pre-processing might depend on the existence of the one well-known index.html (and if index.html doesn't exist then the rule should generate it and also all the other html files). I don't see why creating that first rule though would affect the (unchanged) second rule (which uses a wildcard, does post-processing, ...
ChrisW
... and sort-of-works already). If, for some preculiar reason, creating and running the first rule does break the behaviour of the second rule, does it make any difference to run the second rule in a separate makefile?
ChrisW
+1  A: 

I'm going to blindly assume GNU Make here; if not, similar techniques should apply with slightly altered syntax.

If it were me, I'd use a rule akin to yours above, possibly with a file list generated by the wildcard function

And then I'd put that rule in a separate sub-makefile, called recursively

That is, in your main Makefile,


  build:
    # do the docbook processing
    $(MAKE) -f htmlprocessmakefile

That Makefile will see the full list of HTML files that have been created.

Paul Roub