www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/22/08:16:53

Xref: news2.mv.net comp.os.msdos.djgpp:1323
From: itmiller AT taz DOT dra DOT hmg DOT gb ()
Newsgroups: comp.os.msdos.djgpp
Subject: Using GNU make (AHHHHHHH!), a solution
Date: 19 Feb 1996 10:39:45 GMT
Organization: Defence Research Agency
Lines: 91
Distribution: world
Message-ID: <4g9k1h$16h@trog.dra.hmg.gb>
Reply-To: itmiller AT taz DOT dra DOT hmg DOT gb ()
NNTP-Posting-Host: taz.dra.hmg.gb
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I spent ALL weekend (and it was my birthday on Saturday :))
reading the make info files and setting up a template makefile.
EVENTUALLY, I came up with one that lets me keep the COFF files
(required by the debuggers) as *.out if I define DEBUG, and put
my project C++ source and header files in ./src and ./include
respectively in the interests of neatness. Ideally, I would also
put the object files in a subdirectory, but I gave up on that to
save my sanity.

I include the result at the end of this posting to save other
beginners this hassle.

Of the more experienced djgpp programmers I ask does "dj make"
behave in EXACTLY the same way as under, say, unix? My guess is
that it does as every other make I have come across has also
been perverse. Notice, for instance, that I have had to use both
VPATH and vpath to search for dependencies because it will not
(yes, I think it is being deliberately annoying :)) find the .cc
files if I just use VPATH defined as ./src:./include. I find that
searches for dependencies not in the current directory are
generally problematic, perhaps because the searches happen in a
non-obvious (and therefore not useful) order. The default rules
are not what the info files say they are either. My rule for
making %.o from %.cc is the one they say I should have already;
but just try leaving it out...

Constructive comments/elegant solutions are welcome, Ian.

# Reasonably useful makefile
PHONY: all clean distclean \
	testTile \
	testBag \
	t_setup

all: testTile testBag t_setup

VPATH=./include
vpath %.cc ./src

COMPILE.cc = gcc
LINK.cc    = gcc
CPPFLAGS   = $(patsubst %,-I%,$(subst :, ,$(VPATH))) -I-
CXXFLAGS   = -O3
LDLIBS     = -lgpp

ifdef DEBUG
CXXFLAGS += -g
endif

testBag: testBag.exe ;
testBag.exe: testBag.o Bag.o Tile.o
	$(LINK.cc) $(CXXFLAGS) -o $(@:%.exe=%.out) $^ $(LDLIBS)
ifndef DEBUG
	-del $(@:%.exe=%.out)
endif

testTile: testTile.exe ;
testTile.exe: testTile.o Tile.o
	$(LINK.cc) $(CXXFLAGS) -o $(@:%.exe=%.out) $^ $(LDLIBS)
ifndef DEBUG
	-del $(@:%.exe=%.out)
endif

t_setup: t_setup.exe ;
t_setup.exe: t_setup.o Tile.o Bag.o setup.o
	$(LINK.cc) $(CXXFLAGS) -o $(@:%.exe=%.out) $^ $(LDLIBS)
ifndef DEBUG
	-del $(@:%.exe=%.out)
endif

%.o: %.cc
	$(COMPILE.cc) -c $(CPPFLAGS) $(CXXFLAGS) $<

clean:
	-del *.o
	-del *.out

distclean: clean
	-del *.exe

# DEPENDENCIES (hard to maintain)

Tile.o:  Tile.h
Bag.o:   Bag.h Tile.h
setup.o: setup.h

testTile.o: Tile.h
testBag.o:  Bag.h Tile.h
t_setup.o:  setup.h Bag.h
#end of makefile

- Raw text -


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