# This has the target platform defined, this is modified by fix.bat or fix.sh
include target.os

# Suggested by GNU Coding Stardards
SHELL = /bin/sh

# platform specific stuff:

# ------------------
# DJGPP target
# ------------------
ifeq ($(TARGET),DJGPP)

PLATFORMDIR=djgpp
GPP = gxx
BINSUF = .exe
CFLAGS = -Iinclude -O3 -Wall -s -ffast-math -fomit-frame-pointer
LFLAGS = -lm -O3 -Wall -s -ffast-math -fomit-frame-pointer -lalleg
#CFLAGS = -Iinclude -g -Wall
#LFLAGS = -g -lalleg

endif

# ------------------
# MingW32
# ------------------
ifeq ($(TARGET),MINGW32)

PLATFORMDIR=mingw
GPP = g++
BINSUF = w.exe
CFLAGS = -Iinclude -O3 -Wall -s -ffast-math -fomit-frame-pointer -D__GTHREAD_HIDE_WIN32API 
LFLAGS = -lm -O3 -Wall -s -ffast-math -fomit-frame-pointer -mwindows -lalleg -D__GTHREAD_HIDE_WIN32API 
#CFLAGS = -Iinclude -g -Wall -D__GTHREAD_HIDE_WIN32API 
#LFLAGS = -g -mwindows -lalleg -D__GTHREAD_HIDE_WIN32API 

endif

# ------------------
# Linux
# ------------------
ifeq ($(TARGET),LINUX)

PLATFORMDIR=linux
GPP = g++
BINSUF =
CFLAGS = -Iinclude -O3 -Wall -s -ffast-math -fomit-frame-pointer
LFLAGS = -lm -O3 -Wall -s -ffast-math -fomit-frame-pointer `allegro-config --libs`
#CFLAGS = -Iinclude -g -Wall
#LFLAGS = -g `allegro-config --libs`

endif

#below is platform non-specific
OBJDIR = obj/$(PLATFORMDIR)

SRC = $(wildcard src/*.cpp)
OBJ = $(addprefix $(OBJDIR)/,$(addsuffix .o, $(basename $(notdir $(SRC)))))
DEP = $(addprefix $(OBJDIR)/,$(addsuffix .d, $(basename $(notdir $(SRC)))))
BIN = mars$(BINSUF)

all: $(BIN)

$(BIN) : $(OBJ)
	$(GPP) $^ -o $@ $(LFLAGS)

$(OBJ) : $(OBJDIR)/%.o : src/%.cpp
	$(GPP) $(CFLAGS) -MMD -c $< -o $@

# include the .d files
# they contain extra rules about how .o files depend on headers
-include $(DEP)

.PHONY: clean
clean: 
	rm -rf $(BIN) $(OBJ) $(DEP)
