#    Awesome Tower Defense
#    Copyright (C) 2008-2009  Trygve Vea and contributors (read AUTHORS)
#
#    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.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

PLATFORM = LINUX

OBJS = awesometd-ysdl.o ysdl.o

CFLAGS = -Wall -pipe -DYSDL_WANT_IMAGE
ifdef RELEASE
	CFLAGS += -march=native -O2 -fomit-frame-pointer -funroll-loops
else
	#CFLAGS += -pg -ggdb -O0
	CFLAGS += -Wall -g -O2
endif

ifeq ($(PLATFORM),LINUX)
	TARGET = awesometd-ysdl
	CC = gcc
	CFLAGS += $(shell sdl-config --cflags) -I/opt/lua/include
	LDFLAGS += -lm $(shell sdl-config --libs) -lSDL_image -llua -lm -L/opt/lua/lib
	#OBJCOPY += objcopy -I binary -O elf32-i386 -B i386
endif
ifeq ($(PLATFORM),WIN32)
	TARGET = awesometd-ysdl.exe
	CC = i586-mingw32msvc-gcc
	WINDRES := i586-mingw32msvc-windres
	CFLAGS += $(shell /home/trygve/sdl/SDL-1.2.13/bin/sdl-config --cflags)
	LDFLAGS += $(shell /home/trygve/sdl/SDL-1.2.13/bin/sdl-config --libs) -lSDL_image -llua -lm
	#OBJCOPY += i586-mingw32msvc-objcopy -I binary -O pe-i386 -B i386
	OBJS += res.o
endif

all: $(TARGET)

$(TARGET): $(OBJS) Makefile
	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)

%.o: %.c %.h Makefile
	$(CC) $(CFLAGS) -c $< -o $@

#%.o: %.bmp
#	$(OBJCOPY) $< $@

res.o: res.rc icon.ico
	$(WINDRES) -o $@ res.rc

clean:
	rm -f $(OBJS) $(TARGET)

.PHONY: all clean
