[geeks] non-recursive make

Sridhar Ayengar ploopster at gmail.com
Thu Nov 10 09:25:30 CST 2005


Charles Shannon Hendrix wrote:
> Wed, 09 Nov 2005 @ 13:03 -0500, Sridhar Ayengar said:
> 
> 
>>When I'm not nesting projects, I use the "single Makefile multiple 
>>source" method all the time.  It works fine.  I usually just maintain a 
>>list of source files and object file targets in a variable.
> 
> 
> Are your Makefiles portable?  I'd like to see one if you don't mind.

I tend to use GNU syntax, although there's nothing I do that you can't 
make portable.  There's probably a better way, but I would probably use 
something like this:

<CODE>

DEST=objects
SUBDIRA=subdira
SUBDIRAOBJECTS=$(DEST)/subdira.o $(DEST)/subdira-aux.o \
		$(DEST)/subdira-extern.o
SUBDIRB=subdirb
SUBDIRBOBJECTS=$(DEST)/subdirb.o $(DEST)subdirb-extern.o
MAINOBJECTS=$(DEST)/main.o $(DEST)/aux.o $(DEST)/io.o
OBJECTS=$(MAINOBJECTS) $(SUBDIRAOBJECTS) $(SUBDIRBOBJECTS)
CC=cc
CFLAGS=-O3 -funroll-loops -pipe
PROGRAM=main-program

all: $(OBJECTS)
	$(CC) $(CFLAGS) -o $(DESTINATION)/$(PROGRAM) $(OBJECTS)

$(MAINOBJECTS): $(DEST)/%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(SUBDIRAOBJECTS): $(DEST)/%.o: $(SUBDIRA)/%.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(SUBDIRBOBJECTS): $(DEST)/%.o: $(SUBDIRB)/%.c
	$(CC) $(CFLAGS) -c -o $@ $<

</CODE>

No problems jump out at me, but there might be one or two in there.  You 
get the gist of it though.

Peace...  Sridhar



More information about the geeks mailing list