# Shell used for executing scripts
SHELL = /bin/sh

# Intall things to the following directories
PREFIX = /usr/local
MANDIR = $(PREFIX)/share/man/man1
BINDIR = $(PREFIX)/bin
SHAREDIR = $(PREFIX)/share/qemu-launcher
PIXMAPSDIR = $(PREFIX)/share/pixmaps
ICONSDIR = $(PREFIX)/share/icons/hicolor
DOCSDIR = $(PREFIX)/share/doc/qemu-launcher
LOCALEDIR = $(PREFIX)/share/locale
APPLICATIONSDIR = $(PREFIX)/share/applications

# Files to be installed
SOURCEFILE = qemu-launcher.pl
EXECUTABLE = qemu-launcher
MENUFILE = qemu-launcher.desktop
MANPAGE = qemu-launcher.1
DOCS = README FAQ TODO Changelog
POFILES =

.PHONY: clean targets

targets: executable

executable:
	cp -f $(SOURCEFILE) $(EXECUTABLE)
	perl -pi -e "s#INSTALLED_UNDER = undef#INSTALLED_UNDER = '$(PREFIX)'#" $(EXECUTABLE)
	touch $@

install: targets
	install -d $(DESTDIR)$(BINDIR)
	install -m755 $(EXECUTABLE) $(DESTDIR)$(BINDIR)

	install -d $(DESTDIR)$(SHAREDIR)/modules
	install -m644 modules/ql_*.pl $(DESTDIR)$(SHAREDIR)/modules

	install -d $(DESTDIR)$(SHAREDIR)/glade
	install -m644 glade/ql_*.glade $(DESTDIR)$(SHAREDIR)/glade

	install -d $(DESTDIR)$(SHAREDIR)/icons
	install -m644 icons/qemu-launcher.svg $(DESTDIR)$(SHAREDIR)/icons
	install -m644 icons/tux.svg $(DESTDIR)$(SHAREDIR)/icons
	install -m644 icons/redmond.svg $(DESTDIR)$(SHAREDIR)/icons

	install -d $(DESTDIR)$(DOCSDIR)
	install -m644 $(DOCS) $(DESTDIR)$(DOCSDIR)

	install -d $(DESTDIR)$(MANDIR)
	install -m644 $(MANPAGE) $(DESTDIR)$(MANDIR)
	gzip --best $(DESTDIR)$(MANDIR)/$(MANPAGE)

	install -d $(DESTDIR)$(APPLICATIONSDIR)
	install -m644 $(MENUFILE) $(DESTDIR)$(APPLICATIONSDIR)

	install -d $(DESTDIR)$(PIXMAPSDIR)
	install -m644 icons/qemu-launcher-16x16.xpm $(DESTDIR)$(PIXMAPSDIR)
	install -m644 icons/qemu-launcher-32x32.xpm $(DESTDIR)$(PIXMAPSDIR)

	install -d $(DESTDIR)$(ICONSDIR)/scalable/apps
	install -m644 icons/qemu-launcher.svg $(DESTDIR)$(ICONSDIR)/scalable/apps/qemu-launcher.svg

	install -d $(DESTDIR)$(ICONSDIR)/48x48/apps
	install -m644 icons/qemu-launcher-48x48.png $(DESTDIR)$(ICONSDIR)/48x48/apps/qemu-launcher.png

	for POFILE in $(POFILES) ;\
	do \
	  POBASE=`basename $$POFILE .po` ;\
	  install -d $(DESTDIR)$(LOCALEDIR)/$$POBASE/LC_MESSAGES ;\
	  msgfmt -c -o $(DESTDIR)$(LOCALEDIR)/$$POBASE/LC_MESSAGES/qemu-launcher.mo po/$$POFILE ;\
	done

uninstall:
	rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)
	rm -f $(DESTDIR)$(APPLICATIONSDIR)/$(MENUFILE)
	rm -f $(DESTDIR)$(MANDIR)/$(MANPAGE).gz
	rm -f $(DESTDIR)$(PIXMAPSDIR)/qemu-launcher-16x16.xpm
	rm -f $(DESTDIR)$(PIXMAPSDIR)/qemu-launcher-32x32.xpm
	rm -f $(DESTDIR)$(ICONSDIR)/scalable/apps/qemu-launcher.svg
	rm -f $(DESTDIR)$(ICONSDIR)/48x48/apps/qemu-launcher.png

	rm -rf $(DESTDIR)$(SHAREDIR)
	rm -rf $(DESTDIR)$(DOCSDIR)

	for POFILE in $(POFILES) ;\
	do \
	  POBASE=`basename $$POFILE .po` ;\
	  rm -f $(DESTDIR)$(LOCALEDIR)/$$POBASE/LC_MESSAGES/qemu-launcher.mo ;\
	done

clean:
	rm -f executable
	rm -f $(EXECUTABLE)
