#  This file is part of the program:
#
#   nV@derz! (nvaderz)
#   Copyright (C) 2006-2013  Eric Pellegrin

#   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.

#   Eric Pellegrin can be reached by email at pellea72(at)yahoo(dot)com
#   (Note: email address modified to evade unsolicited email search bots.
#       Change (at) to @ and (dot) to . to read name@company.com )
#

# nV@derz! Makefile
# (c) 2007 Eric Pellegrin
# last updated: February 19, 2010

# variables
objects = applysettings.o displaymenu.o draw.o gamecontrol.o \
    gamefunction.o getfilesettings.o io.o main.o bonus.o \
    nvaderz_ext.o roundoff.o timer.o hud.o highscores.o optionsmenu.o \
    joystick.o
srcdir = .
objdir = $(srcdir)/../__obj
builddir = $(objdir)/nvaderz
bindir = $(srcdir)/../__bin
releasedir = $(bindir)/nvaderz_Directory

objects_full_path = $(addprefix $(builddir)/, $(objects))

CC = cc
# uncomment -Wextra for versions of gcc that recognize the flag
CCFLAGS = -ansi -pedantic -Wall # -Wextra

# Change the following to match where you have allegro-config installed,
# such as /usr/bin or /usr/local/bin.
ALLEGRO_BUILD_SCRIPT = `/usr/local/bin/allegro-config --libs`
LDFLAGS = $(ALLEGRO_BUILD_SCRIPT)

VPATH = $(srcdir) $(builddir)

# target rules

nvaderz : SETUP $(objects)
	$(CC) -o $(builddir)/nvaderz $(objects_full_path) $(LDFLAGS)
	cp $(builddir)/nvaderz $(releasedir)/nvaderz

SETUP :
	if test ! -d $(objdir); then mkdir $(objdir); fi
	if test ! -d $(builddir); then mkdir $(builddir); fi
	if test ! -d $(bindir); then mkdir $(bindir); fi
	if test ! -d $(releasedir); then mkdir $(releasedir); fi
	if test ! -d $(releasedir)/Resources; then \
	    cp -r $(srcdir)/../Resources $(releasedir)/Resources; fi
	cp $(srcdir)/../LICENSE $(srcdir)/../README $(srcdir)/../INSTALL $(releasedir)

$(objects) : nvaderz.h

applysettings.o : applysettings.c getfilesettings.h
	$(CC) $(CCFLAGS) -c $(srcdir)/applysettings.c -o $(builddir)/applysettings.o
displaymenu.o : displaymenu.c highscores.h optionsmenu.h joystick.h
	$(CC) $(CCFLAGS) -c $(srcdir)/displaymenu.c -o $(builddir)/displaymenu.o
draw.o : draw.c
	$(CC) $(CCFLAGS) -c $(srcdir)/draw.c -o $(builddir)/draw.o
gamecontrol.o : gamecontrol.c highscores.h bonus.h
	$(CC) $(CCFLAGS) -c $(srcdir)/gamecontrol.c -o $(builddir)/gamecontrol.o
gamefunction.o : gamefunction.c highscores.h bonus.h
	$(CC) $(CCFLAGS) -c $(srcdir)/gamefunction.c -o $(builddir)/gamefunction.o
getfilesettings.o : getfilesettings.c getfilesettings.h
	$(CC) $(CCFLAGS) -c $(srcdir)/getfilesettings.c -o $(builddir)/getfilesettings.o
io.o : io.c joystick.h
	$(CC) $(CCFLAGS) -c $(srcdir)/io.c -o $(builddir)/io.o
main.o : main.c
	$(CC) $(CCFLAGS) -c $(srcdir)/main.c -o $(builddir)/main.o
nvaderz_ext.o : nvaderz_ext.c
	$(CC) $(CCFLAGS) -c $(srcdir)/nvaderz_ext.c -o $(builddir)/nvaderz_ext.o
roundoff.o : roundoff.c
	$(CC) $(CCFLAGS) -c $(srcdir)/roundoff.c -o $(builddir)/roundoff.o
timer.o : timer.c
	$(CC) $(CCFLAGS) -c $(srcdir)/timer.c -o $(builddir)/timer.o
hud.o : hud.c hud.h
	$(CC) $(CCFLAGS) -c $(srcdir)/hud.c -o $(builddir)/hud.o
highscores.o : highscores.c highscores.h
	$(CC) $(CCFLAGS) -c $(srcdir)/highscores.c -o $(builddir)/highscores.o
bonus.o : bonus.c bonus.h
	$(CC) $(CCFLAGS) -c $(srcdir)/bonus.c -o $(builddir)/bonus.o
optionsmenu.o : optionsmenu.c optionsmenu.h
	$(CC) $(CCFLAGS) -c $(srcdir)/optionsmenu.c -o $(builddir)/optionsmenu.o
joystick.o : joystick.c joystick.h
	$(CC) $(CCFLAGS) -c $(srcdir)/joystick.c -o $(builddir)/joystick.o

install : ;

.PHONY: clean
clean :
	if test -d $(builddir); then rm -r $(builddir); fi
	if test -d $(objdir); then rm -r $(objdir); fi
	if test -d $(releasedir); then rm -r $(releasedir); fi
	if test -d $(bindir); then rm -r $(bindir); fi
