Skip to content

Commit

Permalink
Use a variable for source file extension in Makefiles
Browse files Browse the repository at this point in the history
Reduce duplication when maintaining each AoC year's Makefile.
  • Loading branch information
ericvw committed Jan 9, 2024
1 parent be4e279 commit e13c62c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions 2021/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions 2022/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ 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

answer_%.txt: puzzle_% input_%.txt
./$< < $(filter-out $<, $^) | tee $@

.NOTINTERMEDIATE: puzzle_%
puzzle_%: puzzle_%.nim nim.cfg
puzzle_%: puzzle_%$(ext) nim.cfg
$(NIM) c $<

.PHONY: format
Expand Down

0 comments on commit e13c62c

Please sign in to comment.