# derived from:
# install
# Greg Hankins, 30 September 1995

prefix=/usr/local
LINUXDOCBIN=$(prefix)/bin
LINUXDOCLIB=$(prefix)/lib/linuxdoc-sgml
LINUXDOCDOC=$(prefix)/doc/linuxdoc-sgml
LINUXDOCMAN=$(prefix)/man/man1
PERL=$(prefix)/bin/perl
OPTIMIZE=-O

all:
	if [ ! -d tmp ]; then mkdir tmp; fi
	for i in bin/sgml* ; do \
		sed -e "s!linuxdocbin!$(LINUXDOCBIN)!1" \
			-e "s!linuxdoclib!$(LINUXDOCLIB)!1" \
			< $$i > tmp/`basename $$i` ; \
	done
	sed -e "s|perl|\#\!$(PERL)|1" < bin/genertoc > tmp/genertoc
	echo "Compiling the SGML parsing tools (in sgmls-1.1/)..."
	( cd sgmls-1.1 ; \
	  make config.h OPTIMIZE="$(OPTIMIZE)" && \
	  make OPTIMIZE="$(OPTIMIZE)" )
	echo "Compiling HTML conversion tools (in html-fix/)..."
	( cd html-fix ; \
	  make CFLAGS="$(OPTIMIZE)" || exit -1 )
	echo "Compiling RTF conversion tools (in rtf-fix/)..."
	( cd rtf-fix ; \
	  make CFLAGS="$(OPTIMIZE)" || exit -1 )

install::
	echo "Installing binaries in $(LINUXDOCBIN) ..."
	if [ ! -d $(LINUXDOCBIN) ]; then mkdir -p $(LINUXDOCBIN); fi
	chmod 755 $(LINUXDOCBIN)
	cp sgmls-1.1/sgmls sgmls-1.1/sgmlsasp $(LINUXDOCBIN)
	cp html-fix/fixref html-fix/html2html rtf-fix/rtf2rtf $(LINUXDOCBIN)
	cp tmp/* $(LINUXDOCBIN)
	echo "Installing library and support files in $(LINUXDOCLIB)..."
	if [ ! -d $(LINUXDOCLIB) ]; then mkdir -p $(LINUXDOCLIB); fi
	chmod 755 $(LINUXDOCLIB)
	cp -r lib/* $(LINUXDOCLIB)
	echo "Installing documentation in $(LINUXDOCDOC) ..."
	if [ ! -d $(LINUXDOCDOC) ]; then mkdir -p $(LINUXDOCDOC); fi
	chmod 755 $(LINUXDOCDOC)
	cp -r doc/* $(LINUXDOCDOC) 
	echo "Installing man pages in $(LINUXDOCMAN) ..." 
	if [ ! -d $(LINUXDOCMAN) ]; then mkdir -p $(LINUXDOCMAN) ; fi
	chmod 755 $(LINUXDOCMAN)
	cp -r man/* $(LINUXDOCMAN)
# fix permissions
	find $(LINUXDOCDOC) -type d -exec chmod 755 {} \;
	find $(LINUXDOCDOC) -type f -exec chmod 644 {} \;
	find $(LINUXDOCLIB) -type d -exec chmod 755 {} \;
	find $(LINUXDOCLIB) -type f -exec chmod 644 {} \;
	chmod 644 $(LINUXDOCMAN)/{sgml2html.1,sgml2latex.1,sgml2rtf.1,sgmls.1,sgml2info.1,sgml2lyx.1,sgml2txt.1,sgmlsasp.1}
# don't use wildcards, there could be other things in $LINUXDOCBIN!
#
# chmod bin files after lib and doc files, because they could be in the same 
# directory, and that would make them 644
#
	chmod 755 $(LINUXDOCBIN)/sgmls $(LINUXDOCBIN)/sgmlsasp
	chmod 755 $(LINUXDOCBIN)/{fixref,html2html,rtf2rtf}
	chmod 755 $(LINUXDOCBIN)/{sgml2html,sgml2info,sgml2latex,sgml2txt,sgml2rtf,sgml2lyx,sgmlcheck,genertoc}

clean:
	-rm -f tmp/* *~ bin/*~
	(cd sgmls-1.1 && make clean )
	( cd html-fix ; make clean)
	( cd rtf-fix ; make clean)
