# Author: Tobi Vollebregt

#   TankZone: My second Allegro game.
#   Copyright (C) 2003  Tobi Vollebregt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#   See `License.txt', which contains a verbatim copy of the
#   GNU General Public License, for details.
#
#   Please send your reaction to: tobivollebregt@hotmail.com



#   -=- Makefile targets -=-
#
#   make [all]     - Compile the program.
#   make clean     - Remove the object and dependency files.
#   make distclean - Remove the object, dependency and executable files.
#   make compress  - Compress the executable file.
#
#   Set USE_ASM=1 before executing "make" to link the program with an
#   assembler version of the draw_multiply_sprite4() routine.
#   Please check if the correct object file output format is specified:
#   For DJGPP, the default is COFF, otherwise the default is ELF32.
#   Check also if you have NASM installed when using this option.
#



.PHONY: all clean distclean compress

SRCDIR=src/
OBJDIR=tmp/
DEPDIR=tmp/

EXE=tankzone$(EXE_SUFFIX)
SRC=tankzone.c ai.c blend.c engine.c \
	sprite4.c fade16.c flame.c intro.c \
	jgmod.c lighting.c random.c
OBJ=$(addprefix $(OBJDIR),$(addsuffix .o,$(basename $(SRC))))
DEP=$(addprefix $(DEPDIR),$(addsuffix .d,$(basename $(SRC))))

ifdef DJGPP

EXE_SUFFIX=.exe
CXX=gpp
LDLIBS=-lalleg
NASMFLAGS=-f coff

else

EXE_SUFFIX=
CXX=g++
LDLIBS=`allegro-config --libs`
NASMFLAGS=-f elf

endif

ifdef DEBUGMODE

CFLAGS=-Wall -g
CXXFLAGS=-Wall -g
CPPFLAGS=-DDEBUGMODE=1
LDFLAGS=

else

CFLAGS=-O3
CXXFLAGS=-O3
CPPFLAGS=
LDFLAGS=-s

endif

ifdef USE_ASM
SRC+=sprite4a.asm
CPPFLAGS+=-DUSE_ASM=1
endif

CC=gcc
LD=gcc
NASM=nasm$(EXE_SUFFIX)
RM=rm -f
UPX_BIN=upx$(EXE_SUFFIX)

all: $(EXE) ;
clean: ; $(RM) $(OBJ) $(DEP)
distclean: clean ; $(RM) $(EXE)
compress: ; $(UPX_BIN) $(EXE)

$(EXE): $(OBJ)
	$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(OBJDIR)%.o: $(SRCDIR)%.c
	$(CC) -c -MMD -MF $(DEPDIR)$(notdir $(@:.o=.d)) $(CPPFLAGS) $(CFLAGS) -o $@ $<
$(OBJDIR)%.o: $(SRCDIR)%.cpp
	$(CXX) -c -MMD -MF $(DEPDIR)$(notdir $(@:.o=.d)) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
$(OBJDIR)%.o: $(SRCDIR)%.asm
	$(NASM) -o $@ $(NASMFLAGS) $<

$(DEPDIR)%.d: $(OBJDIR)%.o

-include $(DEPDIR)*.d
