From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: Generic makefile! (Re: Reverse-compiler) Date: Thu, 06 Apr 2000 00:28:28 +0100 Organization: Customer of Planet Online Lines: 61 Message-ID: References: <8c3eae$j1l$1 AT news6 DOT svr DOT pol DOT co DOT uk> <8c457a$162$1 AT news7 DOT svr DOT pol DOT co DOT uk> <8caj5q$ii3$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <8cb2cm$t25$1 AT news6 DOT svr DOT pol DOT co DOT uk> <38EB7931 DOT C8B9E132 AT is DOT elta DOT co DOT il> <38EB8F1B DOT 16885EDC AT corel DOT com> NNTP-Posting-Host: modem-8.oxygen.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg2.svr.pol.co.uk 954978001 13749 62.136.7.8 (5 Apr 2000 23:40:01 GMT) NNTP-Posting-Date: 5 Apr 2000 23:40:01 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 Jonathan Meunier wrote: > Make knows how to compile C files, but is there any easy way to make it > compile C++ files? Sure, there are built in rules for C++ too. :-) > What I'm doing right now is this: > > CC = gpp > CFLAGS = -Wall -O3 The C++ rules use different variables: CXX = gpp CXXFLAGS = -Wall -O3 LDFLAGS = -g # Linker flags (see below) > > OBJS = file1.o file2.o > HEADS = file1.h file2.h > > file.exe: $(OBJS) > $(CC) $(CFLAGS) -o $@ $(OBJS) You shouldn't need CFLAGS for linking (AFAIK). Normally the linker flags are set with LDFLAGS. And you can simplify the command too: file: $(OBJS) $(CXX) $(LDFLAGS) -o $@ $^ > file1.o: $(HEADS) > $(CC) $(CFLAGS) -c file1.cpp > file2.o: $(HEADS) > $(CC) $(CFLAGS) -c file2.cpp Omit the command lines if you want to use the built in commands: file1.o: $(HEADS) file2.o: $(HEADS) > > This gets very long in big projects.. :\ There must be a way to simply > tell make to take each .cpp file and compile them with gpp with those > flags. Hopefully the above will do what you want. But you can make life even easier if you get the compiler to create dependency files for you, that way you don't have to worry about the headers. CXX = gpp CXXFLAGS = -Wall -O3 # C++ Compiler flags LDFLAGS = -g # Linker flags OBJS = file1.o file2.o file: $(OBJS) $(CXX) $(LDFLAGS) -o $@ $^ CPPFLAGS += -MMD # Pre-Processor flags -include $(OBJS:.o=.d)