#!/usr/bin/make -f
#
SHELL=/bin/bash

# X Bibliotheken werden benoetigt:
INCLUDEDIRS=-I/usr/X11R6/include
# dito.
LIBDIRS=-L/usr/X11R6/lib

CC=g++
CXX=g++
#OPTIMIZE=
#DEBUG=-g
OPTIMIZE=-O6 -mpentiumpro
#DEBUG=-DDEBUG=1
CPPFLAGS=$(DEBUG) $(OPTIMIZE) -pedantic -ansi -Wall -pipe $(INCLUDEDIRS)
#LDFLAGS=-lMesaGL -lglut -lMesaGLU -lm -lXmu -lX11 -lXi -lpthread -L/usr/X11R6/lib -ljpeg
LDFLAGS=-lMesaGL -lglut -lXmu -lXi -lMesaGLU -ljpeg $(LIBDIRS)

SOURCES=$(wildcard *.cc)

PROGRAMS=finalpool

ALL_DEPS = finalpool.o cObject.o cCube.o cLight.o cColor.o \
	cWorld.o iocVertex.o iocMatrix.o cMsgException.o cException.o \
	cVisibleObject.o cADSEColor.o cMaterial.o \
	cInteractiveObject.o cEventConsumer.o cEvent.o cEventProducer.o \
	cEventDispatcher.o cVertexEvent.o cAddressEvent.o cRotationEvent.o \
	cEventInput.o cKeyEvent.o cMousePressEvent.o cWorldControl.o \
	cPlane.o cTextureMaterial.o cHoledPlane.o cIntEvent.o cWater.o \
	cEnvTextureMaterial.o cDirectionLight.o cSpotLight.o

COMMON_INCLUDES=cVertex.hh cMatrix.hh cQuaternion.hh common.hh \
	misc_docu.hh $(wildcard events_*.hh)

ALL_SOURCES=$(shell for f in $(ALL_DEPS:.o=) ; do \
		for ext in cc c hh h ; do \
			[ -f $$f.$$ext ] && echo $$f.$$ext ; \
		done ; \
	done | sort | uniq) $(COMMON_INCLUDES)

DIST_FILES=$(ALL_SOURCES) Makefile improvements \
	textures/bottom.jpg textures/brick.jpg \
	textures/front.jpg textures/kacheln.jpg textures/left.jpg \
	textures/right.jpg textures/top.jpg textures/wellen.jpg \
	textures/wiese.xcf.gz textures/wiese.jpg textures/wiese2.jpg \
	README



.PHONY:  default backup dep clean ccdocs linecount

default:	$(PROGRAMS) linecount

backup:
	tar cfz backup.tar.gz $(DIST_FILES)

dep:
	rm -f *.d

clean:
	rm -f $(ALL_DEPS) $(ALL_DEPS:.o=.d)

linecount:
	@echo -n "Anzahl Codezeilen:"
	@cat $(ALL_SOURCES) | wc -l

finalpool: $(ALL_DEPS)

# shortcut to have make automagically run the compiled program
%.run:	%
	./$< -geometry 640x480-0+0 2>&1 | tee $<.log

%.gdb:	%
	gdb $<

# everything depends from Makefile
#$(ALL_DEPS):	Makefile

# automatic depency generation (thanks to make docu for this)
%.d:  %.cc
	@$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< | \
        sed -e '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@ ; \
        [ -s $@ ] || rm -f $@'

%.d:  %.c
	@$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< | \
        sed -e '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@ ; \
        [ -s $@ ] || rm -f $@'

include $(CFILES:.c=.d) $(CCFILES:.cc=.d)

