#############################################################################
#
#
#
#############################################################################
# edit this for pvm-support (0/1)
PVM_SUPPORT	= 0
#
# edit this for rtti-use (0/1)
USE_RTTI	= 0
#
# edit this for the use of libqimgio (0/1)
USE_QIMAGEIO	= 0
#
# edit this for the use of QToolTip in non KDE-components (0/1)
USE_QTOOLTIP	= 0
#
# edit this if QTDIR is not defined or exported
QTINC		= $$QTDIR/include
QTLIB		= $$QTDIR/lib
#
# edit this if KDEDIR is not defined or exported
KDEINC		= $$KDEDIR/include
KDELIB		= $$KDEDIR/lib
#
# edit this
XINC		= /usr/X11R6/include
XLIB		= /usr/X11R6/lib
#
#############################################################################
#
#
#
#############################################################################


.EXPORT_ALL_VARIABLES:


TARGET		= k4de
VERSION		= 0.4.0



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


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

CPPFLAGS 	= -O2 -Wall

SUBDIRS		= src

all:		release

release:	version makerelease texture

debug:		version makedebug texture

makerelease:
	set -e;
	for i in $(SUBDIRS); do $(MAKE) -C $$i "CPPFLAGS= -fno-rtti -pipe -O2 -UDEBUG -DUSE_PVM=$(PVM_SUPPORT) -DUSE_RTTI=$(USE_RTTI) -DUSE_QIMAGEIO=$(USE_QIMAGEIO) -DUSE_QTOOLTIP=$(USE_QTOOLTIP) -I$(QTINC) -I$(KDEINC) -I$(XINC)" LDFLAGS="-L$(XLIB) -L$(QTLIB) -L$(KDELIB)"; done
	
makedebug:
	set -e;
	for i in $(SUBDIRS); do $(MAKE) -C $$i "CPPFLAGS= -fno-rtti -pipe -g -Wall -DDEBUG -DUSE_PVM=$(PVM_SUPPORT) -DUSE_RTTI=$(USE_RTTI) -DUSE_QIMAGEIO=$(USE_QIMAGEIO) -DUSE_QTOOLTIP=$(USE_QTOOLTIP) -I$(QTINC) -I$(KDEINC) -I$(XINC)" LDFLAGS="-L$(XLIB) -L$(QTLIB) -L$(KDELIB)"; 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`
	$(RM) -r `find * | grep .xvpics`
	$(RM) -r data/mo
	

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://www.k4de.de" >> ./$(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:  all
	$(MAKE) -f makefile.bin install

uninstall:
	$(MAKE) -f makefile.bin uninstall

licence:
	tools/version.sh src tools/version.txt

stat:
	tools/stat.sh

