# Makefile del programma usbinstall
# Linguaggi: python, bash


PACKAGE := usbinstall

include VERSION

distdir := $(PACKAGE)-$(VERSION)
dist_archive := $(distdir).tar.bz2

# Directory
bindir 		:= /usr/bin
sbindir 	:= /usr/sbin
sysconfdir	:= /etc
datadir 	:= /usr/share
mambadir 	:= ${datadir}/openmamba
polkitdir 	:= ${datadir}/polkit-1/actions
dbussystemdir 	:= ${sysconfdir}/dbus-1/system.d
localesdir 	:= ${datadir}/locale
libexecdir 	:= /usr/libexec

DESTDIR 	:=
INSTALL 	:= /usr/bin/install 
INSTALL_PROGRAM := ${INSTALL} -m 755
INSTALL_DATA 	:= ${INSTALL} -m 644
INSTALL_DIR 	:= ${INSTALL} -d -m 755
INSTALL_SCRIPT 	:= ${INSTALL_PROGRAM}


pck_catalogs := $(wildcard po/*.po)

.SUFFIXES: .po .mo
.po.mo:; msgfmt $< -o $@

all: locales

locales: $(pck_catalogs:.po=.mo)

install-locales: locales
	@for f in $(pck_catalogs); do\
	   lang=`echo $$f | sed 's,.*/\(.*\)\.po,\1,'`;\
	   echo "installing i18n file for language \`$$lang'...";\
	   dir="$(DESTDIR)$(localesdir)/$$lang/LC_MESSAGES";\
	   $(INSTALL_DIR) $$dir;\
	   $(INSTALL_DATA) $${f/.po/.mo} $$dir/usbinstall.mo;\
	done

install-dirs:
	@$(INSTALL_DIR) $(DESTDIR)$(sbindir)
	@$(INSTALL_DIR) $(DESTDIR)$(mambadir)/usbinstall
	@$(INSTALL_DIR) $(DESTDIR)$(datadir)/applications
	@$(INSTALL_DIR) $(DESTDIR)$(mambadir)/usbinstall/img
	@$(INSTALL_DIR) $(DESTDIR)$(polkitdir)
	@$(INSTALL_DIR) $(DESTDIR)$(dbussystemdir)
	@$(INSTALL_DIR) $(DESTDIR)$(libexecdir)

install: install-dirs install-locales
	$(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py
	$(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(sbindir)/usbinstall
	$(INSTALL_SCRIPT) src/rootfsinstall.sh $(DESTDIR)$(sbindir)/rootfsinstall
	$(INSTALL_SCRIPT) src/mmcinstall.sh $(DESTDIR)$(sbindir)/mmcinstall
	$(INSTALL_SCRIPT) src/init_resize.sh $(DESTDIR)$(libexecdir)/init_resize
	$(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/
	$(INSTALL_DATA) src/org.openmamba.usbinstall.policy $(DESTDIR)$(polkitdir)/org.openmamba.usbinstall.policy
	$(INSTALL_DATA) src/org.openmamba.usbinstall.conf $(DESTDIR)$(dbussystemdir)/org.openmamba.usbinstall.conf
	$(INSTALL_DATA) src/usbinstall.desktop $(DESTDIR)$(datadir)/applications/usbinstall.desktop

clean: 
	rm -f $(pck_catalogs:.po=.mo)
	rm -f $(dist_archive)

dist: clean
	@mkdir /tmp/$(distdir)
	@cp -a * /tmp/$(distdir)/
	@rm -f $(dist_archive);\
	tar cf - -C /tmp $(distdir) | bzip2 -9 -c > $(dist_archive)
	@rm -rf /tmp/$(distdir)
	@echo "file \`$(dist_archive)' created"

dist-rpm: dist
	@rpm_sourcedir=`rpm --eval=%{_sourcedir}`;\
	mv -f $(PACKAGE)-$(VERSION).tar.bz2 $$rpm_sourcedir;\
	echo "File $$rpm_sourcedir/$(PACKAGE)-$(VERSION).tar.bz2 created."
