-
Notifications
You must be signed in to change notification settings - Fork 30
/
Makefile
337 lines (295 loc) · 15.3 KB
/
Makefile
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# Copyright 2002-2011 Nick Mathewson. See LICENSE for licensing information.
# Okay, we'll start with a little make magic. The goal is to define the
# make variable '$(FINDPYTHON)' as a chunk of shell script that sets
# the shell variable '$PYTHON' to a working python2 interpreter.
#
# (This is nontrivial because not all python2 installers install a command
# called 'python2'.)
#
# (If anybody can think of a better way to do this, please let me know.)
# XXXX This fails when PYTHON is set to a version of Python earlier than 1.3
PYTHON_CANDIDATES = python \
python3.0 python3 \
python2p7 python2.7 python2.7x \
python2p6 python2.6 python2.6x \
python2p5 python2.5 python2.5x \
python2p4 python2.4 python2.4x \
python2p3 python2.3 python2.3x \
python2p2 python2.2 python2.2x \
python2p1 python2.1 python2.1x \
python2.0 python2.0x \
python2
FINDPYTHON = \
if [ "x`which which`" = "x" ]; then \
echo "Ouch! I couldn't run 'which' on your system."; \
echo "Please make sure it is there, and try again."; \
exit; \
fi; \
if [ 'x' = "x$$PYTHON" ]; then \
for n in $(PYTHON_CANDIDATES) ; do \
if [ 'x' = "x$$PYTHON" ]; then \
if [ -x "`which $$n 2>&1`" ]; then \
if [ 'x' != "`$$n -V 2>&1 | grep 'Python [23456789]'`x" ]; then\
if [ '1' != "`$$n -c 'import thread; print 1'`" ]; then \
echo "Skipping $$n; no thread support."; \
else \
PYTHON=$$n; \
fi \
else \
echo "Skipping `which $$n`; Not recent enough."; \
fi; \
fi; \
fi; \
done; \
if [ 'x' = "x$$PYTHON" ]; then \
echo "ERROR: couldn't find Python 2 or later (with threads) on PATH as any of ";\
echo " $(PYTHON_CANDIDATES) in PATH"; \
echo " Please install python in your path, or set the PYTHON"; \
echo ' environment variable'; \
exit; \
fi; \
if [ 'x' = "`$$PYTHON -V 2>&1 | grep 'Python [23456789]'`x" ]; then \
echo "WARNING: $$PYTHON doesn't seem to be version 2 or later."; \
echo ' If this fails, please set the PYTHON environment variable.';\
fi \
fi
#
# Here are the real make targets.
#
all: do_build
do_build:
@$(FINDPYTHON); \
echo $$PYTHON setup.py build; \
$$PYTHON -tt setup.py build
clean:
@$(FINDPYTHON); \
echo $$PYTHON -tt setup.py clean; \
$$PYTHON -tt setup.py clean
rm -rf build dist
rm -f MANIFEST
rm -f lib/mixminion/_unittest.py
rm -f lib/mixminion/_textwrap.py
rm -f lib/mixminion/_zlibutil.py
rm -f lib/mixminion/*.pyc
rm -f lib/mixminion/*.pyo
rm -f lib/mixminion/*/*.pyc
rm -f lib/mixminion/*/*.pyo
find . -name '*~' -print0 |xargs -0 rm -f
find . -name '.#*' -print0 |xargs -0 rm -f
find . -name '*.bak' -print0 |xargs -0 rm -f
test:
@$(FINDPYTHON); \
echo $$PYTHON -tt setup.py run --subcommand=unittests; \
$$PYTHON -tt setup.py run --subcommand=unittests
time:
@$(FINDPYTHON); \
echo $$PYTHON setup.py run --subcommand=benchmarks; \
$$PYTHON -tt setup.py run --subcommand=benchmarks
testvectors:
@$(FINDPYTHON); \
echo $$PYTHON setup.py run --subcommand=testvectors; \
$$PYTHON -tt setup.py run --subcommand=testvectors
#======================================================================
# Install target (minimal.)
install: do_build
@$(FINDPYTHON); \
ARGS="install --compile --optimize=1 --force"; \
PREFIXARG=""; \
ROOTARG=""; \
if [ 'x' != "x$(PREFIX)" ] ; then \
PREFIX="$(PREFIX)"; export PREFIX; \
PREFIXARG=--prefix="$(PREFIX)"; \
fi; \
if [ 'x' != "x$(DESTDIR)" ] ; then \
ROOTARG=--root="$(DESTDIR)"; \
fi; \
echo $$PYTHON -tt setup.py $$ARGS $$PREFIXARG $$ROOTARG; \
$$PYTHON -tt setup.py $$ARGS $$PREFIXARG $$ROOTARG
update:
@$(FINDPYTHON); \
PYVER=`$$PYTHON -c 'import sys; print sys.version[:3]'`; \
if [ 'x' = "x$(PREFIX)" ] ; then \
PFX=`$$PYTHON -c 'import sys; print sys.prefix'`; \
LIB=$$PFX/lib/python$$PYVER/site-packages/mixminion; \
else \
LIB=$(PREFIX)/lib/python$$PYVER/site-packages/mixminion; \
fi; \
if [ ! -d $$LIB ] ; then \
echo "Didn't find an existing installation in $$LIB; bailing."; \
elif [ ! -w $$LIB ] ; then \
echo "You don't seem to have write access to $$LIB; bailing."; \
else \
rm -rf $$LIB; \
$(MAKE) install; \
fi
upgrade: update
#======================================================================
# Uninstall target (phony.)
uninstall:
@echo "Sorry, I don't do that yet... but if you run"; \
echo "'make uninstall-help', I might be able to offer some advice."
uninstall-help:
@$(FINDPYTHON); \
PYVER=`$$PYTHON -c 'import sys; print sys.version[:3]'`; \
if [ 'x' = "x$(PREFIX)" ] ; then \
EPFX=`$$PYTHON -c 'import sys; print sys.exec_prefix'`; \
PFX=`$$PYTHON -c 'import sys; print sys.prefix'`; \
BIN=$$EPFX/bin/mixminon; \
LIB=$$PFX/lib/python$$PYVER/site-packages/mixminion; \
else \
BIN=$(PREFIX)/bin/mixminion; \
LIB=$(PREFIX)/lib/python$$PYVER/site-packages/mixminion; \
fi; \
echo "Sorry, but I'm too cowardly to remove files for you."; \
echo "To remove your installation of mixminion, I think you should"; \
echo "delete:"; \
echo " * The file $$BIN"; \
echo " * All the files under $$LIB"; \
echo; \
if [ 'x' = "x$(PREFIX)" ] ; then \
echo "(But if you installed with 'make install PREFIX=XX', you"; \
echo "should run 'make uninstall-help PREFIX=XX' to get the real"; \
echo "story.)"; \
else \
echo "(But if you installed without PREFIX, you should run"; \
echo "'make uninstall-help' without PREFIX to get the real story)";\
fi
#======================================================================
# Source dist target
sdist: clean
@$(FINDPYTHON); \
echo $$PYTHON -tt setup.py sdist; \
$$PYTHON -tt setup.py sdist; \
VERSION=`ls dist/*.tar.gz | sed -e s/.*-// | sed -e s/.tar.gz//`; \
cp README dist/README-$$VERSION
signdist: sdist
gpg -ba dist/Mixminion*.tar.gz
#======================================================================
# Packaging related targets
# create a Debian package
# requires you installed at least build-essential, devscripts,
# fakeroot, and whatever is listed as Build-Depends: in debian/control.
bdist_debian:
if [ -e debian/changelog.shipped ]; then mv debian/changelog.shipped debian/changelog; fi
cp debian/changelog debian/changelog.shipped
VERSION=`grep '^VERSION = ' setup.py | sed -e "s/.*'\(.*\)'.*/\1/"`; \
debchange \
--newversion $$VERSION'-0.custom'\
--distribution unofficial \
--preserve \
'Build unofficial debian package.'
#dpkg-buildpackage -rfakeroot -uc -us
bdist_wininst:
@$(FINDPYTHON); \
echo $$PYTHON -tt setup.py bdist_wininst; \
$$PYTHON -tt setup.py bdist_wininst
bdist_py2exe:
@$(FINDPYTHON); \
VERSION=`grep '^VERSION = ' setup.py | sed -e "s/.*'\(.*\)'.*/\1/"`; \
rm -rf dist Mixminion-$$VERSION; \
echo $$PYTHON -tt setup.py py2exe; \
$$PYTHON -tt setup.py py2exe; \
mv dist Mixminion-$$VERSION; \
zip -9 Mixminion-$$VERSION.win32.zip Mixminion-$$VERSION/* \
Mixminion-$$VERSION/lib/*
#======================================================================
# OpenSSL-related targets
OPENSSL_URL = http://www.openssl.org/source/openssl-1.0.0e.tar.gz
OPENSSL_FILE = openssl-1.0.0e.tar.gz
OPENSSL_SRC = ./contrib/openssl
OPENSSL_SHA = 235eb68e5a31b0f7a23bc05f52d7a39c596e2e69
# I have verified that the above digest matches the tarball signed by the
# openssl maintainer. If you are paranoid, you should doublecheck. -Nick.
download-openssl:
@if [ -x "`which wget 2>&1`" ] ; then \
cd contrib; wget $(OPENSSL_URL); \
elif [ -x "`which curl 2>&1`" ] ; then \
cd contrib; curl -o $(OPENSSL_FILE) $(OPENSSL_URL); \
else \
echo "I can't find wget or curl. Please download $(OPENSSL_URL)";\
echo "and put the file in ./contrib"; \
fi
destroy-openssl:
cd ./contrib; \
rm -rf `ls -d openssl* | grep -v .tar.gz`
build-openssl: $(OPENSSL_SRC)/libcrypto.a
$(OPENSSL_SRC)/libcrypto.a: $(OPENSSL_SRC)/config
cd $(OPENSSL_SRC); \
./config; \
make
./contrib/openssl/config:
$(MAKE) unpack-openssl
# This target assumes you have openssl-foo.tar.gz in contrib, and you
# want to unpack it into ./contrib/openssl-foo, and symlink ./openssl to
# ./openssl-foo.
#
# It checks 1) whether there is a single, unique openssl-foo.tar.gz
# 2) whether contrib/openssl is a real file or directory
unpack-openssl:
@$(FINDPYTHON); \
cd ./contrib; \
if [ -d ./openssl -a ! -h ./openssl ]; then \
echo "Ouch. contrib/openssl seems not to be a symlink: " \
"I'm afraid to delete it." ; \
exit; \
fi; \
if [ -f $(OPENSSL_FILE) ]; then \
SHA=`$$PYTHON -c "import sha;print sha.sha(open(\"$(OPENSSL_FILE)\").read()).hexdigest()"`; \
if [ "$$SHA" != "$(OPENSSL_SHA)" ]; then \
echo "Unexpected digest on $(OPENSSL_FILE)!"; \
exit; \
fi; \
echo "Digest on $(OPENSSL_FILE) is correct."; \
else \
echo "Found unexpected version of $(OPENSSL_FILE); not checking digest."; \
fi; \
TGZ=`ls openssl-*.tar.gz` ; \
if [ "x$$TGZ" = "x" ]; then \
echo "I didn't find any openssl-*.tar.gz in ./contrib/"; \
echo "Try 'make download-openssl'."; \
exit; \
fi; \
for n in $$TGZ; do \
if [ $$n != "$$TGZ" ]; then \
echo "Found more than one openssl-*.tar.gz in ./contrib/"; \
echo "(Remove all but the most recent.)"; \
exit; \
fi; \
done; \
UNPACKED=`echo $$TGZ | sed -e s/.tar.gz$$//`; \
echo "Unpacking $$TGZ..."; \
gunzip -c $$TGZ | tar xf -; \
if [ ! -d $$UNPACKED ]; then \
echo "Oops. I unpacked $$TGZ, but didn't find $$UNPACKED."; \
fi; \
rm -f ./openssl; \
ln -sf $$UNPACKED openssl
#======================================================================
# Coding style targets
pychecker: do_build
( export PYTHONPATH=.; cd build/lib*; pychecker -F ../../pycheckrc \
./mixminion/*.py ./mixminion/*/*.py )
lines:
@$(FINDPYTHON); \
$$PYTHON -tt etc/countlines.py src/*.[ch] lib/mixminion/[A-Z_]*.py \
lib/mixminion/*/*.py --noncode lib/mixminion/[a-z]*.py
xxxx:
find lib src \( -name '*.py' -or -name '*.[ch]' \) -print0 \
| xargs -0 grep 'XXXX\|FFFF\|DOCDOC\|????'
xxxx007:
find lib src \( -name '*.py' -or -name '*.[ch]' \) -print0 \
| xargs -0 grep 'XXXX00[1-7]\|FFFF00[1-7]\|DOCDOC\|????00[1-7]'
eolspace:
perl -i.bak -pe 's/\s+\n$$/\1\n/;' ACKS HACKING LICENSE HISTORY \
MANIFEST.in \
Makefile README HISTORY TODO pycheckrc setup.py src/*.[ch] \
lib/mixminion/*.py lib/mixminion/*/*.py
update-copyright:
touch -t 200401010000 jan1
find . -type f -newer jan1 | xargs perl -i.bak -pe \
's/Copyrigh[t] 2002.* Nick Mathewson/Copyright 2002-2011 Nick Mathewson/;'
find . -type f -newer jan1 | xargs perl -i.bak -pe \
's/Copyrigh[t] 2003.* Nick Mathewson/Copyright 2003-2011 Nick Mathewson/;'
longlines:
find lib src \( -name '*.py' -or -name '*.[ch]' \) -print0 \
| xargs -0 grep '^................................................................................'