CC      = gcc
PROF    = 
L_FLAGS = $(PROF)

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

#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 -Werror -Wshadow -Wformat-security -Winline -Wpointer-arith -Wcast-align -Wredundant-decls -Wstrict-prototypes

C_FLAGS = -g2 $(W_FLAGS) $(PROF)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c boards.c \
	  build.c clans.c color.c comm.c comments.c const.c db.c fight.c \
	  handler.c hashstr.c interp.c magic.c makeobjs.c \
	  md5.c misc.c mud_comm.c mud_prog.c player.c \
	  reset.c save.c shops.c skills.c special.c tables.c track.c update.c \
	  space.c bounty.c swskills.c functions.c slicers.c marriage.c hunter.c \
          planets.c pfiles.c newarena.c tech.c \
          editor.c ships.c force.c finfo.c fskills.c 11.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 swr

swr: $(O_FILES)
ifdef CYGWIN
	rm -f swr
	$(CC) $(L_FLAGS) -o swr.exe $(O_FILES) -lm
	echo "Done compiling mud.";
	chmod g+w swr.exe
	chmod g+w $(O_FILES)
else
	rm -f swr
	$(CC) $(L_FLAGS) -o swr $(O_FILES) -lm
	echo "Done compiling mud.";
	chmod g+w swr
	chmod g+w $(O_FILES)
endif

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

clean:
ifdef CYGWIN
	rm -f swr.exe $(O_FILES)
else
	rm -f swr $(O_FILES)
endif

new:
	$(MAKE) clean
	$(MAKE) all

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