
# version of the package
VERSION=1.1.27
# name of the tarball
TARBALL = bins-$(VERSION).tar
# files to put in the tarball
DIST =  bins bins_edit bins_cleanupgallery bins-edit-gui bins-edit-gui.glade \
	bins_txt2xml install.sh binsrc anti_bins \
	LICENSE README README.gui RELEASE.gui TODO ChangeLog CREDITS \
	doc/*.html doc/*.sgml doc/album.xml \
	doc/bins.1 doc/bins_edit.1 doc/bins-edit-gui.1 \
	doc/bins_man.html doc/bins_edit_man.html doc/bins-edit-gui_man.html \
	templates*/*.html templates*/*.txt templates*/static/*.* \
	bash_completion \
        intl/*.po \
	intl/generate_mo.sh \
	intl/fr.mo intl/pl.mo intl/de.mo intl/it.mo intl/ru.mo intl/es.mo \
	intl/zh_TW.mo intl/nl.mo intl/ja.mo intl/eo.mo intl/fi.mo intl/hu.mo \
	intl/gui-fr.mo

# name of the dir in the tarball
DIR-DIST = bins-$(VERSION)

# files to publish on the web
PUBLISH = $(TARBALL).gz $(TARBALL).bz2 ChangeLog $(wildcard doc/*.html)

#PUBLISH = $(TARBALL).gz $(TARBALL).bz2 ChangeLog doc/index_fr.html doc/index.html

# where to publish files
PUBLISH-DEST = $(HOME)/public_html/perso/BINS

PUBLISH-TMP = $(PUBLISH:doc/%=%)
PUBLISH-TARGET = $(PUBLISH-TMP:%=$(PUBLISH-DEST)/%)

.PHONY: all install tar publish filepublish wwwpublish upload test album demo famille clean

all:
	@echo "see README file to install bins"
	@echo "publish upload clean"

install: .install

.install: $(TARBALL).gz
	rm -Rf /tmp/bins*
	tar -C /tmp -xzvf $(TARBALL).gz
	sudo mount -o rw,remount /usr
	yes|sudo sh /tmp/$(DIR-DIST)/install.sh
	sudo mount -o ro,remount /usr || true
	touch .install

tar: $(TARBALL).gz

#sudo cp /tmp/$(DIR-DIST)/intl/fr.mo /usr/local/share/locale/fr/LC_MESSAGES/bins.mo

publish: filepublish wwwpublish

filepublish: $(PUBLISH-TARGET)

wwwpublish:
	cd www/xml && make publish

upload: publish
	@if [ `hostname` != "ketama" ]; then\
		cp -afuv ~/public_html/perso/BINS/* ~/kashmir/public_html/perso/BINS ;\
		ssh kashmir 'PATH=$$PATH:~/bin update_www free' ;\
		ssh kashmir 'PATH=$$PATH:~/bin update_www libertysurf' ;\
	else\
		update_www tiscali ;\
	fi
#		update_www free ;\

test: install
	time bins -p ~/share/pics/test ~/public_html/test

album: install
	time nice -14 bins -p ~/share/pics/album ~/public_html/album

demo:
	time cp -afuv ~/public_html/album/.??* ~/public_html/album/* ~/kashmir/public_html/album
#	time rsync -avu ~/public_html/album/ ~/kashmir/public_html/album

dormans: .install
	time nice -14 bins -p ~/share/pics/Dormans ~/kashmir/public_html/photos/Dormans

famille: .install
	time nice -14 bins -p ~/share/pics/famille ~/kashmir/public_html/photos/famille

clean: 
	rm -f *~ *.old *.tar */*~ .install

#cp Makefile $(DIR-DIST)
#cp bins $(DIR-DIST)/bins.src
$(TARBALL): $(DIST) Makefile
	mkdir $(DIR-DIST)
	cp --parents $^ $(DIR-DIST)
	cp www/xml/*.html www/xml/*.xml $(DIR-DIST)/doc
	$(HOME)/bin/change 1.1.27 $(VERSION) $(DIR-DIST)/*
	tar \
	    --exclude=*~ \
	    --exclude=*.old \
	    --exclude=*.bak \
	    --exclude=\#* \
	    -cvf  $(TARBALL) bins-$(VERSION)
	rm -Rf $(DIR-DIST)


$(PUBLISH-DEST)/%.html : doc/%.html
	cp $< $@

$(PUBLISH-DEST)/%: %
	cp $< $@

%_man.html: %.sgml
	docbook2html -o /tmp/$(notdir $@) $<
	mv /tmp/$(notdir $@)/index.html $@
	rmdir /tmp/$(notdir $@)

%.1: %.sgml
	docbook-to-man $< >$@

%.mo: %.po bins
	./intl/generate_mo.sh $<
#	msgfmt -o $@ $<

%.gz: %
	gzip -c --best $< >$@

%.bz2: %
	bzip2 -c $< >$@

