summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 7960aabb3b8873553dc6d683b804e8619ce92dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Makefile for Cabal packages in stockholm[0].
# [0]: http://cgit.cd.krebsco.de/stockholm

pkg-name := $(basename $(wildcard *.cabal))

ifneq ($(words $(pkg-name)),1)
$(error pkg-name is not a single word but '$(pkg-name)')
endif

.ONESHELL:
.SHELLFLAGS := -efu -c

export STOCKHOLM := $(HOME)/stockholm
nix-shell-flags := -I nixpkgs="$$STOCKHOLM"

# make V=1 to enable verbose output
ifeq ($(V),1)
nix-shell-flags += -v
endif

# This is basically what load-env[1] did, which is mostly dead.  Eventually
# this should also become a wrapper for entering a development environment.
# Notice that setting HOME is required for project-local GHCi history[2].  And
# as we have to do it anyway, we're also reusing it for other stuff.
# [1]: http://cgit.cd.krebsco.de/load-env
# [2]: https://ghc.haskell.org/trac/ghc/ticket/9089
.PHONY: shell
shell: shell.nix
	@verbose() { echo "$$*" >&2; "$$@"; }
	verbose export HOME="$$HOME"/.env-home/$(pkg-name)
	test -d "$$HOME" || verbose mkdir -p -m 0700 "$$HOME"
	! test -f "$$HOME"/profile || verbose . "$$HOME"/profile
	export HISTFILE="$$HOME"/histfile HISTSIZE=100000
	verbose nix-shell $(nix-shell-flags) --command 'exec ghci'

shell.nix: $(pkg-name).cabal
	cabal2nix --shell . > $@