home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / chplus / cpp / 3 / Tools.exe / make.txt < prev    next >
Text File  |  1998-02-09  |  34KB  |  1,071 lines

  1. MAKE Help
  2.  
  3. This file contains details on using MAK.
  4. --------------------------------------------------------------------
  5.                         TABLE OF CONTENTS
  6.                         - - - - - - - - -
  7.    MAKE basics
  8.       BUILTINS.MAK
  9.       Using TOUCH.EXE
  10.       MAKE options
  11.          Setting options on as defaults
  12.          Compatibility with Microsoft's NMAKE
  13.    Using makefiles
  14.       Symbolic targets
  15.          Rules for symbolic targets
  16.    Explicit and implicit rules
  17.       Explicit rule syntax
  18.          Single targets with multiple rules
  19.       Implicit rule syntax
  20.          Explicit rules with implicit commands
  21.       Commands syntax
  22.          Command prefixes
  23.          Using @
  24.          Using -num and -
  25.          Using &
  26.          Command operators
  27.          Debugging with temporary files
  28.    Using MAKE macros
  29.       Defining macros
  30.       Using a macro
  31.       String substitutions in macros
  32.       Default MAKE macros
  33.       Modifying default macros
  34.    Using MAKE directives
  35.       .autodepend
  36.       !error
  37.          Summing up error-checking controls
  38.       !if and other conditional directives
  39.       !include
  40.       !message
  41.       .path.ext
  42.       .precious
  43.       .suffixes
  44.       !undef
  45.       Using macros in directives
  46. --------------------------------------------------------------------
  47.  
  48. MAKE.EXE is a command-line project-manager utility that helps you
  49. quickly compile only those files in a project that have changed since
  50. the last compilation. (MAKER is a real-mode version of MAKE.)
  51.  
  52. This chapter covers the following topics:
  53.   o  MAKE basics
  54.   o  Makefile contents
  55.   o  Using explicit and implicit rules
  56.   o  Using MAKE macros
  57.   o  Using MAKE directives
  58.  
  59.  
  60. MAKE basics
  61. ===========
  62. MAKE uses rules from a text file (MAKEFILE or MAKEFILE.MAK by default)
  63. to determine which files to build and how to build them. For example,
  64. you can get MAKE to compile an .EXE file if the date-time stamps for
  65. the .CPP files that contain the code for the .EXE are more recent than
  66. the .EXE itself. MAKE is very useful when you build a program from
  67. more than one file because MAKE will recompile only the files that you
  68. modified since the last compile.
  69.  
  70. Two types of rules (explicit and implicit) tell MAKE what files depend
  71. on each other. MAKE then compares the date-time stamp of the files in
  72. a rule and determines if it should execute a command (the commands
  73. usually tell MAKE which files to recompile or link, but the commands
  74. can be nearly any operating system command).
  75.  
  76. The general syntax for MAKE is:
  77.  
  78.     MAKE [options...] [targets[s]]
  79.  
  80. (To get command-line help for MAKE, type MAKE -? or MAKE -h.)
  81.  
  82. "Options" are MAKE options that control how MAKE works, and
  83. "targets" are the names of the files in a makefile that you want MAKE to
  84. build. Options are separated from MAKE by a single space. Options and
  85. targets are also separated by spaces.
  86.  
  87. If you type MAKE at the command prompt, MAKE performs the following
  88. default tasks:
  89.  
  90. To place MAKE instructions in a file other than MAKEFILE, see
  91. the section titled "MAKE options."
  92.  
  93. MAKE looks in the current directory for a file called BUILTINS.MAK
  94. (this file contains rules MAKE always follows unless you use the -r option).
  95. If it can't find the file in the current directory, it looks in the
  96. directory where MAKE.EXE is stored. After loading BUILTINS.MAK, MAKE looks
  97. for a file called MAKEFILE or MAKEFILE.MAK. If MAKE can't find any of these
  98. files, it gives you an error message.
  99.  
  100. When MAKE finds a makefile, it tries to build only the first target
  101. file in the makefile (although the first target can force other
  102. targets to be built). MAKE checks the time and date of the dependent
  103. files for the first target. If the dependent files are more recent
  104. than the target file, MAKE executes the target commands, which update
  105. the target. See the section called "Using makefiles" for more
  106. information on instructions in makefiles.
  107.  
  108.  1) If a dependent file for the first target appears as a target elsewhere
  109.     in the makefile, MAKE checks its dependencies and builds it before
  110.     building the first target. This chain reaction is called linked
  111.     dependency.
  112.  
  113.  2) If the MAKE build process fails, MAKE deletes the target file it was
  114.     building. To get MAKE to keep a target when a build fails, see the
  115.     .precious directive.
  116.  
  117. You can stop MAKE by using <Ctrl><Break> or <Ctrl><C>.
  118.  
  119.  
  120. BUILTINS.MAK
  121. ------------
  122. BUILTINS.MAK contains standard rules and macros that MAKE uses before
  123. it uses a makefile (you can use the -r option to tell MAKE to ignore
  124. BUILTINS.MAK). Use BUILTINS.MAK for instructions or macros you want
  125. executed each time you use MAKE. Here's the default text of
  126. BUILTINS.MAK:
  127.  
  128. #
  129. # Borland C++ - (C) Copyright 1993 by Borland International
  130. #
  131.  
  132. # default is to target 32BIT
  133. # pass -DWIN16 to make to target 16BIT
  134.  
  135. !if !$d(WIN16)
  136. CC       = bcc32
  137. RC       = brcc32
  138. AS       = tasm32
  139. !else
  140. CC       = bcc
  141. RC       = brcc
  142. AS       = tasm
  143. !endif
  144.  
  145. .asm.obj:
  146.       $(AS) $(AFLAGS) $&.asm
  147.  
  148. .c.exe:
  149.       $(CC) $(CFLAGS) $&.c
  150.  
  151. .c.obj:
  152.       $(CC) $(CFLAGS) /c $&.c
  153.  
  154. .cpp.exe:
  155.       $(CC) $(CFLAGS) $&.cpp
  156.  
  157. .cpp.obj:
  158.       $(CC) $(CPPFLAGS) /c $&.cpp
  159.  
  160. .rc.res:
  161.       $(RC) $(RFLAGS) /r $&
  162.  
  163. .SUFFIXES: .exe .obj .asm .c .res .rc
  164.  
  165. !if !$d(BCEXAMPLEDIR)
  166. BCEXAMPLEDIR = $(MAKEDIR)\..\EXAMPLES
  167. !endif
  168.  
  169.  
  170. Using TOUCH.EXE
  171. ---------------
  172. Sometimes you'll want to force a target file to be recompiled or
  173. rebuilt even though you haven't changed it. One way to do this is to
  174. use the TOUCH utility. TOUCH changes the date and time of one or more
  175. files to the current date and time, making it "newer" than the files
  176. that depend on it.
  177.  
  178. You can force MAKE to rebuild a target file by touching one of the
  179. files that target depends on. To touch a file (or files), type the
  180. following at the command prompt:
  181.  
  182.     touch filename [filename...]
  183.  
  184. TOUCH updates the file's creation date and time.
  185.  
  186. Before you use TOUCH, make sure your system's internal clock is set
  187. correctly. If it isn't, TOUCH and MAKE won't work properly.
  188.  
  189.  
  190. MAKE options
  191. ------------
  192. Command-line options control MAKE behavior. Options are
  193. case-sensitive. Type options with either a preceding - or /. For
  194. example, to use a file called PROJECTA.MAK as the makefile, type MAKE
  195. -fPROJECTA.MAK (a space after -f is optional). Many of the
  196. command-line options have equivalent directives that are used in the
  197. makefile. The following table describes MAKE's command-line options.
  198.  
  199.  
  200. Option        Description
  201. ------        -----------
  202. -h or -?    Displays MAKE options and shows defaults with
  203.         a trailing plus sign.
  204.  
  205. -B        Builds all targets regardless of file dates.
  206.  
  207. -D<macro>    Defines <macro> as a single character, causing
  208.         an expression <!ifdef macro> written in the
  209.         makefile to return true.
  210.  
  211. [-D]<macro>=[string]    Defines <macro> as "string." If "string"
  212.             contains any spaces or tabs, enclose "string"
  213.             in quotation marks. The -D is optional.
  214.  
  215. -I<directory>    Searches for include files in the current
  216.         directory first, then in <directory>.
  217.  
  218. -K        Keeps temporary files that MAKE creates (MAKE
  219.         usually deletes them).
  220.  
  221. -N        Executes MAKE like Microsoft's NMAKE (see the
  222.         section following this table for more
  223.         information).
  224.  
  225. -U<macro>    Undefines previous definitions of <macro>.
  226.  
  227. -W        Writes the current specified non-string
  228.         options to MAKE.EXE making them defaults.
  229.  
  230. -f<filename>    Uses <filename> or <filename>.MAK instead of
  231.         MAKEFILE (space after -f is optional).
  232.  
  233. -a        Checks dependencies of include files and
  234.         nested include files associated with .OBJ
  235.         files and updates the .OBJ if the .H file
  236.         changed. See also -c.
  237.  
  238. -c        Caches autodependency information, which can
  239.         improve MAKE's speed. Use with -a; don't use
  240.         if MAKE changes include files (such as using
  241.         TOUCH from a makefile or creating header or
  242.         include files during the MAKE process).
  243.  
  244. -d<directory>    Used with -S to specify the drive and
  245.         directory MAKE uses when it swaps out of
  246.         memory. The option is ineffective when used
  247.         with the MAKER.
  248.  
  249. -e        Ignores a macro if its name is the same as an
  250.         environment variable (MAKE uses the
  251.         environment variable instead of the macro).
  252.  
  253. -i        Ignores the exit status of all programs run
  254.         from MAKE and continues the build process.
  255.  
  256. -m        Displays the date and time stamp of each file
  257.         as MAKE processes it.
  258.  
  259. -n        Prints the commands but doesn't actually
  260.         perform them, which is helpful for debugging
  261.         a makefile.
  262.  
  263. -p        Displays all macro definitions and implicit
  264.         rules before executing the makefile.
  265.  
  266. -q        Returns 0 if the target is up-to-date and
  267.         nonzero if is is not (for use with batch
  268.         files).
  269.  
  270. -r        Ignores any rules defined in BUILTINS.MAK.
  271.  
  272. -s        Suppresses onscreen command display.
  273.  
  274. -S        Swaps MAKER out of memory while commands are
  275.         executed, reducing memory overhead and
  276.         allowing compilation of large modules. This
  277.         option has no effect on MAKER.
  278.  
  279. -W        Sets MAKE defaults.
  280.  
  281.  
  282. Setting options on as defaults
  283. - - - - - - - - - - - - - - - -
  284. The -W option lets you set some MAKE options on as defaults so that
  285. each time you use MAKE, those options are used. To set MAKE options,
  286. type:
  287.  
  288.     make  -option[-]  [-option][-]  . . . -W
  289.  
  290. For example, you could type "MAKE -m -W" to always view file dates and
  291. times. Type "MAKE -m- -W" to turn off the default option. When MAKE asks
  292. you to write changes to MAKE.EXE, type Y.
  293.  
  294. The -W option doesn't work when the DOS Share program
  295. is running. The message "Fatal: unable to open file MAKE.EXE" is
  296. displayed. The -W option doesn't work with the following MAKE options:
  297.   o  -D<macro>
  298.   o  -D<macro>=<string>
  299.   o  -d<directory>
  300.   o  -U<symbol>
  301.   o  -f<filename>
  302.   o  -? or -h
  303.   o  -I<directory>
  304.  
  305.  
  306. Compatibility with Microsoft's NMAKE
  307. - - - - - - - - - - - - - - - - - - -
  308. Use the -N option if you want to use makefiles that were originally
  309. created for Microsoft's NMAKE. The following changes occur when you
  310. use -N:
  311.  
  312.   MAKE interprets the << operator like the && operator: temporary files
  313.   are used as response files, then deleted. To keep a file, either use
  314.   the -K command-line option or use KEEP in the makefile.
  315.  
  316.     <<TEMPFILE.TXT!
  317.     text
  318.  
  319.     !KEEP
  320.  
  321.   If you don't want to keep a temporary file, type NOKEEP or type
  322.   only the temporary file name. If you use NOKEEP with a temporary
  323.   file, then use the -K option with MAKE, MAKE deletes the temporary file.
  324.  
  325.   o  The $d macro is treated differently. Use "!ifdef" or "!ifndef" instead.
  326.  
  327.   o  Macros that return paths won't return the last \. For example, if
  328.      $(<D) normally returns C:\CPP\, the -N option makes it return C:\CPP.
  329.  
  330.   o  Unless there's a matching .suffixes directive, MAKE searches rules
  331.      from bottom to top of the makefile.
  332.  
  333.   o  The $* macro always expands to the target name instead of the
  334.      dependent in an implicit rule.
  335.  
  336.  
  337. Using makefiles
  338. ===============
  339. A makefile is an ASCII file of instructions for MAKE.EXE. MAKE assumes
  340. your makefile is called MAKEFILE or MAKEFILE.MAK unless you use the -f
  341. option.
  342.  
  343. MAKE either builds targets you specify at the MAKE command line or it
  344. builds only the first target it finds in the makefile (to build more
  345. than one target, see the section "Symbolic targets.") Makefiles can
  346. contain:
  347.   o  Comments
  348.   o  Explicit rules
  349.   o  Implicit rules
  350.   o  Macros
  351.   o  Directives
  352.  
  353.  
  354. Symbolic targets
  355. ----------------
  356. A symbolic target forces MAKE to build multiple targets in a makefile
  357. (you don't need to rely on linked dependencies). The dependency line
  358. lists all the targets you want to build. You don't type any commands
  359. for a symbolic target.
  360.  
  361. In the following makefile, the symbolic target "allFiles" builds both
  362. FILE1.EXE and FILE2.EXE:
  363.  
  364.   allFiles: file1.exe file2.exe     #Note this target has no commands.
  365.   file1.exe: file1.obj
  366.       bcc file1.obj
  367.   file2.exe: file2.obj
  368.       bcc file2.obj
  369.  
  370.  
  371. Rules for symbolic targets
  372. - - - - - - - - - - - - - -
  373. Observe the following rules with symbolic targets:
  374.  
  375.   o  Symbolic targets don't need a command line.
  376.  
  377.   o  Give your symbolic target a unique name; it can't be the name of a
  378.      file in your current directory.
  379.  
  380.   o  Name symbolic targets according to the operating system rules for
  381.      naming files.
  382.  
  383.  
  384. Explicit and implicit rules
  385. ===========================
  386. The explicit and implicit rules that instruct MAKE are generally
  387. defined as follows:
  388.  
  389.   o  Explicit rules give MAKE instructions for specific files.
  390.  
  391.   o  Implicit rules give general instructions that MAKE follows when it
  392.      can't find an explicit rule.
  393.  
  394. Rules follow this general format:
  395.  
  396.   Dependency line
  397.     Commands
  398.  
  399. The dependency line is different for explicit and implicit rules, but
  400. the commands are the same.
  401.  
  402. MAKE supports multiple rules for one target. You can add dependent
  403. files after the first explicit rule, but only one should contain a
  404. command line. For example:
  405.  
  406.   Target1: dependent1 dep2 dep3 dep4 dep5
  407.   Target1: dep6 dep7 dep8
  408.     bcc -c $**
  409.  
  410.  
  411. Explicit rule syntax
  412. --------------------
  413. Explicit rules are instructions to MAKE that specify exact file names.
  414. The explicit rule names one or more targets followed by one or two
  415. colons. One colon means one rule is written for the target; two colons
  416. mean that two or more rules are written for the target.
  417.  
  418. Explicit rules follow this syntax:
  419.  
  420.   target [target...]:[:][{path}] [dependent[s]...]
  421.     [commands]
  422.  
  423.  o  target    The name and extension of the file to be updated
  424.         ("target" must be at the start of the line--no spaces or
  425.         tabs are allowed). One or more targets must be
  426.         separated by spaces or tabs. Don't use a target's name
  427.         more than once in the target position of an explicit
  428.         rule in a makefile.
  429.  
  430.  o  path    A list of directories, separated by semicolons and
  431.         enclosed in braces, that points to the dependent files.
  432.  
  433.  o  dependent    The file (or files) whose date and time MAKE checks to
  434.         see if it is newer than "target" (dependent must be
  435.         preceded by a space). If a dependent file also appears
  436.         in the makefile as a target, MAKE updates or creates
  437.         the target file before using it as a dependent for
  438.         another target.
  439.  
  440.  o  commands    Any operating system command. Multiple commands are
  441.         allowed in a rule. Commands must be indented by at
  442.         least one space or tab.
  443.  
  444. If the dependency or command continues on to the next line, use the
  445. backslash (\) at the end of the line after a target or a dependent
  446. file name. For example:
  447.  
  448.   MYSOURCE.EXE: FILE1.OBJ\
  449.               FILE2.OBJ\
  450.               FILE3.OBJ
  451.      bcc file1.obj file2.obj file3.obj
  452.  
  453.  
  454. Single targets with multiple rules
  455. - - - - - - - - - - - - - - - - - -
  456. A single target can have more than one explicit rule. You must use the
  457. double colon (::) after the target name to tell MAKE to expect multiple
  458. explicit rules. The following example shows how one target can have
  459. multiple rules and commands:
  460.  
  461.   .cpp.obj:
  462.     bcc -c -ncobj $<
  463.  
  464.   .asm.obj:
  465.     tasm  /mx $<, asmobj\\
  466.  
  467.   mylib.lib :: f1.obj f2.obj
  468.     echo Adding C files
  469.     tlib mylib -+cobj\f1 -+cobj\f2
  470.  
  471.   mylib.lib :: f3.obj f4.obj
  472.     echo Adding ASM files
  473.     tlib mylib -+asmobj\f3 -+asmobj\f4
  474.  
  475.  
  476. Implicit rule syntax
  477. --------------------
  478. An implicit rule starts with either a path or a period and implies a
  479. target-dependent file relationship. Its main components are file
  480. extensions separated by periods. The first extension belongs to the
  481. dependent, the second to the target.
  482.  
  483. If implicit dependents are out-of-date with respect to the target or
  484. if they don't exist, MAKE executes the commands associated with the
  485. rule. MAKE updates explicit dependents before it updates implicit
  486. dependents.
  487.  
  488. Implicit rules follow this basic syntax:
  489.  
  490.   [{source_dirs}].source_ext[{target_dirs}].target_ext:
  491.      [commands]
  492.  
  493.   o  {source_dirs}    The directory of the dependent files.
  494.             Separate multiple directories with a semicolon.
  495.  
  496.   o  .source_ext    The dependent file-name extension.
  497.  
  498.   o  {target_dirs}    The directory of the target (executable) files.
  499.             Separate multiple directories with a semicolon.
  500.  
  501.   o  .target_ext    The target file-name extension. Macros are allowed.
  502.  
  503.   o  :            Marks the end of the dependency line.
  504.  
  505.   o  commands        Any operating system command. Multiple commands
  506.             are allowed. Commands must be indented by one
  507.             space or tab.
  508.  
  509. If two implicit rules match a target extension but no dependent
  510. exists, MAKE uses the implicit rule whose dependent's extension
  511. appears first in the .SUFFIXES list.
  512.  
  513.  
  514. Explicit rules with implicit commands
  515. - - - - - - - - - - - - - - - - - - -
  516. A target in an explicit rule can get its command line from an implicit
  517. rule. The following example shows an implicit rule and an explicit
  518. rule without a command line:
  519.  
  520.   .c.obj:
  521.      bcc -c $<     #This command uses a macro $< described later.
  522.  
  523.   myprog.obj:      #This explicit rule uses the command: bcc -c myprog.c
  524.  
  525. The implicit rule command tells MAKE to compile MYPROG.C (the macro $<
  526. replaces the name "myprog.obj" with "myprog.c").
  527.  
  528.  
  529. Commands syntax
  530. ---------------
  531. Commands can be any operating system command, but they can also
  532. include MAKE macros, directives, and special operators that operating
  533. systems can't recognize (note that | can't be used in commands). Here
  534. are some sample commands:
  535.  
  536.   cd..
  537.  
  538.   bcc -c mysource.c
  539.  
  540.   COPY *.OBJ C:\PROJECTA
  541.  
  542.   bcc -c $(SOURCE)     #Macros are explained later in the chapter.
  543.  
  544. Commands follow this general syntax:
  545.  
  546.     [prefix...] commands
  547.  
  548.  
  549. Command prefixes
  550. - - - - - - - - -
  551. Commands in both implicit and explicit rules can have prefixes that
  552. modify how MAKE treats the commands. The following table lists the prefixes
  553. you can use in makefiles:
  554.  
  555. Option        Description
  556. ------        -----------
  557. @        Don't display command while it's being executed.
  558.  
  559. -<num>        Stop processing commands in the makefile when the
  560.         exit code returned from command exceeds <num>.
  561.         Normally, MAKE aborts if the exit code is nonzero.
  562.         No white space is allowed between - and <num>.
  563.  
  564. -        Continue processing commands in the makefile,
  565.         regardless of the exit code returned by them.
  566.  
  567. &        Expand either the macro $**, which represents all
  568.         dependent files, or the macro $?, which represents
  569.         all dependent files stamped later than the target.
  570.         Execute the command once for each dependent file
  571.         in the expanded macro.
  572.  
  573.  
  574. Using @
  575. - - - -
  576. The following command uses the modifier @, which prevents the command
  577. from displaying onscreen when MAKE executes it.
  578.  
  579.   diff.exe : diff.obj
  580.     @bcc diff.obj
  581.  
  582.  
  583. Using -num and -
  584. - - - - - - - - -
  585. The "-num" and "-" modifiers control MAKE processing under error
  586. conditions. You can choose to continue with the MAKE process if an
  587. error occurs or only if the errors exceed a given number.
  588.  
  589. In the following example, MAKE continues processing if BCC isn't run
  590. successfully:
  591.  
  592.   target.exe : target.obj
  593.   target.obj : target.cpp
  594.     bcc -c target.cpp
  595.  
  596.  
  597. Using &
  598. - - - -
  599. The & modifier issues a command once for each dependent file. It is
  600. especially useful for commands that don't take a list of files as
  601. parameters. For example,
  602.  
  603.   copyall : file1.cpp file2.cpp
  604.     © $** c:\temp
  605.  
  606. results in COPY being invoked twice as follows:
  607.  
  608.   copy file1.cpp c:\temp
  609.   copy file2.cpp c:\temp
  610.  
  611. Without the & modifier, COPY would be called only once.
  612.  
  613. Command operators
  614. - - - - - - - - -
  615. You can use any operating system command in a MAKE commands section.
  616. MAKE uses the normal operators (such as +, -, and so on), but it also
  617. has other operators you can use.
  618.  
  619. Operator    Description
  620. --------    -----------
  621. <        Take the input for use by "command" from
  622.         "file" rather than from standard input.
  623.  
  624. >        Send the output from "command" to "file".
  625.  
  626. >>        Append the output from "command" to "file".
  627.  
  628. <<        Create a temporary, inline file and use
  629.         its contents as standard input to
  630.         "command".
  631.  
  632. &&        Create a temporary file and insert its
  633.         name in the makefile.
  634.  
  635. delimiter    Any character other than # and \ used
  636.         with << and && as a starting and ending
  637.         delimiter for a temporary file. Any
  638.         characters on the same line and
  639.         immediately following the starting
  640.         delimiter are ignored. The closing
  641.         "delimiter" must be written on a line by
  642.         itself.
  643.  
  644.  
  645. Debugging with temporary files
  646. - - - - - - - - - - - - - - - -
  647. Temporary files can help you debug a command set by placing the actual
  648. commands MAKE executes into the temporary file. Temporary file names
  649. start at MAKE0000.@@@, where the 0000 increments for each temporary
  650. file you keep. You must place delimiters after && and at the end of
  651. what you want sent to the temporary file (! is a good delimiter).
  652.  
  653. The following example shows && instructing MAKE to create a file of
  654. the input to TLINK.
  655.  
  656.   prog.exe: A.obj B.obj
  657.      TLINK /c &&!
  658.      c0s.obj $**
  659.      prog.exe
  660.      prog.map
  661.      maths.lib cs.lib
  662.      !
  663.  
  664. The response file created by && contains these instructions:
  665.  
  666.      c0s.obj a.obj b.obj
  667.      prog.exe
  668.      prog.map
  669.      maths.lib cs.lib
  670.  
  671.  
  672. Using MAKE macros
  673. =================
  674. A MAKE macro is a string that is expanded (used) wherever the macro is
  675. called in a makefile. Macros let you create template makefiles that
  676. you can change to suit different projects. For example, to define a
  677. macro called LIBNAME that represents the string "mylib.lib," type
  678. "LIBNAME = mylib.lib". When MAKE encounters the macro "$(LIBNAME)", it
  679. uses the string "mylib.lib".
  680.  
  681. If MAKE finds an undefined macro in a makefile, it looks for an
  682. operating-system environment variable of that name (usually defined
  683. with SET) and uses its definition as the expansion text. For example,
  684. if you wrote "$(path)" in a makefile and never defined "path", MAKE would
  685. use the text you defined for PATH in your AUTOEXEC.BAT. (See the
  686. manuals for your operating system for information on defining
  687. environment variables.)
  688.  
  689.  
  690. Defining macros
  691. ---------------
  692. The general syntax for defining a macro in a makefile is:
  693.  
  694.     MacroName = expansion_text
  695.  
  696.   o  "MacroName" is case-sensitive and is limited to 512 characters.
  697.  
  698.   o  "expansion_text" is limited to 4096 characters consisting of
  699.      alpha-numeric characters, punc-tuation, and white space.
  700.  
  701. Each macro must be on a separate line in a makefile. Macros are
  702. usually put at the top of the makefile. If MAKE finds more than one
  703. definition for a "macroName", the new definition replaces the old one.
  704.  
  705. Macros can also be defined using the command-line option -D. More than
  706. one macro can be defined by separating them with spaces. The following
  707. examples show macros defined at the command line:
  708.  
  709.   make -Dsourcedir=c:\projecta
  710.   make command="bcc -c"
  711.   make command=bcc option=-c
  712.  
  713. The following differences in syntax exist between macros entered on
  714. the command line and macros written in a makefile.
  715.  
  716.             Makefile    Command line
  717.             --------    ------------
  718. Spaces allowed before
  719. and after =        Yes        No
  720.  
  721. Space allowed before
  722. macroName        No        Yes
  723.  
  724.  
  725. Using a macro
  726. -------------
  727. To use a macro in a makefile, type "$(MacroName)" where MacroName is the
  728. name of a defined macro. You can use braces {} and parentheses () to
  729.  
  730. MAKE expands macros at various times depending on where they appear in
  731. the makefile:
  732.  
  733.   o  Nested macros are expanded when the outer macro is invoked.
  734.  
  735.   o  Macros in rules and directives are expanded when MAKE first looks at
  736.      the makefile.
  737.  
  738.   o  Macros in commands are expanded when the command is executed.
  739.  
  740.  
  741. String substitutions in macros
  742. ------------------------------
  743. MAKE lets you temporarily substitute characters in a previously
  744. defined macro.  For example, if you defined a macro called SOURCE as
  745. "SOURCE = f1.cpp f2.cpp f3.cpp", you could substitute the characters
  746. .OBJ for the characters .CPP by using "$(SOURCE:.CPP=.OBJ)". The
  747. substitution doesn't redefine the macro.
  748.  
  749. Rules for macro substitution:
  750.  
  751.   o  Syntax: $(MacroName:original_text=new_text)
  752.  
  753.   o  No whitespace before or after the colon.
  754.  
  755.   o  Characters in "original_text" must exactly match the characters in the
  756.      macro definition; this text is case-sensitive.
  757.  
  758. MAKE now lets you use macros within substitution macros. For example:
  759.  
  760.   MYEXT=.C
  761.   SOURCE=f1.cpp f2.cpp f3.cpp
  762.   $(SOURCE:.cpp=$(MYEXT))         #Changes f1.cpp to f1.C, etc.
  763.  
  764.  
  765. Default MAKE macros
  766. -------------------
  767. MAKE contains several default macros you can use in your makefiles.
  768. The following table lists the macro definition and what it expands to
  769. in explicit and implicit rules.
  770.  
  771. Macro    Expands in implicit:    Expands in explicit:    Example
  772. -----    --------------------    --------------------    -------
  773. $*    path\dependent file    path\target file    C:\PROJ\MYTARGET
  774.  
  775. $<    path\dependent file+ext    path\target file+ext    C:\PROJ\MYTARGET.OBJ
  776.  
  777. $:    path for dependents    path for target        C:\PROJ
  778.  
  779. $.    dependent file+ext    target file + ext    MYSOURCE.C
  780.  
  781. $&    dependent file       target file         MYSOURCE
  782.  
  783. $@    path\target file+ext    path\target file+ext    C:\PROJ\MYSOURCE.C
  784.  
  785. $**    path\dependent file+ext    all dependents file+ext    F1.CPP F2.CPP F3.CPP
  786.  
  787. $?    path\dependent file+ext    old dependents        FILE1.CPP
  788.  
  789.  
  790. Macro        Expands to:    Comment
  791. -----        -----------    -------
  792. __MSDOS__    1        If running under DOS.
  793.  
  794. __MAKE__    0x0370        MAKE's hex version number.
  795.  
  796. MAKE        make        MAKE's executable file name.
  797.  
  798. MAKEFLAGS    options        The options typed at the
  799.                 command line.
  800.  
  801. MAKEDIR        directory    Directory where MAKE.EXE is
  802.                 located.
  803.  
  804.  
  805. Modifying default macros
  806. ------------------------
  807. When the default macros listed in the preceding table doesn't give you
  808. the exact string you want, macro modifiers let you extract parts of
  809. the string to suit your purpose.
  810.  
  811. To modify a default macro, use this syntax:
  812.  
  813.     $(MacroName [modifier])
  814.  
  815. The following table lists macro modifiers and provides examples of
  816. their use.
  817.  
  818. Modifier    Part of file name expanded    Example    Result
  819. --------    --------------------------    --------------
  820. D        Drive and directory        $(<D)    C:\PROJECTA\
  821.  
  822. F        Base and extension        $(<F)    MYSOURCE.C
  823.  
  824. B        Base only            $(<B)    MYSOURCE
  825.  
  826. R        Drive, directory, and base    $(<R)    C:\PROJECTA\MYSOURCE
  827.  
  828.  
  829. Using MAKE directives
  830. =====================
  831. MAKE directives resemble directives in languages such as C and Pascal,
  832. and perform various control functions, such as displaying commands
  833. onscreen before executing them. MAKE directives begin either with an
  834. exclamation point or a period. The following table lists MAKE directives
  835. and their corresponding command-line options (directives override
  836. command-line options). Each directive is described in more detail
  837. following the table.
  838.  
  839. Directive    Option        Description
  840. ---------    ------        -----------
  841. .autodepend    -a        Turns on autodependency checking.
  842.  
  843. !elif                Acts like a C "else if".
  844.  
  845. !else                Acts like a C "else".
  846.  
  847. !endif                Ends an "!if", "!ifdef", or "!ifndef"
  848.                 statement.
  849.  
  850. !error                Stops MAKE and prints an error message.
  851.  
  852. !if                Begins a conditional statement.
  853.  
  854. !ifdef                If defined that acts like a C "ifdef", but
  855.                 with macros rather than "#define" directives.
  856.  
  857. !ifndef                If not defined.
  858.  
  859. .ignore        -i        MAKE ignores the return value of a command.
  860.  
  861. !include            Specifies a file to include in the makefile.
  862.  
  863. !message            Lets you print a message from a makefile.
  864.  
  865. .noautodepend    -a-        Turns off autodependency checking.
  866.  
  867. .noIgnore    -i-        Turns off ".Ignore".
  868.  
  869. .nosilent    -s-        Displays commands before MAKE executes them.
  870.  
  871. .noswap        -S-        Tells MAKE not to swap itself out of memory
  872.                 before executing a command.
  873.  
  874. .path.ext            Tells MAKE to search for files with the
  875.                 extension .ext in path directories.
  876.  
  877. .precious            Saves the target or targets even if the
  878.                 build fails.
  879.  
  880. .silent        -s        Executes without printing the commands.
  881.  
  882. .suffixes            Determines the implicit rule for ambiguous
  883.                 dependencies.
  884.  
  885. .swap        -S        Tells MAKE to swap itself out of memory
  886.                 before executing a command.
  887.  
  888. !undef                Clears the definition of a macro.
  889.  
  890.  
  891. .autodepend
  892. -----------
  893. Autodependencies occur in .OBJ files that have corresponding .CPP, .C,
  894. or .ASM files. With ".autodepend" on, MAKE compares the dates and times
  895. of all the files used to build the .OBJ. If the dates and times of the
  896. files used to build the .OBJ are different from the date-time stamp of
  897. the.OBJ file, the .OBJ file is recompiled. You can use ".autodepend" or
  898. -a in place of linked dependencies.
  899.  
  900.  
  901. !error
  902. ------
  903. This is the syntax of the !error directive:
  904.  
  905.   !error message
  906.  
  907. MAKE stops processing and prints the following string when it
  908. encounters this directive:
  909.  
  910.   Fatal makefile exit code: Error directive: message
  911.  
  912. Embed !error in conditional statements to abort processing and print
  913. an error message, as shown in the following example:
  914.  
  915.   !if !$d(MYMACRO)
  916.   #if MYMACRO isn't defined
  917.   !error MYMACRO isn't defined
  918.   !endif
  919.  
  920. If MYMACRO in the example isn't defined, MAKE prints the following
  921. message:
  922.  
  923.   Fatal makefile 4: Error directive: MYMACRO isn't defined
  924.  
  925.  
  926. Summing up error-checking controls
  927. - - - - - - - - - - - - - - - - - -
  928. Four different controls turn off error checking:
  929.  
  930.   o  The .ignore directive turns off error checking for a selected portion
  931.      of the makefile.
  932.  
  933.   o  The -i command-line option turns off error checking for the entire
  934.      makefile.
  935.  
  936.   o  The -num command operator, which is entered as part of a rule, turns
  937.      off error checking for the related command if the exit code exceeds
  938.      the specified number.
  939.  
  940.   o  The - command operator turns off error checking for the related
  941.      command regardless of the exit code.
  942.  
  943.  
  944. !if and other conditional directives
  945. ------------------------------------
  946. The !if directive works like C if statements. The syntax of !if and the
  947. other conditional directives resembles compiler conditionals.
  948.  
  949.  
  950. !include
  951. --------
  952. This directive is like the #include preprocessor directive for the C
  953. or C++ language--it lets you include the text of another file in the
  954. makefile:
  955.  
  956.   !include <filename>
  957.  
  958. You can enclose <filename> in quotation marks ("") or angle brackets
  959. (<>) and nest directives to unlimited depth, but writing duplicate
  960. !include directives in a makefile isn't permitted--you'll get the
  961. error message "cycle in the include file".
  962.  
  963. Rules, commands, or directives must be complete within a single source
  964. file; you can't start a command in an !include file, then finish it in
  965. the makefile.
  966.  
  967. MAKE searches for !include files in the current directory unless
  968. you've specified another directory with the -I option.
  969.  
  970.  
  971. !message
  972. --------
  973. The !message directive lets you send messages to the screen from a
  974. makefile. You can use these messages to help debug a makefile that
  975. isn't working the way you'd like it to. For example, if you're having
  976. trouble with a macro definition, you could put this line in your
  977. makefile:
  978.  
  979.   !message The macro is defined here as: $(<MacroName>)
  980.  
  981. When MAKE interprets this line, it will print onscreen "The macro is
  982. defined here as: .CPP", if the macro expands to .CPP at that line.
  983. Using a series of !message directives, you can debug your makefiles.
  984.  
  985.  
  986. .path.ext
  987. ---------
  988. The .path.ext directive tells MAKE where to look for files with a
  989. certain extension. The following example tells MAKE to look for files
  990. with the .c extension in C:\SOURCE or C:\CFILES and to look for files
  991. with the .obj extension in C:\OBJS.
  992.  
  993.   .path.c = C:\CSOURCE;C:\CFILES
  994.   .path.obj = C:\OBJS
  995.  
  996.  
  997. .precious
  998. ---------
  999. If a MAKE build fails, MAKE deletes the target file. The .precious
  1000. directive prevents the file deletion, which is desired for certain
  1001. kinds of targets such as libraries. When a build fails to add a module
  1002. to a library, you don't want the library to be deleted.
  1003.  
  1004. The syntax for .precious is:
  1005.  
  1006.   .precious: target [target] . . . [target]
  1007.  
  1008.  
  1009. .suffixes
  1010. ---------
  1011. The .suffixes directive tells MAKE the order (by file extensions) for
  1012. building implicit rules.
  1013.  
  1014. The syntax of the .suffixes directive is:
  1015.  
  1016.   .suffixes: .ext [.ext]  [.ext] . . . [.ext]
  1017.  
  1018. .ext represents the dependent file extension in implicit rules. For
  1019. example, you could include the line ".suffixes: .asm .c .cpp" to tell
  1020. MAKE to interpret implicit rules beginning with the ones dependent on
  1021. .ASM files, then .C files, then .CPP files, regardless of what order
  1022. they appear in the makefile.
  1023.  
  1024. The following example shows a makefile containing a .suffixes
  1025. directive that tells MAKE to look for a source file (MYPROG.EXE) first
  1026. with an .ASM extension, next with a .C extension, and finally with a
  1027. .CPP extension. If MAKE finds MYPROG.ASM, it builds MYPROG.OBJ from
  1028. the assembler file by calling TASM. MAKE then calls TLINK; otherwise,
  1029. MAKE searches for MYPROG.C to build the .OBJ file, and so on.
  1030.  
  1031.   .suffixes: .asm .c .cpp
  1032.  
  1033.   myprog.exe: myprog.obj
  1034.   tlink myprog.obj
  1035.  
  1036.   .cpp.obj:
  1037.     bcc -P $<
  1038.   .asm.obj:
  1039.     tasm /mx $<
  1040.   .c.obj:
  1041.     bcc -P- $<
  1042.  
  1043.  
  1044. !undef
  1045. ------
  1046. The syntax of the !undef directive is:
  1047.  
  1048.   !undef MacroName
  1049.  
  1050. !undef (undefine) clears the given macro, MacroName, causing an !ifdef
  1051. MacroName test to fail.
  1052.  
  1053.  
  1054. Using macros in directives
  1055. --------------------------
  1056. The macro $d is used with the !if conditional directive to perform
  1057. some processing if a specific macro is defined. The $d is followed by
  1058. a macro name, enclosed in parentheses or braces, as shown in the
  1059. following example.
  1060.  
  1061.   !if $d(DEBUG)                #If DEBUG is defined,
  1062.   bcc -v f1.cpp f2.cpp         #compile with debug information;
  1063.   !else                        #otherwise (else)
  1064.   bcc -v- f1.cpp f2.cpp        #don't include debug information.
  1065.   !endif
  1066.  
  1067. Don't use the $d macro when MAKE is invoked with the -N option.
  1068.  
  1069. /**************************** END OF FILE ********************************/
  1070.  
  1071.