all: src firetools.1 firejail-ui.1

datarootdir=@datarootdir@
PREFIX=@prefix@
prefix=@prefix@
VERSION=@PACKAGE_VERSION@
NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
DOCDIR=@docdir@


firetools_config_extras.h:
	echo "#define PACKAGE_LIBDIR \"$(DESTDIR)/$(PREFIX)/lib/firetools\"" > firetools_config_extras.h
	
.PHONY: src
src: firetools_config_extras.h
	$(MAKE) -C $@ $(MFLAGS)


firetools.1: src/man/firetools.txt
	./mkman.sh $(VERSION) src/man/firetools.txt firetools.1

firejail-ui.1: src/man/firejail-ui.txt
	./mkman.sh $(VERSION) src/man/firejail-ui.txt firejail-ui.1

clean:;rm -f build/*; rm -f *.1 *.1.gz; make -C src clean

distclean: clean
	rm -f `find src/firetools -name Makefile`
	rm -f `find src/fmgr -name Makefile`
	rm -f `find src/firejail-ui -name Makefile`
	rm -f `find src/debmenu -name Makefile`
	rm -f firetools_config.h firetools_config_extras.h Makefile config.status config.log
	rm -f  src/firetools/config.log src/firetools/config.status #fedora fix
	rm -f  src/fmgr/config.log src/fmgr/config.status #fedora fix
	rm -f  src/debmenu/config.log src/debmenu/config.status #fedora fix
	rm -f  src/firejail-ui/config.log src/firejail-ui/config.status #fedora fix
	rm -fr autom4te.cache
	rm -f sanitizer.sh

	
install: all
	mkdir -p $(DESTDIR)/$(PREFIX)/bin
	mkdir -p $(DESTDIR)/$(PREFIX)/share/applications
	mkdir -p $(DESTDIR)/$(PREFIX)/share/pixmaps
	mkdir -p $(DESTDIR)/$(PREFIX)/lib/firetools
	mkdir -p $(DESTDIR)/$(DOCDIR)
	mkdir -p $(DESTDIR)/$(PREFIX)/share/man/man1
	install -c -m 0755 build/firetools $(DESTDIR)/$(PREFIX)/bin/.
	install -c -m 0755 build/firejail-ui $(DESTDIR)/$(PREFIX)/bin/.
	install -c -m 0755 build/fmgr $(DESTDIR)/$(PREFIX)/lib/firetools/fmgr
	install -c -m 0755 build/fstats $(DESTDIR)/$(PREFIX)/lib/firetools/fstats
	install -c -m 0644 src/firejail-ui/uimenus $(DESTDIR)/$(PREFIX)/lib/firetools/.
	install -c -m 0644 src/firejail-ui/uihelp $(DESTDIR)/$(PREFIX)/lib/firetools/.
	install -c -m 0644 src/firetools/firetools.desktop $(DESTDIR)/$(PREFIX)/share/applications/.
	install -c -m 0644 src/firejail-ui/firejail-ui.desktop $(DESTDIR)/$(PREFIX)/share/applications/.
	install -c -m 0644 src/firetools/resources/firetools.png $(DESTDIR)/$(PREFIX)/share/pixmaps/.
	install -c -m 0644 src/firejail-ui/resources/firejail-ui.png $(DESTDIR)/$(PREFIX)/share/pixmaps/.
	install -c -m 0644 COPYING $(DESTDIR)/$(DOCDIR)/.
	install -c -m 0644 README $(DESTDIR)/$(DOCDIR)/.
	install -c -m 0644 RELNOTES $(DESTDIR)/$(DOCDIR)/.
	rm -f firetools.1.gz
	gzip -n9 firetools.1
	install -c -m 0644 firetools.1.gz $(DESTDIR)/$(PREFIX)/share/man/man1/.
	rm -f firejail-ui.1.gz
	gzip -n9 firejail-ui.1
	install -c -m 0644 firejail-ui.1.gz $(DESTDIR)/$(PREFIX)/share/man/man1/.

uninstall:;
	rm -f $(DESTDIR)/$(PREFIX)/bin/firetools
	rm -f $(DESTDIR)/$(PREFIX)/bin/firejail-ui
	rm -f $(DESTDIR)/$(PREFIX)/share/pixmaps/firetools.png
	rm -f $(DESTDIR)/$(PREFIX)/share/pixmaps/firejail-ui.png
	rm -f $(DESTDIR)/$(PREFIX)/share/applications/firetools.desktop
	rm -f $(DESTDIR)/$(PREFIX)/share/applications/firejail-ui.desktop
	rm -fr $(DESTDIR)/$(PREFIX)/share/doc/firetools
	rm -fr $(DESTDIR)/$(PREFIX)/share/man/man1/firetools.1*
	rm -fr $(DESTDIR)/$(PREFIX)/share/man/man1/firejail-ui.1*
	rm -fr $(DESTDIR)/$(PREFIX)/lib/firetools

dist:
	mv config.status config.status.old
	make distclean
	mv config.status.old config.status
	rm -fr $(NAME)-$(VERSION) $(NAME)-$(VERSION).tar.xz
	mkdir $(NAME)-$(VERSION)
	cd $(NAME)-$(VERSION); cp -a ../src .; cp -a ../platform .;
	cd $(NAME)-$(VERSION); cp -a ../configure .; cp -a ../configure.ac .; cp -a ../Makefile.in .; cp -a ../install.sh .; cp -a ../mkdeb.sh .;cp -a ../mkask.sh .; cp -a ../mkman.sh .;cd ..
	cd $(NAME)-$(VERSION); cp -a ../COPYING .; cp -a ../README .; cp -a ../RELNOTES .; cd ..
	cd $(NAME)-$(VERSION); rm -fr `find . -name .svn`; rm -fr $(NAME)-$(VERSION); cd ..
	tar -cJvf $(NAME)-$(VERSION).tar.xz $(NAME)-$(VERSION)
	rm -fr $(NAME)-$(VERSION)


deb: dist
	./mkdeb.sh $(NAME) $(VERSION)

cppcheck: clean
	cppcheck --force .

scan-build: clean
	scan-build make

asc:; ./mkasc.sh $(VERSION)
