man(1) Manual page archive


     MAKE(1)                                                   MAKE(1)

     NAME
          make - maintain collections of programs

     SYNOPSIS
          make [ -f makefile ] [ option ... ] [ name ... ]

     DESCRIPTION
          Make executes recipes in makefile to update the target names
          (usually programs).  If no target is specified, the targets
          of the first rule in makefile are updated.  If no -f option
          is present, `makefile' and `Makefile' are tried in order.
          If makefile is `-', the standard input is taken.  More than
          one -f option may appear.

          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.  The prerequisites are
          updated before the target.

          The makefile comprises a sequence of rules and macro defini-
          tions.  The first line of a rule is a blank-separated list
          of targets, then a single or double colon, then a list of
          prerequisite files terminated by semicolon or newline.  Text
          following a semicolon, and all following lines that begin
          with a tab, are shell commands: the recipe for updating the
          target.

          If a name appears as target in more than one single-colon
          rule, it depends on all of the prerequisites of those rules,
          but only one recipe may be specified among the rules.  A
          target in a double-colon rule is updated by the following
          recipe only if it is out of date with respect to the prereq-
          uisites of that rule.

          Two special forms of name are recognized.  A name like a(b)
          means the file named b stored in the archive named a. A name
          like a((b)) means the file stored in archive a and contain-
          ing the entry point b.

          Sharp and newline surround comments.

          In this makefile `pgm' depends on two files `a.o' and `b.o',
          and they in turn depend on `.c' files and a common file
          `ab.h':

          pgm: a.o b.o
               cc a.o b.o -lplot -o pgm

          a.o: ab.h a.c
               cc -c a.c

     MAKE(1)                                                   MAKE(1)

          b.o: ab.h b.c
               cc -c b.c

          Makefile lines of the form

               string1 = string2

          are macro definitions.  Subsequent appearances of $(string1)
          are replaced by string2. If string1 is a single character,
          the parentheses are optional; $$ is replaced by $.  Each
          entry in the environment (see sh(1)) of the make command is
          taken as a macro definition, as are command arguments with
          embedded equal signs.

          Lines of the form string1 := string2 occurring in a recipe
          are assignments: macro definitions that are made in the
          course of executing the recipe.

          A target containing a single % introduces a pattern rule,
          which controls the making of names that do not occur explic-
          itly as targets.  The % matches an arbitrary string called
          the stem: A%B matches any string that begins with A and ends
          with B. A % in a prerequisite name stands for the stem; and
          the special macro $% stands for the stem in the recipe.  A
          name that has no explicit recipe is matched against the tar-
          get of each pattern rule.  The first pattern rule for which
          the prerequisites exist specifies further dependencies.

          The following pattern rule maintains an object library where
          all the C source files share a common include file `defs.h'.

          arch.a(%.o) : %.c defs.h
               cc -c $%.c
               ar r arch.a $%.o
               rm $%.o

          A set of default pattern rules is built in, and effectively
          follows the user's list of rules.  Assuming these rules,
          which tell, among other things, how to make .o files from .c
          files, the first example becomes:

          pgm: a.o b.o
               cc a.o b.o -lplot -o pgm

          a.o b.o: ab.h

          Here, greatly simplified, is a sample of the built-in rules:

           CC = cc
           %.o: %.c
               $(CC) $(CFLAGS) -c $%.c
           %.o: %.f

     MAKE(1)                                                   MAKE(1)

               f77 $(FFLAGS) -c $%.f
           % : %.c
               $(CC) $(CFLAGS) -o $% $%.c

          The first rule says that a name ending in .o could be made
          if a matching name ending in .c were present.  The second
          states a similar rule for files ending in .f.  The third
          says that an arbitrary name can be made by compiling a file
          with that name suffixed by .c.

          Macros make the builtin pattern rules flexible: CC names the
          particular C compiler, CFLAGS gives cc(1) options, FFLAGS
          for f77(1), LFLAGS for lex(1), YFLAGS for yacc(1), and
          PFLAGS for pascal(A).

          An older, now disparaged, means of specifying default rules
          is based only on suffixes.  Prerequisites are inferred
          according to selected suffixes listed as the `prerequisites'
          for the special name .SUFFIXES; multiple lists accumulate;
          an empty list clears what came before.

          The rule to create a file with suffix s2 that depends on a
          similarly named file with suffix s1 is specified as an entry
          for the `target' s1s2. Order is significant; the first pos-
          sible name for which both a file and a rule exist is
          inferred.  An old style rule for making optimized .o files
          from .c files is

          .SUFFIXES: .c .o
          .c.o: ; cc -c -O -o $@ $*.c

          The following two macros are defined for use in any rule:

          $($@)
               full name of target
          $($/)
               target name beginning at the last slash, if any

          A number of other special macros are defined automatically
          in rules invoked by one of the implicit mechanisms:

          $*   target name with suffix deleted
          $@   full target name
          $<   list of prerequisites in an implicit rule
          $?   list of prerequisites that are out of date
          $^   list of all prerequisites

          The following are included for consistency with System V:

          $(@D)
               directory part of $@ (up to last slash)
          $(@F)

     MAKE(1)                                                   MAKE(1)

               file name part of $@ (after last slash)
          $(*D)
               directory part of $* (up to last slash)
          $(*F)
               file name part of $* (after last slash)
          $(<D)
               directory part of $< (up to last slash)
          $(<F)
               file name part of $< (after last slash)

          Recipe lines are executed one at a time, each by its own
          shell.  A line is printed when it is executed unless the
          special target .SILENT is in the makefile, or the first
          character of the command is @.

          Commands that return nonzero status cause make to terminate
          unless the special target .IGNORE is in the makefile or the
          command begins with <tab><hyphen>.

          Interrupt and quit cause the target to be deleted unless the
          target depends on the special name .PRECIOUS.

          Make includes a rudimentary parallel processing ability.  If
          the separation string is :& or ::& , make can run the com-
          mand sequences to create the prerequisites simultaneously.
          If two names are separated by an ampersand on the right side
          of a colon, those two may be created in parallel.

          Other options:

          -i   Equivalent to the special entry `.IGNORE: .'

          -k   When a command returns nonzero status, abandon work on
               the current entry, but continue on branches that do not
               depend on the current entry.

          -n   Trace and print, but do not execute the commands needed
               to update the targets.

          -t   Touch, i.e. update the modified date of targets, with-
               out executing any commands.

          -r   Turn off built-in rules.

          -s   Equivalent to the special entry .SILENT:.

          -e   Environment definitions override conflicting defini-
               tions in arguments or in makefiles.  Ordinary prece-
               dence is argument over makefile over environment.

          -o   Assume old style default suffix list: .SUFFIXES: .out
               .o .c .e .r .f .y .l .s .p

     MAKE(1)                                                   MAKE(1)

          -Pn  Permit n command sequences to be done in parallel with
               &.

          -z   Run commands by passing them to the shell; normally
               simple commands are run directly by exec(2).

     FILES
     SEE ALSO
          sh(1), touch in chdate(1), ar(1), mk(1)

     BUGS
          Comments can't appear on recipe lines.
          Archive entries are not handled reliably.