Board index » cppbuilder » How to use the '#' symbol in makefiles

How to use the '#' symbol in makefiles


2005-06-09 11:52:51 PM
cppbuilder92
[I'm using bcc 5.5 command line free tools on winxp sp2]
Hi,
I need to write a borland makefile with a command like:
mytarget:
echo #define HELLO $(HELLO_OPTION)>myfile.h
however, I've found that MAKE does not behaves as I need since it
(correctly!) thinks that everything on the right of # is a comment... so
my question is: how can I use the '#' symbol in makefile without having
it recognized as a comment marker ?
Thanks indeed,
Francesco Montorsi
 
 

Re:How to use the '#' symbol in makefiles

Francesco Montorsi < XXXX@XXXXX.COM >writes:
Quote
[I'm using bcc 5.5 command line free tools on winxp sp2]
Then you are posting to the wrong newsgroup. What identifies itself as
Borland C++ 5.5 is the compiler of C++ Builder 5.
Please direct your browser at info.borland.com/newsgroups/ and
read the newsgroup descriptions and guidelines. This will help you
find the appropriate newsgroup for your question.
C++ Builder groups have .cppbuilder. in their name.
 

Re:How to use the '#' symbol in makefiles

Francesco Montorsi wrote:
Quote
[I'm using bcc 5.5 command line free tools on winxp sp2]

mytarget:
echo #define HELLO $(HELLO_OPTION)>myfile.h

however, I've found that MAKE does not behaves as I need since it
(correctly!) thinks that everything on the right of # is a comment... so
my question is: how can I use the '#' symbol in makefile without having
it recognized as a comment marker ?
First, I wouldn't do that, I'd use a compiler directive:
-DHELLO=$(HELLO_OPTION)
in the compiler commandline.
Otherwise, I'd use a batch file.
 

{smallsort}

Re:How to use the '#' symbol in makefiles

Make defines the '#' character as a delimiter indicating that what follows
or is to the right is to be ignored. I do not know of any way to change
that.
There are many different ways to do that. The inablity to use '#' as a
character in the make file should not be much of a problem. You could use a
batch file, use a file that you copy or write a program only a couple of
lines long to do what you want.
. Ed
Quote
Francesco Montorsi wrote in message
news: XXXX@XXXXX.COM ...

[I'm using bcc 5.5 command line free tools on winxp sp2]

Hi,
I need to write a borland makefile with a command like:

mytarget:
echo #define HELLO $(HELLO_OPTION)>myfile.h

however, I've found that MAKE does not behaves as I need since it
(correctly!) thinks that everything on the right of # is a comment... so
my question is: how can I use the '#' symbol in makefile without having it
recognized as a comment marker ?
 

Re:How to use the '#' symbol in makefiles

Ed Mulroy < XXXX@XXXXX.COM >wrote:
Quote
Make defines the '#' character as a delimiter indicating that what follows
or is to the right is to be ignored. I do not know of any way to change
that.
Treating it as special even in the command section of a production
rule feels like a bug in make, to me.
It's none of make's business to limit what can and what cannot be part
of stuff written in there, because it is ultimately not going to be
processed by make, but by external programs make knows nothing about.
At the very least, every known character must be producable in there.
It may take an escape sequence (like $$ or \$ to get a single actual
$), but it must absolutely be possible to generate it and have it
passed to the program being run.
--
Hans-Bernhard Broeker ( XXXX@XXXXX.COM )
Even if all the snow were burnt, ashes would remain.
 

Re:How to use the '#' symbol in makefiles

# is the comment start character and it has been that way for over 19 years.
. Ed
Quote
Hans-Bernhard Broeker wrote in message
news: XXXX@XXXXX.COM ...

Treating it as special even in the command section of a production
rule feels like a bug in make, to me.

It's none of make's business to limit what can and what cannot be part
of stuff written in there, because it is ultimately not going to be
processed by make, but by external programs make knows nothing about.

At the very least, every known character must be producable in there.
It may take an escape sequence (like $$ or \$ to get a single actual
$), but it must absolutely be possible to generate it and have it
passed to the program being run.
 

Re:How to use the '#' symbol in makefiles

Ed Mulroy < XXXX@XXXXX.COM >wrote:
Quote
# is the comment start character and it has been that way for over
19 years.
I know. I even agree that's how it should be, as far as those lines
of the makefile are concerned that only make actually reads,
w.e. variable definitions, general comments and whatnot.
But if '#' acts as a make-processed comment character even in the
*command* part of a rule, i.e. a command line from the makefile
reading
foo bar #value
ends up invoking
foo bar
, with no way of getting the "#value" part passed along, too, then I
don't see any other possible conclusion than that it's been buggy for
all those 19 years. Other make implementations get this right.
And no, putting the desired command line into a
separate batch file to be invoked by make is not a viable workaround.
To start with, return status from batch files is not reliably
available, so make wouldn't know if this command succeeded or not.
--
Hans-Bernhard Broeker ( XXXX@XXXXX.COM )
Even if all the snow were burnt, ashes would remain.
 

Re:How to use the '#' symbol in makefiles

There is no way it can both be a start of comment char at one point and a
normal char at another. Something must change if the parsing in make.exe is
to detect for which purpose it is intended. If you want to use it
immediately following whitespace, then has to be escaped.
----------------------------
C:\Documents and Settings\Edward\My Documents\Projects\play
Quote
type makefile
file2.txt : file1.txt
copy /v file1.txt file2.txt
del file1.txt
file1.txt :
echo \#define>file1.txt
echo abc>>file1.txt
C:\Documents and Settings\Edward\My Documents\Projects\play
Quote
make
MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
echo #define>file1.txt
echo abc>>file1.txt
copy /v file1.txt file2.txt
1 file(s) copied.
del file1.txt
C:\Documents and Settings\Edward\My Documents\Projects\play
Quote
type file2.txt
#define
abc
C:\Documents and Settings\Edward\My Documents\Projects\play
Quote

----------------------------
. Ed
Quote
Hans-Bernhard Broeker wrote in message
news: XXXX@XXXXX.COM ...

># is the comment start character and it has been that way for over
>19 years.

I know. I even agree that's how it should be, as far as those lines
of the makefile are concerned that only make actually reads,
w.e. variable definitions, general comments and whatnot.

But if '#' acts as a make-processed comment character even in the
*command* part of a rule, i.e. a command line from the makefile
reading

foo bar #value

ends up invoking

foo bar

, with no way of getting the "#value" part passed along, too, then I
don't see any other possible conclusion than that it's been buggy for
all those 19 years. Other make implementations get this right.

And no, putting the desired command line into a
separate batch file to be invoked by make is not a viable workaround.
To start with, return status from batch files is not reliably
available, so make wouldn't know if this command succeeded or not.
 

Re:How to use the '#' symbol in makefiles

Ed Mulroy < XXXX@XXXXX.COM >wrote:
Quote
There is no way it can both be a start of comment char at one point and a
normal char at another.
Oh, but of course there is. The makefile parser only has to know
whether it's currently reading the command part of a rule, or some
other piece of a makefile, at the point it decides what to do with
that '#'. The only case in which this could be even mildly
complicated would be if comment-removal were done by a pre-processing
stage that doesn't actually know about makefile syntax. A
single-stage parser would have no problem whatsoever --- otherwise,
how could a C parser ever recognized that */ means the comment end
only if it's found inside a comment?
But let's put this issue to rest, now that you've demonstrated that it
is, indeed, possible to put a '#' in a command line from inside the
makefile, settling the OP's question.
--
Hans-Bernhard Broeker ( XXXX@XXXXX.COM )
Even if all the snow were burnt, ashes would remain.