#RollCageX (sci-fi racer inspired by the original RollCage games)
#Copyright (C) 2009-2010  Mats Wahlberg ("Slinger" on gorcx.net forum)
#
#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 3 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, see <http://www.gnu.org/licenses/>.


#OBJS	= build/main.o build/shared/shared.o build/events/events.o build/loaders/loaders.o build/graphics/graphics.o build/physics/physics.o
OBJS    = $(patsubst %.cpp,build/%.o, $(wildcard */*.cpp) main.cpp)
LIBLST	= sdl gl glu ode

LIBS	= `pkg-config --libs $(LIBLST)`
FLAGS	= `pkg-config --cflags $(LIBLST)`
ARGS	= -O2 -pipe -Wall -march=native -mtune=native -lm $(FLAGS)

all: rcx

#final normal target
rcx: builddirs $(OBJS)
	@echo "Linking..."
	@g++ -o ../rcx $(OBJS) $(LIBS) $(ARGS)

#prerequisites
include prereqs.lst

#universal build rule
$(OBJS): build/%.o:%.cpp
	@echo "Compiling $(<)..."
	@g++ -c -o $@ $< $(ARGS)

.PHONY: builddirs clean distclean

builddirs:
	@echo "Making sure build directories exists..."
	@mkdir -p build/shared build/events build/loaders build/graphics build/physics

clean:
	-rm -f $(OBJS)

distclean: clean
	-rm -f ../rcx

