NAME = handbook
VIEWER = xpdf

BASEOBJ = $(NAME).tex
OBJECTS = *.tex
BULLSHIT = *.aux *.log *.idx *.toc *.out
TARGET = $(NAME).pdf
PAGE =

.PHONY: all clean distclean help

all: $(TARGET) 

$(TARGET): $(OBJECTS)
	# run twice to generate tableofcontents
	pdflatex $(BASEOBJ)
	pdflatex $(BASEOBJ)
	echo $(OBJECTS)

clean:
	-rm $(BULLSHIT)

tclean:
	-rm $(TARGET)

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'

