# pygtk-fsacls make file
# bbou@ac-toulouse.fr
# 2005-11-27 11:35:46   
VERSION=2.0.1

prefix = 

dos2unix := $(shell whereis -b dos2unix | awk '{print $$2}')
ifeq ($(dos2unix),)
dos2unix = perl -pi -e 's/\r\n/\n/g'
endif

BASE = $(prefix)/$(DESTDIR)/usr/local
BIN = $(BASE)/bin
LIB = $(BASE)/lib

SHORTCUT = $(BIN)
FOLDER = $(LIB)/pygtk-fsacls-$(VERSION)
VARFOLDER = $(prefix)/$(DESTDIR)/var/lib/pygtk-fsacls

default:

showconfig:
	@echo "-------------------"
	@echo "version: $(VERSION)"
	@echo "prefix: $(prefix)"
	@echo "bin: $(BIN)"
	@echo "repository: $(FOLDER)"
	@echo "dos2unix: $(dos2unix)"
	@echo "-------------------"
	
cleanfiles: 
	rm -Rf $(FOLDER)
	rm -Rf $(VARFOLDER)
	
copyfiles: 
	if [ ! -d $(FOLDER) ];then mkdir -p $(FOLDER); fi
	cp -R bin/* $(FOLDER)
	
installshortcuts:
	ln -s ../lib/pygtk-fsacls-$(VERSION)/acls.py $(SHORTCUT)/fsacls

uninstallshortcuts:
	if [ -L $(SHORTCUT)/fsacls ];then rm $(SHORTCUT)/fsacls; fi
	
install: uninstall chkfileattr preinstall copyfiles installshortcuts

uninstall: uninstallshortcuts cleanfiles
	
preinstall:
	if [ ! -d $(BASE) ];then mkdir -p $(BASE); fi
	if [ ! -d $(BIN) ];then mkdir -p $(BIN); fi
	if [ ! -d $(LIB) ];then mkdir -p $(LIB); fi

clean:
	
cleansources:
	find . -name "*~" -exec rm {} \;
	find . -name "*bak" -exec rm {} \;
	find . -name "*.gladep" -exec rm {} \;
	
chkfileformat:
	find . -name "*.sh" -exec $(dos2unix) {} \;
	find . -name "*.py" -exec $(dos2unix) {} \;
	
chkfileown:
	chown -R root.root ./*

chkfileattr:
	chmod -R u=rw,g=rw,o=r ./*
	find . -type d -exec chmod ugo+x {} \;
	find . -name "*.sh" -exec chmod ugo+x {} \;
	find . -name "*.py" -exec chmod ugo+x {} \;

stamp:
	echo "$(VERSION)" > bin/version
	echo "(build `date '+%Y%m%d-%H%M'`)" >> bin/version

predist: stamp chkfileformat chkfileown chkfileattr cleansources
	echo "ready to distribute"
		
dist: predist
	cd ..; if [ ! -L pygtk-fsacls-$(VERSION) ];then ln -s sadms-$(VERSION) pygtk-fsacls-$(VERSION); fi
	tar cvzf pygtk-fsacls-$(VERSION).tar.gz -C .. \
		pygtk-fsacls-$(VERSION)/bin/acls.py \
		pygtk-fsacls-$(VERSION)/bin/remote.py \
		pygtk-fsacls-$(VERSION)/bin/runner.py \
		pygtk-fsacls-$(VERSION)/bin/acls.glade \
		pygtk-fsacls-$(VERSION)/bin/remote.glade \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-index.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-toc.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-home.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-changelog.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-acls.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-remote.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-tut-remote.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-tut-acls.html \
		pygtk-fsacls-$(VERSION)/htmldocs/acls-tut-remote.html \
		pygtk-fsacls-$(VERSION)/htmldocs/sadms.css \
		pygtk-fsacls-$(VERSION)/htmldocs/images/pygtk-fsacls.gif \
		pygtk-fsacls-$(VERSION)/htmldocs/images/eye.gif \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-directory-default.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-directory.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-file.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-fs.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-fs0.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-fs2.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/acls-text.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-agent.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-agent0.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-clone-data.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-key.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-key0.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-passwords.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-remote.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-remote0.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-remotekey.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-remotekey0.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-run.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/remote-data.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/select-users.png \
		pygtk-fsacls-$(VERSION)/htmldocs/images/key-password.png \
		pygtk-fsacls-$(VERSION)/Makefile-fsacls \
		pygtk-fsacls-$(VERSION)/AUTHORS \
		pygtk-fsacls-$(VERSION)/COPYING \
		pygtk-fsacls-$(VERSION)/README \
		pygtk-fsacls-$(VERSION)/CHANGELOG \
		pygtk-fsacls-$(VERSION)/NEWS
	
.PHONY: default showconfig \
	cleanfiles copyfiles uninstallshortcuts installshortcuts uninstall preinstall install
	cleansources chkfileformat chkfileown chkfileattr stamp predist predist \
	dist
