Article View: comp.unix.programmer
Article #3363Re: Makefile dependencies for multiple directories project using g++
From: toby
Date: Mon, 08 Jan 2007 16:59
Date: Mon, 08 Jan 2007 16:59
56 lines
2821 bytes
2821 bytes
Yos P. wrote: > Hello, > I'm using this makefile to compile a C++ project (using g++): > > CC = g++ > CFLAGS = -Wall > OBJ = somefile.o somefile.o... somefile_in_another_dir.o... > somefile_in_another_dir.o... > > all: test > > .cpp.o: > $(CC) $(CFLAGS) -c $< > > test: $(OBJ) > $(CC) $(CFLAGS) $^ -o $@ > > clean: > rm -f *.o *~ test > > depend: > echo -e '\n' >> Makefile > $(CC) -MM *.cpp >> Makefile > > .PHONY: all clean > > By now, all of my files were in the same directory, but since my > project grew larger I've add some sub-directories. > My questions are: > 1. How do I config the depend to include dependencies from other > directories. In this case, you would wildcard in those directories also. There are more sophisticated ways to generate dependencies that do not modify the makefile and automatically regenerate when out of date (see 'info make'). > > 2. I'll be happy if anyone could remind me the g++ flags for compiling > when #include from other directories, and linking when involved .o > files from multiple directories. If each source file has a distinct name, then simply use 'vpath' directive to add them to make's search path, and they will be found and trigger your stated pattern rule for compilation. vpath %.cpp dir1 dir2 Your dependency rules only need to give the prerequisite's filename (excluding directory). > > Thanks, > Yos P.
Technical Details
Message-ID:
<1168275557.890417.241520@38g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!38g2000cwa.googlegroups.com!not-for-mailReferences:
<1168257415.104749.312440@42g2000cwt.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: fc89c,d9c06db749d745aa X-Google-Thread: 10ba33,d9c06db749d745aa X-Google-Attributes: gidfc89c,gid10ba33,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!38g2000cwa.googlegroups.com!not-for-mail From: "toby" <toby@telegraphics.com.au> Newsgroups: comp.unix.programmer,gnu.g++.help Subject: Re: Makefile dependencies for multiple directories project using g++ Date: 8 Jan 2007 08:59:17 -0800 Organization: http://groups.google.com Lines: 57 Message-ID: <1168275557.890417.241520@38g2000cwa.googlegroups.com> References: <1168257415.104749.312440@42g2000cwt.googlegroups.com> NNTP-Posting-Host: 204.15.192.18 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1168275564 20873 127.0.0.1 (8 Jan 2007 16:59:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 8 Jan 2007 16:59:24 +0000 (UTC) In-Reply-To: <1168257415.104749.312440@42g2000cwt.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 toronto2.smartgames.ca:3128 (squid/2.6.STABLE5) Complaints-To: groups-abuse@google.com Injection-Info: 38g2000cwa.googlegroups.com; posting-host=204.15.192.18; posting-account=WnDYPgwAAAD134uw4c1soGzKsLX8U0qE