PROJECT = ${shell cat CMakeLists.txt | grep "PROJECT_NAME " | cut -f2 -d\"}
VERSION = ${shell cat CMakeLists.txt | grep "PROJECT_VERSION " | cut -f2 -d\"}

all:
	@echo make compile
	@echo make install
	@echo make uninstall
	@echo make po
	@echo make clean
	@echo make www
	@echo make upload
	@echo make archpack
	@echo make debpack
	@echo make slackpack

compile: build/Makefile src/*
	( cd build; make )

build/Makefile: CMakeLists.txt src/CMakeLists.txt po/CMakeLists.txt
	mkdir -p build
	( cd build; cmake .. -DCMAKE_INSTALL_PREFIX=/usr )

install: compile
	( cd build; sudo make install)

uninstall: build/install_manifest.txt
	( cd build; sudo make uninstall )

po:	build/Makefile
	( cd build; make update_po )
	
clean:
	rm -rf build
	rm -rf www

www: doc/README.md doc/INSTALL.md doc/ChangeLog.md doc/tep-screenshot.png doc/gcryfolder-screenshot.png favicon.png sitegen.sh.cfg
	sitegen.sh

upload: clean www
	cd ..; tar -czvf ${PROJECT}-${VERSION}.tar.gz ${PROJECT}-${VERSION}
	scp ../${PROJECT}-${VERSION}.tar.gz frankendres@ftp.tuxfamily.org:gcryfolder/gcryfolder-repository/
	rm -f ../${PROJECT}-${VERSION}.tar.gz
	scp -r www/* frankendres@ftp.tuxfamily.org:/home/gcryfolder/${PROJECT}.tuxfamily.org-web/htdocs/
	make clean

archpack: clean
	mkdir build
	cd ..; tar -czvf ${PROJECT}-${VERSION}.tar.gz ${PROJECT}-${VERSION}
	mv ../${PROJECT}-${VERSION}.tar.gz build/
	cat distrib/arch/PKGBUILD | sed "s/PKGVER/${VERSION}/" > build/PKGBUILD
	cd build; makepkg
	mv build/${PROJECT}-${VERSION}-*.tar.* .
	rm -rf build

debpack: clean compile
	( cd build; make install DESTDIR=pack )
	strip --strip-unneeded build/pack/usr/bin/gcryfolder-password-prompt build/pack/usr/lib/thunarx-3/libthunar-encryption-plugin.so
	mv build/pack/usr/doc build/pack/usr/share/doc
	mkdir build/pack/DEBIAN
	cat distrib/debian/control | sed "s/PKGVER/${VERSION}/" > build/pack/DEBIAN/control
	find build/pack -type d -exec chmod 755 {} \;
	sudo chown -R root:root build/pack
	sudo dpkg-deb --build build/pack
	mv build/pack.deb ${PROJECT}_${VERSION}_${shell uname -m}.deb
	sudo rm -rf build

slackpack: clean
	mkdir build
	( cd build; cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib64 ; make )
	( cd build; make install DESTDIR=pack )
	strip --strip-unneeded build/pack/usr/bin/gcryfolder-password-prompt build/pack/usr/lib64/thunarx-3/libthunar-encryption-plugin.so
	mkdir build/pack/install
	cp distrib/slackware/slack-desc build/pack/install/
	( cd build/pack; makepkg -l y -c y ../../${PROJECT}-${VERSION}-${shell uname -m}-orig.txz )
	rm -rf build
