#!/bin/sh cp Makefile.orig Makefile for tgt in */document.tex; do DIR=$(dirname $tgt) ( echo; echo -n "${DIR}/document.pdf: ${DIR}/document.tex "; find $DIR \!\ -type d \! -name "document.tex" -a -name "*.tex" -exec echo {} +; ) >> Makefile done