TARGET=asher-pogodalla

DEP= asher-pogodalla-macros.tex introduction.tex intro-salt-20.tex philippe-s-proposal.tex veltman.tex modal-subordination.tex belief.tex belief-salt-20.tex

FIGURES = $(wildcard *.fig)

BIBDIR=.

BIBFILELIST=$(addsuffix .bib,$(shell grep "\\\\bibliography{" $(TARGET).tex | sed -e 's/.*bibliography{\(.*\)}.*/\1/' | sed -e 's/,/ /'))

BIB=$(foreach file,$(BIBFILELIST),$(shell find $(BIBDIR) -name $(file))) $(foreach file,$(BIBFILELIST),$(shell find . -name $(file)))

MAG = 0.5

DIR=$(notdir $(PWD))

PDFLATEX=pdflatex
PSLATEX=latex

LATEX=$(PDFLATEX)

ifeq ($(strip $(LATEX)),$(PDFLATEX))
EXT=pdf
else
EXT=ps
endif

.PHONY : first all clean

.PRECIOUS : $(FIGURES:%.fig=%.pdf %.pdftex_t %.pstex %.pstex_t) %.bbl %.bbg


first: $(TARGET).$(EXT)

%.pdf : %.tex $(DEP) $(FIGURES:%.fig=%.pdftex_t) $(TARGET).bbl
	$(PDFLATEX) $<

%.ps : %.tex $(DEP) $(FIGURES:%.fig=%.pstex_t)  $(TARGET).bbl
	$(PSLATEX) $<
	dvips -o $@ $(<:%.tex=%.dvi)

%.bbl : $(BIB)
	if ! [ -f $(TARGET).aux ] ; then $(LATEX) $(TARGET).tex ; fi
	bibtex $(TARGET)

all : $(TARGET).$(EXT) $(TARGET).bbl
	$(LATEX) $(TARGET).tex
	$(LATEX) $(TARGET).tex


%.pdftex_t : %.fig
	fig2dev -L pdftex -p dummyarg  -m $(MAG) $< $(@:%.pdftex_t=%.pdf)
	fig2dev -L pdftex_t -p $(@:%.pdftex_t=%.pdf) -m $(MAG) $< $@

%.pstex_t : %.fig
	fig2dev -L pstex -m $(MAG) $< $(@F:%.pstex_t=%.pstex)
	fig2dev -L pstex_t -p $(@F:%.pstex_t=%.pstex) -m $(MAG) $< $@

clean :
	-rm -f *.log *.aux *.pdf *.bbl *.blg *~ *.tar.gz *.pdftex_t *.pstex *.pstex_t *.dvi *.zip *.ps *.out *.bak *.nav *.snm *.toc

tar :
	tar cvfz $(DIR).tar.gz -C .. --exclude ".svn" --exclude "*.aux" --exclude "*.log" --exclude "*.blg" --exclude "*.ps" --exclude "*.dvi" --exclude "*.bbl" --exclude "*~" --exclude "*.tar.gz" --exclude "*.bak" --exclude "#*" --exclude ".#*" --exclude "*.snm" --exclude "*.toc" --exclude "*.nav" --exclude "*.out"  $(DIR)


status:
	svn status -u


update:
	svn up


commit:
	@printf "Enter a message: " && read -e msg &&  svn ci -m "$$msg"

