@@ -6,6 +6,16 @@ BINARY := $(PACKAGE)
66CABAL_FILE := $(PACKAGE ) .cabal
77PROJECT := $(PACKAGE ) -haskell
88
9+ MAINTAINER_NAME = Travis Cardwell
10+ MAINTAINER_EMAIL =
[email protected] 11+
12+ DESTDIR ?=
13+ PREFIX ?= /usr/local
14+ bindir ?= $(DESTDIR ) /$(PREFIX ) /bin
15+ datarootdir ?= $(DESTDIR ) /$(PREFIX ) /share
16+ docdir ?= $(datarootdir ) /doc/$(PROJECT )
17+ man1dir ?= $(datarootdir ) /man/man1
18+
919# #############################################################################
1020# Make configuration
1121
@@ -37,13 +47,22 @@ ifneq ($(origin CONFIG), undefined)
3747 STACK_YAML_ARGS := "--stack-yaml" "$(CONFIG ) "
3848endif
3949
50+ MODE := stack
51+ ifneq ($(origin CABAL ) , undefined)
52+ MODE := cabal
53+ endif
54+
4055# #############################################################################
4156# Functions
4257
4358define all_files
4459 find . -not -path '*/\.*' -type f
4560endef
4661
62+ define checksum_files
63+ find . -maxdepth 1 -type f -not -path './*SUMS' | sed 's,^\./,,' | sort
64+ endef
65+
4766define die
4867 (echo "error: $(1 ) " ; false)
4968endef
@@ -55,28 +74,59 @@ endef
5574# #############################################################################
5675# Rules
5776
77+ build : hr
5878build : # build package *
59- > @command -v hr >/dev/null 2>&1 && hr -t || true
79+ ifeq ($(MODE ) , cabal)
80+ > @cabal v2-build
81+ else
6082> @stack build $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS)
83+ endif
6184.PHONY : build
6285
86+ checksums : # calculate checksums of build artifacts
87+ > @cd build && $(call checksum_files) | xargs md5sum > MD5SUMS
88+ > @cd build && $(call checksum_files) | xargs sha1sum > SHA1SUMS
89+ > @cd build && $(call checksum_files) | xargs sha256sum > SHA256SUMS
90+ > @cd build && $(call checksum_files) | xargs sha512sum > SHA512SUMS
91+ .PHONY : checksums
92+
6393clean : # clean package
94+ ifeq ($(MODE ) , cabal)
95+ > @rm -rf dist-newstyle
96+ else
6497> @stack clean
98+ endif
6599.PHONY : clean
66100
67101clean-all : clean # clean package and remove artifacts
102+ > @rm -rf .hie
68103> @rm -rf .stack-work
69104> @rm -rf build
105+ > @rm -rf dist-newstyle
70106> @rm -f *.yaml.lock
107+ > @rm -f cabal.project.local
71108.PHONY : clean-all
72109
110+ coverage : hr
73111coverage : # run tests with code coverage *
74- > @command -v hr >/dev/null 2>&1 && hr -t || true
75112> @stack test --coverage $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS)
76113> @stack hpc report .
77114.PHONY : coverage
78115# https://github.com/commercialhaskell/stack/issues/1305
79116
117+ deb : # build .deb package for VERSION in a Debian container
118+ > $(eval VERSION := $(shell \
119+ grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
120+ > $(eval SRC := "$(PROJECT)-$(VERSION).tar.xz")
121+ > @test -f build/$(SRC) || $(call die,"build/$(SRC) not found")
122+ > @docker run --rm -it \
123+ > -e DEBFULLNAME="$(MAINTAINER_NAME)" \
124+ > -e DEBEMAIL="$(MAINTAINER_EMAIL)" \
125+ > -v $(PWD ) /build :/host \
126+ > extremais/pkg-debian-stack :buster \
127+ > /home/docker/bin/make-deb.sh "$(SRC)"
128+ .PHONY : deb
129+
80130grep : # grep all non-hidden files for expression E
81131> $(eval E:= "")
82132> @test -n "$(E ) " || $(call die,"usage : make grep E=expression")
@@ -91,12 +141,17 @@ help: # show this help
91141> @echo "* Use STACK_NIX_PATH to specify a Nix path."
92142> @echo "* Use RESOLVER to specify a resolver."
93143> @echo "* Use CONFIG to specify a Stack configuration file."
144+ > @echo "* Use CABAL to use Cabal instead of Stack."
94145.PHONY : help
95146
96147hlint : # run hlint on all Haskell source
97148> @$(call hs_files) | xargs hlint
98149.PHONY : hlint
99150
151+ hr : # internal# display a horizontal rule
152+ > @command -v hr >/dev/null 2>&1 && hr -t || true
153+ .PHONY : hr
154+
100155hsgrep : # grep all Haskell source for expression E
101156> $(eval E := "")
102157> @test -n "$(E ) " || $(call die,"usage : make hsgrep E=expression")
@@ -114,12 +169,36 @@ hssloc: # count lines of Haskell source
114169> @$(call hs_files) | xargs wc -l | tail -n 1 | sed 's/^ *\([0-9]*\).*$$/\1/'
115170.PHONY : hssloc
116171
172+ install : install-bin
173+ install : install-man
174+ install : install-doc
175+ install : # install everything to PREFIX
176+ .PHONY : install
177+
178+ install-bin : build
179+ install-bin : # install executable to PREFIX/bin
180+ > $(eval LIROOT := $(shell stack path --local-install-root))
181+ > @mkdir -p "$(bindir)"
182+ > @install -m 0755 "$(LIROOT)/bin/$(BINARY)" "$(bindir)/$(BINARY)"
183+ .PHONY : install-bin
184+
185+ install-doc : # install documentation to PREFIX/share/doc/queue-sheet-haskell
186+ > @mkdir -p "$(docdir)"
187+ > @install -m 0644 -T <(gzip -c README.md) "$(docdir)/README.md.gz"
188+ > @install -m 0644 -T <(gzip -c CHANGELOG.md) "$(docdir)/changelog.gz"
189+ > @install -m 0644 -T <(gzip -c LICENSE) "$(docdir)/LICENSE.gz"
190+ .PHONY : install-doc
191+
192+ install-man : # install manual to PREFIX/share/man/man1
193+ > @mkdir -p "$(man1dir)"
194+ > @install -m 0644 -T <(gzip -c doc/$(BINARY).1) "$(man1dir)/$(BINARY).1.gz"
195+ .PHONY : install-man
196+
117197man : # build man page
118198> $(eval VERSION := $(shell \
119199 grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
120200> $(eval DATE := $(shell date --rfc-3339=date))
121- > @mkdir -p build
122- > @pandoc -s -t man -o build/$(BINARY).1 \
201+ > @pandoc -s -t man -o doc/$(BINARY).1 \
123202> --variable header="$(BINARY) Manual" \
124203> --variable footer="$(PROJECT) $(VERSION) ($(DATE))" \
125204> doc/$(BINARY).1.md
@@ -133,13 +212,38 @@ recent: # show N most recently modified files
133212.PHONY : recent
134213
135214repl : # enter a REPL *
215+ ifeq ($(MODE ) , cabal)
216+ > @cabal repl
217+ else
136218> @stack exec ghci $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS)
219+ endif
137220.PHONY : repl
138221
222+ rpm : # build .rpm package for VERSION in a Fedora container
223+ > $(eval VERSION := $(shell \
224+ grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
225+ > $(eval SRC := "$(PROJECT)-$(VERSION).tar.xz")
226+ > @test -f build/$(SRC) || $(call die,"build/$(SRC) not found")
227+ > @docker run --rm -it \
228+ > -e RPMFULLNAME="$(MAINTAINER_NAME)" \
229+ > -e RPMEMAIL="$(MAINTAINER_EMAIL)" \
230+ > -v $(PWD ) /build :/host \
231+ > extremais/pkg-fedora-stack :34 \
232+ > /home/docker/bin/make-rpm.sh "$(SRC)"
233+ .PHONY : rpm
234+
139235source-git : # create source tarball of git TREE
140236> $(eval TREE := "HEAD")
141237> $(eval BRANCH := $(shell git rev-parse --abbrev-ref $(TREE)))
142- > @test "${BRANCH}" = "main" || echo "WARNING : Not in main branch!" >&2
238+ > @test "$(BRANCH ) " = "main" || echo "WARNING : Not in main branch!" >&2
239+ > $(eval DIRTY := $(shell git diff --shortstat | wc -l))
240+ > @test "$(DIRTY)" = "0" \
241+ > || echo "WARNING : Not including non-committed changes!" >&2
242+ > $(eval UNTRACKED := $(shell \
243+ git ls-files --other --directory --no-empty-directory --exclude-standard \
244+ | wc -l))
245+ > @test "$(UNTRACKED)" = "0" \
246+ > || echo "WARNING : Not including untracked files!" >&2
143247> $(eval VERSION := $(shell \
144248 grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
145249> @mkdir -p build
@@ -149,6 +253,14 @@ source-git: # create source tarball of git TREE
149253.PHONY : source-git
150254
151255source-tar : # create source tarball using tar
256+ > $(eval DIRTY := $(shell git diff --shortstat | wc -l))
257+ > @test "$(DIRTY)" = "0" \
258+ > || echo "WARNING : Including non-committed changes!" >&2
259+ > $(eval UNTRACKED := $(shell \
260+ git ls-files --other --directory --no-empty-directory --exclude-standard \
261+ | wc -l))
262+ > @test "$(UNTRACKED)" = "0" \
263+ > || echo "WARNING : Including untracked files!" >&2
152264> $(eval VERSION := $(shell \
153265 grep '^version :' $(CABAL_FILE ) | sed 's/^version: * //'))
154266> @mkdir -p build
@@ -162,50 +274,50 @@ source-tar: # create source tarball using tar
162274> @rm -f build/.gitignore
163275.PHONY : source-tar
164276
277+ stan : hr
278+ stan : export STAN_USE_DEFAULT_CONFIG=True
279+ stan : # run stan static analysis
280+ ifeq ($(MODE ) , cabal)
281+ > @cabal v2-build -f write-hie
282+ else
283+ > @stack build --flag $(PACKAGE ) :write-hie
284+ endif
285+ > @stan
286+ .PHONY : stan
287+
288+ test : hr
165289test : # run tests, optionally for pattern P *
166290> $(eval P := "")
167- > @command -v hr >/dev/null 2>&1 && hr -t || true
291+ ifeq ($(MODE ) , cabal)
292+ > @test -z "$(P)" \
293+ > && cabal v2-test --enable-tests --test-show-details=always \
294+ > || cabal v2-test --enable-tests --test-show-details=always \
295+ > --test-option '--patern=$(P)'
296+ else
168297> @test -z "$(P)" \
169298> && stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS) \
170299> || stack test $(RESOLVER_ARGS) $(STACK_YAML_ARGS) $(NIX_PATH_ARGS) \
171300> --test-arguments '--pattern $(P)'
301+ endif
172302.PHONY : test
173303
174- test-all : # run tests for all versions
175- > $(eval CONFIG := $(shell \
176- test -f stack-nix-8.2.2.yaml \
177- && echo stack-nix-8.2.2.yaml \
178- || echo stack-8.2.2.yaml))
179- > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
180- > @make test CONFIG=$(CONFIG)
181- > $(eval CONFIG := $(shell \
182- test -f stack-nix-8.4.4.yaml \
183- && echo stack-nix-8.4.4.yaml \
184- || echo stack-8.4.4.yaml))
185- > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
186- > @make test CONFIG=$(CONFIG)
187- > $(eval CONFIG := $(shell \
188- test -f stack-nix-8.6.5.yaml \
189- && echo stack-nix-8.6.5.yaml \
190- || echo stack-8.6.5.yaml))
191- > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
192- > @make test CONFIG=$(CONFIG)
193- > $(eval CONFIG := $(shell \
194- test -f stack-nix.yaml \
195- && echo stack-nix.yaml \
196- || echo stack.yaml))
197- > @command -v hr >/dev/null 2>&1 && hr $(CONFIG) || true
198- > @make test CONFIG=$(CONFIG)
199- > $(eval STACK_NIX_PATH := $(shell \
200- test -f stack-nix-nightly.path \
201- && cat stack-nix-nightly.path \
202- || true))
203- > @command -v hr >/dev/null 2>&1 && hr nightly || true
204- > @test -f stack-nix-nightly.path \
205- > && make test RESOLVER=nightly STACK_NIX_PATH="$(STACK_NIX_PATH)" \
206- > || make test RESOLVER=nightly
304+ test-all : # run tests for all configured Stackage releases
305+ > @command -v hr >/dev/null 2>&1 && hr "stack-8.2.2.yaml" || true
306+ > @make test CONFIG=stack-8.2.2.yaml
307+ > @command -v hr >/dev/null 2>&1 && hr "stack-8.4.4.yaml" || true
308+ > @make test CONFIG=stack-8.4.4.yaml
309+ > @command -v hr >/dev/null 2>&1 && hr "stack-8.6.5.yaml" || true
310+ > @make test CONFIG=stack-8.6.5.yaml
311+ > @command -v hr >/dev/null 2>&1 && hr "stack-8.8.4.yaml" || true
312+ > @make test CONFIG=stack-8.8.4.yaml
313+ > @command -v hr >/dev/null 2>&1 && hr "stack-8.10.4.yaml" || true
314+ > @make test CONFIG=stack-8.10.4.yaml
207315.PHONY : test-all
208316
317+ test-nightly : # run tests for the latest Stackage nightly release
318+ > @make test RESOLVER=nightly
319+ .PHONY : test-nightly
320+
209321todo : # search for TODO items
210322> @find . -type f \
211323> -not -path '*/\.*' \
0 commit comments