NAME = handbook-dev
VIEWER = xpdf

BASEOBJ = $(NAME).tex
OBJECTS = *.tex
BULLSHIT = *.aux *.log *.idx *.toc *.out
TARGETS = $(NAME).pdf allinone splitup

PAGE =
HTMLOPTS = -no_navigation -noinfo -noaddress -local_icons -image_type png -noimages -noparbox_images

.PHONY: all clean distclean help allinone splitup

all: $(TARGETS) 

allinone: $(OBJECTS)
	mkdir -p $@
	latex2html $(HTMLOPTS) -split 0 -dir $@ $(BASEOBJ)

splitup: $(OBJECTS)
	mkdir -p $@
	latex2html $(HTMLOPTS) -split +3 -dir $@ $(BASEOBJ)

$(NAME).pdf: $(OBJECTS)
	# run twice to generate tableofcontents
	pdflatex $(BASEOBJ)
	pdflatex $(BASEOBJ)

clean:
	rm -rf $(BULLSHIT)

tclean:
	rm -rf $(TARGETS)

distclean: clean tclean

show: all
		$(VIEWER) $(TARGET) $(PAGE)

help:
	@echo 'Makefile for $(BASEOBJ)'
	@echo 'Targets:'
	@echo 'all       - make $(TARGET) (default)'
	@echo 'show		 - call $(VIEWER) to view $(TARGET)' 
	@echo '				(runs make first if needed)'
	@echo '				override VIEWER if xpdf is not ok'
	@echo '				override PAGE for argv[2] of VIEWER'
	@echo 'clean     - remove crap ($(BULLSHIT))'
	@echo 'tclean    - remove pdf-file ($(TARGET))'
	@echo 'distclean - clean for commit (run clean and tclean'

