home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / make.info-4 (.txt) < prev    next >
GNU Info File  |  1994-11-12  |  50KB  |  955 lines

  1. This is Info file make.info, produced by Makeinfo-1.55 from the input
  2. file ./make.texinfo.
  3.    This file documents the GNU Make utility, which determines
  4. automatically which pieces of a large program need to be recompiled,
  5. and issues the commands to recompile them.
  6.    This is Edition 0.47, last updated 1 November 1994, of `The GNU Make
  7. Manual', for `make', Version 3.72 Beta.
  8.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94 Free Software
  9. Foundation, Inc.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by the Free Software Foundation.
  21. File: make.info,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
  22. The `override' Directive
  23. ========================
  24.    If a variable has been set with a command argument (*note Overriding
  25. Variables: Overriding.), then ordinary assignments in the makefile are
  26. ignored.  If you want to set the variable in the makefile even though
  27. it was set with a command argument, you can use an `override'
  28. directive, which is a line that looks like this:
  29.      override VARIABLE = VALUE
  30.      override VARIABLE := VALUE
  31.    To append more text to a variable defined on the command line, use:
  32.      override VARIABLE += MORE TEXT
  33. *Note Appending More Text to Variables: Appending.
  34.    The `override' directive was not invented for escalation in the war
  35. between makefiles and command arguments.  It was invented so you can
  36. alter and add to values that the user specifies with command arguments.
  37.    For example, suppose you always want the `-g' switch when you run the
  38. C compiler, but you would like to allow the user to specify the other
  39. switches with a command argument just as usual.  You could use this
  40. `override' directive:
  41.      override CFLAGS += -g
  42.    You can also use `override' directives with `define' directives.
  43. This is done as you might expect:
  44.      override define foo
  45.      bar
  46.      endef
  47. *Note Defining Variables Verbatim: Defining.
  48. File: make.info,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
  49. Defining Variables Verbatim
  50. ===========================
  51. Another way to set the value of a variable is to use the `define'
  52. directive.  This directive has an unusual syntax which allows newline
  53. characters to be included in the value, which is convenient for defining
  54. canned sequences of commands (*note Defining Canned Command Sequences:
  55. Sequences.).
  56.    The `define' directive is followed on the same line by the name of
  57. the variable and nothing more.  The value to give the variable appears
  58. on the following lines.  The end of the value is marked by a line
  59. containing just the word `endef'.  Aside from this difference in
  60. syntax, `define' works just like `=': it creates a recursively-expanded
  61. variable (*note The Two Flavors of Variables: Flavors.).  The variable
  62. name may contain function and variable references, which are expanded
  63. when the directive is read to find the actual variable name to use.
  64.      define two-lines
  65.      echo foo
  66.      echo $(bar)
  67.      endef
  68.    The value in an ordinary assignment cannot contain a newline; but the
  69. newlines that separate the lines of the value in a `define' become part
  70. of the variable's value (except for the final newline which precedes
  71. the `endef' and is not considered part of the value).
  72.    The previous example is functionally equivalent to this:
  73.      two-lines = echo foo; echo $(bar)
  74. since two commands separated by semicolon behave much like two separate
  75. shell commands.  However, note that using two separate lines means
  76. `make' will invoke the shell twice, running an independent subshell for
  77. each line.  *Note Command Execution: Execution.
  78.    If you want variable definitions made with `define' to take
  79. precedence over command-line variable definitions, you can use the
  80. `override' directive together with `define':
  81.      override define two-lines
  82.      foo
  83.      $(bar)
  84.      endef
  85. *Note The `override' Directive: Override Directive.
  86. File: make.info,  Node: Environment,  Prev: Defining,  Up: Using Variables
  87. Variables from the Environment
  88. ==============================
  89.    Variables in `make' can come from the environment in which `make' is
  90. run.  Every environment variable that `make' sees when it starts up is
  91. transformed into a `make' variable with the same name and value.  But
  92. an explicit assignment in the makefile, or with a command argument,
  93. overrides the environment.  (If the `-e' flag is specified, then values
  94. from the environment override assignments in the makefile.  *Note
  95. Summary of Options: Options Summary.  But this is not recommended
  96. practice.)
  97.    Thus, by setting the variable `CFLAGS' in your environment, you can
  98. cause all C compilations in most makefiles to use the compiler switches
  99. you prefer.  This is safe for variables with standard or conventional
  100. meanings because you know that no makefile will use them for other
  101. things.  (But this is not totally reliable; some makefiles set `CFLAGS'
  102. explicitly and therefore are not affected by the value in the
  103. environment.)
  104.    When `make' is invoked recursively, variables defined in the outer
  105. invocation can be passed to inner invocations through the environment
  106. (*note Recursive Use of `make': Recursion.).  By default, only
  107. variables that came from the environment or the command line are passed
  108. to recursive invocations.  You can use the `export' directive to pass
  109. other variables.  *Note Communicating Variables to a Sub-`make':
  110. Variables/Recursion, for full details.
  111.    Other use of variables from the environment is not recommended.  It
  112. is not wise for makefiles to depend for their functioning on
  113. environment variables set up outside their control, since this would
  114. cause different users to get different results from the same makefile.
  115. This is against the whole purpose of most makefiles.
  116.    Such problems would be especially likely with the variable `SHELL',
  117. which is normally present in the environment to specify the user's
  118. choice of interactive shell.  It would be very undesirable for this
  119. choice to affect `make'.  So `make' ignores the environment value of
  120. `SHELL'.
  121. File: make.info,  Node: Conditionals,  Next: Functions,  Prev: Using Variables,  Up: Top
  122. Conditional Parts of Makefiles
  123. ******************************
  124.    A "conditional" causes part of a makefile to be obeyed or ignored
  125. depending on the values of variables.  Conditionals can compare the
  126. value of one variable to another, or the value of a variable to a
  127. constant string.  Conditionals control what `make' actually "sees" in
  128. the makefile, so they *cannot* be used to control shell commands at the
  129. time of execution.
  130. * Menu:
  131. * Conditional Example::         Example of a conditional
  132. * Conditional Syntax::          The syntax of conditionals.
  133. * Testing Flags::               Conditionals that test flags.
  134. File: make.info,  Node: Conditional Example,  Next: Conditional Syntax,  Up: Conditionals
  135. Example of a Conditional
  136. ========================
  137.    The following example of a conditional tells `make' to use one set
  138. of libraries if the `CC' variable is `gcc', and a different set of
  139. libraries otherwise.  It works by controlling which of two command
  140. lines will be used as the command for a rule.  The result is that
  141. `CC=gcc' as an argument to `make' changes not only which compiler is
  142. used but also which libraries are linked.
  143.      libs_for_gcc = -lgnu
  144.      normal_libs =
  145.      
  146.      foo: $(objects)
  147.      ifeq ($(CC),gcc)
  148.              $(CC) -o foo $(objects) $(libs_for_gcc)
  149.      else
  150.              $(CC) -o foo $(objects) $(normal_libs)
  151.      endif
  152.    This conditional uses three directives: one `ifeq', one `else' and
  153. one `endif'.
  154.    The `ifeq' directive begins the conditional, and specifies the
  155. conditi