Files
brevetcard/Makefile
T
Peter Adam ca995a1c1f Add duplex PDF build targets with pdftk page interleaving
- Add pdftk-java to Docker image for PDF page manipulation
- Extend generate_backside() to repeat back content num_pages times so
  front and back PDFs have matching page counts for pdftk shuffle
- Add build-duplex and build-blanko-duplex Makefile targets that combine
  front and back PDFs with alternating pages (front1, back1, front2, back2)
- Document duplex targets in README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:16:20 +02:00

143 lines
4.9 KiB
Makefile

# Makefile for building Brevet card PDF in Docker
IMAGE_NAME := brevetcard-builder
TEX_FILE_PERSONALIZED := brevetkarte-personalized.tex
TEX_FILE_BLANKO := brevetkarte-blanko.tex
TEX_FILE_BACK := brevetkarte-rueckseite.tex
PDF_FILE_PERSONALIZED := brevetkarte-personalized.pdf
PDF_FILE_BLANKO := brevetkarte-blanko.pdf
PDF_FILE_BACK := brevetkarte-rueckseite.pdf
PDF_FILE_DUPLEX := brevetkarte-duplex.pdf
PDF_FILE_BLANKO_DUPLEX := brevetkarte-blanko-duplex.pdf
CSV_FILE := export_brevetcard.csv
.PHONY: all build clean build-image build-back generate build-personalized build-blanko build-duplex build-blanko-duplex run shell help
# Default target
all: build-personalized build-blanko
# Build Docker image
build-image:
@echo "Building Docker image..."
docker build -t $(IMAGE_NAME) .
# Compile back side PDF (after generate)
build-back: build-image
@echo "Compiling back side LaTeX to PDF..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdflatex -interaction=nonstopmode $(TEX_FILE_BACK)
@echo "PDF generated: $(PDF_FILE_BACK)"
# Generate all tex files from CSV + event.yml
generate: build-image
@echo "Generating cards from $(CSV_FILE) + event.yml..."
@if [ ! -f "$(CSV_FILE)" ]; then \
echo "Error: $(CSV_FILE) not found!"; \
exit 1; \
fi
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
python3 generate_cards.py
# Build personalized front + event back side PDFs
build-personalized: generate build-image
@echo "Compiling personalized front side to PDF..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdflatex -interaction=nonstopmode $(TEX_FILE_PERSONALIZED)
@echo "PDF generated: $(PDF_FILE_PERSONALIZED)"
@echo "Compiling back side to PDF..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdflatex -interaction=nonstopmode $(TEX_FILE_BACK)
@echo "PDF generated: $(PDF_FILE_BACK)"
# Build blank (blanko) front + event back side PDFs (no CSV required)
build-blanko: build-image
@echo "Generating blank card..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
python3 generate_cards.py --blanko
@echo "Compiling blank front side to PDF..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdflatex -interaction=nonstopmode $(TEX_FILE_BLANKO)
@echo "PDF generated: $(PDF_FILE_BLANKO)"
@echo "Compiling back side to PDF..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdflatex -interaction=nonstopmode $(TEX_FILE_BACK)
@echo "PDF generated: $(PDF_FILE_BACK)"
# Build duplex PDF (personalized front + back interleaved for duplex printing)
build-duplex: build-personalized
@echo "Combining front and back for duplex printing..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdftk A=$(PDF_FILE_PERSONALIZED) B=$(PDF_FILE_BACK) shuffle A B output $(PDF_FILE_DUPLEX)
@echo "PDF generated: $(PDF_FILE_DUPLEX)"
# Build duplex PDF (blank front + back interleaved for duplex printing)
build-blanko-duplex: build-blanko
@echo "Combining blank front and back for duplex printing..."
docker run --rm \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
pdftk A=$(PDF_FILE_BLANKO) B=$(PDF_FILE_BACK) shuffle A B output $(PDF_FILE_BLANKO_DUPLEX)
@echo "PDF generated: $(PDF_FILE_BLANKO_DUPLEX)"
# Run container interactively
run:
docker run --rm -it \
-v $(PWD):/workspace \
$(IMAGE_NAME) \
/bin/bash
# Open shell in container for debugging
shell:
docker run --rm -it \
-v $(PWD):/workspace \
--entrypoint /bin/bash \
$(IMAGE_NAME)
# Clean generated files
clean:
@echo "Cleaning generated files..."
rm -f *.aux *.log *.out *.toc *.pdf brevetkarte-personalized.tex brevetkarte-blanko.tex brevetkarte-rueckseite.tex $(PDF_FILE_DUPLEX) $(PDF_FILE_BLANKO_DUPLEX)
# Clean everything including Docker image
clean-all: clean
@echo "Removing Docker image..."
docker rmi $(IMAGE_NAME) 2>/dev/null || true
# Rebuild from scratch
rebuild: clean-all build-personalized
# Show help
help:
@echo "Brevet Card PDF Builder"
@echo ""
@echo "Available targets:"
@echo " make - Generate and compile front + back side PDFs (default)"
@echo " make build-image - Build Docker image only"
@echo " make generate - Generate tex files from CSV + event.yml"
@echo " make build-personalized - Generate and compile front + back side PDFs"
@echo " make build-blanko - Generate and compile blank card (no CSV needed)"
@echo " make build-duplex - Build duplex PDF (front+back interleaved)"
@echo " make build-blanko-duplex - Build blank duplex PDF"
@echo " make build-back - Compile back side PDF only (after generate)"
@echo " make shell - Open interactive shell in container"
@echo " make clean - Remove generated files (aux, log, pdf)"
@echo " make clean-all - Remove all files and Docker image"
@echo " make rebuild - Clean everything and rebuild"
@echo " make help - Show this help message"