
PROGRAM = galaxy
VERSION = 1.8
SOURCE = $(PROGRAM)-$(VERSION).cpp
CFLAGS = -O -Wall -c `pkg-config --cflags gtk+-2.0`
LFLAGS = -O -Wall -rdynamic `pkg-config --libs gtk+-2.0 gthread-2.0`
LAUNCHER = $(HOME)/Desktop/kornelix-$(PROGRAM).desktop
LOWNER = `stat --format="%u:%g" $(HOME)/Desktop`

# use $PREFIX if defined, else assume /usr/local

ifeq "$(PREFIX)" ""
	PREFIX = /usr/local
endif

BINDIR = $(PREFIX)/bin
DATADIR = $(PREFIX)/share/$(PROGRAM)
DOCDIR = $(PREFIX)/share/doc/$(PROGRAM)


$(PROGRAM): $(PROGRAM).o zfuncs.o
	@g++ $(LFLAGS) -o $(PROGRAM) $(PROGRAM).o zfuncs.o

$(PROGRAM).o: $(SOURCE) zfuncs.h
	@g++ $(CFLAGS) -o $(PROGRAM).o $(SOURCE)		\
	-D "DATADIR=\"$(DATADIR)\"" -D "DOCDIR=\"$(DOCDIR)\""

zfuncs.o: zfuncs.cpp zfuncs.h
	@g++ $(CFLAGS) zfuncs.cpp	\
	-D "DATADIR=\"$(DATADIR)\"" -D "DOCDIR=\"$(DOCDIR)\"" -D "BINDIR=\"$(BINDIR)\""


install: $(PROGRAM)
	mkdir -p $(DESTDIR)$(DATADIR) 
	mkdir -p $(DESTDIR)$(DOCDIR) 
	mkdir -p $(DESTDIR)$(BINDIR)
	cp  -R doc/*  $(DESTDIR)$(DOCDIR)
	cp  -R data/*  $(DESTDIR)$(DATADIR)
	cp   $(PROGRAM)  $(DESTDIR)$(BINDIR)


uninstall:
	rm -f $(DESTDIR)$(BINDIR)/$(PROGRAM)
	rm -R -f $(DESTDIR)$(DOCDIR)
	rm -R -f $(DESTDIR)$(DATADIR)


launcher:
	@rm -f $(LAUNCHER)
	@echo "[Desktop Entry]" > $(LAUNCHER)
	@echo "Name=$(PROGRAM)" >> $(LAUNCHER)
	@echo "Categories=Game" >> $(LAUNCHER)
	@echo "Type=Application" >> $(LAUNCHER)
	@echo "Terminal=false" >> $(LAUNCHER)
	@echo "Exec=$(BINDIR)/$(PROGRAM)" >> $(LAUNCHER)
	@echo "Icon=$(DATADIR)/icons/$(PROGRAM).png" >> $(LAUNCHER)
	@echo "GenericName=Stellar Simulation" >> $(LAUNCHER)
	@chown $(LOWNER) $(LAUNCHER)
	@xdg-desktop-menu install $(LAUNCHER)


