A description file, some options, some general templates, some targets to be made, and some macro defnitions.
Make is a command generator, file maintainer, a project backbone able to tie together the execution or build environment.
The natural use of make is to sort out dependency relations among files; also make is commonly used to determine any pieces needed to be produced/updated, and issue any necessary commands.
The description file is also referred to as the makefile.
Its purpose is to describe some of the relationships amongst the files
and state any commands needed to update the files or bind the files together
into an entity [a library or an application or ...].
make [-f descrfile] [options] [targets] [macro definitions]
Options, targets, & macro definitions can be in any order
Several options may be combined after a single hyphen
The format of a macro defnition is name=string
If a descrfile is omitted most versions of make
search the
curr dir for (& use) a filename called 'makefile' or 'Makefile'
Some standard options :
-b | Accept description files from previous implementations of make |
-c dir | Change to directory dir before reading the makefile(s) or doing anything else. |
-d | Debug mode -print detailed info about internal flags & the last-modified times of files |
-e | Let environment variables override macro defnitions inside descrip files. |
-f | Following argument is name of the description file (if the argument is a hyphen then standard in is used) |
-i | Ignore error codes |
-I dir | Specify a directory dir to search for included makefiles. |
-k | Error terminates work on current branch of the build heirarchy, but not on other build branches. |
-n | Echo command lines, not executing them |
-o file | Do not remake the file file even if it is older than its dependencies; also do not remake anything on account of changes in file. |
-p | Print out macro definitions, suffixes, suffix rules & explicit description file entries. |
-q | Return 0 or non-0 exit status based on whether the target is up to date or not. |
-r | Do not use the default rules |
-s | Do not echo commands as they are executed. |
-t | Touch target files, without executing any other commands. |
Operation Summary
Make updates a target
if it depends on prerequisite files
that have
been modified since
the target was last
modified, or if the target does not exist.
*USE*
the macros : $@, $?, $$@, $<, $% as often as possible to simply the
description file entries
Description File Lines
Any line can be followed by a # sign and comment
Blank lines are ignored
Any line ending in \ is considered to continue on the next line [all the whitespace b4 the \ and at the beginning of the following line is compressed to a single space
Suffix Rule :
.suffix[.suffix] :[:]
Specifies that files ending with the 1st suffix can be prerequisites of files that have the same names but end with the second suffix (or no suffix, if the 2nd suffix is omitted).
No spaces are permitted between the suffixes.
Anything after a colon is ignored
Double colon has no effect [it is permitted because it is consistent with dependency lines].
Suffixes should contain only letters, digits, periods, and underscores (other characters may be allowed by various make versions)
Dependency line :
targets :[:] [ prerequisites ] [; [command] ]
Specifies that targets depend on prerequisites.
Targets & prerequisites must be separated by spaces or tabs
Spaces before and after colons are optional
No tab is permitted before targets
The double colon allows one to specify the same target on multiple dependency lines
Target names should contain only letters, digits, periods, and underscores (other characters may be allowed by various make versions)
After a ; a command can appear
Command :
tab [- @] command
Specifies a command to be executed when building a target
The tab MUST be present
Optional spaces and tabs may follow
No line can start with a tab unless a command follows
A hyphen causes make to ignore any error returned
The @ causes suppression of line echo (except for make -n runs)
Macro definition :
name = string
Assigns string to the macro named name
Optional spaces are allowed (and are stripped off) but a tab may NOT begin the line
If the string contains a backslash \ followed by a newline, then make continues the string on the following line [one space is substituted for the backslash and newline pair; also, all of the whitespace before the backslash and at the the beginning of the following text is compressed to a single space]
Macro names should contain only letters, digits, and underscores (other characters may be allowed by various versions of make)
Include statement :
include file
Reads and evaluates the contents of file as if it were part of the description file
Macros :
$? | List of prerequisites that have been changed more recently than the current target. Can be used only in normal description file entries; can NOT be used in suffix rules. |
$@ | The name of the current target, except in description file entries for making libraries, where it becomes the library name. Can be used in both normal description file entries and suffix rules. |
$$@ | The name of the current target. Can only be used to the right of the colon in dependency lines. |
$* | The name -- minus the suffix -- of the current prerequisite that has been modified more recently than the curr target. Can be used only in suffix rules. |
$< | The name of the current prerequisite that has been modified more recently than the current target. Can only be used in suffix rules and the .DEFAULT entry |
$% | The name of the corresponding .o file when the current target is a library module. Can be used in both normal description file entries |
Macro Modifiers
D | The directory portion of any internal macro except $? Valid uses : ${*D}, $${@D}, ${@D}, ${<D} |
F | The file portion of any internal macro except $? Valid uses: ${*F}, $${@F}, ${@F}, ${<D} |
Special Macros
VPATH | Specifies a list of directories that make searches to find prerequisites if they are not in the curr dir |
SHELL | Determines which shell is used to interpret commands. If this macro is not defined in the description file, some implementations take the shell from the user's env variable. Some versions set SHELL to /bin/sh by default. |
Macro String Substitution
${macro:s0=s1}
Evaluates to the current definition of ${macro}, after substituting the string s1 for every occurrence of s0 that occurs either immediately before a blank or tab, or at the end of the macro definition.
Special Targets
.DEFAULT | Commands associated with this target are executed if make cannot find any description file entries or suffix rules to build a requested target |
.IGNORE | Ignore error codes |
.PRECIOUS | Files you specify for this target are NOT removed when you send a signal that aborts make, or when a command line in the description file returns an error. |
.SILENT | Execute commands but do not echo them |
.SUFFIXES | The prerequisites associated with this target are suffixes that become significant for make and can be associated with suffix rules. If present but without any suffixes listed, this target then nullifies the existing suffix list. Suffixes listed must be separated by spaces and/or tabs |
nmake
Assumes a very modular directory structure [some dirs dedicated to source files, some to header files, some to libraries and so on and so forth.
By utilizing this one can tell nmake where to find files by assigning directories to the targets .SOURCE.h, .SOURCE.c, and so on. There is also a special way to specify a search path for description files.
Like make, nmake recognizes the VPATH macro
Predefined suffix rules may embrace multiple levels
There are 'base rules' which represent fairly universal operations such as
building .o files from .c files.
There are global rules which change from project to project.
There are also 'user rules' defined in individual description files.
Precedence : user rules, global rules, base rules
Nmake forces one to indicate on each dependency line whether to build the target using explicit user-supplied assertions or predefined rules.
The syntax for defining rules is more extensive,
allowing more powerful/flexible pattern-matching than standard make suffix
rules.
A %-sign represents the string
to be matched, and it is able to be delimited by periods at both the front
and the back. eg t.%.c
nmake can scan source files to find dependencies on header files
nmake can supply the missing links in backward chaining : if you want to rebuild a .o file and nmake finds the corresponding .y file, it is able to figure out what to do from its built-in .y-to.c & .c-to.o rules.
nmake saves state information for rebuilds in state variables (akin to macros) The variables/macros one supplies on the nmake command line are preserved in a special file named makefile.ms and reused on future builds.
Powerful macro assignment features such as the ability to tie changes in one macro to changes in another
Improved speed through compiled description files. Possible parallelism
Execution of multipe lines in one shell
Built in flow control statements
More detailed control per an assertion-by-assertion basis over various features
More internal macros
makedepend
able to extract hidden dependencies on header files
able to recursively search included header files
automated determination of standard directories
recognition of preprocessor directives that might affect included files
able to discriminate C compiler options
Sample Makefiles
(1)
program : iodat.o main.o quo.o /usr/xkey/lib/crtn.a
cc -o program iodat.o main.o quo.o /usr/xkey/lib/crtn.a
(2)
rplot : prot.o; cc -o rplot prot.o
Last revision : 04-24-2000 by