# Makefile for latex-packages

BUILD_DIR=build
DOC_SUBDIR=doc
PACKAGES_SUBDIR=packages
COMPILE_SUBDIR=.compile
BUILD_FLAGS=--recursive --git-version --pytex-version --license --author "Maximilian Keßler" --pytex-info-text --extra-header ".build/header_info.txt" --name "prepend-author" --clean-old-files

ROOT=$(shell pwd)
BUILD_ROOT=${ROOT}/${BUILD_DIR}


# Build packages
build: .initsubmodulelock
	python3 build.py --source-dir src --build-dir ${BUILD_ROOT}/${PACKAGES_SUBDIR} ${BUILD_FLAGS}

# Build packages and allow repo to be dirty (use with caution and only when developing)
dirty: .initsubmodulelock
	python3 build.py --source-dir src --build-dir ${BUILD_ROOT}/${PACKAGES_SUBDIR} ${BUILD_FLAGS} --allow-dirty

# generate documentation files from /doc
doc:
	@scripts/compile_doc.sh
	@mkdir -p ${BUILD_ROOT}/${DOC_SUBDIR}
	@cp .compile/*.pdf ${BUILD_ROOT}/${DOC_SUBDIR}
	@echo Documentation files written to ${BUILD_ROOT}/${DOC_SUBDIR}
	
init: .initsubmodulelock .gitconfiglock

config: .gitconfiglock

.initsubmodulelock:
	@git submodule update --init
	@touch .initsubmodulelock

.gitconfiglock:
	@echo "[Make config] Setting git configs to prevent wrong pushes"
	@git config push.recurseSubmodules check
	@git config status.submodulesummary 1
	@echo "[Push annotated tags by default]"
	@git config push.followTags true
	@touch .gitconfiglock

all: clean build

clean:
	@-rm -r build/
	@-rm -r .compile/

.PHONY: build doc
#!/bin/bash
# Compiles all correspondence letters in repository