From 0cc7e7a7d1f4508e7fbc1bb4cbb6e042ee4578ec Mon Sep 17 00:00:00 2001 From: Clint Plummer Date: Sat, 6 Jan 2024 10:24:42 +1100 Subject: [PATCH] DRY up Makefile using automatic variables see https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html --- Makefile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 76f260fe..f711c44d 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,28 @@ .PHONY: lint check_dupes install + +sources :=$(wildcard ./exercises/**.json) + lint: - check-jsonschema --schemafile ./schema.json ./exercises/**.json + check-jsonschema --schemafile ./schema.json $(sources) check_dupes: # check for duplicate id's, if there's ID's listed here # we've got duplicate id's that need to be resolved - jq -s ".[]" exercises/**.json | jq '.id' | sort | uniq -d + jq -s ".[]" $(sources) | jq '.id' | sort | uniq -d install: pip install check-jsonschema -dist/exercises.json: ./exercises/**.json +dist/exercises.json: $(sources) # requires jq # brew install jq (for macos) - jq -s '.' ./exercises/**.json > ./dist/exercises.json -dist/exercises.nd.json: ./exercises/**.json + jq -s '.' $^ > $@ +dist/exercises.nd.json: $(sources) # output to new line delimited JSON # for use to import into PostgreSQL via the COPY command # # https://konbert.com/blog/import-json-into-postgres-using-copy # https://www.postgresql.org/docs/current/sql-copy.html - jq -s '.[]' ./exercises/**.json > ./dist/exercises.nd.json + jq -s '.[]' $^ > $@ dist/exercises.csv: dist/exercises.json # output to csv format # requires in2csv which is part of # https://csvkit.readthedocs.io/ - in2csv ./dist/exercises.json > ./dist/exercises.csv + in2csv ./dist/exercises.json > $@