VALAC = valac
PACKAGES = --pkg gtk+-3.0
TARGET = mu-math-effects
SRC = main.vala mathfunction.vala mathfunction1.vala mathfunction2.vala mathfunction3.vala
PREFIX ?= /usr/local
VERSION = 1.0.0

all: $(TARGET)

$(TARGET): $(SRC)
	$(VALAC) $(SRC) $(PACKAGES) -X -lm -o $(TARGET)

clean:
	rm -f $(TARGET) *.deb *.pet *.tar.gz
	rm -rf pkg_build pkg_build_pet

run: $(TARGET)
	./$(TARGET)

install: $(TARGET)
	install -d $(DESTDIR)$(PREFIX)/bin
	install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/mu-math-effects
	install -d $(DESTDIR)$(PREFIX)/share/applications
	install -m 644 mu-math-effects.desktop $(DESTDIR)$(PREFIX)/share/applications/

deb: all
	rm -rf pkg_build
	mkdir -p pkg_build/DEBIAN pkg_build$(PREFIX)/bin pkg_build$(PREFIX)/share/applications
	cp $(TARGET) pkg_build$(PREFIX)/bin/mu-math-effects
	cp mu-math-effects.desktop pkg_build$(PREFIX)/share/applications/
	echo "Package: mu-math-effects" > pkg_build/DEBIAN/control
	echo "Version: $(VERSION)" >> pkg_build/DEBIAN/control
	echo "Section: graphics" >> pkg_build/DEBIAN/control
	echo "Priority: optional" >> pkg_build/DEBIAN/control
	echo "Architecture: amd64" >> pkg_build/DEBIAN/control
	echo "Maintainer: Developer <dev@local>" >> pkg_build/DEBIAN/control
	echo "Depends: libc6, libglib2.0-0, libgtk-3-0, libcairo2" >> pkg_build/DEBIAN/control
	echo "Description: Modular high-performance port of Kurt Moerman's micro(A) mathematical animation" >> pkg_build/DEBIAN/control
	dpkg-deb --build pkg_build mu-math-effects_$(VERSION)_amd64.deb
	rm -rf pkg_build
	@echo ">>> Debian package (.deb) successfully created!"

pet: all
	rm -rf pkg_build_pet
	mkdir -p pkg_build_pet/usr/bin pkg_build_pet/usr/share/applications
	cp $(TARGET) pkg_build_pet/usr/bin/mu-math-effects
	cp mu-math-effects.desktop pkg_build_pet/usr/share/applications/
	cd pkg_build_pet && tar -czvf ../mu-math-effects-$(VERSION).pet usr/
	rm -rf pkg_build_pet
	@echo ">>> Puppy Linux package (.pet) successfully created!"

source:
	tar -czvf mu-math-effects-$(VERSION)-source.tar.gz main.vala mathfunction.vala mathfunction1.vala mathfunction2.vala Makefile mu-math-effects.desktop readme.txt
	@echo ">>> Source archive successfully created!"

.PHONY: all clean run install deb pet source