#
# This is primary Makefile for manpages-ru project
#
# $Id: Makefile,v 1.8 2000/04/30 21:35:36 alexm Exp $
#

#
# This is where to install manpages
#
INSTALLPATH = /usr/local/share/man

#
# This is language subdirectory in $INSTALLPATH
# See $LANG description in man(1)
#
LANG_SUBDIR = ${LANG}

#
# How to compress manpages.
# Known compressors are `none', `gzip', `compress', `bzip2'
#
COMPRESS = gzip

#
# Compress manpage only if its size is greater than $COMPRESS_SIZE
#
COMPRESS_SIZE = 4096

#
#
#
INSTALL = /bin/install -m 644


VERSION = 0.3

all:

install:
	[ -d $(INSTALLPATH) ] || mkdir $(INSTALLPATH)
	[ -d $(INSTALLPATH)/$(LANG_SUBDIR) ] || mkdir $(INSTALLPATH)/$(LANG_SUBDIR)
	if [ x$(COMPRESS) != xgzip -a \
	     x$(COMPRESS) != xbzip2 -a \
	     x$(COMPRESS) != xnone -a \
	     x$(COMPRESS) != xcompress ]; then \
	  echo Error: Invalid compressor $(COMPRESS) ; \
	  exit 1; \
	fi
	for section in 1 2 3 4 5 6 7 8; do \
	  [ -d $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section ] || \
		mkdir $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section; \
	  cd man$$section; \
	  if [ x"`echo *.$$section`" != x\*.$$section ]; then \
	    for manpage in *.$$section; do \
	      rm -f $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section/$$manpage; \
	      for ext in gz Z bz2; do \
	        rm -f $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section/$$manpage.$$ext; \
	      done; \
	      $(INSTALL) $$manpage $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section; \
	      FILESIZE=`ls -l $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section/$$manpage | \
	                tr -s ' ' | cut -d ' ' -f 5`; \
	      if [ $$FILESIZE -gt $(COMPRESS_SIZE) ]; then \
	        if [ x$(COMPRESS) != xnone ]; then \
	          $(COMPRESS) $(INSTALLPATH)/$(LANG_SUBDIR)/man$$section/$$manpage; \
	        fi;\
	      fi; \
	    done; \
	  fi; \
	  cd ..; \
	done

html:
	./mkindex.html.sh > index.html

dist:
	TARFILE=man-pages-ru-$(VERSION).tar; \
	rm -f $$TARFILE $$TARFILE.gz $$TARFILE.bz2; \
	DISTDIR=man-pages-ru-$(VERSION); \
	rm -f $$DISTDIR; \
	ln -s . $$DISTDIR; \
	tar -c -f $$TARFILE $$DISTDIR/Makefile \
		$$DISTDIR/README \
		$$DISTDIR/INSTALL \
		$$DISTDIR/INSTALL.ru \
		$$DISTDIR/NEWS; \
	for section in 1 2 3 4 5 6 7 8; do \
	  if [ x"`echo man$$section/*.$$section`" != x\man$$section/\*.$$section ]; then \
	    tar -r -f $$TARFILE $$DISTDIR/man$$section/*.$$section; \
	  fi; \
	done; \
	gzip $$TARFILE; \
	rm -f $$DISTDIR

publish:
	-mkdir ../public_html/manpages-ru
	cyrrecode -k -w < index.html > ../public_html/manpages-ru/index.html
	cp man-pages-ru-$(VERSION).tar.gz ../public_html/manpages-ru
	for section in 1 2 3 4 5 6 7 8; do \
	  [ -d ../public_html/manpages-ru/man$$section ] || mkdir ../public_html/manpages-ru/man$$section; \
	  if [ x"`echo man$$section/*.$$section`" != x\man$$section/\*.$$section ]; then \
	    for manpage in man$$section/*.$$section; do \
	      cyrrecode -k -w < $$manpage.html > ../public_html/manpages-ru/$$manpage.html; \
	    done; \
	  fi; \
	done
