@@ -20,6 +20,13 @@ SHELL := bash
2020MAKEFLAGS += --no-builtin-rules
2121MAKEFLAGS += --warn-undefined-variables
2222
23+ .DEFAULT_GOAL := build
24+
25+ NIX_PATH_ARGS :=
26+ ifneq ($(origin STACK_NIX_PATH ) , undefined)
27+ NIX_PATH_ARGS := "--nix-path=$(STACK_NIX_PATH ) "
28+ endif
29+
2330RESOLVER_ARGS :=
2431ifneq ($(origin RESOLVER ) , undefined)
2532 RESOLVER_ARGS := "--resolver" "$(RESOLVER ) "
@@ -48,75 +55,59 @@ endef
4855# #############################################################################
4956# Rules
5057
51- _default : build
52- .PHONY : _default
53-
54- build :
58+ build : # build package *
5559> @command -v hr >/dev/null 2>&1 && hr -t || true
56- > @stack build $(RESOLVER_ARGS) $(STACK_YAML_ARGS)
60+ > @stack build $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS)
5761.PHONY : build
5862
59- clean :
63+ clean : # clean package
6064> @stack clean
6165.PHONY : clean
6266
63- clean-all : clean
67+ clean-all : clean # clean package and remove artifacts
6468> @rm -rf .stack-work
6569> @rm -rf build
6670> @rm -f *.yaml.lock
6771.PHONY : clean-all
6872
69- grep :
73+ grep : # grep all non-hidden files for expression E
7074> $(eval E:= "")
7175> @test -n "$(E ) " || $(call die,"usage : make grep E=expression")
7276> @$(call all_files) | xargs grep -Hn '$(E)' || true
7377.PHONY : grep
7478
75- help :
76- > @echo "make build build package (default) *"
77- > @echo "make clean clean package"
78- > @echo "make clean-all clean package and remove artifacts"
79- > @echo "make grep grep all non-hidden files for expression E"
80- > @echo "make help show this help"
81- > @echo "make hlint run hlint on all Haskell source"
82- > @echo "make hsgrep grep all Haskell source for expression E"
83- > @echo "make hsrecent show N most recently modified Haskell files"
84- > @echo "make hssloc count lines of Haskell source"
85- > @echo "make man build man page"
86- > @echo "make recent show N most recently modified files"
87- > @echo "make repl enter a REPL *"
88- > @echo "make source-git create source tarball of git TREE"
89- > @echo "make source-tar create source tarball using tar"
90- > @echo "make test run tests, optionally for pattern P *"
91- > @echo "make todo search for TODO items"
92- > @echo "make version show current version"
79+ help : # show this help
80+ > @grep '^[a-zA-Z0-9_-]\+ :[^# ]*# ' $(MAKEFILE_LIST) \
81+ > | sed 's/^\([^:]\+\):[^#]*# \(.*\)/make \1\t\2/' \
82+ > | column -t -s $$'\t'
9383> @echo
84+ > @echo "* Use STACK_NIX_PATH to specify a Nix path."
9485> @echo "* Use RESOLVER to specify a resolver."
9586> @echo "* Use CONFIG to specify a Stack configuration file."
9687.PHONY : help
9788
98- hlint :
89+ hlint : # run hlint on all Haskell source
9990> @$(call hs_files) | xargs hlint
10091.PHONY : hlint
10192
102- hsgrep :
93+ hsgrep : # grep all Haskell source for expression E
10394> $(eval E := "")
10495> @test -n "$(E ) " || $(call die,"usage : make hsgrep E=expression")
10596> @$(call hs_files) | xargs grep -Hn '$(E)' || true
10697.PHONY : hsgrep
10798
108- hsrecent :
99+ hsrecent : # show N most recently modified Haskell files
109100> $(eval N := "10")
110101> @find . -not -path '*/\.*' -type f -name '*.hs' -printf '%T+ %p\n' \
111102> | sort --reverse \
112103> | head -n $(N)
113104.PHONY : hsrecent
114105
115- hssloc :
106+ hssloc : # count lines of Haskell source
116107> @$(call hs_files) | xargs wc -l | tail -n 1 | sed 's/^ *\([0-9]*\).*$$/\1/'
117108.PHONY : hssloc
118109
119- man :
110+ man : # build man page
120111> $(eval VERSION := $(shell \
121112 grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
122113> $(eval DATE := $(shell date --rfc-3339=date))
@@ -127,18 +118,18 @@ man:
127118> doc/$(BINARY).1.md
128119.PHONY : man
129120
130- recent :
121+ recent : # show N most recently modified files
131122> $(eval N := "10")
132123> @find . -not -path '*/\.*' -type f -printf '%T+ %p\n' \
133124> | sort --reverse \
134125> | head -n $(N)
135126.PHONY : recent
136127
137- repl :
138- > @stack exec ghci $(RESOLVER_ARGS) $(STACK_YAML_ARGS)
128+ repl : # enter a REPL *
129+ > @stack exec ghci $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS)
139130.PHONY : repl
140131
141- source-git :
132+ source-git : # create source tarball of git TREE
142133> $(eval TREE := "HEAD")
143134> $(eval BRANCH := $(shell git rev-parse --abbrev-ref $(TREE)))
144135> @test "${BRANCH}" = "master" || echo "WARNING : Not in master branch!" >&2
@@ -150,7 +141,7 @@ source-git:
150141> > build/$(PROJECT)-$(VERSION).tar.xz
151142.PHONY : source-git
152143
153- source-tar :
144+ source-tar : # create source tarball using tar
154145> $(eval VERSION := $(shell \
155146 grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
156147> @mkdir -p build
@@ -164,16 +155,51 @@ source-tar:
164155> @rm -f build/.gitignore
165156.PHONY : source-tar
166157
167- test :
158+ test : # run tests, optionally for pattern P *
168159> $(eval P := "")
169160> @command -v hr >/dev/null 2>&1 && hr -t || true
170161> @test -z "$(P)" \
171- > && stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) \
172- > || stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) \
162+ > && stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS) \
163+ > || stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS) \
173164> --test-arguments '--pattern $(P)'
174165.PHONY : test
175166
176- todo :
167+ test-all : # run tests for all versions
168+ > $(eval CONFIG := $(shell \
169+ test -f stack-nix-8.2.2.yaml \
170+ && echo stack-nix-8.2.2.yaml \
171+ || echo stack-8.2.2.yaml))
172+ > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
173+ > @make test CONFIG=$(CONFIG)
174+ > $(eval CONFIG := $(shell \
175+ test -f stack-nix-8.4.4.yaml \
176+ && echo stack-nix-8.4.4.yaml \
177+ || echo stack-8.4.4.yaml))
178+ > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
179+ > @make test CONFIG=$(CONFIG)
180+ > $(eval CONFIG := $(shell \
181+ test -f stack-nix-8.6.5.yaml \
182+ && echo stack-nix-8.6.5.yaml \
183+ || echo stack-8.6.5.yaml))
184+ > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
185+ > @make test CONFIG=$(CONFIG)
186+ > $(eval CONFIG := $(shell \
187+ test -f stack-nix.yaml \
188+ && echo stack-nix.yaml \
189+ || echo stack.yaml))
190+ > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
191+ > @make test CONFIG=$(CONFIG)
192+ > $(eval STACK_NIX_PATH := $(shell \
193+ test -f stack-nix-nightly.path \
194+ && cat stack-nix-nightly.path \
195+ || true))
196+ > @command -v hr >/dev/null 2>&1 && hr nightly || true
197+ > @test -f stack-nix-nightly.path \
198+ > && make test RESOLVER=nightly STACK_NIX_PATH="$(STACK_NIX_PATH)" \
199+ > || make test RESOLVER=nightly
200+ .PHONY : test-all
201+
202+ todo : # search for TODO items
177203> @find . -type f \
178204> -not -path '*/\.*' \
179205> -not -path './build/*' \
@@ -182,6 +208,6 @@ todo:
182208> | xargs grep -Hn TODO || true
183209.PHONY : todo
184210
185- version :
211+ version : # show current version
186212> @grep '^version :' $(CABAL_FILE ) | sed 's/^version: * /$(PROJECT ) /'
187213.PHONY : version
0 commit comments