-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
52 lines (41 loc) · 2.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Used docu:
# - http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
# - http://stackoverflow.com/questions/4971865/patsubst-on-makefile
# - http://blog.softwaresafety.net/2010/09/transforming-files-with-wildcards-in.html
# - http://stackoverflow.com/questions/1435861/computing-makefile-variable-on-assignment
#
TMP := $(shell mktemp -d /tmp/MAS_LibreOffice_to_PDF.XXXXXX)
#ODP_FILES := $(wildcard *.odp) # will include symlinks, which we don't want
ODP_FILES := $(shell find . -maxdepth 2 -name "*.odp" -type f)
RST_FILES := $(shell find . -maxdepth 2 -name "*.rst" -type f)
MD_FILES := $(shell find . -maxdepth 1 -name "*.md" -type f ! -name README.md)
C_FILES := $(shell find . -maxdepth 1 -name "*.c" -type f)
PY_FILES := $(shell find . -maxdepth 1 -name "*.py" -type f)
SYM_FILES := $(shell find . -maxdepth 1 \( -name "*.rst" -o -name "*.odp" \) -type l)
OPDF_FILES := $(patsubst %.odp,PDF/%.pdf, $(ODP_FILES))
RPDF_FILES := $(patsubst %.rst,PDF/%.pdf, $(RST_FILES))
MPDF_FILES := $(patsubst %.md,PDF/%.pdf, $(MD_FILES))
CPDF_FILES := $(patsubst %.c,PDF/%.c, $(C_FILES))
PPDF_FILES := $(patsubst %.py,PDF/%.py, $(PY_FILES))
SPDF_FILES := $(patsubst %.rst,PDF/%.pdf, $(patsubst %.odp, PDF/%.pdf, $(SYM_FILES)))
PDF/%.pdf: %.odp
libreoffice -env:UserInstallation=file://$(TMP) --headless --invisible --convert-to pdf --outdir PDF "$<"
# libreoffice will put the generated file directly into outdir, lets move it where it belongs
# this only needs to be done for files in optional/ -> PDF/optional
output_file=`echo $@|sed 's#./optional/##'`; \
[ "$$output_file" != "$@" ] && mv $$output_file $@; \
true
PDF/%.pdf: %.md latex.template
pandoc --pdf-engine=xelatex --template=latex.template --standalone --self-contained --listings "$<" -o "$@"
PDF/%.pdf: %.rst
rst2pdf --header "T.Pospíšek, MAS: Betriebssysteme, ###Title###" --footer "###Page###/###Total###" "$<" -o "$@"
PDF/%.c: %.c
cd PDF && ln -s "../$<" "$<"
PDF/%.py: %.py
cd PDF && ln -s "../$<" "$<"
# echo $(for i in $(SYM_FILES); do $(basename $i)
.PHONY: all symlinks
all: $(OPDF_FILES) $(RPDF_FILES) $(MPDF_FILES) $(CPDF_FILES) $(PPDF_FILES) extra_symlinks
extra_symlinks:
cd PDF && [ -h 02-1_Shell.pdf ] || ln -s 01-1_Shell.pdf 02-1_Shell.pdf
cd PDF && [ -h 03-2_Architekturansätze.pdf ] || ln -s 02-2_Architekturansätze.pdf 03-2_Architekturansätze.pdf