Makefile Macro Substitution Help

T

tmponko

OK...I'm new to this and I'm sure I'm missing something obvious, so
please be kind.

I've tried several different approaches to this problem (including
various if, ifeq, and case constructs), and I'm about to give up. Can
any tell me why this doesn't work? In a nutshell, I want a Makefile
that will "include" either a Linux.mk or a SunOS.mk without having to
rely on an explicit command line parameter or env var.

Here is the segment that is giving me trouble:


#########################################################################
#
#
# Sample Makefile #
#
#
#########################################################################

#.SILENT:

# Use a known shell
SHELL=/bin/sh

# Obtain OS name (e.g., "Linux" or "SunOS")
THE_OS := `uname`

# Name the INCFILE using the OS name (e.g., "Macros.Linux.mk")
INCFILE := $(HOME)/src/Macros.$(THE_OS).mk

# Test defined macros to see if I have what I expect
echo:
@echo "THE_OS = :"$(THE_OS)":"
@echo "INCFILE = :"$(INCFILE)":"
ls -al $(INCFILE)

# Include the project default macros
include $(INCFILE)

<EOF>

-----------------------And here is the error I get
---------------------------

localhost.localdomain]/home/tponko/src% make
Makefile:20: /home/tponko/src/Macros.`uname`.mk: No such file or
directory
make: *** No rule to make target `/home/tponko/src/Macros.`uname`.mk'.
Stop.


Any/all help will be greatly appreciated.

Thanks...
 
A

a_the_s

The Makefile is fine. Simply running the command "make", though, is not. The parser thinks that
THE_OS :=
is a command-rule. Simply run "make echo", and you should get what you're looking for!

Hope I helped!
-Elliot :)



On 16 Dec 2003 14:19:30 -0800
OK...I'm new to this and I'm sure I'm missing something obvious, so
please be kind.

I've tried several different approaches to this problem (including
various if, ifeq, and case constructs), and I'm about to give up. Can
any tell me why this doesn't work? In a nutshell, I want a Makefile
that will "include" either a Linux.mk or a SunOS.mk without having to
rely on an explicit command line parameter or env var.

Here is the segment that is giving me trouble:


#########################################################################
#
#
# Sample Makefile #
#
#
#########################################################################

#.SILENT:

# Use a known shell
SHELL=/bin/sh

# Obtain OS name (e.g., "Linux" or "SunOS")
THE_OS := `uname`

# Name the INCFILE using the OS name (e.g., "Macros.Linux.mk")
INCFILE := $(HOME)/src/Macros.$(THE_OS).mk

# Test defined macros to see if I have what I expect
echo:
@echo "THE_OS = :"$(THE_OS)":"
@echo "INCFILE = :"$(INCFILE)":"
ls -al $(INCFILE)

# Include the project default macros
include $(INCFILE)

<EOF>

-----------------------And here is the error I get
---------------------------

localhost.localdomain]/home/tponko/src% make
Makefile:20: /home/tponko/src/Macros.`uname`.mk: No such file or
directory
make: *** No rule to make target `/home/tponko/src/Macros.`uname`.mk'.
Stop.


Any/all help will be greatly appreciated.

Thanks...


--
"Serpent!" screamed the Pigeon.
"I'm not a serpent!" said Alice indignantly. "Let me alone!"
"Serpent, I say again!" repeated the Pigeon, but in a more subdued tone, and added with a kind of sob, "I've tried every way, and nothing seems to suit them!"
- L. Carroll
-==++==++==++==++==++==-
"Always the hours."
 
T

tmponko

The Makefile is fine. Simply running the command "make", though, is not. The parser thinks that
THE_OS :=
is a command-rule. Simply run "make echo", and you should get what you're looking for!

Hope I helped!
-Elliot :)

Elliot,
I gave your suggestion another shot (see below), but got the same
result.

From the reading I've done I get the impression that make performs two
passes, and macro substitution for the "include $(INCFILE)" statement
is not resolving to the value of function `uname` used in the INCFILE
declaration.

So I'm still stumped...

Thanks

[tponko@localhost src]$ make echo
Makefile:19: /home/tponko/src/Macros.`uname`.mk: No such file or
directory
make: *** No rule to make target `/home/tponko/src/Macros.`uname`.mk'.
Stop.
 
T

tmponko

So I gave up and moved the compiler definition to my login script.
Since make recognizes env vars, this brute force approach was
sufficient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top