0

I want to achieve the following syntax using a makefile:

make install program1
make install program2

Right now i have a simple makefile:

install:
    #installing program1...

What is the cleanest way to achieve the syntax i want?

amit levin
  • 183
  • 1
  • 2
  • 15
  • 1
    Possible duplicate of [Passing additional variables from command line to make](http://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make) – michael_bitard Jun 08 '16 at 09:51
  • It's unclear what you mean. What's the "nesting"? What do you want to achieve? – Mike Kinghan Jun 08 '16 at 10:44
  • Maybe nested isn't a good description. It comes from my logic of the command is: i'm looking for an installation in the make file, which is for program1. I was expecting that nested logic to be somehow applied to the makefile. something like: install: program1: .. program2: .. – amit levin Jun 08 '16 at 13:48
  • 1
    @TimF answers you question. You don't like that answer, but you can't have the answer you consider more elegant. The `make` commandline syntax is: `make [FLAGS] [(VAR=VALUE|TARGET)...]`. So `make install program1` means: make targets `install` and `program1`. and `make install PROGRAM=progam1` means: make target install with `$(PROGRAM)` = `program1`. Nothing you can do in a makefile can change that. You'd have to change `make`. – Mike Kinghan Jun 08 '16 at 14:47

1 Answers1

0

You can have a variable called PROGRAM=... in your Makefile and your target install would look like :

install:
#installing $(PROGRAM)

Then you could call make like this :

make install PROGRAM=program1
Tim
  • 1,853
  • 2
  • 24
  • 36
  • I know, but i think it is less elegant than: make install program1 – amit levin Jun 08 '16 at 13:45
  • @amitlevin It might be less elegant, but other solutions (like looking inside the `$(MAKECMDGOALS)`) inside the Makefile have much much less elegant implementation. – Dummy00001 Jun 08 '16 at 15:13
  • If "install" is the default target, you can get a little closer to the behavior your looking for by using the variable name "install" instead of "PROGRAM", allowing you to type "make install=program1" – Eric Miller Jun 11 '16 at 14:23