delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/23/19:30:20

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Make file wildcards
Date: Fri, 23 Jun 2000 23:56:28 +0100
Organization: Customer of Planet Online
Lines: 66
Message-ID: <mjq7lskslq2g3h46oeobjouvhjuuujantm@4ax.com>
References: <395309A1 DOT 881A2311 AT pacbell DOT net> <200006230948 DOT MAA02794 AT mailgw1 DOT netvision DOT net DOT il> <3953D200 DOT 897086E1 AT pacbell DOT net>
NNTP-Posting-Host: modem-57.oxygen.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg1.svr.pol.co.uk 961801096 20516 62.136.7.57 (23 Jun 2000 22:58:16 GMT)
NNTP-Posting-Date: 23 Jun 2000 22:58:16 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Wesel <nospam AT pacbell DOT net> wrote:

> Eli Zaretskii wrote:
> > 
> > > I built my makefile as follows:
> > >
> > > --------------------------------------------------------
> > > CC = gcc

CC = gpp
(or you won't link with the C++ library)

> > > CFLAGS = -g
> > > OBJECTS = test.o
> > >
> > > main.exe : $(OBJECTS)
> > >       $(CC) $(CFLAGS) $(OBJECTS) -o main.exe
> > >
> > > %.o : %.c %.cpp %.h
> > >       $(CC) $(CFLAGS) -c $<

This would work if you used separate rules:

%.o : %.c %.h
	$(CC) $(CFLAGS) -c $<
%.o : %.cpp %.h
	$(CC) $(CFLAGS) -c $<

> > > what I saw was
> > >
> > > --------------------------------------------------------
> > > make -k
> > > gpp    -c -o test.o test.cpp
> > > gcc -g test.o -o main.exe
> > 
> > This is expected behavior.  As written, the implicit rule you used
> > is just another implicit rule, not unlike the one that Make already
> > knows about.  When Make sees more than one implicit rule to build the
> > same target, it chooses the first one, which will always be the one
> > that's built into Make.

Do you really mean that?  I don't follow.  Normally if you redefine a
rule it should overide the built in rule.  

> > Lesson no.1: do not use implicit rules if Make already has a built-in
> > rule for that case.  Instead, tailor the existing implicit rule to
> > your need by changing the variables used by that rule, such as CC,
> > CXX, CXXFLAGS, etc.
> 
> I tried using the built in rules, and it worked!  My problem before was
> compiling a .cpp file but only modifying the CFLAGS variable.  CPPFLAGS
> put the proper debugging flags in.

CPPFLAGS is for the pre-processor options.
CXXFLAGS is the C++ equivalent to CFLAGS.
CXX is the C++ equivalent to CC (but these are already set by make)

Other macros of interest:
LDFLAGS for setting linker options.
LDLIBS for setting libraries to link with.

`info make cat' tells more.

You can set the macros as environment variables too, and make will use
them if they are not defined in the makefile.  But IMHO this is more
trouble than it is worth.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019