TARGET = k4de
VERSION = 0.3.0

LSM	= $(TARGET)-$(VERSION).lsm
DATE	= `date +%x`


MAKE		= make
LD		= ld
RM		= rm -f
CP		= cp
MV		= mv
TAR		= tar
CPP		= g++
CC		= gcc
STRIP		= strip
MOC		= moc
MSGFMT		= msgfmt

CPPFLAGS 	= -O2 -Wall

SUBDIRS	= src

all:		subdirs

release:	version makerelease texture

debug:		version makedebug texture

makerelease:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i "CPPFLAGS= -O2 -Wall -UDEBUG"; done

makedebug:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i "CPPFLAGS= -g -Wall -DDEBUG"; done

version:
	@echo "#ifndef VERSION"  > src/include/version.h
	@echo "#define VERSION " '"$(VERSION)"' >> src/include/version.h
	@echo "#endif"  >> src/include/version.h
	@echo "" >>  src/include/version.h
	@echo "#ifndef PROGNAME"  >> src/include/version.h
	@echo "#define PROGNAME " '"'`echo $(TARGET) | tr "[a-z]" "[A-Z]"`'"' >> src/include/version.h
	@echo "#endif"  >> src/include/version.h
	@echo ""  >> src/include/version.h
	@echo "#ifndef BINNAME"  >> src/include/version.h
	@echo "#define BINNAME " '"$(TARGET)"' >> src/include/version.h
	@echo "#endif"  >> src/include/version.h

subdirs:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i "CPPFLAGS=$(CPPFLAGS)"; done


