##########################################################################
# Copyright (C) 2011 Stefan Stäglich
#
# This file is part of pung.
#
# Pung 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.
#
# Pung 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 pung.  If not, see <http://www.gnu.org/licenses/>.
##########################################################################

CXX = g++ -Wall -lSDL -lGL -lGLU -O3
MAIN_BINARIES = $(basename $(wildcard *Main.cpp))
TEST_BINARIES = $(basename $(wildcard *Test.cpp))
OBJECTS = $(addsuffix .o, $(basename $(filter-out %Main.cpp %Test.cpp,$(wildcard *.cpp))))
HEADER = $(wildcard *.h)

.PRECIOUS: %.o

all: build test lint

build: $(MAIN_BINARIES) $(TEST_BINARIES)
	
lint:
	python ../cpplint.py *.cpp *.h
	
test: $(TEST_BINARIES)
	for T in $(TEST_BINARIES); do ./$$T; done

clean:
	rm -f *Main
	rm -f *Test
	rm -f *.o
	rm -f *~
	rm -f core
	rm -f *TMP*

%Main: %Main.o $(OBJECTS)
	$(CXX) -o $@ $^
	
%Test: %Test.o $(OBJECTS)
	$(CXX) -o $@ $^ -lgtest_main -lpthread

%.o: %.cpp $(HEADER)
	$(CXX) -c $<
