05-25-05 11:02 PM
"pieter" <pieter@gmail.com> wrote:
>I'm trying to set a variable in my makefile to a numeric value, but I
>don't know how this is done.
Can't be done, by definition. From the info file on GNU make,
How to Use Variables
********************
A "variable" is a name defined in a makefile to represent a
string of text, called the variable's "value".
..
Variables can represent lists of file names, options to pass
to compilers, programs to run, directories to look in for
source files, directories to write output in, or anything
else you can imagine.
Hence, variable are by definition strings and *cannot* represent
a numeric value. Of course you *can* save a string that is a
representation of a numeric value... but you need to make the
distinction that it is a string and not an integer.
>Consider for instance:
>
>index = 1
>index += 1
Add to that,
index := 1
They each make a variable named "index" and set its value to be
a string containing the single character "1". Except, with +=
if such a variable already exists, then the new string is
concatenated (with separating whitespace) to the end of the
original string value. Hence,
index =
index = a number
index += 1
would be just the same as
index = a number 1
Note the difference between = and := is useful too:
"Variables defined with `=' are "recursively expanded"
variables. Variables defined with `:=' are "simply
expanded" variables; these definitions can contain
variable references which will be expanded before the
definition is made. *Note The Two Flavors of Variables:
Flavors."
GNU info for make
>How do I do this? It's a rather simple problem, but I've been searching
>the manual pages and the web for numeric and makefile, etc. I don't get
>any helpful results ... Please help.
One thing you need to do is *experiement*! With variables, that
is fairly easy to do. First, almost all command files for make
have the name "Makefile", but if there is a file named
"makefile" it will be executed instead. Hence right in the
middle of any project, you can test something by using a
"makefile", and when you are finished just "rm makefile" and
you're back to where you started. You might want to start by
copying your Makefile to makefile, or by just writing a small
new one.
Here is an example of a makefile that shows you what the above
operations with variables do,
# test makefile
index =
index = a number
index += 1
the first target is executed:
@echo "index: $(index)"
# end of makefile
Examples of experiments that are instructive would be to change
the amount of white space in the strings, and then put comments
after them, such as
index = a number # comment
Also try all of that with double quote and single quote mark
delimiting the strings.
--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
[ Post a follow-up to this message ]
|