# Thanks for juvinious for making the makefile linux-compatible

SRC := $(wildcard *.cpp)
OBJS := $(SRC:.cpp=.o) resource.o
OPTIONS = -Wno-deprecated -Wno-deprecated-declarations -O3 -I/usr/local/gp2xdev/include
EX_NAME = ../bin/bunkermaster.exe
RUN_WINDRES=windres -O coff -o -i resource.rc -o resource.o
LIBFLAGS=-lalleg
RM=del

#Operating System Checks to change certain flags and variables
ifeq "$(findstring Windows, $(shell ver))" "Windows"
	ifdef STATICLINK
		LIBFLAGS=-lalleg_s -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound
	else
		LIBFLAGS=-lalleg
	endif
	OBJS := $(SRC:.cpp=.o) resource.o
	EX_NAME=..\bin\bunkermaster.exe
	RUN_WINDRES=windres -O coff -o -i resource.rc -o resource.o
	RM=del
endif

ifeq "$(findstring linux, $(shell echo $$OSTYPE))" "linux"
	LIBFLAGS=`allegro-config --static`
#	LIBFLAGS+=-pg
	OBJS := $(SRC:.cpp=.o)
	EX_NAME=../bin/bunkermaster
	RUN_WINDRES=-echo "HI"
	RM=-rm
	NO_FBLEND=1
endif

ifdef NO_FBLEND
	OPTIONS += -DNO_FBLEND
else
	ifdef STATICLINK
		LIBS += -lfblend_s
	else
		LIBS += -lfblend
	endif
endif
ifdef STATICLINK
	OPTIONS += -DALLEGRO_STATICLINK
	LIBS += -laldmb -ldumb $(LIBFLAGS)
else
	LIBS += -laldmb -ldumb $(LIBFLAGS)
endif

all: bunkermaster

clean:
	$(RM) *.o $(EX_NAME)
	
bunkermaster: $(OBJS)
	gp2x-g++ $^ -o $(EX_NAME) $(LIBS)
	
resource.o: resource.rc
	$(RUN_WINDRES)

%.o: %.cpp
	gp2x-g++ -c $(OPTIONS) $< -o $@
