Skip to content

Instantly share code, notes, and snippets.

@rkrug
Created August 9, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkrug/6aab472682210381a1947411aef20dba to your computer and use it in GitHub Desktop.
Save rkrug/6aab472682210381a1947411aef20dba to your computer and use it in GitHub Desktop.
Makefile to build html, pdf and docx
## Based on https://github.com/kjhealy/rmd-starter/blob/master/Makefile
## All Rmarkdown files in the working directory
SRC = $(wildcard *.Rmd)
FILES = $(wildcard *_files)
PDFS = $(SRC:.Rmd=.pdf)
HTML = $(SRC:.Rmd=.html)
TEX = $(SRC:.Rmd=.tex)
DOCX = $(SRC:.Rmd=.docx)
SPDIR ='./../../../../../SharePoint/Global - Chapter 4 documents/Figures/Graphs.TOD/'
TODDIR='./../../../../../SharePoint/Global - Chapter 4 documents/TOD/'
pdf: $(PDFS)
html: $(HTML)
docx: $(DOCX)
%.html: %.Rmd
@Rscript -e "rmarkdown::render('$<', output_format = 'html_document')"
%.pdf: %.html
wkhtmltopdf --header-center "pdf autogenerated from [webpage]" '$<' '$@'
%.docx: %.Rmd
@Rscript -e "rmarkdown::render('$<', output_format = 'word_document')"
%.all: %.Rmd
@Rscript -e "rmarkdown::render('$<', output_format = 'all')"
clean: cleanpdf cleanhtml cleandocx cleancsv
rm -f *.md *.tex
rm -rf *_files
cleanfresh: clean cleancache cleansharepoint
cleanpdf:
rm -f $(PDFS)
cleanhtml:
rm -f $(HTML)
cleandocx:
rm -f $(DOCX)
cleancsv:
rm -f *.csv
cleancache:
rm -rf *_cache
cleansharepoint:
rm -rf $(SPDIR)
mkdir $(SPDIR)
mkdir $(SPDIR)/csv
rm -f $(TODDIR)/$(HTML)
rm -f $(TODDIR)/$(PDFS)
rm -f $(TODDIR)/$(DOCX)
sharepoint:
cp -rvf $(FILES) $(SPDIR)
cp -vf $(HTML) $(SPDIR)
cp -vf $(PDFS) $(SPDIR)
cp -vf $(DOCX) $(SPDIR)
cp -vf *.csv $(SPDIR)/csv
cp -vf $(HTML) $(TODDIR)
cp -vf $(PDFS) $(TODDIR)
cp -vf $(DOCX) $(TODDIR)
all: cleanfresh html pdf docx sharepoint
## mkdir -p $(SPDIR)/html
## cp -vf $(HTML) $(SPDIR)
## mkdir -p $(SPDIR)/docx
## cp -vf $(DOCX) $(SPDIR)
## from https://stackoverflow.com/a/26339924/632423
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
.PHONY: clean cleanfresh cleanpdf cleanhtml cleandocx cleancsv cleancache sharepoint list all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment