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?
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 '.
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".
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.
$@ 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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With