English 中文(简体)
How to use pattern-dependent variables in dependencies in make pattern rules
原标题:

I d like to define a GNU make pattern rule with the dependencies in a pattern-dependent variable. What I d like is something like this:

%.exe : $(%_EXE_SOURCES) $(%_EXE_RESOURCES)
    $(CSC_V)$(CSC) $(CSCFLAGS) $($*_EXE_CSCFLAGS) -target:exe 
            -out:$@ $($*_EXE_SOURCES) $($*_EXE_RESOURCES)

And to later define something like

FOO_EXE_SOURCES = src/Foo.cs
all: Foo.exe

The rule presented works to build; in the body of the rule the $($*_EXE_SOURCES) variable is expanded to $(FOO_EXE_SOURCES), which expands to src/Foo.cs. The dependencies don t expand properly, however; changing src/Foo.cs does not cause Foo.exe to be rebuilt.

I suspect that this can t actually be done in make, but perhaps someone has a work-alike make fragment?

最佳回答

You could use "secondary expansion". Something like this should accomplish what you are looking for:

Foo_EXE_SOURCES := foo.cs bar.cs baz.cs
all: Foo.exe

.SECONDEXPANSION:
%.exe: $$($$*_EXE_SOURCES)
    $(CSC_V)$(CSC) $(CSCFLAGS) $($*_EXE_CSCFLAGS) -target:exe 
            -out:$@ $($*_EXE_SOURCES) $($*_EXE_RESOURCES)

Enabling secondary expansion allows the use of automatic variables (i.e. $* in this case) in the prerequesites list, which is something that would otherwise not work.

问题回答

暂无回答




相关问题
makefile: how to show line numbers for debugging?

Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...

What is the reasoning behind the Makefile whitespace syntax?

I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...

Debugging GNU make

Is there a command line way in make to find out which of the prerequisites of a target is not updated?

How to add an all rule to this Makefile?

I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...

Using extern in C doesn t work as expected

I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...

热门标签