🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #1211

The answer to make with multiple executables from same source files

#1211
From: Paul Chamberlain
Date: Tue, 13 Nov 1990 22:12
49 lines
2336 bytes
I wrote
>I have two executables that depend on the same source files but are
>compiled with different CFLAGS.  Anybody have a good way to make a
>makefile understand this?

Well, I got it figured out.  Below I have included a makefile for
two hypothetical executables that use the same .c's.  A fringe
benefit is that even if you only have one executable, using this
style of make file will allow you to remove all the .o's and it
still won't recompile anything unless a .c or .h changed.

Paul Chamberlain | I do NOT represent IBM.     tif@doorstop, sc30661 at ausvm6
512/838-7008     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif

# This is a really bizarre makefile that allows two executables to be made
# from one set of source.  In this example, the exe's are to be compiled
# with slightly different compile lines and libraries.  This should handle
# all manner of interrupted and restarted compiles.

OBJ	= obj1.o obj2.o obj3.o
HFILES	= local1.h local2.h
CFLAGS	= -O $(NAME)
LDFLAGS	= $(OTHER_LIB)

# by default, make both executables
all:	exe1 exe2

clean:
	rm -f *.o making.exe1 making.exe2

# This will prevent recompilation if everything is
# up to date even if no .o's are around.
exe1:	$(OBJ:.o=.c) exe1.c $(HFILES)
	if test ! -f making.exe1;then make clean;fi
	touch making.exe1
	$(MAKE) NAME=-DEXE1 OTHER_LIB=-lx exe1.make

exe1.make:	$(OBJ) exe1.o
	$(CC) $(CFLAGS) $(OBJ) exe1.o $(LDFLAGS) -o exe1

# This will prevent recompilation if everything is
# up to date even if no .o's are around.
exe2:	$(OBJ:.o=.c) exe2.c $(HFILES)
	if test ! -f making.exe2;then make clean;fi
	touch making.exe2
	$(MAKE) NAME=-DEXE2 exe2.make

exe2.make:	$(OBJ) exe2.o
	$(CC) $(CFLAGS) $(OBJ) exe2.o $(LDFLAGS) -o exe2
Technical Details
Message-ID: <4223@awdprime.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!cs.utexas.edu!ut-emx!ibmchs!auschs!awdprime!doorstop.austin.ibm.com!tif
References: <4196@awdprime.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!cs.utexas.edu!ut-emx!ibmchs!auschs!awdprime!doorstop.austin.ibm.com!tif
From: tif@doorstop.austin.ibm.com (Paul Chamberlain)
Newsgroups: comp.unix.programmer
Subject: The answer to make with multiple executables from same source files
Message-ID: <4223@awdprime.UUCP>
Date: 13 Nov 90 22:12:51 GMT
References: <4196@awdprime.UUCP>
Sender: news@awdprime.UUCP
Reply-To: tif@doorstop.austin.ibm.com (Paul Chamberlain)
Distribution: usa
Organization: IBM AWD, Austin, TX
Lines: 49