#
# RAM $Id: Makefile 14 2008-10-20 03:13:51Z ram $
#

CC      	= g++

CRYPT		= #-DNOCRYPT		# Uncomment to use clear-text passwords
RAND		= #-DOLD_RAND		# Uncomment if your random number generator is broken
MALLOC		= #-DMALLOC_DEBUG	# Uncomment for extra malloc debugging code
SOCIAL		= #-DSOCIAL_DEBUG	# Uncomment for debugging of the socials

# Comment out the -Wmissing-format-attribute flag if you're using gcc 2.95
# or upgrade!
#
# The W_CONLY set of flags are only valid when using C, not for C++
# -Wmissing-declarations is C only under g++ 4.2.x and older!

W_ERROR         = -Werror
W_ANSI          = #-pedantic
W_UBER          = -Wall
W_FORMAT        = -Wformat -Wformat-security -Wmissing-format-attribute
W_MESSY         = -Wmissing-braces -Wparentheses -Wshadow -Wredundant-decls
W_TYPE          = -Wcast-qual -Wcast-align -Wchar-subscripts -Wreturn-type -Wswitch -Wwrite-strings
W_EXTRA         = -Wunused -Wuninitialized #-Wunreachable-code
W_NITPICK       = -Wpointer-arith -Winline
ifeq ($(CC), gcc)
W_CONLY		= -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes 
endif

WARN		= $(W_ERROR) $(W_ANSI) $(W_UBER) $(W_FORMAT) $(W_MESSY) $(W_TYPE) $(W_EXTRA) $(W_NITPICK) $(W_CONLY)

OPT	    	= -O3 				# You trust the compiler, don't you?
DEBUG		= -g				# Just enough to fix the occasional crash
#DEBUG		= -ggdb3			# Full debugging with ALL defined symbols!
PROF		= #-pg				# Enable profiling via gprof

OPTIONS		= $(OPT) $(DEBUG) $(PROF) $(CRYPT) $(RAND) $(MALLOC) $(SOCIAL)

C_FLAGS 	= $(WARN) $(OPTIONS)
L_FLAGS 	= $(DEBUG) $(PROF)

LIBS		= 				# Uncomment if you're using Linux
#LIBS		= 				# Uncomment if you're using BSD or OS X
#LIBS		= -lsocket -lresolv -lnsl	# Uncomment if you're using Solaris

O_FILES		= act_comm.o act_info.o act_move.o act_obj.o act_wiz.o \
		  alias.o ban.o comm.o const.o db.o \
		  effects.o fight.o handler.o healer.o interp.o \
		  magic.o note.o recycle.o save.o sha256.o \
		  skills.o special.o tables.o update.o

rom: $(O_FILES)
	@rm -f $@
	$(CC) $(L_FLAGS) -o $@ $(O_FILES) $(LIBS)
	@ls -l $@

%o : %c
	$(CC) $(C_FLAGS) -c $< -o $@

tags :
	@rm -f $@
	@ctags *.[ch]
	@ls -l $@

clean:
	@rm -f *.o

spotless:
	@rm -f *.o tags rom gmon.out

dep:
	@find . -name \*.c -a -type f | sort | xargs -P 1 -r $(CC) $(OPTIONS) -MM

#--- Dependancies go below here ---

act_comm.o: act_comm.c merc.h recycle.h tables.h db.h interp.h act.h
act_info.o: act_info.c sha256.h merc.h recycle.h tables.h db.h interp.h \
  magic.h act.h
act_move.o: act_move.c merc.h db.h interp.h act.h
act_obj.o: act_obj.c merc.h db.h interp.h magic.h act.h
act_wiz.o: act_wiz.c merc.h recycle.h tables.h db.h interp.h magic.h \
  special.h act.h
alias.o: alias.c merc.h db.h interp.h
ban.o: ban.c merc.h recycle.h db.h interp.h
comm.o: comm.c sha256.h merc.h recycle.h tables.h db.h act.h interp.h
const.o: const.c merc.h magic.h interp.h
db.o: db.c merc.h recycle.h tables.h act.h db.h interp.h magic.h \
  special.h
effects.o: effects.c merc.h recycle.h db.h magic.h
fight.o: fight.c merc.h db.h interp.h act.h magic.h
handler.o: handler.c merc.h recycle.h tables.h db.h act.h interp.h \
  magic.h
healer.o: healer.c merc.h db.h interp.h magic.h
interp.o: interp.c merc.h db.h act.h interp.h
magic.o: magic.c merc.h recycle.h db.h act.h interp.h magic.h
note.o: note.c merc.h db.h interp.h recycle.h tables.h
recycle.o: recycle.c merc.h db.h recycle.h
save.o: save.c merc.h recycle.h tables.h db.h magic.h
sha256.o: sha256.c sha256.h
skills.o: skills.c merc.h recycle.h db.h interp.h magic.h
special.o: special.c merc.h db.h act.h interp.h magic.h special.h
tables.o: tables.c merc.h db.h interp.h tables.h
update.o: update.c merc.h db.h act.h interp.h magic.h