# Makefile to create flyers with LaTeX
# $Id: Makefile,v 1.2 2006/03/12 14:41:11 hubertf Exp $

REQUIRED_PACKAGES=\
	teTeX \
	ghostscript-gnu \
	netpbm

FILES= \
	netbsd-a1-poster-de \
	netbsd-a1-poster-en \
	netbsd-a5-flyer-de  \
	netbsd-a5-flyer-de-sicherheit \
	netbsd-a5-flyer-en \
	netbsd-a5-flyer-en-security \
	netbsd-a4-flyer-de+en-xen \

all: \
	check-packages \
	a0poster.cls \
	jornada.jpg \
	${FILES:=.pdf} \
	${FILES:=.jpg} \

check-packages:
	@for pkg in ${REQUIRED_PACKAGES} ; do \
		echo -n Required package $$pkg ... \  ; \
		if pkg_info -qe $$pkg ; then \
			echo installed ; \
		else \
			echo MISSING. ; \
			exit 1 ; \
		fi ; \
	done

a0poster.cls: 
	ftp ftp://ftp.dante.de/pub/tex/macros/latex/contrib/a0poster/a0poster.cls
	ftp ftp://ftp.dante.de/pub/tex/macros/latex/contrib/a0poster/a0size.sty
	ftp ftp://ftp.dante.de/pub/tex/macros/latex/contrib/rcsinfo/rcsinfo.sty

jornada.jpg: ../../in-Action/hpeyerl-jornada.jpg
	cat ../../in-Action/hpeyerl-jornada.jpg \
	| jpegtopnm | pamcut -bottom 950 | pnmtojpeg >jornada.jpg

.SUFFIXES:	.tex .pdf .jpg

clean: 
	rm -f *.log *.out *.toc *.aux *.lol *.ind *.ilg *.idx;	
	rm -f a0header.ps

cleandir distclean: clean
	rm -f *.pdf
	rm -f a0poster.cls a0size.sty rcsinfo.sty
	rm -f jornada.jpg
	rm -f netbsd-a[145]*jpg

.tex.pdf: 
	echo /usr/pkg/bin/pdflatex $< $@ \
	&& /usr/pkg/bin/pdflatex $< $@ \
	&& make clean ;

.pdf.jpg:
	gs -dNOPAUSE -dBATCH -sDEVICE=pnm -sOutputFile=$*.pnm $*.pdf
	case $* in \
	*poster*) scale=0.05 ;; \
	*)	  scale=0.25 ;; \
	esac ; \
	cat $*.pnm | pnmscale $$scale | pnmtojpeg	>$*.jpg
	rm $*.pnm
