# Makefile im Top-Level-Verzeichnis
.SILENT: help
-include Makefile.rules

GTKDIRS = base gui mapsys main gtk draw
WINCEDIRS = base gui mapsys main wince draw
NCURSESDIRS = base mapsys main
SDLGLDIRS = base gui mapsys main draw sdlgl
ANDROIDDIRS = base gui mapsys main draw

#
# curses version
#
ifeq "$(NCURSESVERSION)" "1"

all: cleanapp sposmedit

sposmedit:
	for i in $(NCURSESDIRS); \
	do if ! make -C $$i; then \
		exit -2; \
	fi done
	$(CC) -o sposmedit -lmain -lncurses -lmapsys -lbase -lmain -Lbase -Lmapsys -Lmain `pkg-config --libs libxml-2.0` -lbz2 -ggdb -pg $(DEBUG)

cleanapp:
	rm -rf sposmedit

endif

#
# sdl gl-version
#
ifeq "$(SDLGLVERSION)" "1"

all: cleanapp sposmroutegl

sposmroutegl:
	for i in $(SDLGLDIRS); \
	do if ! make -C $$i; then \
		exit -2; \
	fi done
	$(CC) -o sposmroute -lsdlgl -lmain -lgui -lmain -lmapsys -ldraw -lsdlgl -lbase -Lbase -Lmain -Lsdlgl -Ldraw -Lgui -Lmapsys -lbz2 $(DEBUG) `sdl-config --libs` `pkg-config --libs freetype2 libpng` -lGL -lGLU -L/usr/X11R6/lib -L/usr/lib 
cleanapp:
	rm -rf sposmroutegl
endif

#
# gtk version
#
ifeq "$(GTKVERSION)" "1"

all: cleanapp sposmroute

sposmroute:
	for i in $(GTKDIRS); \
	do if ! make -C $$i; then \
		exit -2; \
	fi done
	$(CC) -o sposmroute -lgtk -lmapsys -lgui -ldraw -lmain -lbase -lgui -Lbase -Lmain -Lgtk -Ldraw -Lgui -Lmapsys `pkg-config --libs gtk+-2.0 libxml-2.0` -lbz2 $(DEBUG)

cleanapp:
	rm -rf sposmroute

endif

#
# windows version
#
ifeq "$(WINVERSION)" "1"

all: cleanapp sposmroute.exe

sposmroute.exe:
	for i in $(WINCEDIRS); \
	do if ! make -C $$i; then \
		exit -2; \
	fi done
#	echo `for i in \`make -sf wince/Makefile displayobj\`; do echo wince/$$i; done`
	$(CC) -o sposmroute.exe wince/wince.rsc `for i in \`make -sf wince/Makefile displayobj\`; do echo wince/$$i; done` -ldraw -lmapsys -lgui -lmain -lbase -Lbase -Lmain -Ldraw -Lgui -Lmapsys -Lwince $(LIBS) $(DEBUG)

cleanapp:
	rm -rf sposmroute.exe
	
endif

#
# windowsce version
#
ifeq "$(WINCEVERSION)" "1"

all: cleanapp sposmroutece.exe

sposmroutece.exe:
	for i in $(WINCEDIRS); \
	do if ! make -C $$i; then \
		exit -2; \
	fi done
	$(CC) -o sposmroutece.exe wince/wince.rsc -lwince -lmapsys -ldraw -lbase -lgui -lmain -Lbase -Lmain -Ldraw -Lgui -Lmapsys -Lwince $(LIBS) $(DEBUG)

cleanapp:
	rm -rf sposmroutece.exe
	
endif


#
# android version
#
ifeq "$(ANDROIDVERSION)" "1"

all:
	cd android; make; cd .. 

endif




help:
	echo "no configuration found yet, please run"
	echo "  make configwin      to configure windows version"
	echo "  make configwince    to configure windowsce version"
	echo "  make configgtk      to configure gtk version"
	echo "  make configncurses  to configure ncurses version"
	echo "  make configsdlgl    to configure sdl-gl version"
	echo "  make configandroid  to configure android version"

configandroid: clean
	cp -f Makefile.rules.android Makefile.rules
	mkdir android/assets
	cp -f data/*.ttf android/assets
	cp -f data/*.png android/assets
	for i in $(ANDROIDDIRS); do ln -s ../../$$i android/jni/ ; done

configwin: clean
	cp -f Makefile.rules.win Makefile.rules
	for i in $(WINCEDIRS); do make -C $$i dep; done

configwince: clean
	cp -f Makefile.rules.wince Makefile.rules
	for i in $(WINCEDIRS); do make -C $$i dep; done

configsdlgl: clean
	cp -f Makefile.rules.sdlgl Makefile.rules
	for i in $(SDLGLDIRS); do make -C $$i dep; done
	
configgtk: clean
	cp -f Makefile.rules.gtk Makefile.rules
	for i in $(GTKDIRS); do make -C $$i dep; done

configncurses: clean
	cp -f Makefile.rules.ncurses Makefile.rules
	for i in $(NCURSESDIRS); do make -C $$i dep; done

clean:
	touch Makefile.rules
	for i in $(NCURSESDIRS); do make -C $$i clean; done
	for i in $(GTKDIRS); do make -C $$i clean; done
	for i in $(WINCEDIRS); do make -C $$i clean; done
	for i in $(SDLGLDIRS); do make -C $$i clean; done
	for i in $(ANDROIDDIRS); do rm -f android/jni/$$i; done
	rm -rf android/assets
	cd android; make clean; cd ..
	rm -rf Makefile.rules

cleanall:
	touch Makefile.rules
	for i in $(NCURSESDIRS); do make -C $$i clean; done
	for i in $(GTKDIRS); do make -C $$i clean; done
	for i in $(WINCEDIRS); do make -C $$i clean; done
	for i in $(SDLGLDIRS); do make -C $$i clean; done
	for i in $(ANDROIDDIRS); do rm -f android/jni/$$i; done
	rm -rf android/assets
	cd android; make clean; cd ..
	rm -rf sposmroute
	rm -rf sposmroutegl
	rm -rf sposmedit
	rm -rf sposmroute.exe
	rm -rf sposmroutece.exe
	rm -rf cache
	rm -rf Makefile.rules
	rm -rf gmon.out
	rm -rf .anjuta_sym_db.db
	rm -rf tmposm
	rm -rf output.svg
	rm -rf cache

