help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Disambiguating # within commands


From: Paul D. Smith
Subject: Re: Disambiguating # within commands
Date: Fri, 12 Apr 2002 19:07:44 -0400

%% Trevor Jenkins <address@hidden> writes:

  tj> I'm trying to understand the use of # in makefiles. The commands
  tj> I'm need to manage my project include a literal # as part of the
  tj> program option.  However, it isn't clear to me when make sees a
  tj> number sign as a comment start and when it doesm't.

Any occurance of a literal "#" in the makefile is considered a comment
except in the following situations:

 1) It's escaped with a \, as in \#

 2) It appears in a variable name or function, as in $(foo#bar)

 3) It appears in a command script (that is, a line that starts with a
    TAB).

Every other occurrence of a literal "#" is treated as a comment by make.

  tj> The Makefile I'm trying to write is for a Docbook/SGML/DSSSL
  tj> documentation project. Thought this would be simple until I came
  tj> across an option where I need to use an option like this:

  tj>     -d projdir/project-driver.dsl#print

  tj> Where a # mark found right about ^ there is vital to the correct
  tj> operation of (open)jade. It forms part of the option string.

If you need this to appear in a make variable, you will have to escape
it when you define the variable value, like this:

  FLAGS = -d projdir/project-driver.dsl\#print

If you put it directly into a script, you don't need to escape it.

  tj> INCLUDEFILE = #include <stdio.h>

  tj> Where again the # symbol is clearly data rather than introducing a
  tj> comment.

"Clearly?"  Clear to who?  :).  It's certainly not clear to make.  From
make's perspective what's the difference between the above and something
like this:

  INCLUDEFILE = -I/usr/include   # needed for #include <stdio.h>

  tj> In both these anecdotal cases the # sign can't be swapped for
  tj> something else. So how can I be certain that make won't see these
  tj> characters as commentary and screw up my Makefile? I could follow
  tj> an empiricist line and test the current behaviour of make but I
  tj> require something I rely upon.

Using backslash to escape the comment character is the official method.
This is even required by the POSIX standard for make.  If the docs don't
make this clear, there's a bug there.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist



reply via email to

[Prev in Thread] Current Thread [Next in Thread]