1#!/usr/bin/make -f
2
3# Makefile for monkeysphere
4
5# © 2008-2010 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
6# Licensed under GPL v3 or later
7
8MONKEYSPHERE_VERSION = `head -n1 Changelog | sed 's/.*(\([^-]*\)).*/\1/'`
9
10# these defaults are for debian.  porters should probably adjust them
11# before calling make install
12ETCPREFIX ?=
13ETCSUFFIX ?=
14PREFIX ?= /usr
15MANPREFIX ?= $(PREFIX)/share/man
16LOCALSTATEDIR ?= /var/lib
17
18CFLAGS += $(shell libassuan-config --cflags)
19CFLAGS += $(shell libgcrypt-config --cflags)
20CFLAGS += --pedantic -Wall -Werror -std=c99
21LIBS += $(shell libassuan-config --libs)
22LIBS += $(shell libgcrypt-config --libs)
23
24REPLACEMENTS = src/monkeysphere src/monkeysphere-host		\
25src/monkeysphere-authentication src/share/defaultenv $(wildcard	\
26src/transitions/*)
27
28REPLACED_COMPRESSED_MANPAGES = $(addsuffix .gz,$(addprefix replaced/,$(wildcard man/*/*)))
29
30all: src/agent-transfer/agent-transfer $(addprefix replaced/,$(REPLACEMENTS)) $(REPLACED_COMPRESSED_MANPAGES)
31
32src/agent-transfer/agent-transfer: src/agent-transfer/main.c src/agent-transfer/ssh-agent-proto.h
33	$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBS)
34
35debian-package:
36	git buildpackage -uc -us
37
38# don't explicitly depend on the tarball, since our tarball
39# (re)generation is not idempotent even when no source changes.
40freebsd-distinfo:
41	./utils/build-freebsd-distinfo
42
43macports-portfile:
44	./utils/build-macports-portfile
45
46clean:
47	rm -f src/agent-transfer/agent-transfer
48	rm -rf replaced/
49	# clean up old monkeysphere packages lying around as well.
50	rm -f monkeysphere_*
51
52replaced/%: %
53	mkdir -p $(dir $@)
54	sed < $< > $@ \
55	-e 's:__SYSSHAREDIR_PREFIX__:$(PREFIX):' \
56	-e 's:__SYSCONFDIR_PREFIX__:$(ETCPREFIX):' \
57	-e 's:__SYSDATADIR_PREFIX__:$(LOCALSTATEDIR):'
58
59replaced/%.gz: replaced/%
60	gzip -n $<
61
62# this target is to be called from the tarball, not from the git
63# working dir!
64install: all installman
65	mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/sbin
66	mkdir -p $(DESTDIR)$(PREFIX)/share/monkeysphere/m $(DESTDIR)$(PREFIX)/share/monkeysphere/mh $(DESTDIR)$(PREFIX)/share/monkeysphere/ma $(DESTDIR)$(PREFIX)/share/monkeysphere/transitions
67	mkdir -p $(DESTDIR)$(ETCPREFIX)/etc/monkeysphere
68	mkdir -p $(DESTDIR)$(PREFIX)/share/doc/monkeysphere
69	printf "Monkeysphere %s\n" $(MONKEYSPHERE_VERSION) > $(DESTDIR)$(PREFIX)/share/monkeysphere/VERSION
70	install replaced/src/monkeysphere $(DESTDIR)$(PREFIX)/bin
71	install replaced/src/monkeysphere-host $(DESTDIR)$(PREFIX)/sbin
72	install replaced/src/monkeysphere-authentication $(DESTDIR)$(PREFIX)/sbin
73	install src/monkeysphere-authentication-keys-for-user $(DESTDIR)$(PREFIX)/share/monkeysphere
74	install -m 0644 src/share/common $(DESTDIR)$(PREFIX)/share/monkeysphere
75	install -m 0644 replaced/src/share/defaultenv $(DESTDIR)$(PREFIX)/share/monkeysphere
76	install -m 0755 src/share/checkperms $(DESTDIR)$(PREFIX)/share/monkeysphere
77	install -m 0755 src/share/keytrans $(DESTDIR)$(PREFIX)/share/monkeysphere
78	ln -sf ../share/monkeysphere/keytrans $(DESTDIR)$(PREFIX)/bin/pem2openpgp
79	ln -sf ../share/monkeysphere/keytrans $(DESTDIR)$(PREFIX)/bin/openpgp2ssh
80	ln -sf ../share/monkeysphere/keytrans $(DESTDIR)$(PREFIX)/bin/openpgp2pem
81	ln -sf ../share/monkeysphere/keytrans $(DESTDIR)$(PREFIX)/bin/openpgp2spki
82	install -m 0755 src/agent-transfer/agent-transfer $(DESTDIR)$(PREFIX)/bin
83	install -m 0744 replaced/src/transitions/* $(DESTDIR)$(PREFIX)/share/monkeysphere/transitions
84	install -m 0644 src/transitions/README.txt $(DESTDIR)$(PREFIX)/share/monkeysphere/transitions
85	install -m 0644 src/share/m/* $(DESTDIR)$(PREFIX)/share/monkeysphere/m
86	install -m 0644 src/share/mh/* $(DESTDIR)$(PREFIX)/share/monkeysphere/mh
87	install -m 0644 src/share/ma/* $(DESTDIR)$(PREFIX)/share/monkeysphere/ma
88	install -m 0644 Changelog $(DESTDIR)$(PREFIX)/share/doc/monkeysphere
89	install -d $(DESTDIR)$(PREFIX)/share/doc/monkeysphere/examples
90	install -m 0644 examples/* $(DESTDIR)$(PREFIX)/share/doc/monkeysphere/examples
91	install -m 0644 etc/monkeysphere.conf $(DESTDIR)$(ETCPREFIX)/etc/monkeysphere/monkeysphere.conf$(ETCSUFFIX)
92	install -m 0644 etc/monkeysphere-host.conf $(DESTDIR)$(ETCPREFIX)/etc/monkeysphere/monkeysphere-host.conf$(ETCSUFFIX)
93	install -m 0644 etc/monkeysphere-authentication.conf $(DESTDIR)$(ETCPREFIX)/etc/monkeysphere/monkeysphere-authentication.conf$(ETCSUFFIX)
94
95installman: $(REPLACED_COMPRESSED_MANPAGES)
96	mkdir -p $(DESTDIR)$(MANPREFIX)/man1 $(DESTDIR)$(MANPREFIX)/man7 $(DESTDIR)$(MANPREFIX)/man8
97	install replaced/man/man1/* $(DESTDIR)$(MANPREFIX)/man1
98	install replaced/man/man7/* $(DESTDIR)$(MANPREFIX)/man7
99	install replaced/man/man8/* $(DESTDIR)$(MANPREFIX)/man8
100	ln -sf openpgp2ssh.1.gz $(DESTDIR)$(MANPREFIX)/man1/openpgp2pem.1.gz
101	ln -sf openpgp2ssh.1.gz $(DESTDIR)$(MANPREFIX)/man1/openpgp2spki.1.gz
102
103# this target depends on you having the monkeysphere-docs
104# repo checked out as a peer of your monkeysphere repo.
105releasenote:
106	../monkeysphere-docs/utils/build-releasenote
107
108test: test-keytrans test-basic
109
110check: test
111
112test-basic: src/agent-transfer/agent-transfer
113	MONKEYSPHERE_TEST_NO_EXAMINE=true ./tests/basic
114
115test-keytrans: src/agent-transfer/agent-transfer
116	MONKEYSPHERE_TEST_NO_EXAMINE=true ./tests/keytrans
117
118.PHONY: all tarball debian-package freebsd-distinfo clean install installman releasenote test check
119