# Makefile para processar as entregas de exercĂ­cio de POV-Ray
# Last edited on 2003-12-10 20:50:45 by stolfi

# Large portrait
# 
# WIDTH := 480
# HEIGHT := 640
# 
# ICONWIDTH := 75
# ICONHEIGHT := 100

# Small landscape
# 
# WIDTH := 320
# HEIGHT := 240
# 
# ICONWIDTH := 80
# ICONHEIGHT := 60

# Large landscape

WIDTH := 640
HEIGHT := 480

ICONWIDTH := 80
ICONHEIGHT := 60

NRAYS = 2

OTHERINPUTS := 

# No need to change below here

NAME = main

POVPUB := /home/staff/stolfi/pkg/povray-3.50c-1/PUB
POVRAY := ${POVPUB}/i686-Linux-2.2/bin/povray
POVINC := ${POVPUB}/share/povray-3.5/include
POVTTF := /home/staff/stolfi/PUB/povray/tt-fonts
TOOLDIR := /home/staff/stolfi/public_html/courses/mc930-2003-2-A/progs/tools

# These are defined with "=" rather than ":=" in order to defer expansion
DIRTAIL = ${shell pwd | sed -e 's:^.*/::'}
IMVIEW = display -title "${DIRTAIL}/%f"

.PHONY: all cleanup  image showimage all-images index

all: image showimage

cleanup: 
	-/bin/rm -f ${NAME}.png 
	-/bin/rm -f ${NAME}-*-i.png ${NAME}-i.png
	-/bin/rm -f ${NAME}-*.log ${NAME}.log

image: ${NAME}.png 

showimage: ${NAME}.png
	-${IMVIEW} ${NAME}.png

${NAME}.png: ${NAME}.pov ${OTHERINPUTS}
	-/bin/rm -f ${NAME}.png
	nice ${POVRAY} \
            +FN +Q9 \
            +W${WIDTH} +H${HEIGHT} \
            +AM1 +A0.0 +R${NRAYS} \
            +D +SP32 +EP4 \
            +L${POVINC} \
            +L${POVTTF} \
	    +I${NAME}.pov \
	    +O${NAME}.png
        
all-images: rausrs.txt
	${TOOLDIR}/make-all-images \
          `cat rausrs.txt | egrep -v '^ *([#]|$$)' | gawk '//{print $$1;}' `

INDEXOPTS := -iconHeight ${ICONHEIGHT} 

index: title.txt rausrs.txt aus.txt \
          absent.png absent-i.png \
          missing.png missing-i.png
	dir=`pwd`; \
        if [ "$${dir##*/}" = "aula" ]; then \
          ${TOOLDIR}/make-labday-image-page ${INDEXOPTS} "`cat title.txt`" ; \
        else \
          ${TOOLDIR}/make-labday-image-page ${INDEXOPTS} -absentOK "`cat title.txt`" ; \
        fi

index-orig: title.txt rausrs.txt aus.txt \
          absent.png absent-i.png \
          missing.png missing-i.png
	${TOOLDIR}/make-labday-image-page ${INDEXOPTS} -absentOK -original "`cat title.txt`"

absent.png: Makefile
	ppmmake 'rgbi:0.75/0.75/0.75' ${WIDTH} ${HEIGHT} \
          | pnmdepth 255 \
          | ppmquant 254 \
          | convert PPM:- absent.png
	-${IMVIEW} absent.png
        
missing.png: Makefile
	ppmmake 'rgbi:0.80/0.15/0.15' ${WIDTH} ${HEIGHT} \
          | pnmdepth 255 \
          | ppmquant 254 \
          | convert PPM:- missing.png
	-${IMVIEW} missing.png

%-i.png: %.png
	convert $*.png \
            -geometry "x${ICONHEIGHT}" \
            +profile '*' \
            -colors 254 -dither \
          $*-i.png