PYTHON ?= python3
LATEXMK ?= latexmk
override MPLCONFIGDIR := .mplconfig
export SOURCE_DATE_EPOCH := 1786334400
export FORCE_SOURCE_DATE := 1
export TZ := UTC
export LANG := C
export LC_ALL := C
export PYTHONHASHSEED := 0
export PYTHONNOUSERSITE := 1
export PYTHONDONTWRITEBYTECODE := 1
export PYTHONPATH :=
export MPLBACKEND := Agg

.NOTPARALLEL:
.PHONY: all rebuild theory analysis assets articles supplements letter verify archives clean

all: theory analysis assets articles supplements letter verify

rebuild:
	$(MAKE) clean
	@if [ -f replication/build_reviewer_archives.py ]; then \
		$(MAKE) archives; \
	else \
		$(MAKE) all; \
	fi

theory:
	$(PYTHON) replication/check_theory.py

analysis:
	$(PYTHON) replication/run_analysis.py

assets: analysis
	MPLCONFIGDIR=$(MPLCONFIGDIR) $(PYTHON) replication/render_assets.py

articles: assets
	cd manuscript && $(LATEXMK) -norc -pdf -interaction=nonstopmode -halt-on-error anonymous.tex
	@if [ -f manuscript/identified.tex ]; then \
		cd manuscript && $(LATEXMK) -norc -pdf -interaction=nonstopmode -halt-on-error identified.tex; \
	fi

supplements:
	cd supplement && $(LATEXMK) -norc -pdf -interaction=nonstopmode -halt-on-error anonymous_supplement.tex
	@if [ -f supplement/identified_supplement.tex ]; then \
		cd supplement && $(LATEXMK) -norc -pdf -interaction=nonstopmode -halt-on-error identified_supplement.tex; \
	fi

letter:
	@if [ -f cover_letter/cover_letter.tex ]; then \
		cd cover_letter && $(LATEXMK) -norc -pdf -interaction=nonstopmode -halt-on-error cover_letter.tex; \
	fi

verify: theory articles supplements letter
	$(PYTHON) replication/verify_submission.py

archives: verify
	$(PYTHON) replication/build_reviewer_archives.py

clean:
	$(PYTHON) replication/clean_generated.py
