From e13c62c3fab85cadeb53f307e90858d85c1019ee Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Tue, 9 Jan 2024 16:41:47 -0500 Subject: [PATCH] Use a variable for source file extension in Makefiles Reduce duplication when maintaining each AoC year's Makefile. --- 2021/Makefile | 7 ++++--- 2022/Makefile | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/2021/Makefile b/2021/Makefile index def2d8e..da34a7c 100644 --- a/2021/Makefile +++ b/2021/Makefile @@ -11,12 +11,13 @@ black := $(PYTHON) -m black mypy := $(PYTHON) -m mypy ruff := $(PYTHON) -m ruff -srcs := $(wildcard *.py) -answers := $(subst puzzle,answer,$(srcs:.py=.txt)) +ext := .py +srcs := $(wildcard puzzle_*$(ext)) +answers := $(subst puzzle,answer,$(srcs:$(ext)=.txt)) include $(CURDIR)/../mk-common/common.mk -answer_%.txt: puzzle_%.py input_%.txt +answer_%.txt: puzzle_%$(ext) input_%.txt $(PYTHON) ./$< < $(filter-out $<, $^) | tee $@ .PHONY: lint diff --git a/2022/Makefile b/2022/Makefile index a707312..c5eec27 100644 --- a/2022/Makefile +++ b/2022/Makefile @@ -7,8 +7,9 @@ SHELL := bash NIM ?= nim -srcs := $(wildcard puzzle_*.nim) -answers := $(subst puzzle,answer,$(srcs:.nim=.txt)) +ext := .nim +srcs := $(wildcard puzzle_*$(ext)) +answers := $(subst puzzle,answer,$(srcs:$(ext)=.txt)) include $(CURDIR)/../mk-common/common.mk @@ -16,7 +17,7 @@ answer_%.txt: puzzle_% input_%.txt ./$< < $(filter-out $<, $^) | tee $@ .NOTINTERMEDIATE: puzzle_% -puzzle_%: puzzle_%.nim nim.cfg +puzzle_%: puzzle_%$(ext) nim.cfg $(NIM) c $< .PHONY: format