views:

65

answers:

3

Hello,

I have the following macros in my make file:


pdf: // do something

clean: // just another fancy thing


No I want to declare a macro all: which include (or call) the macros above. The following thing doesn't work:


all: pdf: clean:


I don't want to repeat the code from pdf: and clean: in order not to rebel against DRY principle.

Thanks for your help.

+2  A: 

Those are not macros, they are targets.

Makefiles take the syntax of [target]: [dependent target 1] [dependent target 2]

Try:

all: pdf clean
Yann Ramin
Thanks theatrus, I think I must learn at least the basics of makefile.
Matthias Guenther
A: 

You also can run:

make clean pdf

Any way, all is commonly used as a default make target - in other words executing make without argument is same as calling make all. This maybe very confusing for expirienced users, therefore if you want "such a shortcut", call it deferently (e.g. cpdf)

dimba
Thanks idimba for this shortcut idea!
Matthias Guenther
+1  A: 

executing make without argument is same as calling make all.

That's not correct. The first normal target in the file is the default target. There's nothing magical about all, though it is conventional to use that as the first target.

Larry Engholm
"it is conventional to use that as the first target" - with myown makefiles, I prefer to have that be `help`, which echoes the makefile's options to stdout.
Charles Stewart