chiark / gitweb /
subdirmk: Change stub force target to `run-main.mk'
[secnet.git] / Subdir.sd.mk
1 # Makefile for secnet
2 #
3 # This file is part of secnet.
4 # See README for full list of copyright holders.
5 #
6 # secnet is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # secnet is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # version 3 along with secnet; if not, see
18 # https://www.gnu.org/licenses/gpl.html.
19
20 .PHONY: all clean realclean distclean dist install
21
22 PACKAGE:=secnet
23 VERSION=0.5.1
24
25 VPATH:=@srcdir@
26 srcdir:=@srcdir@
27 include common.make
28
29 INSTALL:=@INSTALL@
30 INSTALL_PROGRAM:=@INSTALL_PROGRAM@
31 INSTALL_SCRIPT:=@INSTALL_SCRIPT@
32 INSTALL_DATA:=@INSTALL_DATA@
33
34 prefix:=$(DESTDIR)@prefix@
35 exec_prefix:=@exec_prefix@
36 sbindir:=@sbindir@
37 sysconfdir:=$(DESTDIR)@sysconfdir@
38 datarootdir:=@datarootdir@
39 transform:=@program_transform_name@
40 mandir:=@mandir@
41
42 ALL_CFLAGS:=@DEFS@ -I$(srcdir) -I. $(CFLAGS) $(EXTRA_CFLAGS)
43 CPPFLAGS:=@CPPFLAGS@ -DDATAROOTDIR='"$(datarootdir)"' $(EXTRA_CPPFLAGS)
44 LDFLAGS:=@LDFLAGS@ $(EXTRA_LDFLAGS)
45 LDLIBS:=@LIBS@ $(EXTRA_LDLIBS)
46
47 TARGETS:=secnet
48
49 OBJECTS:=secnet.o util.o conffile.yy.o conffile.tab.o conffile.o modules.o \
50         resolver.o random.o udp.o site.o transform-cbcmac.o transform-eax.o \
51         comm-common.o polypath.o \
52         netlink.o rsa.o dh.o serpent.o serpentbe.o \
53         md5.o sha512.o tun.o slip.o sha1.o ipaddr.o log.o \
54         process.o @LIBOBJS@ \
55         hackypar.o
56 # version.o is handled specially below and in the link rule for secnet.
57
58 PYMODULES := ipaddrset.py argparseactionnoyes.py
59
60 TEST_OBJECTS:=eax-aes-test.o eax-serpent-test.o eax-serpentbe-test.o \
61                 eax-test.o aes.o
62
63 ifeq (version.o,$(MAKECMDGOALS))
64 OBJECTS:=
65 TEST_OBJECTS:=
66 endif
67
68 &OBJECTS += $(OBJECTS) $(TEST_OBJECTS)
69 &:include subdirmk/cdeps.sd.mk
70
71 STALE_PYTHON_FILES=     $(foreach e, py pyc, \
72                         $(foreach p, /usr /usr/local, \
73                         $(foreach l, ipaddr, \
74                         $(DESTDIR)$p/share/secnet/$l.$e \
75                         )))
76
77 %.c:    %.y
78
79 %.yy.c: %.fl
80         flex --header=$*.yy.h -o$@ $<
81
82 %.tab.c %.tab.h:        %.y
83         bison -d -o $@ $<
84
85 %.o: %.c conffile.yy.h
86         $(CC) $(CPPFLAGS) $(ALL_CFLAGS) $(CDEPS_CFLAGS) -c $< -o $@
87
88 all::   $(TARGETS)
89
90 ${srcdir}/config.h.in: configure.ac
91         cd ${srcdir} && autoheader
92         touch $@
93
94 MAKEFILE_TEMPLATES += config.h.in
95 CONFIG_STATUS_OUTPUTS += config.h
96
97 # Manual dependencies section
98 conffile.yy.c:  conffile.fl conffile.tab.c
99 conffile.yy.h:  conffile.yy.c
100 conffile.tab.c: conffile.y
101 # End of manual dependencies section
102
103 conffile.yy.o: ALL_CFLAGS += -Wno-sign-compare
104
105 secnet: $(OBJECTS)
106         $(MAKE) version.o # *.o $(filter-out %.o, $^)
107         $(CC) $(LDFLAGS) $(ALL_CFLAGS) -o $@ $(OBJECTS) version.o $(LDLIBS)
108 # We (always) regenerate the version, but only if we regenerate the
109 # binary.  (This is necessary as the version string is can depend on
110 # any of the source files, eg to see whether "+" is needed.)
111
112 ifneq (,$(wildcard .git/HEAD))
113 # If we have (eg) committed, relink and thus regenerate the version
114 # with the new info from git describe.
115 secnet: Makefile .git/HEAD $(shell sed -n 's#^ref: #.git/#p' .git/HEAD)
116 secnet: $(wildcard .git/packed-refs)
117 endif
118
119 TESTDIRS=stest mtest
120
121 &TARGETS_check = eax-aes-test.confirm eax-serpent-test.confirm \
122         eax-serpentbe-test.confirm ipaddrset.confirm
123
124 &TARGETS_fullcheck += $(&TARGETS_check)
125 &TARGETS_fullcheck += msgcode-test.confirm
126
127 recheck:
128         rm -f $(&TARGETS_check)
129         rm -rf $(addsuffix /d-*, $(TESTDIRS))
130         $(MAKE) check
131
132 .PHONY: FORCE
133 version.c: FORCE
134         echo "#include \"secnet.h\"" >$@.new
135         @set -ex; if test -e .git && type -p git >/dev/null; then \
136                 v=$$(git describe --match 'v*'); v=$${v#v}; \
137                 if ! git diff --quiet HEAD; then v="$$v+"; fi; \
138         else \
139                 v="$(VERSION)"; \
140         fi; \
141         echo "char version[]=\"secnet $$v\";" >>$@.new
142         mv -f $@.new $@
143
144 eax-%-test: eax-%-test.o eax-test.o %.o
145         $(CC) $(LDFLAGS) $(ALL_CFLAGS) -o $@ $^
146
147 eax-%-test.confirm: eax-%-test eax-%-test.vectors
148         ./$< <$(srcdir)/eax-$*-test.vectors >$@.new
149         mv -f $@.new $@
150
151 msgcode-test: msgcode-test.o
152         $(CC) $(LDFLAGS) $(ALL_CFLAGS) -o $@ $^
153
154 msgcode-test.confirm: msgcode-test
155         ./msgcode-test
156         touch $@
157
158 ipaddrset.confirm: ipaddrset-test.py ipaddrset.py ipaddrset-test.expected
159         $(srcdir)/ipaddrset-test.py >ipaddrset-test.new
160         diff -u $(srcdir)/ipaddrset-test.expected ipaddrset-test.new
161         touch $@
162
163 .PRECIOUS: eax-%-test
164
165 installdirs:
166         $(INSTALL) -d $(prefix)/share/secnet $(sbindir)
167         $(INSTALL) -d $(mandir)/man8
168         $(INSTALL) -d $(datarootdir)/secnet
169
170 install: installdirs
171         set -e; ok=true; for f in $(STALE_PYTHON_FILES); do \
172                 if test -e $$f; then \
173                         echo >\&2 "ERROR: $$f still exists "\
174                                 "- try \`make install-force'"; \
175                         ok=false; \
176                 fi; \
177         done; \
178         $$ok
179         $(INSTALL_PROGRAM) secnet $(sbindir)/`echo secnet|sed '$(transform)'`
180         $(INSTALL_PROGRAM) ${srcdir}/make-secnet-sites $(sbindir)/`echo make-secnet-sites|sed '$(transform)'`
181         set -e; for m in $(PYMODULES); do \
182                 $(INSTALL_DATA) ${srcdir}/$$m $(prefix)/share/secnet/$$m; \
183                 done
184         $(INSTALL_SCRIPT) ${srcdir}/polypath-interface-monitor-linux \
185                 $(datarootdir)/secnet/.
186         $(INSTALL_DATA) ${srcdir}/secnet.8 $(mandir)/man8/secnet.8
187
188 install-force:
189         rm -f $(STALE_PYTHON_FILES)
190         $(MAKE) install
191
192 clean::
193         $(RM) -f *.o *.yy.[ch] *.tab.[ch] $(TARGETS) core version.c
194         $(RM) -f *.pyc *~ eax-*-test.confirm eax-*-test
195         $(RM) $(&CLEAN)
196         $(RM) -rf __pycache__
197         $(RM) -f msgcode-test.confirm msgcode-test
198
199 realclean::     clean
200         $(RM) -f *~ Makefile config.h \
201         config.log config.status config.cache \
202         config.stamp Makefile.bak
203
204 distclean::     realclean
205
206 include subdirmk/regen.mk
207
208 # Release checklist:
209 #
210 #  0. Use this checklist from Subdir.sd.mk
211 #
212 #  1. Check that the tree has what you want
213 #
214 #  2. Update changelog:
215 #         gbp dch --since=<PREVIOUS VERSION>
216 #     and then edit debian/changelog.
217 #
218 #  3. Update VERSION (in this file, above) and
219 #     finalise debian/changelog (removing ~ from version) and commit.
220 #
221 #  4. Build source and binaries:
222 #       dgit -wgf sbuild -A -c stretch -j8
223 #
224 #  5. dpkg -i on zealot just to check
225 #       dpkg -i ~ian/things/Fvpn/bpd/secnet_${VERSION}_amd64.deb
226 #
227 #  6. run it on chiark
228 #     check we can still ping davenant and chiark
229 #
230 #  7. Make git tag and source tarball signature:
231 #       git-tag -u general -m "secnet $VERSION" -s v${VERSION//\~/_}
232 #       gpg -u general --detach-sign ../bpd/secnet_$VERSION.tar.gz
233 #
234 #  8. Publish the branch and distriubtion files:
235 #       git-push origin v${VERSION//\~/_} v${VERSION//\~/_}~0:master
236 #       dcmd rsync -v ../bpd/secnet_${VERSION}_multi.changes chiark:/home/ianmdlvl/public-html/secnet/download/
237 #
238 #  9. Sort out html.  On chiark as user secnet:
239 #       cd ~secnet/public-html/release/
240 #       mkdir $VERSION
241 #       cd $VERSION
242 #       ln -s /home/ianmdlvl/public-html/secnet/download/secnet?$VERSION* .
243 #       ln -sfn $VERSION ../current
244 #
245 # 10. write and post a release announcement
246 #       cd ../bpd
247 #       dcmd sha256sum secnet_${VERSION}_multi.changes
248 #       ...
249 #       gpg --clearsign ../release-announcement
250 #       rsync -vP ../release-announcement.asc c:mail/d/
251 #
252 # 11. bump changelog version in master, to new version with ~