TheSourcery | RecentChanges | Preferences | Index | RSS

Here's a mechanism that solves many of the problems associated with makefile dependencies. See [Autodependencies with GNU make] for information on exactly what problems are solved by this technique. The makefile below was based on stock rom so you may have to modify it to suit you.

CC      = gcc
PROF    = -O -g
C_FLAGS =  -Wall -W $(PROF) $(NOCRYPT) 

O_FILES = act_comm.o act_enter.o act_info.o act_move.o act_obj.o act_wiz.o \ 
          alias.o ban.o comm.o const.o db.o db2.o effects.o fight.o flags.o \ 
	  handler.o healer.o interp.o note.o lookup.o magic.o magic2.o \ 
	  music.o recycle.o save.o scan.o skills.o special.o tables.o \ 

rom: $(O_FILES)
	$(CC) $(L_FLAGS) -o rom $(O_FILES)

# pull in dependency info for *existing* .o files
-include $(O_FILES:.o=.d)

# compile and generate dependency info;
# more complicated dependency computation, so all prereqs listed
# will also become command-less, prereq-less targets
#   sed:    append directory to object target. (gcc bug?)
#   sed:    strip the target (everything before colon)
#   sed:    remove any continuation backslashes
#   fmt -1: list words one per line
#   sed:    strip leading spaces
#   sed:    add trailing colons
%.o: %.c
	$(CC) -c $(C_FLAGS) $*.c -o $*.o 
	$(CC) -MM $(C_FLAGS) $*.c > $*.d
	@mv -f $*.d $*.d.tmp
	@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ 
	  sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
	@rm -f $*.d.tmp

clean :
	rm -rf rom $(O_FILES) $(O_FILES:.o=.d)

TheSourcery | RecentChanges | Preferences | Index | RSS
Edit text of this page | View other revisions
Last edited January 22, 2010 3:00 pm by Tyche (diff)
All material on this Wiki is the property of the contributing authors.
©2004-2006 by the contributing authors.
Ideas, requests, problems regarding this site? Send feedback.