clean:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
	$(RM) -f $(TARGET) $(TARGET).debug *~ *.lsm *.tga *.ppm \
		data/*.tga data/*.ppm data/*~ \
		data/pov/*.tga data/pov/*.ppm data/pov/*~ \
		data/texture/*.ppm data/texture/*~ \
		data/anim/*.ppm data/anim/*~ \
		data/scripts/*~ \
		doc/*~ doc/handbuch/*~  
	$(RM) -r `find * | grep .directory`

new:	clean all

tgz:	clean lsm
	@echo Making tgz-package
	@echo
	cp -f ./$(LSM) ..
	tar --directory .. --create --gzip --verbose --file=../$(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION)
	@echo
	@echo done.

tbz:	clean lsm
	@echo Making tbz-package
	@echo
	cp -f ./$(LSM) ..
	tar --directory .. --create --bzip2 --verbose --file=../$(TARGET)-$(VERSION).tbz $(TARGET)-$(VERSION)
	@echo
	@echo done.

#bintgz:	clean release lsm
bintgz:	 release lsm
	@echo Making bintgz-package
	@echo
	@$(MV) makefile makefile.tmp
	@$(CP) makefile.bin makefile
	@$(TAR) --directory .. --create --gzip --verbose --file=../$(TARGET)-$(VERSION).bin.tgz $(TARGET)-$(VERSION)/k4de \
		$(TARGET)-$(VERSION)/makefile $(TARGET)-$(VERSION)/data $(TARGET)-$(VERSION)/doc 
	@$(MV) makefile.tmp makefile
	@$(RM) makefile.tmp
	@echo
	@echo done.

bintbz:	clean release lsm
	@echo Making bintgz-package
	@echo
	@$(MV) makefile makefile.tmp
	@$(CP) makefile.bin makefile
	@$(TAR) --directory .. --create --bzip2 --verbose --file=../$(TARGET)-$(VERSION).bin.tbz $(TARGET)-$(VERSION)/k4de \
		$(TARGET)-$(VERSION)/makefile $(TARGET)-$(VERSION)/data $(TARGET)-$(VERSION)/doc
	@$(MV) makefile.tmp makefile
	@$(RM) makefile.tmp
	@echo
	@echo done.

lsm:
	@echo Making LSM
	@echo Writing $(LSM)
	@echo
	@echo Begin3 > ./$(LSM)
	@echo "Title:            "$(TARGET) >> ./$(LSM)
	@echo "Version:          "$(VERSION) >> ./$(LSM)
	@echo "Entered-date:     "$(DATE) >> ./$(LSM)
	@echo "Description:      3Deditor for the KDE, generates source for POVray 3.1." >> ./$(LSM)
	@echo "                  Animation available through shellscripts" >> ./$(LSM)
	@echo "Keywords:         kde editor 3d modelling csg textures animation povray" >> ./$(LSM)
	@echo "Author:           mweber@gmx.de (Markus Weber)" >> ./$(LSM)
	@echo "Author:           Tobias.Wollgam@gmx.de (Tobias Wollgam)">> ./$(LSM)
	@echo "Maintained-by:    Tobias.Wollgam@gmx.de (Tobias Wollgam)" >> ./$(LSM)
	@echo "Primary-site:     ftp://ftp.kde.org/pub/kde/apps/graphics/" >> ./$(LSM)
	@echo "Alternate-site:   none" >> ../$(LSM)
	@echo "Original-site:    ftp://ftp.kde.org/pub/kde/apps/graphics/" >> ./$(LSM)
	@echo "Home-Page:        http://come.to/k4de" >> ./$(LSM)
	@echo "Platform:         unix (only tested on linux)" >> ./$(LSM)
	@echo "Copying-policy:   GPL" >> ./$(LSM)
	@echo End >> ./$(LSM)
	@echo
	@echo done.

texture:	data/texture/none.ppm

data/texture/none.ppm:
	povray +W100 +H100 +FP +Idata/texture/none.pov +Odata/texture/none.ppm

install:  help

uninstall:  help

installtest:  all
	@echo "HOME="$(HOME)
	mkdir -p $(HOME)/.$(TARGET)/model/3dds
	mkdir -p $(HOME)/.$(TARGET)/model/tddd
	mkdir -p $(HOME)/.$(TARGET)/font
	mkdir -p $(HOME)/.$(TARGET)/pov
	mkdir -p $(HOME)/.$(TARGET)/images
	mkdir -p $(HOME)/.$(TARGET)/animations
	mkdir -p $(HOME)/.$(TARGET)/texture/normalmap
	mkdir -p $(HOME)/.$(TARGET)/texture/imagemap
	mkdir -p $(HOME)/.$(TARGET)/material
	mkdir -p $(HOME)/.$(TARGET)/heightfield
	@echo "KDE="$(KDEDIR)
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)/doc
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)/font
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)/texture/normalmap
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)/texture/imagemap
	mkdir -p $(KDEDIR)/share/apps/$(TARGET)/model
	mkdir -p $(KDEDIR)/share/doc/HTML/de/$(TARGET)
	cp $(TARGET) $(KDEDIR)/bin
	cp data/k4derc $(KDEDIR)/share/apps/$(TARGET)
	cp data/k4derc $(HOME)/.$(TARGET)
	cp -r doc/handbuch $(KDEDIR)/share/doc/HTML/de/$(TARGET)/
	cp -f data/$(TARGET).xpm $(KDEDIR)/share/icons
#	cp -f data/K4DE.kdelnk $(KDEDIR)/share/applnk/Graphics/
	cp -f data/$(TARGET).kdelnk $(KDEDIR)/share/applnk/Graphics/
	cp -f data/3dds.kdelnk $(KDEDIR)/share/mimelnk/application/
#	cp -f data/texture/none.ppm $(KDEDIR)/share/apps/$(TARGET)/texture/
#	cp -f data/texture/none.ppm $(HOME)/.$(TARGET)/texture/
#	cp -f doc/* $(KDEDIR)/share/apps/$(TARGET)/doc/

uninstalltest: 
	rm -f $(KDEDIR)/bin/$(TARGET)
	rm -r -f $(KDEDIR)/share/apps/$(TARGET)
	rm -r -f $(KDEDIR)/share/doc/HTML/de/$(TARGET)
	rm -r -f $(HOME)/.$(TARGET)

help:
	@echo "#######################################################"
	@echo "#                                                     #"
	@echo "# Sorry! There is no (un)installation-support now.    #"
	@echo "# Compile and start k4de from base-directory!         #"
	@echo "#                                                     #"
	@echo "# Please read the documentation in the directory doc. #"
	@echo "#                                                     #"
	@echo "# *************************************************** #"
	@echo "# * If you know what you do then try:               * #"
	@echo "# * make installtest                                * #"
	@echo "# * make uninstalltest                              * #"
	@echo "# *************************************************** #"
	@echo "#                                                     #"
	@echo "#######################################################"

licence:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i licence; done

stat:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i stat; done

