Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple makefiles in one directory

Tags:

makefile

I have a makefile in a directory of mine which builds scripts with certain environment variables set. What if I want to create another makefile in the same directory with different environment variables set? How should I name the two make files? Does makefile.1 and makefile.2 work? How do I call them?

like image 745
William Jia Avatar asked Aug 21 '12 15:08

William Jia


People also ask

Can you have two makefiles in the same directory?

If you use more than one ' -f ' or ' --file ' option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names GNUmakefile , makefile and Makefile are not checked automatically if you specify ' -f ' or ' --file '.

How do I combine two makefiles?

Simply use make -f xyz.mk to get this makefile in action. The next thing is, that you can also include one makefile from another with "include".

How makefiles can be used to manage large C projects?

Makefile is a set of commands (similar to terminal commands) with variable names and targets to create object file and to remove them. In a single make file we can create multiple targets to compile and to remove object, binary files. You can compile your project (program) any number of times by using Makefile.

What is $@ in makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.


2 Answers

You can give sensible names to the files like makefile.win and makefile.nix and use them:

make -f makefile.win make -f makefile.nix 

or have a Makefile that contains:

win:   make -f makefile.win  nix:   make -f makefile.nix 

and use make win or make nix

like image 134
perreal Avatar answered Sep 20 '22 14:09

perreal


You can name makefile whatever you want. I usually name it like somename.mk. To use it later you need to tell make what makefile you want. Use -f option for this:

make -f somename.mk 
like image 44
Leonid Volnitsky Avatar answered Sep 18 '22 14:09

Leonid Volnitsky