LANG=it
prefix=/usr
mandir=$(prefix)/man/$(LANG)
xmandir=$(prefix)/X11R6/man/$(LANG)


# Sezioni da installare:  importante che ci sia un file in ciascuna
# sezione!

# Sections to be installed: it's important that there is some file in
# each section!

SECTIONS=[1-8]
XSECTIONS=[1]


# Se non vuoi comprimere le pagine, scommenta quanto segue. Se vuoi
# usare bzip2 o compress, dovrebbe esserti ovvio cosa fare.

# If you don't want compressed manpages, uncomment the following. If
# you'd rather use bzip2 or compress, it should be pretty obvious what
# to do.

#ZIP=
#UNZIP=
#ZIP_SUFFIX=

ZIP=gzip
UNZIP=gunzip
ZIP_SUFFIX=.gz

######################## Da qui in gi non dovresti toccare niente!
######################## You shouldn't touch anything from here on!



all:
	@echo "Fare \"make install\" per installare, o leggete \"INSTALL\""
	@echo "Please issue \"make install\", or look at \"INSTALL.eng\" first"
	@exit 1

install.dir:
	for i in man[0-9]; do \
		install -d -m 755 $(mandir)/$$i $(xmandir)/$$i; \
	done

install: $(ZIP) install.dir install.pages install.xpages

install.pages:
	for i in man$(SECTIONS); do \
		echo "Installing $$i"; \
		install -m 644 $$i/*[1-8]$(ZIP_SUFFIX)  $(mandir)/$$i; \
	done

install.xpages:
	for i in man$(XSECTIONS); do \
		echo "Installing $$i"; \
		install -m 644 $$i/*[1-8]x$(ZIP_SUFFIX) $(xmandir)/$$i; \
	done

$(ZIP):
	$(ZIP) man?/*[1-8]{x,}

$(UNZIP): 
	$(UNZIP) man?/*$(ZIP_SUFFIX)


######################## Queste regole, invece le uso io per la mia
######################## manutenzione del pacchetto.

distrib tar: clean
	n=`basename \`/bin/pwd\``; \
	cd ..; \
	tar cvf -  --exclude=CVS --exclude-from=$$n/.cvsignore $$n \
		| gzip > $$n.tar.gz


LIST = ../wholemanlist
FILES = $(wildcard man?/*)
PAGES = $(FILES:.gz=)

rpm: tar
	cp man-pages-it.xpm ..
	n=`basename \`/bin/pwd\``; rpm -ta ../$$n.tar.gz

clean:
	rm -f current* whole* missing* *~ .*~ */*~ core
	rm -rf packages html-temp
	chmod -R +rw .; chmod -R g-w .

current: man? $(LIST)
	rm $@; touch $@
	for n in $(PAGES); do \
		grep -i /$$n $(LIST) >> $@ || echo "*** unknown $$n"; \
	done

whole:
	cp $(LIST) $@

%.sorted: %
	sort $^ | uniq | sed 's/: .*[0-9]\//: /' > $@

%.oneline: %.sorted
	awk '$$1!=S {printf "\n%s",$$1; S=$$1} {printf " %s",$$2}' $^ > $@

checkpkg: current.oneline whole.oneline
	for n in `cut -f 1 current.oneline`; do \
		grep $$n $^ | sed 's/^.*://' ; echo ""; \
	done


whois: current.oneline
	pages=`grep $(PKG): $^ | sed 's/^.*://'`; \
	for n in $$pages; do grep -i tradu */$$n; done; \
	echo ""; echo "used $$pages"


packages:
	mkdir packages
	for n in tags/*; do \
	   name=`basename $$n`; \
	   itname=$$name; \
	   tmp=packages/$$itname; \
	   echo "Processing $$n"; \
	   set +x; \
	   pages=`awk '/ENDTAGS/ {exit;} \
	      /Pagine:/ {for (N=2; N<=NF; N++) \
	      printf("man?/%s\n",$$N);}' $$n`; \
	   if [ -z "$$pages" ]; then continue; fi; \
	   echo "  Including `echo $$pages | wc -w` pages"; \
	   mkdir $$tmp; cp README* INSTALL* Makefile tags/$$name* $$tmp; \
	   tar cf - $$pages | (cd $$tmp && tar xf -); \
	   (cd $$tmp; for n in `ls man?/*.[1-8]? 2> /dev/null`; do \
		mv $$n `echo $$n | sed 's/.$$//'`; done); \
	   (cd packages; tar czf $$itname.tar.gz $$itname); \
	   rm -rf $$tmp; \
	   set +x; \
	done

html: clean
	mkdir html-temp
	allow_null_glob_expansion=t; \
	for n in {1,2,3,4,5,6,7,8}; do \
	    mkdir html-temp/man$$n; \
	    for page in man$$n/*.$${n}{,x}; do\
		echo Processing $$page; \
		rman -f html -r  '%s.%s.html' < $$page |\
		sed -f html/set-up.sed \
		    > html-temp/$$page.html; \
	    done; \
	    INDEX=html-temp/man$$n/index.html; \
	    cat html/head.html > $$INDEX; \
	    echo "<H3><I>Sezione $$n</I></H3>" >> $$INDEX;\
	    cat html/mid.html >> $$INDEX; \
	    for page in html-temp/man$$n/*.$${n}{,x}.html; do\
		name=`basename $$page .html`; \
		echo "<A HREF=$$name.html>$$name</A>" >> $$INDEX; \
	    done; \
	    cat html/tail.html >> $$INDEX; \
	done
	n=`basename \`/bin/pwd\``; \
	cd html-temp; \
	tar cvf -  . \
		| gzip > ../../$$n-html.tar.gz
