@@ -20,6 +20,13 @@ SHELL := bash
20
20
MAKEFLAGS += --no-builtin-rules
21
21
MAKEFLAGS += --warn-undefined-variables
22
22
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
+
23
30
RESOLVER_ARGS :=
24
31
ifneq ($(origin RESOLVER ) , undefined)
25
32
RESOLVER_ARGS := "--resolver" "$(RESOLVER ) "
@@ -48,75 +55,59 @@ endef
48
55
# #############################################################################
49
56
# Rules
50
57
51
- _default : build
52
- .PHONY : _default
53
-
54
- build :
58
+ build : # build package *
55
59
> @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)
57
61
.PHONY : build
58
62
59
- clean :
63
+ clean : # clean package
60
64
> @stack clean
61
65
.PHONY : clean
62
66
63
- clean-all : clean
67
+ clean-all : clean # clean package and remove artifacts
64
68
> @rm -rf .stack-work
65
69
> @rm -rf build
66
70
> @rm -f *.yaml.lock
67
71
.PHONY : clean-all
68
72
69
- grep :
73
+ grep : # grep all non-hidden files for expression E
70
74
> $(eval E:= "")
71
75
> @test -n "$(E ) " || $(call die,"usage : make grep E=expression")
72
76
> @$(call all_files) | xargs grep -Hn '$(E)' || true
73
77
.PHONY : grep
74
78
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'
93
83
> @echo
84
+ > @echo "* Use STACK_NIX_PATH to specify a Nix path."
94
85
> @echo "* Use RESOLVER to specify a resolver."
95
86
> @echo "* Use CONFIG to specify a Stack configuration file."
96
87
.PHONY : help
97
88
98
- hlint :
89
+ hlint : # run hlint on all Haskell source
99
90
> @$(call hs_files) | xargs hlint
100
91
.PHONY : hlint
101
92
102
- hsgrep :
93
+ hsgrep : # grep all Haskell source for expression E
103
94
> $(eval E := "")
104
95
> @test -n "$(E ) " || $(call die,"usage : make hsgrep E=expression")
105
96
> @$(call hs_files) | xargs grep -Hn '$(E)' || true
106
97
.PHONY : hsgrep
107
98
108
- hsrecent :
99
+ hsrecent : # show N most recently modified Haskell files
109
100
> $(eval N := "10")
110
101
> @find . -not -path '*/\.*' -type f -name '*.hs' -printf '%T+ %p\n' \
111
102
> | sort --reverse \
112
103
> | head -n $(N)
113
104
.PHONY : hsrecent
114
105
115
- hssloc :
106
+ hssloc : # count lines of Haskell source
116
107
> @$(call hs_files) | xargs wc -l | tail -n 1 | sed 's/^ *\([0-9]*\).*$$/\1/'
117
108
.PHONY : hssloc
118
109
119
- man :
110
+ man : # build man page
120
111
> $(eval VERSION := $(shell \
121
112
grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
122
113
> $(eval DATE := $(shell date --rfc-3339=date))
@@ -127,18 +118,18 @@ man:
127
118
> doc/$(BINARY).1.md
128
119
.PHONY : man
129
120
130
- recent :
121
+ recent : # show N most recently modified files
131
122
> $(eval N := "10")
132
123
> @find . -not -path '*/\.*' -type f -printf '%T+ %p\n' \
133
124
> | sort --reverse \
134
125
> | head -n $(N)
135
126
.PHONY : recent
136
127
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)
139
130
.PHONY : repl
140
131
141
- source-git :
132
+ source-git : # create source tarball of git TREE
142
133
> $(eval TREE := "HEAD")
143
134
> $(eval BRANCH := $(shell git rev-parse --abbrev-ref $(TREE)))
144
135
> @test "${BRANCH}" = "master" || echo "WARNING : Not in master branch!" >&2
@@ -150,7 +141,7 @@ source-git:
150
141
> > build/$(PROJECT)-$(VERSION).tar.xz
151
142
.PHONY : source-git
152
143
153
- source-tar :
144
+ source-tar : # create source tarball using tar
154
145
> $(eval VERSION := $(shell \
155
146
grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
156
147
> @mkdir -p build
@@ -164,16 +155,51 @@ source-tar:
164
155
> @rm -f build/.gitignore
165
156
.PHONY : source-tar
166
157
167
- test :
158
+ test : # run tests, optionally for pattern P *
168
159
> $(eval P := "")
169
160
> @command -v hr >/dev/null 2>&1 && hr -t || true
170
161
> @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) \
173
164
> --test-arguments '--pattern $(P)'
174
165
.PHONY : test
175
166
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
177
203
> @find . -type f \
178
204
> -not -path '*/\.*' \
179
205
> -not -path './build/*' \
@@ -182,6 +208,6 @@ todo:
182
208
> | xargs grep -Hn TODO || true
183
209
.PHONY : todo
184
210
185
- version :
211
+ version : # show current version
186
212
> @grep '^version :' $(CABAL_FILE ) | sed 's/^version: * /$(PROJECT ) /'
187
213
.PHONY : version
0 commit comments