Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

CHAPTER 4 make: PROGRAM MAINTAINER The make program provides an easy way to automate the creation of large programs. make reads commands from a user-defined "makefile" that lists the files to be created, the commands that create them, and the files from which they are created. When you direct make to create a program, it makes sure that each file on which the program depends is up to date, then creates the program by executing the given commands. If a file is not up to date, make updates it before creating the program by executing explicitly given commands or one of the many built-in commands. This chapter explains how to use make to automate medium-sized programming projects. It explains how to create makefiles for each project and how to invoke make for creat ing programs and updating files. For more details about the program, see make in "Commands" in the XENIX 286 Reference Manual. Creating a Makefile A makefile contains one or more lines of text called dependency lines. A dependency line shows how a given file depends on other files and what commands are required to bring a file up to date. A dependency line has the form target ... : [ dependent .. . ] [ ; command ... ] where target is the name of a file to be updated, dependent is the name of a file on which the target depends, and command is the XENIX command needed to create the target file. Each dependency line must have at least one command associated with it, even if it is only the null command (;). You may give more than one target name or dependent name if desired. Each name must be separated from the next by at least one space. The target names must be separated from the dependent names by a colon (:). File names must be spelled as defined by the XENIX system. Shell metacharacters, such as star (*) and question mark (?), in file names are expanded when make uses the name. You may give a sequence of commands on the same line as the target and dependent names if you precede each command with a semicolon (;). You can give additional commands on following lines by beginning each line with a tab character. Commands must be given exactly as they would appear on a shell command line. The at sign (@) may be placed in front of a command to prevent make from displaying the command before executing it. Shell commands, such as cd, must appear on single lines; they must not contain the backslash (\} and newline character combination that normally can be used to continue commands between lines. You may add a comment to a makefile by starting the com ment with a nu mber sign (#) and ending it with a newline character. All characters after the nu mber sign are ignored. Comments may be placed at the end of a dependency line if desired. If a command contains a number sign, it must be enclosed in double quotat ion marks ("#"). 4- 1

make: Program Maintainer XENIX Programming If a dependency line is too long, you can continue it by typing a backslash (\) immediately followed by a newline character. The makefile should be kept in the same directory as the given source files. For convenience, the file names makefile, Makefile, s.makefile, and s.Makefile are provided as default file names used by make if no explicit name is given at invocation. You may use one of these names for your makefile or choose one of your own. If the file name begins with the s. prefix, make assumes that it is an sees file and invokes the appropriate sees command to retrieve the latest version of the file. To illustrate dependency lines, consider the following example. A program named prog is made by linking three object files, x.o, y.o, and z.o. These object files are created by compiling the e language source files x.c, y.c, and z.c. Furthermore, the files x.c and y.c contain the line #include "defs" This means that prog depends on the three object files, the object files depend on the e source files, and two of the source files depend on the include file defs. You can represent these relationships in a makefile with the following lines prog : x.o y.o z.o cc x.o y.o z.o -o prog x.o: x.c defs cc -c x.c y.o: y.c defs cc -c y.c z.o: z.c cc -c z.c In the first dependency line, prog is the target file and x.o, y.o, and z.o are its dependents. The command sequence cc x.o y.o z.o -o prog on the next line tells how to create prog if it is out of date. The program is out of date if any one of its dependents has been modified since prog was last created. The second, third, and fourth dependency lines have the same form, with the x.o, y.o, and z.o files as targets and x.c, y.c, z.c, and defs files as dependents. Each dependency line has one command sequence that defines how to update the given target file. 4-2

CHAPTER 4<br />

make: PROGRAM MAINTAINER<br />

The make program provides an easy way to automate the creation of large programs.<br />

make reads commands from a user-defined "makefile" that lists the files to be created,<br />

the commands that create them, and the files from which they are created. When you<br />

direct make to create a program, it makes sure that each file on which the program<br />

depends is up to date, then creates the program by executing the given commands. If a<br />

file is not up to date, make updates it before creating the program by executing<br />

explicitly given commands or one of the many built-in commands.<br />

This chapter explains how to use make to automate medium-sized programming<br />

projects. It explains how to create makefiles for each project and how to invoke make<br />

for creat ing programs and updating files. For more details about the program, see make<br />

in "Commands" in the <strong>XENIX</strong> <strong>2<strong>86</strong></strong> Reference Manual.<br />

Creating a Makefile<br />

A makefile contains one or more lines of text called dependency lines. A dependency<br />

line shows how a given file depends on other files and what commands are required to<br />

bring a file up to date. A dependency line has the form<br />

target ... : [ dependent .. . ] [ ; command ... ]<br />

where target is the name of a file to be updated, dependent is the name of a file on<br />

which the target depends, and command is the <strong>XENIX</strong> command needed to create the<br />

target file. Each dependency line must have at least one command associated with it,<br />

even if it is only the null command (;).<br />

You may give more than one target name or dependent name if desired. Each name<br />

must be separated from the next by at least one space. The target names must be<br />

separated from the dependent names by a colon (:). File names must be spelled as<br />

defined by the <strong>XENIX</strong> system. Shell metacharacters, such as star (*) and question mark<br />

(?), in file names are expanded when make uses the name.<br />

You may give a sequence of commands on the same line as the target and dependent<br />

names if you precede each command with a semicolon (;). You can give additional<br />

commands on following lines by beginning each line with a tab character. Commands<br />

must be given exactly as they would appear on a shell command line. The at sign (@)<br />

may be placed in front of a command to prevent make from displaying the command<br />

before executing it. Shell commands, such as cd, must appear on single lines; they must<br />

not contain the backslash (\} and newline character combination that normally can be<br />

used to continue commands between lines.<br />

You may add a comment to a makefile by starting the com ment with a nu mber sign (#)<br />

and ending it with a newline character. All characters after the nu mber sign are<br />

ignored. Comments may be placed at the end of a dependency line if desired. If a<br />

command contains a number sign, it must be enclosed in double quotat ion marks ("#").<br />

4- 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!