I have some .c and .h files that are generated by a script based on one XML file and optionally another XML file.
From what I've read I should be able to use a wildcard, for example:
%Generated.c %Generated.h : %Compulsory.xml $(wildcard %Optional.xml)
generation-script $< $*
The files XXXGenerated.c/h are being regenerated when I change XXXCompulsory.xml but not when I change XXXOptional.xml. Does anyone know why?
I can get around the problem with duplicate rules as follows:
%Generated.c %Generated.h : %Compulsory.xml
generation-script $< $*
%Generated.c %Generated.h : %Compulsory.xml %Optional.xml
generation-script $< $*
but I would have thought there was a better way to specify an optional dependency?
Thanks!
Note: This same question has been asked before (e.g. How to manage C header file dependencies? ) but in this case I can't have the compiler generate a .d file.
Edit: The location for Optional.xml is fine because it works if I specify only the rule:
%Generated.c %Generated.h : %Compulsory.xml %Optional.xml
generation-script $< $*
And try to compile only for a target which Optional.xml exists.
But I've noticed that doesn't work with the parenthesis:
%Generated.c %Generated.h : %Compulsory.xml $(%Optional.xml)
generation-script $< $*
$$(wildcard %Optional.xml)
probably would have worked.