.SUFFIXES:
CC = valac
TARGET = mu-wetter
VERSION = 1.0
# KORREKTUR: Hier sind nun beide aufgeteilten Dateien hinterlegt
SRC = mu-wetter-gui.vala mu-wetter-logic.vala wetter-api.vala wetter-config.vala wetter-main.vala

VALAFLAGS = -C --pkg gtk+-3.0 --pkg libsoup-2.4 --pkg json-glib-1.0
INCLUDES = -I/usr/include -isystem /usr/include/gtk-3.0 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/pango-1.0 -isystem /usr/include/harfbuzz -isystem /usr/include/cairo -isystem /usr/include/gdk-pixbuf-2.0 -isystem /usr/include/atk-1.0 -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libsoup-2.4 -isystem /usr/include/json-glib-1.0
LIBS = -lgtk-3 -lgdk-3 -lgobject-2.0 -lglib-2.0 -lgdk_pixbuf-2.0 -lgio-2.0 -lpango-1.0 -lcairo -lharfbuzz -latk-1.0 -ljson-glib-1.0 -lsoup-2.4

all: $(TARGET)

$(TARGET): $(SRC)
	$(CC) $(VALAFLAGS) $(SRC)
	gcc mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c -o $(TARGET) $(INCLUDES) $(LIBS)
	rm -f mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c

desktop:
	@echo "[Desktop Entry]" > $(TARGET).desktop
	@echo "Name=MU-Wetter" >> $(TARGET).desktop
	@echo "Comment=International Weather Station for Puppy Linux" >> $(TARGET).desktop
	@echo "Exec=$(TARGET)" >> $(TARGET).desktop
	@echo "Icon=weather-severe-alert" >> $(TARGET).desktop
	@echo "Terminal=false" >> $(TARGET).desktop
	@echo "Type=Application" >> $(TARGET).desktop
	@echo "Categories=Utility;" >> $(TARGET).desktop

install: $(TARGET) desktop
	@echo "Installiere MU-Wetter im System..."
	mkdir -p /etc/mu-wetter
	cp languages.rc /etc/mu-wetter/
	cp $(TARGET) /usr/bin/
	cp $(TARGET).desktop /usr/share/applications/
	@echo "Installation erfolgreich!"

uninstall:
	@echo "Entferne MU-Wetter aus dem System..."
	rm -rf /etc/mu-wetter
	rm -f /usr/bin/$(TARGET)
	rm -f /usr/share/applications/$(TARGET).desktop
	@echo "Deinstallation erfolgreich!"

dist: desktop
	mkdir -p $(TARGET)-$(VERSION)
	cp $(SRC) languages.rc Makefile $(TARGET).desktop $(TARGET)-$(VERSION)/
	tar -czf $(TARGET)-$(VERSION).tar.gz $(TARGET)-$(VERSION)
	rm -rf $(TARGET)-$(VERSION)

deb: deb64

deb64: $(TARGET) desktop
	@echo "Baue DEB Paket (64-Bit)..."
	mkdir -p deby64/usr/bin deby64/usr/share/applications deby64/etc/mu-wetter deby64/DEBIAN
	cp $(TARGET) deby64/usr/bin/
	cp $(TARGET).desktop deby64/usr/share/applications/
	cp languages.rc deby64/etc/mu-wetter/
	@echo "Package: $(TARGET)" > deby64/DEBIAN/control
	@echo "Version: $(VERSION)" >> deby64/DEBIAN/control
	@echo "Architecture: amd64" >> deby64/DEBIAN/control
	@echo "Maintainer: root@puppy" >> deby64/DEBIAN/control
	@echo "Description: Weather monitor with metrics and international languages" >> deby64/DEBIAN/control
	dpkg-deb --build deby64 $(TARGET)_$(VERSION)_amd64.deb
	rm -rf deby64

deb32: desktop
	@echo "Baue DEB Paket (32-Bit)..."
	mkdir -p deby32/usr/bin deby32/usr/share/applications deby32/etc/mu-wetter deby32/DEBIAN
	$(CC) $(VALAFLAGS) $(SRC)
	gcc -m32 mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c -o deby32/usr/bin/$(TARGET) $(INCLUDES) $(LIBS)
	cp languages.rc deby32/etc/mu-wetter/
	cp $(TARGET).desktop deby32/usr/share/applications/
	@echo "Package: $(TARGET)" > deby32/DEBIAN/control
	@echo "Version: $(VERSION)" >> deby32/DEBIAN/control
	@echo "Architecture: i386" >> deby32/DEBIAN/control
	@echo "Maintainer: root@puppy" >> deby64/DEBIAN/control
	@echo "Description: Weather monitor with metrics and international languages" >> deby32/DEBIAN/control
	dpkg-deb --build deby32 $(TARGET)_$(VERSION)_i386.deb
	rm -f mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c
	rm -rf deby32

pet: pet32 pet64

pet64: $(TARGET) desktop
	@echo "Baue PET Paket 64-Bit..."
	mkdir -p pet_64/usr/bin pet_64/usr/share/applications pet_64/etc/mu-wetter
	cp $(TARGET) pet_64/usr/bin/
	cp $(TARGET).desktop pet_64/usr/share/applications/
	cp languages.rc pet_64/etc/mu-wetter/
	dir2pet pet_64
	rm -rf pet_64

pet32: desktop
	@echo "Baue PET Paket 32-Bit..."
	mkdir -p pet_32/usr/bin pet_32/usr/share/applications pet_32/etc/mu-wetter
	$(CC) $(VALAFLAGS) $(SRC)
	gcc -m32 mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c -o pet_32/usr/bin/$(TARGET) $(INCLUDES) $(LIBS)
	cp $(TARGET).desktop pet_32/usr/share/applications/
	cp languages.rc pet_32/etc/mu-wetter/
	rm -f mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c
	dir2pet pet_32
	rm -rf pet_32

clean:
	rm -f $(TARGET) *.desktop *.tar.gz *.deb *.pet
	rm -f mu-wetter-gui.c mu-wetter-logic.c wetter-api.c wetter-config.c wetter-main.c

.PHONY: all clean dist deb deb32 deb64 pet pet32 pet64 desktop install uninstall
