summaryrefslogtreecommitdiffhomepage
path: root/Makefile
blob: 58def76db69fa8eaf979ff3b9a917facdf7571c0 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# The install target will add this before all paths it writes to.
PREFIX?=

# Can be "stack" or "cabal", or "./Setup" to build and use Setup.hs 
BUILDER?=stack

# Options to pass to the BUILDER.
# Using -j1 may result in a reproducible build.
BUILDEROPTIONS?=

# Propigate flags through ghc to linker and compiler.
ghc_options=$(shell \
	for w in $(LDFLAGS); do \
	       printf -- "-optl%s\n" "$$w"; \
	done; \
	for w in $(CFLAGS); do \
	       printf -- "-optc%s\n" "$$w"; \
	done; \
	for w in $(CPPFLAGS); do \
	       printf -- "-optc-Wp,%s\n" "$$w"; \
	done; \
	)

build:
	rm -f keysafe
	$(MAKE) keysafe

keysafe:
	if [ "$(BUILDER)" = ./Setup ]; then ghc --make Setup; fi
	if [ "$(BUILDER)" = stack ]; then \
		$(BUILDER) build --ghc-options="$(ghc_options)" $(BUILDEROPTIONS); \
	else \
		$(BUILDER) configure --ghc-options="$(ghc_options)"; \
		$(BUILDER) build $(BUILDEROPTIONS); \
	fi
	if [ "$(BUILDER)" = stack ]; then \
		ln -sf $$(find .stack-work/ -name keysafe -type f | grep build/keysafe/keysafe | tail -n 1) keysafe; \
	else \
		ln -sf dist/build/keysafe/keysafe keysafe; \
	fi

clean:
	if [ "$(BUILDER)" != ./Setup ] && [ "$(BUILDER)" != cabal ]; then $(BUILDER) clean; fi
	rm -rf keysafe dist .stack-work Setup Setup.hi Setup.o

install: install-files
	useradd --system keysafe
	chmod 700 $(PREFIX)/var/lib/keysafe
	chown keysafe:keysafe $(PREFIX)/var/lib/keysafe

install-files: keysafe
	install -d $(PREFIX)/var/lib/keysafe
	install -d $(PREFIX)/usr/bin
	install -s -m 0755 keysafe $(PREFIX)/usr/bin/keysafe
	install -d $(PREFIX)/usr/share/man/man1
	install -m 0644 keysafe.1 $(PREFIX)/usr/share/man/man1/keysafe.1
	install -d $(PREFIX)/lib/systemd/system
	install -m 0644 keysafe.service $(PREFIX)/lib/systemd/system/keysafe.service
	install -d $(PREFIX)/etc/init.d
	install -m 0755 keysafe.init $(PREFIX)/etc/init.d/keysafe
	install -d $(PREFIX)/etc/default
	install -m 0644 keysafe.default $(PREFIX)/etc/default/keysafe
	install -d $(PREFIX)/usr/share/applications/
	install -m 0644 keysafe.desktop $(PREFIX)/usr/share/applications/keysafe.desktop
	install -d $(PREFIX)/etc/xdg/autostart/
	install -m 0644 keysafe.autostart $(PREFIX)/etc/xdg/autostart/keysafe.desktop