INSTALL_PREFIX?=/usr/local

camlet.debug: meson.build *.[ch] *.cpp *.glsl debug/setup
	meson compile -C debug
	ln -sf debug/camlet camlet.debug
	cp debug/compile_commands.json .
debug/setup:
	rm -rf debug
	meson setup debug
	touch debug/setup
release/camlet: meson.build *.[ch] *.cpp *.glsl release/setup2
	meson compile -C release
release/setup2:
	rm -rf release
	meson setup --buildtype=release release
	touch release/setup2
camlet.deb: release/camlet control.sh
	rm -rf tmp
	mkdir -p tmp/camlet/usr/bin tmp/camlet/DEBIAN tmp/camlet/usr/share/applications tmp/camlet/usr/share/icons/hicolor/48x48/apps
	cp release/camlet tmp/camlet/usr/bin/
	cp camlet.desktop tmp/camlet/usr/share/applications/
	cp camlet.png tmp/camlet/usr/share/icons/hicolor/48x48/apps
	sh control.sh > tmp/camlet/DEBIAN/control
	dpkg-deb --root-owner-group --build tmp/camlet
	mv tmp/camlet.deb .
	rm -rf tmp
install: release/camlet
	@[ -w $(INSTALL_PREFIX) ] || { echo "You need permission to write to $(INSTALL_PREFIX). Try running with sudo/as root." && exit 1; }
	mkdir -p $(INSTALL_PREFIX)/bin $(INSTALL_PREFIX)/share/applications $(INSTALL_PREFIX)/share/icons/hicolor/48x48/apps
	install -m 755 release/camlet $(INSTALL_PREFIX)/bin
	install -m 644 camlet.desktop $(INSTALL_PREFIX)/share/applications
	install -m 644 camlet.png $(INSTALL_PREFIX)/share/icons/hicolor/48x48/apps
uninstall:
	@[ -w $(INSTALL_PREFIX) ] || { echo "You need permission to write to $(INSTALL_PREFIX). Try running with sudo/as root." && exit 1; }
	rm -f $(INSTALL_PREFIX)/bin/camlet $(INSTALL_PREFIX)/share/applications/camlet.desktop $(INSTALL_PREFIX)/share/icons/hicolor/48x48/apps/camlet.png

doc: main_docs python_docs

main_docs:
	$(MAKE) -C doc

python_docs:
	$(MAKE) -C python doc

website:
	cd website && ./build.sh

publish:
	./publish.py

.PHONY: doc website publish
