LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Makefile - passing argument to make? (https://www.linuxquestions.org/questions/linux-software-2/makefile-passing-argument-to-make-793612/)

gayleard 03-06-2010 09:54 AM

Makefile - passing argument to make?
 
I have a number of projects, say test1, test2, test3, ...
I want to make and install all of them in exactly the same way;
so I would like to say
make test2
make install test2
with the same Makefile.

In othe words, I would like to pass the argument test2 (or just 2)
to the Makefile, so this is taken as the target for make
or make install.

This must be a common wish;
but I don't see any appropriate option with "man make"
on my Fedora-12 system.

Any help gratefully received.

irmin 03-06-2010 07:14 PM

There are several options to perform your task:

create a rule install-% for % in test1,test2,test3:
Code:

install-test1:
# install test1

install-test2:
# install test2

install-test3:
# install test3

Or create a rule "install-%:" (in gmake) and refer to the name by $@.

One last options would be to set a variable on calling make:
Code:

make TARGETS=test1 install


All times are GMT -5. The time now is 05:37 PM.