Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I pass compiler switches into a Make file?

5 views
Skip to first unread message

General Schvantzkoph

unread,
Jun 16, 2009, 8:59:20 AM6/16/09
to
How do I pass a compiler switch into a make file?

Lew Pitcher

unread,
Jun 16, 2009, 9:12:56 AM6/16/09
to
On June 16, 2009 08:59, in comp.os.linux.development.apps, General
Schvantzkoph (schvan...@yahoo.com) wrote:

> How do I pass a compiler switch into a make file?

In your Makefile, you code MACRO definition lines that specify the flags

CFLAGS = <flags for the C compilation units>
CPPFLAGS = <flags for the C++ compilation units>

GNU make exposes a number of other macros, so check the documentation for
macros suitable to your needs.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


Art Werschulz

unread,
Jun 16, 2009, 9:49:55 AM6/16/09
to
Hi.

Lew Pitcher <lpit...@teksavvy.com> writes:

> On June 16, 2009 08:59, in comp.os.linux.development.apps, General
> Schvantzkoph (schvan...@yahoo.com) wrote:
>
>> How do I pass a compiler switch into a make file?
>
> In your Makefile, you code MACRO definition lines that specify the flags
>
> CFLAGS = <flags for the C compilation units>
> CPPFLAGS = <flags for the C++ compilation units>

More precisely:
CXXFLAGS = <extra flags to give the C++ compiler>,
whereas
CPPFLAGS = <extra flags to give the C preprocessor and programs that
use it>
I found this by looking at the info files for make.

Most of the time, this is a distinction without a difference. The only
time this would matter is when you want the C preprocessor to have
different flags than the C++ compiler.

--
Art Werschulz (8-{)} "Metaphors be with you." -- bumper sticker
GCS/M (GAT): d? -p+ c++ l++ u+ P++ e--- m* s n+ h f g+ w+ t+ r-
Net: a...@dsm.fordham.edu http://www.dsm.fordham.edu/~agw
Phone: Fordham U. (212) 636-6325, Columbia U. (212) 939-7060

John Reiser

unread,
Jun 16, 2009, 9:53:35 AM6/16/09
to
> How do I pass a compiler switch into a make file?

Shell environment variables can be accessed by using '$$' prefix.

-----foo.mk
all:
echo $$a
-----

$ export a=b
$ make -f foo.mk
echo $a
b

--

Lew Pitcher

unread,
Jun 16, 2009, 9:54:04 AM6/16/09
to
On June 16, 2009 09:49, in comp.os.linux.development.apps, Art Werschulz
(a...@dsm.fordham.edu) wrote:

> Hi.
>
> Lew Pitcher <lpit...@teksavvy.com> writes:
>
>> On June 16, 2009 08:59, in comp.os.linux.development.apps, General
>> Schvantzkoph (schvan...@yahoo.com) wrote:
>>
>>> How do I pass a compiler switch into a make file?
>>
>> In your Makefile, you code MACRO definition lines that specify the flags
>>
>> CFLAGS = <flags for the C compilation units>
>> CPPFLAGS = <flags for the C++ compilation units>
>
> More precisely:
> CXXFLAGS = <extra flags to give the C++ compiler>,
> whereas
> CPPFLAGS = <extra flags to give the C preprocessor and programs that
> use it>

D*mn, I always get those two mixed up. For some reason, I associate CPP
to "C Plus Plus" rather than "C Pre Processor"

Thanks for the correction

General Schvantzkoph

unread,
Jun 16, 2009, 10:12:57 AM6/16/09
to

This sounds like the right thing. To pass the arguments args I would do

setenv args +define+fpga

and then have the following in my make file

foo: foo.v
vlog $$args foo.v

Sergei Organov

unread,
Jun 16, 2009, 10:43:15 AM6/16/09
to
General Schvantzkoph <schvan...@yahoo.com> writes:

No, that's not idiomatic at all. Usually you have the following in your
makefile:

foo: foo.v
vlog $(VLOG_FLAGS) foo.v

And then run make like this:

$ make VLOG_FLAGS="+define+fpga"

-- Sergei.

General Schvantzkoph

unread,
Jun 16, 2009, 2:51:01 PM6/16/09
to

Is there a way to set a default value for the flags in the Makefile which
would be overwritten by the command line argument?

Sergei Organov

unread,
Jun 16, 2009, 4:17:43 PM6/16/09
to
General Schvantzkoph <schvan...@yahoo.com> writes:

Sure,

VLOG_FLAGS = whatever

in the Makefile will do. Command line always overrides what's written
in the Makefile.

Why don't you just RTFM:

<http://www.gnu.org/software/make/manual/make.html#Using-Variables>

and

<http://www.gnu.org/software/make/manual/make.html#Overriding>

in particular.

-- Sergei.

William Pursell

unread,
Jun 17, 2009, 2:01:05 AM6/17/09
to
On 16 June, 19:51, General Schvantzkoph <schvantzk...@yahoo.com>
wrote:

> Is there a way to set a default value for the flags in the Makefile which
> would be overwritten by the command line argument?

RTFM. Here's a quick example that you might find enlightening:

bash-3.2$ make clean a
rm -f a.o b.o c.o
cc -pg -Dbubba -c -o b.o b.c
cc -pg -Dbubba -c -o c.o c.c
cc -pg -Dbubba a.c b.o c.o -o a
bash-3.2$ make clean a CFLAGS=-g
rm -f a.o b.o c.o
cc -g -Dbubba -c -o b.o b.c
cc -g -Dbubba -c -o c.o c.c
cc -g -Dbubba a.c b.o c.o -o a
bash-3.2$ make clean a CFLAGS=-g CPPFLAGS=-Dfoo
rm -f a.o b.o c.o
cc -g -Dfoo -c -o b.o b.c
cc -g -Dfoo -c -o c.o c.c
cc -g -Dfoo a.c b.o c.o -o a
bash-3.2$ cat Makefile

CPPFLAGS = -Dbubba
CFLAGS = -pg
a: b.o c.o
clean:
rm -f a.o b.o c.o

General Schvantzkoph

unread,
Jun 17, 2009, 7:49:57 AM6/17/09
to

Thanks to all

0 new messages