Specifying Compiler for Make

Hi All,

Which would be the best way to force make to use qcc instead of gcc?

I’m compiling some source packages that have many subdirectories, with their
own makefiles, so it’s unrealistic to edit each makefile to change the
compiler. I’m wondering if there is a way of setting this variable in one’s
…profile, for instance.

I’m not aware of any ./configure option that allows one to specify a
compiler.

Thanks,
Neil.

Neil Carter
Psychology Department
University of Wales Swansea, UK
http://psy.swan.ac.uk/staff/carter/

If it is a ./configure based project you can do it ./configure time.

CC=qcc CXX=QCC ./configure --prefix=/usr/local …

If you already have a Makefile then you can try…

CC=qcc CXX=QCC make

…if that works you can just export the two env. variables.

chris

Neil Carter <pstech@swansea.ac.uk> wrote:

Hi All,

Which would be the best way to force make to use qcc instead of gcc?

I’m compiling some source packages that have many subdirectories, with their
own makefiles, so it’s unrealistic to edit each makefile to change the
compiler. I’m wondering if there is a way of setting this variable in one’s
.profile, for instance.

I’m not aware of any ./configure option that allows one to specify a
compiler.

Thanks,
Neil.

Neil Carter
Psychology Department
University of Wales Swansea, UK
http://psy.swan.ac.uk/staff/carter/
\


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

%% Chris McKillop <cdm@qnx.com> writes:

cm> If it is a ./configure based project you can do it ./configure time.

cm> CC=qcc CXX=QCC ./configure --prefix=/usr/local …

cm> If you already have a Makefile then you can try…

cm> CC=qcc CXX=QCC make

cm> …if that works you can just export the two env. variables.

It’s unlikely that this will work–actually I can say with almost
complete certainty it won’t work.

Why? Because make has builtin variables CC, etc. and they have default
values (“cc” usually), and any variable defined in the makefile (even if
it’s built in) will take precedence over any variable found in the
environment (unless you use the -e option–but you don’t want to do
that).

You should use:

$ make CC=qcc

because any variable value set on the make command line will always
override any value set anywhere inside a makefile (including builtin
variables)–unless you’re using GNU make and the “override” keyword–but
you don’t want to do that.


Unfortunately, often QSSL’s makefiles are broken (at least the ones in
the BSP’s we’ve received have been–I keep forgetting to send in a bug
report :-/) which makes recursive builds much more difficult than they
should be; however this approach should still work.

And, if you want to make it automatic you can always add a rule at the
top that does something like:

.PHONY: prebuild
prebuild:
$(MAKE) CC=qcc all

or whatever.

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.

%% “Paul D. Smith” <pausmith@nortelnetworks.com> writes:

pds> unless you’re using GNU make and the “override” keyword–but you
pds> don’t want to do that.

I only meant you don’t want to use “override”, of course–you definitely
do want to use GNU make :slight_smile:.

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.

Paul D. Smith <pausmith@nortelnetworks.com> wrote:

Why? Because make has builtin variables CC, etc. and they have default
values (“cc” usually), and any variable defined in the makefile (even if
it’s built in) will take precedence over any variable found in the
environment (unless you use the -e option–but you don’t want to do
that).

I have tested it and it does work. Unless the Makefile explicity sets
the CC and CXX values, GNU make will honour the env. variable before it’s
own built-in values.

$ make CC=qcc

because any variable value set on the make command line will always
override any value set anywhere inside a makefile (including builtin
variables)–unless you’re using GNU make and the “override” keyword–but
you don’t want to do that.

Fair enough - that is probably a more general solution since it will work
when the Makefile explicity sets CC.

Unfortunately, often QSSL’s makefiles are broken (at least the ones in
the BSP’s we’ve received have been–I keep forgetting to send in a bug
report :-/) which makes recursive builds much more difficult than they
should be; however this approach should still work.

I have yet to see anything that is broken - although you might not be used
to the rules of using our build system. That is, you don’t put anything
into any of the Makefile(s) but do everything from the top level common.mk.

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

%% Chris McKillop <cdm@qnx.com> writes:

cm> I have tested it and it does work. Unless the Makefile explicity
cm> sets the CC and CXX values, GNU make will honour the env. variable
cm> before it’s own built-in values.

Whoops; you’re right: I forgot that builtin variables had a special
precedence.

Unfortunately, often QSSL’s makefiles are broken (at least the ones in
the BSP’s we’ve received have been–I keep forgetting to send in a bug
report :-/) which makes recursive builds much more difficult than they
should be; however this approach should still work.

cm> I have yet to see anything that is broken - although you might not
cm> be used to the rules of using our build system. That is, you
cm> don’t put anything into any of the Makefile(s) but do everything
cm> from the top level common.mk.

This is not what I mean; QSSL has a bad habit of putting $(MAKEFLAGS)
explicitly in the command for recursive makes:

.PHONY: subdir
subdir:
cd $@ && $(MAKE) $(MAKEFLAGS)

This is incorrect: MAKEFLAGS is never meant to be used explicitly on the
command line like this, and depending on what kind of flags you use on
your top-level make the above will fail. MAKEFLAGS is designed to
communicate between parent and sub-makes by being passed through the
environment, not on the command line.

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.