# alltripos-Makefile revision 9, 2011-01-17 by Stephen Kell # Released into the public domain. # # This Makefile will download past Tripos questions from the # University of Cambridge Computer Laboratory web site, # and compile them into a single PDF file. It requires pdfjoin and # pdfnup, from the pdfjam package. # # To use it, I suggest you copy it to, or symlink it from, or include it # in another makefile within a directory whose name # resembles the name of the course, as it appears in URLs on the Lab # web site. If the directory name is of the form "anything-COURSENAME" # then it should work for course COURSENAME out of the box. If you want # to override the coursename, or provide several coursenames, you can # set the COURSENAMES variable when invoking it. For example, # # COURSENAMES="ConcurrentSystems ConcurrentSystemsandApplications" make # # will collect Tripos questions from both the old Concurrent Systems course # and the newer Concurrent Systems And Applications course. # # The "download" target downloads the papers, and the # "all-tripos.pdf" target compiles them into a single PDF. The # default is to do the latter, and also produce a 2up version. # # The downloaded questions will appear in a 'tripos' subdirectory. # If you don't want all the papers to appear in the compiled version, # you can move them the ones you don't want into a tripos/weeded directory. # # I mean to add some support for cropping out the left and right margins # in the 2up version, but haven't done it yet. COURSENAMES ?= $(shell basename $(shell pwd) | sed 's/.*-//') GREP_EXPR='y[0-9]+p[0-9]+q[0-9]+.' default: all-tripos-2x1.pdf all-tripos.pdf tripos: download .PHONY: download download: for COURSENAME in $(COURSENAMES); do \ (mkdir -p tripos && cd tripos && \ wget -r -np -nd -l1 -A pdf \ http://www.cl.cam.ac.uk/teaching/exams/pastpapers/t-$${COURSENAME}.html ) ; \ done for EXTRA_QNAME in $(EXTRA_QNAMES); do \ wget http://www.cl.cam.ac.uk/teaching/exams/pastpapers/$${EXTRA_QNAME}.pdf; \ done if [ -d tripos/weeded ]; then \ find tripos/weeded -name '*.pdf' | sed 's@^tripos/weeded/@tripos/@' | xargs rm -f ; fi # weed any unamended questions superseded by amended version find tripos -name '*A.pdf' | while read line; do \ echo "$$line" | sed 's/A\.pdf$$/\.pdf/' | xargs rm -f; done %-2x1.pdf: %.pdf pdfnup --nup 2x1 --outfile $@ $< #%-crop.pdf: %.pdf # /usr/bin/pdfcrop --margins 50 $< # TODO: fix above # NOTE: the sort command in this pipeline is very fragile! # It depends on the number of characters in the PDF pathnames all-tripos.pdf: tripos $(filter-out $(patsubst tripos/weeded/%,tripos/%,$(shell find tripos/weeded -name '*.pdf')),$(shell find tripos -regex 'tripos/y[0-9]+p[0-9]+q[0-9]+.pdf' )) find tripos -regex 'tripos/y[0-9]+p[0-9]+q[0-9]+.pdf' | sort -n -t' ' -k1.9n -k1.14n | xargs pdfjoin --outfile $@