Running Linux, 5th Edition - Matthias Kalle Dalheimer [390]
@if [ -x /bin/dnsdomainname ]; then \
echo #define LINUX_COMPILE_DOMAIN \"`dnsdomainname`\"; \
else \
echo #define LINUX_COMPILE_DOMAIN \"`domainname`\"; \
fi >> tools/version.h
Another convention is to put a hyphen before a command, which tells make to keep going even if the command fails. This may be useful if you want to continue after an mv or cp command fails:
- mv edimh /usr/local
- mv readimh /usr/local
Including Other makefiles
Large projects tend to break parts of their makefiles into separate files. This makes it easy for different makefiles in different directories to share things, particularly macro definitions. The line
include filename
reads in the contents of filename. You can see this in the Linux kernel makefile, for instance:
include .depend
If you look in the file .depend, you'll find a bunch of makefile entries: these lines declare that object files depend on particular header files. (By the way, .depend might not exist yet; it has to be created by another entry in the makefile.)
Sometimes include lines refer to macros instead of filenames, as in the following example:
include ${INC_FILE}
In this case, INC_FILE must be defined either as an environment variable or as a macro. Doing things this way gives you more control over which file is used.
Interpreting make Messages
The error messages from make can be quite cryptic, so we'd like to give you some help in interpreting them. The following explanations cover the most common messages.
*** No targets specified and no makefile found. Stop.
This usually means that there is no makefile in the directory you are trying to compile. By default, make tries to find the file GNUmakefile first; then, if this has failed, Makefile, and finally makefile. If none of these exists, you will get this error message. If for some reason you want to use a makefile with a different name (or in another directory), you can specify the makefile to use with the -f command-line option.
make: *** No rule to make target 'blah.c', needed by 'blah.o'. Stop.
This means that make cannot find a dependency it needs (in this case, blah.c) in order to build a target (in this case, blah.o). As mentioned, make first looks for a dependency among the targets in the makefile, and if there is no suitable target, for a file with the name of the dependency. If this does not exist either, you will get this error message. This typically means that your sources are incomplete or that there is a typo in the makefile.
*** missing separator (did you mean TAB instead of 8 spaces?). Stop.
The current versions of make are friendly enough to ask you whether you have made a very common mistake: not prepending a command with a tab. If you use older versions of make, missing separator is all you get. In this case, check whether you really have a tab in front of all commands, and not before anything else.
Autoconf, Automake, and Other Makefile Tools
Writing makefiles for a larger project usually is a boring and time-consuming task, especially if the programs are expected to be compiled on multiple platforms. From the GNU project come two tools called Autoconf and Automake that have a steep learning curve but, once mastered, greatly simplify the task of creating portable makefiles. In addition, libtool helps a lot to create shared libraries in a portable manner. You can probably find these tools on your distribution CD, or you can download them from ftp://ftp.gnu.org/gnu.
From a user's point of view, using Autoconf involves running the program configure, which should have been shipped in the source package you are trying to build. This program analyzes your system and configures the makefiles of the package to be suitable for your system and setup. A good thing to try before running the configure script for real is to issue the command:
owl$ ./configure --help
This shows all command-line switches that the configure program understands. Many packages allow different