
all: all_booklets all_docduments

all_docduments: prepare pdf/assambly_report.pdf pdf/rtos_report.pdf
all_booklets: prepare pdf/assambly_report.booklet.pdf pdf/rtos_report.booklet.pdf
prepare:
	mkdir -p pdf

clean:
	rm -r build

clean_all:
	rm -r build pdf

install_arch:
	mkdir -p build/install
	pacman -Sy --noconfirm --needed curl unzip texlive-basic texlive-langeuropean pandoc

	test -e build/install/ubuntu.zip || curl https://assets.ubuntu.com/v1/0cef8205-ubuntu-font-family-0.83.zip -o build/install/ubuntu.zip
	test -d build/install/ubuntu && rm -r build/install/ubuntu || echo
	mkdir build/install/ubuntu
	unzip build/install/ubuntu.zip -d build/install/ubuntu
	mkdir -p /usr/share/fonts/ubuntu
	cp build/install/ubuntu/ubuntu-font-family-0.83/*.ttf /usr/share/fonts/ubuntu/
	chmod 0775 /usr/share/fonts/ubuntu
	chmod 0664 /usr/share/fonts/ubuntu/*

	test -e build/install/roboto.zip || curl https://dl.dafont.com/dl/?f=roboto -o build/install/roboto.zip
	test -d build/install/roboto && rm -r build/install/roboto || echo
	mkdir build/install/roboto
	unzip build/install/roboto.zip -d build/install/roboto
	mkdir -p /usr/share/fonts/roboto
	cp build/install/roboto/*.ttf /usr/share/fonts/roboto/
	chmod 0775 /usr/share/fonts/roboto
	chmod 0664 /usr/share/fonts/roboto/*

install_ubuntu:
	mkdir -p build/install
	apt-get update
	DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
		curl unzip texlive texlive-lang-european texlive-lang-greek texlive-xetex pandoc

	test -e build/install/ubuntu.zip || curl https://assets.ubuntu.com/v1/0cef8205-ubuntu-font-family-0.83.zip -o build/install/ubuntu.zip
	test -d build/install/ubuntu && rm -r build/install/ubuntu || echo
	mkdir build/install/ubuntu
	unzip build/install/ubuntu.zip -d build/install/ubuntu
	mkdir -p /usr/share/fonts/ubuntu
	cp build/install/ubuntu/ubuntu-font-family-0.83/*.ttf /usr/share/fonts/ubuntu/
	chmod 0775 /usr/share/fonts/ubuntu
	chmod 0664 /usr/share/fonts/ubuntu/*

	test -e build/install/roboto.zip || curl https://dl.dafont.com/dl/?f=roboto -o build/install/roboto.zip
	test -d build/install/roboto && rm -r build/install/roboto || echo
	mkdir build/install/roboto
	unzip build/install/roboto.zip -d build/install/roboto
	mkdir -p /usr/share/fonts/roboto
	cp build/install/roboto/*.ttf /usr/share/fonts/roboto/
	chmod 0775 /usr/share/fonts/roboto
	chmod 0664 /usr/share/fonts/roboto/*

# =======================================
# === pdf generation ====================
# =======================================

pdf/assambly_report.pdf: converters/* report-1/*.md
	mkdir -p build/assambly_report
	bash converters/mdToLatex.sh report-1/assambly_report.md

pdf/assambly_report.booklet.pdf: converters/bookletify.latex pdf/assambly_report.pdf
	mkdir -p build/assambly_report.booklet
	sed -e 's|?pdf?|../../pdf/assambly_report.pdf|' converters/bookletify.latex >build/assambly_report.booklet/bookletify.latex
	pdflatex -interaction=nonstopmode -output-directory="build/assambly_report.booklet" "build/assambly_report.booklet/bookletify.latex"
	mv build/assambly_report.booklet/bookletify.pdf pdf/assambly_report.booklet.pdf

pdf/rtos_report.pdf: converters/* report-2/*.md
	mkdir -p build/rtos_report
	bash converters/mdToLatex.sh report-2/rtos_report.md

pdf/rtos_report.booklet.pdf: converters/bookletify.latex pdf/rtos_report.pdf
	mkdir -p build/rtos_report.booklet
	sed -e 's|?pdf?|../../pdf/rtos_report.pdf|' converters/bookletify.latex >build/rtos_report.booklet/bookletify.latex
	pdflatex -interaction=nonstopmode -output-directory="build/rtos_report.booklet" "build/rtos_report.booklet/bookletify.latex"
	mv build/rtos_report.booklet/bookletify.pdf pdf/rtos_report.booklet.pdf

pdf/rust_report.pdf: converters/* report-3/*.md
	mkdir -p build/rust_report
	bash converters/mdToLatex.sh report-3/rust_report.md

pdf/rust_report.booklet.pdf: converters/bookletify.latex pdf/rust_report.pdf
	mkdir -p build/rust_report.booklet
	sed -e 's|?pdf?|../../pdf/rust_report.pdf|' converters/bookletify.latex >build/rust_report.booklet/bookletify.latex
	pdflatex -interaction=nonstopmode -output-directory="build/rust_report.booklet" "build/rust_report.booklet/bookletify.latex"
	mv build/rust_report.booklet/bookletify.pdf pdf/rust_report.booklet.pdf
