A/UX® Programming Languages and Tools, Volume 2
Total Page:16
File Type:pdf, Size:1020Kb
A/UX® Programming Languages and Tools, Volume 2 031-0127 • APPLE COMPUTER, INC. © 1987, 1988, Apple Computer, Inc., and UniSoft Corporation. © 1990, Apple Computer, Inc. All rights reserved. Portions of this document have been previously copyrighted by AT&T Information Systems and the Regents of the University of California, and are reproduced with permission. Under the copyright laws, this manual may not be copied, in whole or part, without the written consent of Apple. The same proprietary and copyright notices must be affIxed to any permitted copies as were affixed to the original. Under the law, copying includes translating into another language or format. The Apple logo is a registered trademark of Apple Computer, Inc. Use of the "keyboard" Apple logo (Option-Shift-K) for commercial purposes without the prior written consent of Apple may constitute trademark infringement and unfair competition in violation of federal and state laws. Apple Computer, Inc. 20525 Mariani Ave. Cupertino, California 95014 (408) 996-1010 Apple, the Apple logo, A!UX, ImageWriter, LaserWriter, and Macintosh are registered trademarks of Apple Computer, Inc. MacPaint is a registered trademark of Claris Corporation. UNIX is a registered trademark of AT&T Information Systems. Simultaneously published in the United States and Canada. 031-0127 LIMITED WARRAN1Y ON MEDIA Even though Apple has reviewed this AND REPLACEMENT manual, APPLE MAKES NO WARRANTY OR REPRESENTATION, If you discover physical defects in the EITHER EXPRESS OR IMPLIED, manual or in the media on which a WITH RESPECT TO TInS MANUAL, software product is distributed, Apple ITS QUAUTY, ACCURACY, will replace the media or manual at MERCHANTABILITY, OR FITNESS no charge to you provided you return FOR A PARTICULAR PURPOSE. AS A the item to be replaced with proof of RESULT, TInS MANUAL IS SOLD purchase to Apple or an authorized "AS IS," AND YOU, mE Apple dealer during the 90-day period PURCHASER, ARE ASSUMING mE after you purchased the software. In ENTIRE RISK AS TO ITS QUAUTY addition, Apple will replace damaged AND ACCURACY. software media and manuals for as long as the software product is IN NO EVENT WILL APPLE BE included in Apple's Media Exchange UABLE FOR DIRECT, INDIRECT, Program. While not an upgrade or SPECIAL, INCIDENTAL, OR update method, this program offers CONSEQUENTIAL DAMAGES additional protection for up to two RESULTING FROM ANY DEFECT OR years or more from the date of your INACCURACY IN mIS MANUAL, original purchase. See your even if advised of the possibility of authorized Apple dealer for program such damages. coverage and details. In some countries the replacement period mE WARRANTY AND REMEDIES may be different; check with your SET FORm ABOVE ARE EXCLUSIVE authorized Apple dealer. AND IN LIEU OF All OmERS, ORAL OR WRfITEN, EXPRESS OR All IMPLIED WARRANTIES ON IMPLIED. No Apple dealer, agent, or THIS MANUAL, INCLUDING employee is authorized to make any IMPliED WARRANTIES OF modification, extension, or addition to MERCHANTABll..ITY AND FITNESS this warranty. FOR A PARTICULAR PURPOSE, ARE LIMITED IN DURATION TO NINETY Some states do not allow the exclusion (90) DAYS FROM TIlE DATE OF TIlE or limitation of implied warranties or ORIGINAL RETAIL PURCHASE OF liability for incidental or consequential TInS PRODUCf. damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state. 031-0127 AlUX Programming Languages and Tools Volume 2 Contents Preface Chapter 16 make Reference Chapter 17 SCCS Reference Chapter 18 awk Reference Chapter 19 lex Reference Chapter 20 yacc Reference Chapter 21 bc Reference Chapter 22 dc Reference Chapter 23 m4 Reference Chapter 24 curses Reference Chapter 25 Other Programming Tools Appendix A Additional Reading Preface Conventions Used in This Manual Throughout the NUX manuals, words that must be typed exactly as shown or that would actually appear on the screen are in Courier type. Words that you must replace with actual values appear in italics (for example, user-name might have an actual value of joe). Key names appear in CAPS (for example, RETURN). Special terms are in bold type when they are introduced; many of these tenns are also defined in the glossary in the AIUX System Overview. Syntax notation All NUX manuals use the following conventions to represent command syntax. A typical NUX command has the form command [flag-option] [argument] ... where: command Command name (the name of an executable file). flag-option One or more flag options. Historically, flag options have the form -[opt .. .J where opt is a letter representing an option. The form of flag options varies from program to program. Note that with respect to flag options, the notation [-a][ -b][ -cJ means you can select one or more letters from the list enclosed in brackets. If you select more than one letter you use only one hyphen, for example, -abo argument Represents an argument to the command, in this context usually a filename or symbols representing one or more filenames. [] Surround an optional item. Follows an argument that may be repeated any number of times. Courier type anywhere in the syntax diagram indicates that characters must be typed literally as shown. italics for an argument name indicates that a value must be supplied for that argument. Other conventions used in this manual are: <CR> indicates that the RETURN key must be pressed. An abbreviation for CONTROL-X, where x may be any key. cmd(sect) A cross-reference to an NUX reference manual. cmd is the name of a command, program, or other facility, and sect is the section number where the entry resides. For example, ca t(l). Chapter 16 make Reference Contents 1. make: a file production tool 1 2. Using make . 1 2.1 Writing a makefile ..•. 2 2.2 make command syntax • 4 2.2.1 Flag options .... 5 2.2.2 Using make on individual files 6 3. The description file . • 6 3.1 Makefile entries 6 3.1.1 Targets vs. rules 7 3.1.2 Fake targets 7 3.1.3 Dependency statements 8 3.1.4 Commands . 9 3.2 Comments . 10 3.3 include lines . • . 10 3.4 Macro definitions • 10 3.4.1 Internal macros 12 3.4.2 Dynamic dependency parameters 13 3.5 Options • • • . • • . • . 15 3.5.1 Suppressing printing of commands . 15 3.5.2 Ignoring errors. 15 3.5.3 Combining commands . 16 3.5.4 Default commands 17 3.5.5 Saving files. • • • 17 3.5.6 Use of selected flag options . 17 4. Suffixes and rules • . • • 18 4.1 Suffixes. • . • • • . 18 4.2 Transformation rules . • • • . 19 4.2.1 The default macro settings 24 - i - 4.3 Changing default suffixes and rules •••. 25 4.3.1 The default suffix list. • • 25 4.3.2 The default rules • • • • 25 5. Operation • . • • • • • 26 5.1 Environment variables 26 5.2 Precedence. • 27 5.3 Archive libraries • • . 29 5.4 sees files . • • • . 32 5.4.1 sees filename prefixes 32 5.4.2 sees filename suffixes 32 5.4.3 sees transformation rules 32 5.4.4 sees makefiles • • . 33 6. Advanced topics . • . • . • . 33 6.1 Walking the directory tree 33 6.2 The make predecessor tree. 35 6.3 The makefile as shell script • .... 36 6.3.1 Unintended targets •..•.•. 36 6.3.2 Mnemonic targets . • • . 36 6.3.3 Macro translation • 37 6.4 A warning for system administrators 38 Figures Figure 16-1. A simple makefile 3 Figure 16-2. A makefile with multiple objects and defs . h file • • • • • • • • • • 3 Figure 16-3. Sample listing of default rules file 21 Figure 16-4. Replacing a default rule 26 Tables Table 16-1. Default suffix list • • • • • . 19 Table 16-2. Macro names and default compilers 24 - ii - Chapter 16 make Reference 1. make: a file production tool The make program automates the production of related sets of files. It simplifies the task of administering libraries, functions, related source and object files, and so on, that must reflect a change when you update one file in the set. Although make is normally used to maintain program code, it can also be used for other batch data processing activities (for example, make is often used to produce technical manuals with traff). make keeps track of program file dependencies; when you change one part of a program, make recompiles related files with a minimum amount of effort. The required information is maintained by the make program itself (which has built-in "rules" for recompilation), by using certain system information such as the timestamp on the files, and by the description of operations kept in a file called the "description file" or "makefile." Once you have set up a makefile for a large project, make keeps track of your files for you and frees you to concentrate on programming or other tasks. 2. Usi ng make The simplest use of make is make filel where a file named filel. c resides in the current directory. filel. c can #include other files. This command causes make to find f i Ie 1 . c in the local directory and issue the proper command to compile it into filel. Note: If filel. c has the same filename prefix (the same filename without the. c suffix) as another file, make may compile that file instead. If, for example, there is a more recent f i Ie 1 . 1 file, it is compiled instead, and f i Ie 1 . c is make Reference 16-1 overwritten in the process. If these files are not different incarnations of the same program, losing the . c file could be quite dangerous.