CC = g++
MAKE = make
#Used LOP profile directions to get a profile of the code.
#Uncomment and run the code long enough to get a good profile and do a normal ingame shutdown.
#Go to the "4liberty/" directory.
#Then do a "prof 4liberty > prof.out"
#PROF    = -p
#Used to get an advanced profile of the code.
#Do same as above one only use "gprof 4liberty > gprof.out"
#Then just look at "prof.out/gprof.out" in an editor to see the profile.
#PROF    = -pg

#Uncomment the line below if you'll be using gdb for debugging information
#USE_GDB = gdb
#DEBUG_LEVEL = 3

#The program executable's name
PROG_NAME = 4liberty

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

#Comment this if you don't want math errors
MATH_LIB = -lm

#Uncomment the line below if compiling on a RedHat (and possibly other Linux) box
LINUX = -DLINUX

#Uncomment the line below if you are getting a line like:
#interp.c:757: warning: int format, time_t arg (arg 7)
#TIME = -DTIMEFORMAT

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

#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

#I3 - Comment out to disable I3 support
I3 = 1

#Directory locations of important lib files
LIBDIR  = ./lib

#Modify the lines below if you want a performance increase though beware your core
#files may not be as much of a benefit if you do. Suggested OPT_FLAG: -O
OPT_LEVEL = 
OPT_FLAG = -O$(OPT_LEVEL)

#Format check flags
FMT_FLG = -Wformat -Wformat-security -Wmissing-format-attribute

WSTRINGS = -Wwrite-strings

#Warning check flags
W_FLAGS = -Wall -Werror -Wunused -Wuinitialized -Wshadow -Wformat-security -Wpointer-arith -Wcast-align -Wredundant -decl -Wconversion $(WSTRINGS)

#Compile and Link flags
CMP_FLG = -g -O $(WRN_FLG) 
C_FLAGS = $(OPT_FLAG) $(CMP_FLG) $(PROF) $(NOCRYPT) $(SOLARIS_FLAG) $(TIME) $(LINUX)
L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz $(NEED_DL) $(NEED_CRYPT) $(MATH_LIB)

#Listing of all '.c' files DO NOT GET OUT OF ALPHABETICAL ORDER
C_FILES = act_comm.c      act_info.c       act_move.c     act_obj.c    act_wiz.c    alias.c     archery.c  \
          arena.c         automap.c        ban.c          bank.c       build.c      buitdy.c    calendar.c city.c \
          channels.c      clans.c          classes.c      color.c      comm.c       comments.c  companion.c   const.c    copyover.c \
          currency.c      crafts.c         db.c           disguise.c   editor.c     events.c    fight.c       filer.c    ftag.c    gboard.c \
          genesis.c                 handler.c      hint.c       hometowns.c  house.c     interp.c      landmark.c \
          location.c      memory.c         misc.c         monk.c       mssp.c       mud_comm.c  mud_prog.c \
          pets.c          new_auth.c       news.c \
          player.c        quests.c         races.c        renumber.c   reset.c      ride.c      run.c         sha256.c \
          save.c          services.c       ships.c        shops.c      skills.c     skills2.c   smell.c       special.c \
          status.c        symref.c         tables.c       teacher.c    track.c      transfer.c  update.c      vault.c       variables.c  \
          vendor.c        weather.c        whereis.c      whois.c      wild_comm.c  wild_mobs.c engineer.c     

#Listing of all '.h' files necessary to create the program binary

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

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

H_FILES = $(wildcard h/*.h)

all:
	@$(MAKE) -s $(PROG_NAME)

$(PROG_NAME): $(O_FILES)
	@rm -f $(PROG_NAME)
	@$(CC) $(L_FLAGS) -o $(PROG_NAME) $(O_FILES) $(L_FLAGS)
	@chmod 700 $(C_FILES)
	@chmod 700 $(H_FILES)
	@chmod g+w $(PROG_NAME)
	@chmod a+x $(PROG_NAME)
	@chmod g+w $(O_FILES)
	mv $(PROG_NAME) ../$(PROG_NAME)
	@echo "Done Compiling $(PROG_NAME)"

symref.c: h/mud.h symref_template.c mktables h/landmark.h 
	./mktables symref.c symref_template.c -h h/mud.h -h h/landmark.h 

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

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

clean:
	rm -f o/*.o ../$(PROG_NAME) *~ h/*~ symref.c
	make all

purge:
	rm -f o/*.o ../$(PROG_NAME) *~ h/*~ symref.c

