7

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 $< $*
6
  • this should work, are you sure you are not confusing the location of Optional?
    – perreal
    Commented Jan 8, 2013 at 3:36
  • 1
    Possible duplicate of How can I make a pattern rule dependency optional in a Makefile? Voting to close this way because the other has the right answer. Commented May 13, 2017 at 18:41
  • 1
    @CiroSantilli709大抓捕六四事件法轮功 this was asked two years before that one - wish someone had mentioned that I just needed a second dollars sign! $$(wildcard %Optional.xml) probably would have worked. Commented May 18, 2017 at 0:12
  • @austinmarton yes... correct answers improve the world a little bit :-) Commented May 18, 2017 at 5:32
  • despite the age difference, please accept the duplicate flag so seekers find the answer more quickly
    – xeruf
    Commented Nov 18, 2022 at 3:22

1 Answer 1

0

when you use the function wildcard, the wildcard character is *, not %

($wildcard *Optional.xml)

1
  • This doesn't seem to work either, also tried $(wildcard *Optional.xml) Commented Jan 9, 2013 at 0:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.