Deletion of O directory necessary?

Posted by Zune on Fri 02 Sep 2005 02:46 PM — 28 posts, 93,206 views.

#0
My question is this: for any .c source file I edit, do I need to delete its corresponding .o object file in the /o directory before I compile?
USA #1
No, not unless you edited a header (*.h) file. If you did, you'll need to do a make clean, which will remove all *.o files and the exec.
#2
Great. Thanks. :)
USA #3
Even then, it depends... if your makefile generates dependency information, then everything will happen automatically. In a proper production environment, you never have to worry about the object files because everything is managed for you.

I don't know offhand if the SMAUGfuss makefiles handle dependencies; it's not incredibly hard to do and it's something that should be added if it's not there. I volunteer if need be. :-) (Here's to hoping Samson is lurking and reading this thread!)
USA #4
ok, now you've piqued my curiousity.. you're saying that if I make a change to my make file I'll never need to bother with doing a make clean before I do a make after I change one of the header files again?

Here's my smaugfuss makefile (not exactly standard anymore as I've added a few things and made a minor change or two as well, but mostly the same as the one that's stock...)
CC      = gcc
#PROF    = -p

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV
#SOLARIS_LINK = -lnsl -lsocket

#Intermud-3 - Comment out to disable I3 support in your code
I3 = 1

#IMC2 - Comment out to disable IMC2 support
IMC = 1

W_FLAGS = -Wall -Wformat-security -Winline -Wpointer-arith -Wcast-align -Wredundant-decls -Wstrict-prototypes
# add this back into to above line after -Wall to revert to having all warnings reported as errors 
# including shadowed declarations: -Werror -Wshadow 

C_FLAGS = -O0 -g -g2 $(W_FLAGS) $(SOLARIS_FLAG) $(PROF) 
L_FLAGS = $(PROF) $(SOLARIS_LINK)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c alias.c ban.c boards.c \
          build.c clans.c color.c comm.c comments.c const.c db.c deity.c fight.c grub.c \
          handler.c hashstr.c hiscores.c hotboot.c imm_host.c interp.c magic.c makeobjs.c \
          mapout.c md5.c misc.c mpxset.c mud_comm.c mud_prog.c news.c planes.c player.c \
          polymorph.c ratings.c renumber.c reset.c save.c services.c shops.c skills.c \
          slay.c special.c tables.c track.c update.c wedding.c arena.c tattoo.c bank.c \
          quest.c

# immscore.c locker.c

ifdef I3
   C_FILES := i3.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DI3 -DI3SMAUG
endif

ifdef IMC
   C_FILES := imc.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DIMC -DIMCSMAUG
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

H_FILES = $(wildcard *.h) 

all:
	$(MAKE) -s smaug

ifdef CYGWIN
smaug: $(O_FILES)
	rm -f smaug.exe
	$(CC) -o smaug.exe $(O_FILES) $(L_FLAGS)
	echo "Done compiling mud.";
	chmod g+w smaug.exe
	chmod a+x smaug.exe
	chmod g+w $(O_FILES)

clean:
	rm -f o/*.o smaug.exe *~
else
smaug: $(O_FILES)
	rm -f smaug
	$(CC) -o smaug $(O_FILES) $(L_FLAGS)
	echo "Done compiling mud.";
	chmod g+w smaug
	chmod a+x smaug
	chmod g+w $(O_FILES)

clean:
	rm -f o/*.o smaug *~
endif

o/%.o: %.c
	echo "  Compiling $@....";
	$(CC) -c $(C_FLAGS) $< -o $@

.c.o: mud.h
	$(CC) -c $(C_FLAGS) $<

What would I need to change to add this dependancy handling you mentioned?
USA #5
That's correct. Having to do a make clean after editing a header file is silliness, really. Proper makefiles can be set up to only compile exactly what needs to be recompiled after a header change. Unfortunately, SMAUG sticks everything into mud.h, so savings are minimal, but still...

In any case, I haven't tested this with your makefile, but here's more or less what you need. I took this from my own makefile, and modified a few things to fit your setup. It's possible that I missed a few things, so be wary. :-)

Replace your o/%.o: %.cpp part with this:


DEPDIR = deps
df = $(DEPDIR)/$(*F)

o/%.o: %.cpp
    $(CC) -MD -c $(C_FLAGS) -o $@ $<
    @cp $*.d $(df).P; \
      sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\$$//' \
          -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(df).P; \
      rm -f $*.d

-include $(O_FILES:o/%.o=$(DEPDIR)/%.P)


Finally, remove the .c.o: mud.h part.

Let me know how it goes, and good luck!
USA #6
Isn't there supposed to be some way you can get gcc to do the work of generating the dependency info for you?
USA #7
That's exactly what this is doing; it has gcc generate the dependency information with the -MD flag and then outputs it to files, which are then included into the makefile.
USA #8
So, after I've made the changes that you've suggested, I need to do one last make clean so that GCC will create all the dependancies so that afterwards I'll never need to do another make clean only make?
Canada #9
all : $(EXECUTABLE) depend

# This is the actual dependency calculation.
.depend: $(SOURCES) $(HEADERS)
rm -f .depend
# For each source, let the compiler run the preprocessor with the -M and -MM
# options, which causes it to output a dependency suitable for make.

for source in $(SOURCES) ; do \
$(CC) $(INCLUDEDIR) $(CPPFLAGS) -M -MM $$source >> .depend ; \
done

# Include the generated dependencies.
# somehow this uses CXXFLAGS.. i donno how
ifneq ($(wildcard .depend),'')
include .depend
endif


That works without alot of the sed stuff too.
Canada #10
Okay, I think I figured it out.
Here's my make file (sans alot of the lines that arn't needed)


CC      = g++

C_FLAGS = -g3 -g2 -W -Wall -Wpointer-arith -Wstrict-prototypes -O2 -pedantic $(DEFINES) $(PROF) $(IMCFLAGS) $(NOCRYPT) $(DBUGFLG) $(DEBUG) $(DLLEXP)
W_FLAGS = -pedantic -W -Wall -Wformat-security -Winline -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wredundant-decls
L_FLAGS = $(PROF) $(DEFINES) $(DYNLIB) $(MCCPLIB) $(CRYPT) -lm
D_FLAGS = -g3

C_FILES = body.c account.c act_comm.c act_html.c act_info.c act_move.c act_obj.c \
          act_wiz.c alias.c arena.c autobuild.c backup.c ban.c \
          boards.c bounty.c build.c changes.c channels.c clans.c cleanup.c color.c comm.c \
          comments.c const.c db.c delivery.c designship.c dns.c editor.c \
          fight.c finger.c handler.c hashstr.c homes.c hotboot.c immcomm.c \
          implants.c installations.c interp.c magic.c makeobjs.c mccp.c \
          medic.c misc.c msp.c mud_comm.c mud_prog.c mxp.c occupations.c \
          olc-shuttle.c olc.c pfiles.c pilot.c player.c quest.c raceskills.c \
          renumber.c reset.c restore.c save.c sharpen.c shell.c shops.c \
          skills.c smuggling.c space.c space2.c special.c swskills.c \
          tables.c track.c update.c vendor.c wedding.c bank.c combat.c \
          starsystem.c

O_FILES = $(patsubst %.c,%.o,$(C_FILES))

H_FILES = $(wildcard *.h)

all: depend
        make -s swr

dns:
        make -s resolver

swr: $(O_FILES)
        @echo "Making Executable"
        @rm -f swr
ifdef WIN
        @dlltool --export-all --output-def swr.def $(O_FILES)
        @dlltool --dllname $(SWR) --output-exp swr.exp --def swr.def
        @$(CC)  $(W_FLAGS) -o $(SWR) $(O_FILES) swr.exp $(L_FLAGS)
else
        @$(CC)  $(DLLEXP) $(W_FLAGS) -o $(SWR) $(O_FILES) $(L_FLAGS)
endif
        @[ -f /usr/bin/bf ] && /usr/bin/bf -s swr && /usr/bin/bf -m swr || true
        @chmod g+w $(SWR)
        @chmod g+w $(O_FILES)

cvs:
        @echo "Updating from CVS"
        @cvs update

clean:
        @echo Cleaning Files
        @rm -f $(O_FILES)

.depend:
        @echo Making Depend
        @rm -f .depend
# For each source, let the compiler run the preprocessor with the -M and -MM
# options, which causes it to output a dependency suitable for make.
        @for source in $(C_FILES) ; do \
                $(CC) $(INCLUDEDIR) $(C_FLAGS) -M -MM $$source >> .depend ; \
        done

neat:
        $(INDENT) $(INDENT_FLAGS) $(C_FILES) $(H_FILES)

# include the .depend file which looks like
# body.o: body.c mud.h commands.h grid.h shell.h pfiles.h installations.h \
#   space2.h autobuild.h color.h hotboot.h implants.h olc.h dns.h imc.h \
#     imccfg.h utils.h body.h
#
ifneq ($(wildcard .depend),'')
include .depend
endif

# Actual compiling is done here
# for each of the .o targets in .depend
%.o: %.c
        @echo -n "  Compiling $@...";
        $(CC) -c $(C_FLAGS) $< -o $@
        @echo "Done"

.c.o: mud.h
        @$(CC) -c $(C_FLAGS) $<

# Tell make that "all" etc. are phony targets, i.e. they should not be confused
# with files of the same names.
.PHONY: all clean depend realclean touch neat tarball bzip

Amended on Sat 03 Sep 2005 11:03 PM by halkeye
USA #11
um, I must have done something wrong...
I tried to do what you've got up there and then got:
Quote:
$ make
make -s smaug
$ make depend
make: Nothing to be done for `depend'.
$ make clean
rm -f o/*.o smaug *~
$ make
make -s smaug
make[1]: *** No rule to make target `o/imc.o', needed by `smaug'. Stop.
make: *** [all] Error 2
$


Here's my modified makefile:
CC      = gcc
#PROF    = -p

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV
#SOLARIS_LINK = -lnsl -lsocket

#Intermud-3 - Comment out to disable I3 support in your code
I3 = 1

#IMC2 - Comment out to disable IMC2 support
IMC = 1

W_FLAGS = -Wall -Wformat-security -Winline -Wpointer-arith -Wcast-align -Wredundant-decls -Wstrict-prototypes
# add this back into to above line after -Wall to revert to having all warnings reported as errors 
# including shadowed declarations: -Werror -Wshadow 

C_FLAGS = -O0 -g -g2 $(W_FLAGS) $(SOLARIS_FLAG) $(PROF) 
L_FLAGS = $(PROF) $(SOLARIS_LINK)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c alias.c ban.c boards.c \
          build.c clans.c color.c comm.c comments.c const.c db.c deity.c fight.c grub.c \
          handler.c hashstr.c hiscores.c hotboot.c imm_host.c interp.c magic.c makeobjs.c \
          mapout.c md5.c misc.c mpxset.c mud_comm.c mud_prog.c news.c planes.c player.c \
          polymorph.c ratings.c renumber.c reset.c save.c services.c shops.c skills.c \
          slay.c special.c tables.c track.c update.c wedding.c arena.c tattoo.c bank.c \
          quest.c

# immscore.c locker.c

ifdef I3
   C_FILES := i3.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DI3 -DI3SMAUG
endif

ifdef IMC
   C_FILES := imc.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DIMC -DIMCSMAUG
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

H_FILES = $(wildcard *.h) 

all: depend
	$(MAKE) -s smaug

ifdef CYGWIN
smaug: $(O_FILES)
	rm -f smaug.exe
	$(CC) -o smaug.exe $(O_FILES) $(L_FLAGS)
	echo "Done compiling mud.";
	chmod g+w smaug.exe
	chmod a+x smaug.exe
	chmod g+w $(O_FILES)

clean:
	rm -f o/*.o smaug.exe *~
else
smaug: $(O_FILES)
	rm -f smaug
	$(CC) -o smaug $(O_FILES) $(L_FLAGS)
	echo "Done compiling mud.";
	chmod g+w smaug
	chmod a+x smaug
	chmod g+w $(O_FILES)
endif

cvs:
	cvs update

clean:
	rm -f o/*.o smaug *~

.depend:
	rm -f .depend
	for source in $(C_FILES) ; do \
		$(CC) $(INCLUDEDIR) $(C_FLAGS) -M -MM $$source >> .depend ; \
	done

#o/%.o: %.c
	echo "  Compiling $@....";
	$(CC) -c $(C_FLAGS) $< -o $@

#.c.o: mud.h
	$(CC) -c $(C_FLAGS) $<

# Tell make that "all" etc. are phony targets, i.e. they should not be confused
# with files of the same names.
.PHONY: all clean depend
I hope someone can maybe see what I've done wrong here. :(
USA #12
Ok... evil forum code... one more time:

My Makefile:

#This is the AFKMud Makefile.
#This should be usable on pretty much any Linux system.
#Refer to your 'man gcc' for explanations of these options
#To compile in FreeBSD or OpenBSD, use the gmake compiler.

#Used for Alsherok stuff, uncommenting it should have no affect, though why would you want to?
ALSHEROK = 1

#Change this to reflect whichever compiler you want to use.
CC      = g++

#Type of machine to compile for. Athlon works just as well on Duron too.
#The march option needs to match the general family of CPU.
#If you don't know what to set for these options, and your system administrator doesn't either, comment this line out
MACHINE = -march=athlon-xp

#Uncomment if compiling in Windows under Cygwin
#WINDOZE = 1

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV -Wno-char-subscripts
#SOLARIS_LINK = -lnsl -lsocket -lresolv

#Uncomment the line below if you are getting undefined references to dlsym, dlopen, and dlclose.
#Comment it out if you get errors about ldl not being found.
NEED_DL = -ldl

#Some systems need this for dynamic linking to work.
EXPORT_SYMBOLS = -export-dynamic

#Math functions - uncomment if you get errors or warnings about math functions.
MATH_LIB = -lm

#IMC2 - Comment out to disable IMC2 support
IMC = 1

#Internal Web Server - comment out to disable web server code.
WEB = 1

#Multiport support. Comment out to disable this feature.
MULTIPORT = 1

#Miscellaneous compiler options.
OPT_FLAG = -pipe -Os
DEBUG_FLAG = -g2
#PROF_FLAG = -p

W_FLAGS = -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wredundant-decls #-pedantic

C_FLAGS = $(MACHINE) $(W_FLAGS) $(DEBUG_FLAG) $(OPT_FLAG) $(PROF_FLAG) $(SOLARIS_FLAG) $(EXPORT_SYMBOLS)
L_FLAGS = $(MACHINE) $(DEBUG_FLAG) $(OPT_FLAG) $(PROF_FLAG) $(EXPORT_SYMBOLS) $(SOLARIS_LINK) $(MATH_LIB) -lz -lgd $(NEED_DL)
#D_FLAGS : For the DNS Resolver process. No need in linking all the extra libs for this.
D_FLAGS = $(MACHINE) $(W_FLAGS) $(DEBUG_FLAG) $(OPT_FLAG) $(PROF_FLAG) $(SOLARIS_LINK)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c \
          archery.c area.c areaconvert.c auction.c ban.c bits.c boards.c \
          build.c calendar.c channels.c character.c clans.c color.c \
          comm.c commands.c comments.c connhist.c const.c db.c deity.c descriptor.c \
          editor.c environment.c event.c event_handler.c features.c \
          fight.c finger.c handler.c hashstr.c help.c hotboot.c iafk.c \
          idale.c imm_host.c interface.c ismaug.c liquids.c magic.c md5.c \
          misc.c mobindex.c mspecial.c mudcfg.c mud_comm.c mud_prog.c \
          new_auth.c object.c objindex.c olcmob.c olcobj.c olcroom.c overland.c \
          pfiles.c player.c polymorph.c rent.c renumber.c reset.c \
          roomindex.c save.c ships.c shops.c skills.c skyship.c slay.c \
          tables.c track.c treasure.c update.c

ifdef WEB
   C_FILES := websvr.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DWEBSVR
endif

ifdef IMC
   C_FILES := imc.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DIMC
endif

#Our specific stuff, see to it this stays out of the AFKMud Makefile!
#And anyone outside of Alsherok who sees this will get errors.
#If this happens, Samson wasn't paying attention to what he was doing.
ifdef ALSHEROK
   C_FILES := apc.c $(C_FILES)
endif

ifdef MULTIPORT
   C_FILES := shell.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DMULTIPORT
   #Sorry folks, this doesn't work in Cygwin
   ifndef WINDOZE
      C_FILES := mudmsg.c $(C_FILES)
   endif
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

H_FILES = $(wildcard *.h)

ifdef WINDOZE
   AFKMUD = afkmud.exe
   RESOLVER = resolver.exe
else
   AFKMUD = afkmud
   RESOLVER = resolver
endif

all: .depend
	@echo "Building AFKMud....";
	$(MAKE) -s afkmud
	@echo "Buidling DNS Resolver...";
	$(MAKE) -s resolver

afkmud: $(O_FILES)
	@rm -f $(AFKMUD)
ifdef WINDOZE
	@dlltool --export-all --output-def afkmud.def $(O_FILES)
	@dlltool --dllname $(AFKMUD) --output-exp afkmud.exp --def afkmud.def
	$(CC) -o $(AFKMUD) $(O_FILES) afkmud.exp $(L_FLAGS)
else
	$(CC) -o $(AFKMUD) $(O_FILES) $(L_FLAGS)
endif
	@echo "Done building AFKMud.";
	@chmod g+w $(AFKMUD)
	@chmod a+x $(AFKMUD)
	@chmod g+w $(O_FILES)

indent:
	@indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(C_FILES) resolver.c
	@indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(H_FILES)

indentclean:
	@rm *.c~ *.h~

resolver: resolver.o
	@rm -f $(RESOLVER) 
	$(CC) $(D_FLAGS) -o $(RESOLVER) resolver.o
	@echo "Done buidling DNS Resolver.";
	@chmod g+w $(RESOLVER)
	@chmod a+x $(RESOLVER)
	@chmod g+w resolver.o

clean:  
	@rm -f o/*.o $(AFKMUD) afkmud.def afkmud.exp core $(RESOLVER) resolver.o
	$(MAKE) all
        
purge:  
	@rm -f o/*.o $(AFKMUD) afkmud.def afkmud.exp core $(RESOLVER) resolver.o

#For each source, let the compiler run the preprocessor with the -M and -MM
#options, which causes it to output a dependency suitable for make.
.depend:
	@echo Making Depend
	@rm -f .depend
	@for source in $(C_FILES) ; do \
		$(CC) $(INCLUDEDIR) $(C_FLAGS) -M -MM $$source >> .depend ; \
	done

o/%.o: %.c
	ifneq ($(wildcard .depend),'')
		include .depend
	endif
	@echo "  Compiling $@....";
	$(CC) -c $(C_FLAGS) $< -o $@

.c.o: mud.h
	$(CC) -c $(C_FLAGS) $<
USA #13
Anyway.... since for some reason 6000 chars is too much.....

Produces:

mudmsg.o: mudmsg.c mud.h mudcfg.h color.h olc.h character.h object.h \
  channels.h roomindex.h
shell.o: shell.c mud.h mudcfg.h color.h olc.h character.h object.h \
  clans.h commands.h descriptor.h shell.h
apc.o: apc.c mud.h mudcfg.h color.h olc.h character.h object.h apc.h
imc.o: imc.c mud.h mudcfg.h color.h olc.h character.h object.h commands.h \
  descriptor.h imc.h imccfg.h md5.h roomindex.h web.h
websvr.o: websvr.c mud.h mudcfg.h color.h olc.h character.h object.h \
  area.h help.h imc.h imccfg.h roomindex.h web.h
act_comm.o: act_comm.c mud.h mudcfg.h color.h olc.h character.h object.h \
  boards.h descriptor.h language.h mobindex.h mud_prog.h objindex.h \
  polymorph.h raceclass.h roomindex.h
act_info.o: act_info.c mud.h mudcfg.h color.h olc.h character.h object.h \
  area.h clans.h descriptor.h fight.h liquids.h mobindex.h mud_prog.h \
  objindex.h overland.h pfiles.h polymorph.h raceclass.h roomindex.h
USA #14
ok, here's my .depend file:
Quote:

imc.o: imc.c md5.h mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
i3.o: i3.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
act_comm.o: act_comm.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
act_info.o: act_info.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
act_move.o: act_move.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
act_obj.o: act_obj.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h bet.h
act_wiz.o: act_wiz.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
alias.o: alias.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
ban.o: ban.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
boards.o: boards.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
build.o: build.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
clans.o: clans.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
color.o: color.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
comm.o: comm.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h md5.h
comments.o: comments.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
const.o: const.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
db.o: db.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
deity.o: deity.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
fight.o: fight.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
grub.o: grub.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
handler.o: handler.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
hashstr.o: hashstr.c
hiscores.o: hiscores.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
hotboot.o: hotboot.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
imm_host.o: imm_host.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
interp.o: interp.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
magic.o: magic.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
makeobjs.o: makeobjs.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
mapout.o: mapout.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
md5.o: md5.c md5.h
misc.o: misc.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
mpxset.o: mpxset.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
mud_comm.o: mud_comm.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
mud_prog.o: mud_prog.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
news.o: news.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h news.h
planes.o: planes.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
player.o: player.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
polymorph.o: polymorph.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
ratings.o: ratings.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
renumber.o: renumber.c mud.h alias.h slay.h color.h hotboot.h i3.h \
i3cfg.h imc.h imccfg.h bank.h
reset.o: reset.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
save.o: save.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
services.o: services.c
shops.o: shops.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
skills.o: skills.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
slay.o: slay.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
special.o: special.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
tables.o: tables.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
track.o: track.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
update.o: update.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
wedding.o: wedding.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
arena.o: arena.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
tattoo.o: tattoo.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
bank.o: bank.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h imc.h \
imccfg.h bank.h
quest.o: quest.c mud.h alias.h slay.h color.h hotboot.h i3.h i3cfg.h \
imc.h imccfg.h bank.h
USA #15
Now then. When I type "make .depend" the .depend file is generated properly from what I can tell. The above post is only part of it, but it has plenty more where that came from.

So one then expects that if an H file is modified, typing "make" at this point should cause it to compile the necessary files, right? It doesn't do anything at all.
USA #16
A solution was found by Eloi@EoD:

http://forums.smaugfuss.org/index.php?a=topic&t=3#p2

[EDIT - 11 March 2008] - The Smaug FUSS site is now http://www.smaugmuds.org/
Amended on Tue 11 Mar 2008 03:22 AM by Nick Gammon
USA #17
Samson, I think your problem is that you include the depend information after you have the o/%.o:%.c rule. That means that the first rule takes precedence, I think. Note that the solution posted on your link does just that - it doesn't have the first rule.

FWIW, I didn't come up with what I posted. It's something I found on google, and the versions posted here are indeed much simpler. I'm not sure why the sed stuff was necessary. To be honest once it worked, I just stopped fiddling with it.

EDIT: Note however that your solution depends on the makedepend program, which is not necessarily a good thing. What I proposed (and others as well IIRC) uses only gcc.
Amended on Sun 04 Sep 2005 05:18 AM by David Haley
USA #18

purge:  
	@rm -f o/*.o $(AFKMUD) afkmud.def afkmud.exp core $(RESOLVER) resolver.o

o/%.o: %.c
	@echo "  Compiling $@....";
	$(CC) -c $(C_FLAGS) $< -o $@

.c.o: mud.h
	$(CC) -c $(C_FLAGS) $<

# Funky "if exists.." stuff could be put here. I'm cheating. :-D
.depend:
	@rm -f .depend
	@touch .depend
	@makedepend -po/ -f .depend $(C_FILES) > /dev/null 2>&1

# Include the generated file.
include .depend


Well that's the last chunk of the Makefile and it has the o/%.o: %.c rule there, and it works just fine this way. Does exactly what I and others are expecting it to do.

So what's wrong with using the makedepend command?
USA #19
Well, the first problem is that GCC does it already, so why introduce another program into the toolchain?

The second and much more significant reason is that makedepend does not seem to be included in Cygwin. At least, I was unable to find 'makedepend' in the list of available Cygwin packages, nor could I run it after updating make to the latest version.

So, since it's not in Cygwin and since gcc does the job already, makedepend seems like a bad choice.

EDIT:
Oh, and here's why I think the new makefile worked but the old one didn't. This one generates dependencies of the .c files and puts those after the dependencies of the .o files. Your previous method though seems to be generating dependencies of the .o files, which were already specified in the o/%.o:%.c rule. All this is just a guess but given what your .depend looks like I think it's fairly likely. I could be completely wrong though...
Amended on Sun 04 Sep 2005 08:55 AM by David Haley
USA #20
Well I tried the method you suggested but it didn't work, was placed as follows:


clean:  
	@rm -f o/*.o $(AFKMUD) afkmud.def afkmud.exp core $(RESOLVER) resolver.o
	$(MAKE) all
        
purge:  
	@rm -f o/*.o $(AFKMUD) afkmud.def afkmud.exp core $(RESOLVER) resolver.o

DEPDIR = deps
df = $(DEPDIR)/$(*F)

o/%.o: %.c
    $(CC) -MD -c $(C_FLAGS) -o $@ $<
    @cp $*.d $(df).P; \
      sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\$$//' \
          -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(df).P; \
      rm -f $*.d

-include $(O_FILES:o/%.o=$(DEPDIR)/%.P)


Touching an H file did not cause it to recompile anything. Perhaps I've done something wrong but it looked to me like I got it in the right spot. The makedepend method may not be the best choice but so far it's the only choice that's worked.
USA #21
I think the problem is that the object files are in a different directory? So when it includes them, it includes dependencies for %.o, not o/%.o...

I know for a fact that what I have works on my MUD, and somebody suggested something else from theirs. The easiest would be to send me the makefile you have and let me tweak it so that we don't have to keep going back-and-forth. Are you using the SMAUGfuss makefile that I can download from your site?

What I suspect has to happen is that the dependency files need to be modified such that any reference to *.o is replaced by a reference to o/*.o. That can probably be done fairly easily with sed, or even maybe makefile substitution rules on include.
USA #22
alright, here's my Makefile (currently working, but using makedepend)
Quote:
CC = gcc
#PROF = -p

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV
#SOLARIS_LINK = -lnsl -lsocket

#Intermud-3 - Comment out to disable I3 support in your code
I3 = 1

#IMC2 - Comment out to disable IMC2 support
IMC = 1

W_FLAGS = -Wall -Wformat-security -Winline -Wpointer-arith -Wcast-align -Wredundant-decls -Wstrict-prototypes
# add this back into to above line after -Wall to revert to having all warnings reported as errors
# including shadowed declarations: -Werror -Wshadow

C_FLAGS = -O0 -g -g2 $(W_FLAGS) $(SOLARIS_FLAG) $(PROF)
L_FLAGS = $(PROF) $(SOLARIS_LINK)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c alias.c ban.c boards.c \
build.c clans.c color.c comm.c comments.c const.c db.c deity.c fight.c grub.c \
handler.c hashstr.c hiscores.c hotboot.c imm_host.c interp.c magic.c makeobjs.c \
mapout.c md5.c misc.c mpxset.c mud_comm.c mud_prog.c news.c planes.c player.c \
polymorph.c ratings.c renumber.c reset.c save.c services.c shops.c skills.c \
slay.c special.c tables.c track.c update.c wedding.c arena.c tattoo.c bank.c \
quest.c

# immscore.c locker.c

ifdef I3
C_FILES := i3.c $(C_FILES)
C_FLAGS := $(C_FLAGS) -DI3 -DI3SMAUG
endif

ifdef IMC
C_FILES := imc.c $(C_FILES)
C_FLAGS := $(C_FLAGS) -DIMC -DIMCSMAUG
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

H_FILES = $(wildcard *.h)

all: .depend
$(MAKE) -s smaug

ifdef CYGWIN
smaug: $(O_FILES)
rm -f smaug.exe
$(CC) -o smaug.exe $(O_FILES) $(L_FLAGS)
echo "Done compiling mud.";
chmod g+w smaug.exe
chmod a+x smaug.exe
chmod g+w $(O_FILES)

clean:
rm -f o/*.o smaug.exe *~
else
smaug: $(O_FILES)
rm -f smaug
$(CC) -o smaug $(O_FILES) $(L_FLAGS)
echo "Done compiling mud.";
chmod g+w smaug
chmod a+x smaug
chmod g+w $(O_FILES)

clean:
rm -f o/*.o smaug *~
$(MAKE) all
endif

o/%.o: %.c
echo " Compiling $@....";
$(CC) -c $(C_FLAGS) $< -o $@

.c.o: mud.h
$(CC) -c $(C_FLAGS) $<

.depend:
@rm -f .depend
@touch .depend
@makedepend -po/ -f .depend $(C_FILES) > /dev/null 2>&1

include .depend
USA #23
The Makefile Conner just posted is the same as the one I'm using in the parts that cover the depends. I'd rather not have to rely on something more than gcc myself but makedepend seems to be widely available. Technically yours relies on sed being available too, and while it may also be widely available, what guarantee do we have that it's on everyone's system? :P

Anyway, yes, would appreciate it if you could look at this and figure something out.
USA #24
Meh. A bit late to the table, but I just realized that this correlates with me not being able to compile the latest distro of FUSS. Apparently makedepend is, as Ksilyan said, not included in Cygwin (at least not the version I have).

Does anyone know if this is currently available for Cygwin so I can update? Not *really* an issue since I was only going to compile it and test something stock versus my own modified base, but nevertheless I am curious.

If nothing else I can always revert the makefile. ;)



USA #25
I looked in the full package list and didn't see makedepend for Cygwin. I'll be working on this makefile thing and will provide a gcc-only solution shortly.
USA #26
Anything more on this?
USA #27
I'm curious about this also. ;)