DOC_NAME=CE
CFG_FILE=../../scripts/node-info.def
CVSROOT=:pserver:anonymous:@lcgdeploy.cvs.cern.ch:/cvs/lcgdeploy
LATEX2HTML = latex2html -split 0 -html_version 4.0 -no_navigation -address          '<A HREF="http://cern.ch/grid-deployment">GRID deployment</A>'


all: doc

doc: pdf html ps txt

template:
	if ! [ -f templateexported ];then \
             export CVSROOT=$(CVSROOT); \
             cvs co lcg-docs/template; \
	     touch templateexported ; \
             mkdir -p build; \
             cp lcg-docs/template/*.* build ;\
             \rm -R lcg-docs;\
        fi

yaim:
	if ! [ -f yaimexported ];then \
             export CVSROOT=$(CVSROOT); \
             cd ../../../ ; \
             cvs co lcg-scripts/yaim; \
             cd -; \
	     touch yaimexported ; \
        fi


cvs: yaim template

prepare: cvs
	cd build; ./create-additional-files.sh $(DOC_NAME); cd ..

tex: prepare
	cd scripts; ./createTexDocs.sh $(CFG_FILE) $(DOC_NAME); cd -

pdf: tex
	cd build; pdfelatex -interaction=nonstopmode $(DOC_NAME).drv; cd ..
	cd build; bibtex $(DOC_NAME); cd ..
	if [ -f $(DOC_NAME).idx ]; then cd build; makeindex $(DOC_NAME); cd ..; fi
	cd build; pdfelatex -interaction=nonstopmode $(DOC_NAME).drv; cd ..
	cd build; pdfelatex -interaction=nonstopmode $(DOC_NAME).drv; cd ..

html: tex
	if [ -f $(DOC_NAME).idx ]; then cd build; makeindex $(DOC_NAME); cd ..;fi
	cd build; $(LATEX2HTML) $(DOC_NAME).drv_html; cd ..
ps: tex
	cd build; latex -interaction=nonstopmode $(DOC_NAME).drv; cd ..
	cd build; makeindex $(DOC_NAME); cd
	cd build; bibtex $(DOC_NAME); cd ..
	cd build; latex -interaction=nonstopmode $(DOC_NAME).drv; cd ..
	cd build; latex -interaction=nonstopmode $(DOC_NAME).drv; cd ..
	cd build; dvips  -o $(DOC_NAME).ps $(DOC_NAME).dvi; cd ..

txt: pdf
	cd build; pdftotext $(DOC_NAME).pdf $(DOC_NAME).dos.txt; cd ..
	cd build; cat $(DOC_NAME).dos.txt | tr -d "\f" > $(DOC_NAME).txt; cd ..

publish: all
	mkdir -p build/$(DOC_NAME)_$(VERSION)/pdf
	mkdir -p build/$(DOC_NAME)_$(VERSION)/html/$(DOC_NAME)_$(VERSION)
	echo $(TITLE) >  build/$(DOC_NAME)_$(VERSION)/meta-data
	cp build/$(DOC_NAME).pdf build/$(DOC_NAME)_$(VERSION)/pdf/$(DOC_NAME)_$(VERSION).pdf
	cp -r build/$(DOC_NAME)/*  build/$(DOC_NAME)_$(VERSION)/html/$(DOC_NAME)_$(VERSION)
	scp -r build/$(DOC_NAME)_$(VERSION) lxplus.cern.ch:/afs/cern.ch/project/gd/www/documentation/$(DISS)/$(SECTION)/
	@echo "Your document is available at http://grid-deployment.web.cern.ch/grid-deployment/documentation/$(DISS)/$(SECTION)/$(DOC_NAME)_$(VERSION)/html/$(DOC_NAME)_$(VERSION)/index.html"

clean : 
	rm -rf build
	rm -f templateexported
	rm -f yaimexported

