I have created a GNUMake building system for pandoc. It has grown quite a bit, I wonder if I can optimize it further. Would it be possible, for instance, that it only runs a target if the output hasn't changed since last run?.DEFAULT_GOAL := pdfINPUTDIR=$(CURDIR)/sourceOUTPUTDIR=$(CURDIR)/outputSTYLEDIR=$(CURDIR)/styleNAME = $(notdir $(shell basename $(CURDIR)))FILFILES = $(wildcard style/*.py)FILTER := $(foreach FILFILES, $(FILFILES), --filter $(FILFILES))TEXFLAGS = --filter pandoc-crossref --filter pandoc-citeproc $(FILTER) --latex-engine=xelatexifeq ($(shell test -e $(STYLEDIR)/template.tex && echo -n yes),yes)    TEXTEMPLATE = --template=$(STYLEDIR)/template.texendififeq ($(shell test -e $(STYLEDIR)/reference.docx && echo -n yes),yes)    DOCXTEMPLATE = --reference-docx=$(STYLEDIR)/reference.docxendifhelp:    @echo '                                                                       '    @echo 'Makefile for automated typography using pandoc.                         '    @echo 'Version 1.0                        '    @echo '                                                                       '    @echo 'Usage:                                                                 '    @echo '   make prepare    first time use, setting the directories     '    @echo '   make html       generate a web version             '    @echo '   make pdf        generate a PDF file             '    @echo '   make docx       generate a Docx file            '    @echo '   make tex        generate a Latex file               '    @echo '   make beamer     generate a beamer presentation              '    @echo '   make all        generate all files                 '    @echo '   make update     update the makefile to last version       '    @echo '   make            will fallback to PDF               '    @echo '                                                                       '    @echo 'It implies some directories in the filesystem: source, output and style'    @echo 'It also implies that the bibliography will be defined via the yaml     '    @echo '                                                                       '    @echo 'Depends on pandoc-citeproc and pandoc-crossref                         '    @echo 'Get local templates with: pandoc -D latex/html/etc                     '    @echo '                                                                       'all : tex docx html epub pdfpdf:    pandoc $(INPUTDIR)/*.md \    -o $(OUTPUTDIR)/$(NAME).pdf \    $(TEXTEMPLATE) \    $(TEXFLAGS) 2>pandoc.log    xdg-open $(OUTPUTDIR)/$(NAME).pdftex:    pandoc $(INPUTDIR)/*.md \    --filter pandoc-crossref \    --filter pandoc-citeproc \    -o $(OUTPUTDIR)/$(NAME).tex \    --latex-engine=xelatexdocx:    pandoc $(INPUTDIR)/*.md \    --filter pandoc-crossref \    --filter pandoc-citeproc \    $(DOCXTEMPLATE) \    --toc \    -o $(OUTPUTDIR)/$(NAME).docxhtml:    pandoc $(INPUTDIR)/*.md \    -o $(OUTPUTDIR)/$(NAME).html \    --include-in-header=$(STYLEDIR)/style.css \    -t html5 \    --toc \    --standalone \    --filter pandoc-crossref \    --filter pandoc-citeproc \    --number-sections    rm -rf $(OUTPUTDIR)/source    mkdir $(OUTPUTDIR)/source    cp -r $(INPUTDIR)/figures $(OUTPUTDIR)/source/figuresepub:    pandoc $(INPUTDIR)/*.md \    -o $(OUTPUTDIR)/$(NAME).epub \    --toc \    --standalone \    --filter pandoc-crossref \    --filter pandoc-citeproc    rm -rf $(OUTPUTDIR)/source    mkdir $(OUTPUTDIR)/source    cp -r $(INPUTDIR)/figures $(OUTPUTDIR)/source/figuresbeamer:    pandoc $(INPUTDIR)/*.md \    -t beamer \    -o $(OUTPUTDIR)/$(NAME).pdf \    $(TEXTEMPLATE) \    $(TEXFLAGS) 2>pandoc.log    xdg-open $(OUTPUTDIR)/$(NAME).pdfprepare:    mkdir output    mkdir source    mkdir styleupdate:    wget http://tiny.cc/mighty_make -O Makefileclean:    rm -f $(OUTPUTDIR)/ *.md *.html *.pdf *.tex *.docx.PHONY: help pdf docx html tex clean
Pandoc builder system
makefile;make
only runs a target if the output hasn't changed since last runConsider writing rules like this:%.pdf: %.md        pandoc -o $@ $<For that to work, the current all: ... pdf would need to mention particular *.pdf files, perhaps by globbing: $(patsubst %.md,%.pdf,*.md)