# hp7470 - Linux port of the KE5FX 7470 HP-GL viewer (no GPIB)
#
#   make            build with X11 viewer
#   make NO_X11=1   build converter only (no X11 needed)
#
# Needs: g++, libpng-dev, libx11-dev
# The original renderer.cpp and 8566plt.h are taken from the parent folder.

SRC_DIR  ?= ..
CXX      ?= g++
CXXFLAGS ?= -O2 -g
CXXFLAGS += -I. -I$(SRC_DIR) -fpermissive -w -fno-strict-aliasing

ifdef NO_X11
CXXFLAGS += -DNO_X11
LIBS      = $(shell pkg-config --libs libpng)
else
LIBS      = $(shell pkg-config --libs libpng x11)
endif

hp7470: hp7470.cpp vfx_shim.h $(SRC_DIR)/renderer.cpp $(SRC_DIR)/8566plt.h
	$(CXX) $(CXXFLAGS) -o $@ hp7470.cpp $(LIBS) -lm

PREFIX  ?= /usr/local
DESTDIR ?=

install: hp7470
	install -Dm755 hp7470            $(DESTDIR)$(PREFIX)/bin/hp7470
	install -Dm644 $(SRC_DIR)/7470.ini $(DESTDIR)$(PREFIX)/share/hp7470/7470.ini
	install -Dm644 LIESMICH.txt      $(DESTDIR)$(PREFIX)/share/doc/hp7470/LIESMICH.txt
	install -Dm644 hp7470.desktop    $(DESTDIR)$(PREFIX)/share/applications/hp7470.desktop
	install -Dm644 hp7470.png        $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps/hp7470.png
	@update-desktop-database -q $(DESTDIR)$(PREFIX)/share/applications 2>/dev/null || true
	@gtk-update-icon-cache -q $(DESTDIR)$(PREFIX)/share/icons/hicolor 2>/dev/null || true

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/hp7470
	rm -rf $(DESTDIR)$(PREFIX)/share/hp7470 $(DESTDIR)$(PREFIX)/share/doc/hp7470
	rm -f $(DESTDIR)$(PREFIX)/share/applications/hp7470.desktop
	rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps/hp7470.png

clean:
	rm -f hp7470

.PHONY: clean install uninstall
