Executable commands

If a target must be created, the sequence of commands is executed. Normally, each command line is printed and then passed to a separate invocation of the shell after substituting for macros. The printing is suppressed in the silent mode (-s option) or if the command line in the description file begins with an ``@'' sign.

make normally stops if any command signals an error by returning a nonzero error code. Errors are ignored if the -i option has been specified on the make command line, if the special target name .IGNORE appears in the description file, or if the command string in the description file begins with a hyphen. If a program is known to return a meaningless status, a hyphen in front of the command that invokes it is appropriate.

NOTE: If a file must be made but there are no explicit commands or relevant built-in rules, the commands associated with the target name .DEFAULT are used. If .DEFAULT is not defined, make prints a message and stops.

Commands contained within a makefile invoke a UNIX system shell and are executed there; a shell is separately invoked for each successive command. For example, the following makefile results in three invocations of the shell:

   Report : data1 data2 awk1
          sort - bdf data1 data2 > /usr/tmp/rptxxx
          awk  - f awk1 /usr/tmp/rptxxx > report
          rm /usr/tmp/rptxxx
Because each command line is passed to a separate invocation of the shell, care must be taken with certain commands (cd and shell control commands, for instance) that have meaning only within a single shell process. These results are forgotten before the next line is executed. Consequently, a cd command remains in effect within a single line. In the following example, the ls command lists the directory where make was invoked, not newdir.
   target1 : comp1 comp2
           cd newdir
To achieve the desired result, try the following example. In this example, the shell is invoked on the entire command line, and the cd remains in effect when the ls is executed.
   target1 : comp1 comp2
   	cd newdir; ls
In general, any shell command can be used in a makefile, but there are restrictions. Each command must be a single line, which constrains the use of the shell multi-line constructs. A way to circumvent this limitation is to use backslashes to prevent the shell interpretation of a newline. In the following example, the middle lines comprise a single shell command. The backslashes suppress the normal interpretation of a newline, resulting in these lines being considered a single line.
       echo "start"
       for i in 1 2 3; do \
           echo "start"; \
           echo "starting..."; \
           echo "...done"; \
       echo "end"

Next topic: Output translations
Previous topic: Macro definitions

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003