#This is the AFKMud Makefile
#Refer to your 'man gcc' for explanations of these options

#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      = gcc
#PROF    = -p
NOCRYPT = 

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

#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
#Also, if you receive the following compile errors:
#mud.h:245: field `total_time' has incomplete type
#mud.h:246: field `min_time' has incomplete type
#mud.h:247: field `max_time' has incomplete type
#comment this out
MACHINE = -mcpu=athlon -march=athlon

#Uncomment the line below if you are getting undefined crypt errors
NEED_CRYPT = -lcrypt

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

#Memory Debugger - comment out to turn the debugger off, uncomment to use it.
#MEMDEBUG = 1

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

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

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

#DBUGFLG = -DREQUESTS

#Miscellaneous compiler options.
OPT_FLAG = -pipe

#Maybe someday we'll get around to cleanly compiling the code with ALL of these defined......
#But for now, only what lies before the # has been done.
W_FLAGS = -Wall -Winline -Wstrict-prototypes -Wnested-externs -Wshadow -Wpointer-arith -Wcast-align #-Wcast-qual

C_FLAGS = $(MACHINE) -g3 -O $(W_FLAGS) $(OPT_FLAG) $(PROF) $(NOCRYPT) $(DBUGFLG) $(SOLARIS_FLAG)
L_FLAGS = $(MACHINE) $(OPT_FLAG) $(PROF) $(SOLARIS_LINK) $(NEED_CRYPT) $(MATH_LIB) -lz -lbfd -liberty
#D_FLAGS : For the DNS Resolver process. No need in linking all the extra libs for this.
D_FLAGS = $(MACHINE) -g3 -O $(W_FLAGS) $(PROF) $(SOLARIS_LINK)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c alias.c \
          afk.c afk_mprog.c afkskills.c afkspells.c \
          archery.c areaconvert.c auction.c ban.c bank.c bits.c boards.c \
          build.c calendar.c camp.c channels.c clans.c color.c comm.c comments.c \
          const.c db.c deity.c dns.c editor.c environment.c event.c fight.c finger.c \
          gsn.c handler.c hashstr.c hotboot.c iafk.c idale.c imm_host.c \
          interface.c interp.c ismaug.c liquids.c magic.c makeobjs.c mccp.c \
          misc.c mpxset.c msp.c mspecial.c mud_comm.c mud_prog.c mxp.c \
          new_auth.c olc.c olcobj.c olcmob.c olcroom.c overland.c pets.c \
	    pfiles.c planes.c player.c polymorph.c reset.c rent.c renumber.c \
	    save.c shell.c ships.c shops.c skills.c skyship.c slay.c starmap.c \
          tables.c track.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 -DIMCSMAUG
endif

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

ifdef MEMDEBUG
   C_FILES := fortify.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DFORTIFY
endif

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

H_FILES = $(wildcard *.h) 

all:
	make -s smaug
	make -s resolver

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

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

resolver: resolver.o
	rm -f resolver
	$(CC) $(D_FLAGS) -o resolver resolver.o
	echo "Done compiling resolver.";
	chmod g+w resolver
	chmod a+x resolver
	chmod g+w resolver.o

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

clean:
	rm -f o/*.o smaug core resolver resolver.o
	make all

purge:
	rm -f o/*.o smaug core resolver resolver.o
