# Makefile for win32 and linux

ifeq ($(OS),Windows_NT)

	COMPILER = mingw32-gcc
	LINKER   = dllwrap

	DELCMD   = -del
	
	CFLAGS   = -mdll -mwindows
	LFLAGS   = -mdll -mwindows -lstdc++ -lwinmm -k -s
	VERSION  = version.o
	RC       = version.rc
	DLLNAME  = buildlimit_i686.dll
	
else

	COMPILER = gcc 
	LINKER   = gcc 
	DELCMD   = -rm -f
	
	CFLAGS   = -fPIC -Dstricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -Dstrcmpi=strcasecmp
	LFLAGS   = -shared -ldl -lm -s
	VERSION  = 
	RC       = 
	DLLNAME  = buildlimit_i686.so

endif

# for debugging add -Wall to 2nd line
# if the plugin seems unstable, change O2 to O1, but O2 has worked fine for me
OFLAGS += -march=i586 -mcpu=i686 -ffast-math -fomit-frame-pointer
CFLAGS += $(OFLAGS) -g0 -O2 -fno-exceptions -fno-rtti
LFLAGS +=

INCLUDEDIRS = -I. -I ../metamod -I ../engine -I ../common -I ../dlls

OBJ =	plugin_api.o	\
plugin_util.o			
$(VERSION)


DOCC = $(COMPILER) $(CFLAGS) $(INCLUDEDIRS) -o $@ -c $<
DOO = $(LINKER) -o $@ $(OBJ) $(LFLAGS)


$(DLLNAME) : $(OBJ) 
	$(DOO)


clean:
	$(DELCMD) $(OBJ) buildlimit_i686.* *.d


./$(VERSION): ./$(RC)
	windres -o $@ -i $<


# pull in dependency info for *existing* .o files
-include $(OBJ:.o=.d)


./%.o: ./%.cpp
	$(DOCC)
	$(COMPILER) -MM $(INCLUDEDIRS) $< > $*.d


