1#!/usr/bin/make -f
2
3#export DH_OPTIONS
4DEB_HOST_GNU_TYPE ?=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
5DEB_BUILD_GNU_TYPE ?=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
6
7STRIP =strip
8ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
9  STRIP =: nostrip
10endif
11
12CFLAGS =-Wall -g
13ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
14  CFLAGS +=-O0
15else
16  CFLAGS +=-O2
17endif
18
19CONFFLAGS =
20CC =gcc
21ifneq (,$(findstring diet,$(DEB_BUILD_OPTIONS)))
22  CONFFLAGS =--disable-zlib
23  CC =diet -v -Os gcc -nostdinc
24endif
25
26DIR =$(shell pwd)/debian/dropbear
27
28patch: deb-checkdir patch-stamp
29patch-stamp:
30	for i in `ls -1 debian/diff/*.diff || :`; do \
31	  patch -p0 <$$i || exit 1; \
32	done
33	touch patch-stamp
34
35config.status: patch-stamp configure
36	CC='$(CC)' \
37	CFLAGS='$(CFLAGS)'' -DSFTPSERVER_PATH="\"/usr/lib/sftp-server\""' \
38	  ./configure --host='$(DEB_HOST_GNU_TYPE)' \
39	    --build='$(DEB_BUILD_GNU_TYPE)' --prefix=/usr \
40	    --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info \
41	    $(CONFFLAGS)
42
43build: deb-checkdir build-stamp
44build-stamp: config.status
45	$(MAKE) CC='$(CC)' LD='$(CC)'
46	touch build-stamp
47
48clean: deb-checkdir deb-checkuid
49	-$(MAKE) distclean
50	test ! -e patch-stamp || \
51	  for i in `ls -1r debian/diff/*.diff || :`; do \
52	    patch -p0 -R <$$i; \
53	  done
54	rm -f patch-stamp build-stamp config.log config.status
55	rm -rf '$(DIR)'
56	rm -f debian/files debian/substvars debian/copyright changelog
57
58install: deb-checkdir deb-checkuid build-stamp
59	rm -rf '$(DIR)'
60	install -d -m0755 '$(DIR)'/etc/dropbear
61	# programs
62	install -d -m0755 '$(DIR)'/usr/sbin
63	install -m0755 dropbear '$(DIR)'/usr/sbin/dropbear
64	install -d -m0755 '$(DIR)'/usr/bin
65	install -m0755 dbclient '$(DIR)'/usr/bin/dbclient
66	install -m0755 dropbearkey '$(DIR)'/usr/bin/dropbearkey
67	install -d -m0755 '$(DIR)'/usr/lib/dropbear
68	install -m0755 dropbearconvert \
69	  '$(DIR)'/usr/lib/dropbear/dropbearconvert
70	$(STRIP) -R .comment -R .note '$(DIR)'/usr/sbin/* \
71	  '$(DIR)'/usr/bin/* '$(DIR)'/usr/lib/dropbear/*
72	# init and run scripts
73	install -d -m0755 '$(DIR)'/etc/init.d
74	install -m0755 debian/dropbear.init '$(DIR)'/etc/init.d/dropbear
75	install -m0755 debian/service/run '$(DIR)'/etc/dropbear/run
76	install -d -m0755 '$(DIR)'/etc/dropbear/log
77	install -m0755 debian/service/log '$(DIR)'/etc/dropbear/log/run
78	ln -s /var/log/dropbear '$(DIR)'/etc/dropbear/log/main
79	ln -s /var/run/dropbear '$(DIR)'/etc/dropbear/supervise
80	ln -s /var/run/dropbear.log '$(DIR)'/etc/dropbear/log/supervise
81	# man pages
82	install -d -m0755 '$(DIR)'/usr/share/man/man8
83	for i in dropbear.8 dropbearkey.8; do \
84	  install -m644 $$i '$(DIR)'/usr/share/man/man8/ || exit 1; \
85	done
86	gzip -9 '$(DIR)'/usr/share/man/man8/*.8
87	install -d -m0755 '$(DIR)'/usr/share/man/man1
88	install -m644 dbclient.1 '$(DIR)'/usr/share/man/man1/
89	gzip -9 '$(DIR)'/usr/share/man/man1/*.1
90	# copyright, changelog
91	cat debian/copyright.in LICENSE >debian/copyright
92	test -r changelog || ln -s CHANGES changelog
93
94binary-indep:
95
96binary-arch: install dropbear.deb
97	test '$(CC)' != 'gcc' || \
98	  dpkg-shlibdeps '$(DIR)'/usr/sbin/* '$(DIR)'/usr/bin/* \
99	    '$(DIR)'/usr/lib/dropbear/*
100	dpkg-gencontrol -isp -pdropbear -P'$(DIR)'
101	dpkg -b '$(DIR)' ..
102
103binary: binary-arch binary-indep
104
105.PHONY: patch build clean install binary-indep binary-arch binary
106
107include debian/implicit
108