-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
326 lines (227 loc) · 11 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
# Intention is to be able to build from the source distribution into binary
# distributions in one step. Ideally including testing.
#################################################################
#################################################################
# VARIABLES
#################################################################
#################################################################
# Current version:
ver = 4
# Whether to build dependencies from source or not
deps_from = download
# deps_from = source
#################################################################
# Variables to let 'make' function.
#################################################################
# The directory names to use in the binary package
packagedir = kSNP$(ver)_Linux_package
binarydir = $(packagedir)/kSNP$(ver)
all_products = kSNP$(ver)_Source.zip kSNP$(ver).zip Examples.zip
# Define the pythonbin target as the compiled binary for ever .py file,
# stored in the binaries directory
python = $(wildcard *.py)
pythonbin = $(patsubst %.py,binaries/%,$(wildcard *.py))
pythonlib = ksnpConfig.py ksnpCache.py
# Likewise perlbin
perl = $(wildcard *.pl)
perlbin = $(patsubst %.pl,binaries/%,$(wildcard *.pl))
shellscripts = binaries/kSNP4 binaries/buildtree binaries/extractNthLocus4 binaries/selectNodeAnnotations4 binaries/installkSNP binaries/getFastaGenomes binaries/getFastaGenomes_python binaries/get_genbank_file4
dependencies = binaries/FastTreeMP binaries/parsimonator binaries/mummer binaries/consense binaries/jellyfish
installer = binaries/installkSNP
download_cache = ~/kSNP/Build
#################################################################
# Which targets are "phony" and should be built even if the
# target exists?
#################################################################
.PHONY: clean distclean all testrun testclean
#################################################################
# Default build target
#################################################################
all: $(all_products)
#################################################################
# Other build target
#################################################################
testrun: RunExamples.sh Examples all
PATH=`pwd`/binaries:"${PATH}" ./RunExamples.sh
testclean:
rm -r tmp.*
#################################################################
#################################################################
# BUILD PACKAGES FOR DISTRIBUTION
#################################################################
#################################################################
# The documents that are to be included in the binary and source distributions.
docs: binaries/THE\ BSD\ OPENSOURCE\ LICENSE.pdf binaries/kSNP3.021\ User\ Guide\ .pdf
# Note that packaging the source depends on the build and packaging of the binaries
# being successful.
# I think this defaults to the revision currently checked out, minus local
# revisions, and excludes the .hg directory to avoid sharing extra detail
kSNP$(ver)_Source.zip: kSNP$(ver)_Source
zip -r $@ $<
kSNP$(ver)_Source: kSNP$(ver).zip
hg archive --exclude ".hg*" $@ || echo "No mercurial available, switching to git"
git clone . $@ && rm -fr $@/.git || echo "No git available. Did mercurial work?"
$(packagedir): $(docs) kSNP$(ver) $(perlbin) $(pythonbin) $(shellscripts) $(dependencies)
mkdir -p $(packagedir)
mkdir -p $(binarydir)
for doc in $(docs) ; do cp $$doc $(packagedir) ; done
for bin in $(perlbin) $(pythonbin) kSNP$(ver) $(shellscripts) ; do cp $$bin $(binarydir) ; done
for dep in $(dependencies) ; do cp $$dep $(binarydir) ; done
cp $(installer) $(packagedir)
kSNP$(ver).zip: $(packagedir)
cd $(packagedir) && zip --symlinks -r ../$@ kSNP$(ver) installkSNP
#################################################################
#################################################################
# BUILD BINARIES / DISTRIBUTION-READY DOCS
#################################################################
#################################################################
# This section is for the building of the binaries for distribution.
# May need separate sections for Mac and Linux? PC builds later?
#################################################################
# Perl
#################################################################
# Build perl scripts into binaries using pp, a tool from CPAN in the PAR::Packer module
binaries/%: %.pl
pp -c -x -o $@ $<
#################################################################
# Python
#################################################################
# Build python binaries using pyinstaller. Wrapped with a temporary directory
# creation and removal to avoid cluttering the working directory. May be more
# efficient to create it and re-use it?
binaries/%: %.py $(pythonlib)
pybuilddir=`mktemp -d` ; \
echo "Build dir: $$pybuilddir" ; \
pyinstaller --workpath "$$pybuilddir" --specpath "$$pybuilddir" --clean --onefile --distpath binaries $< ; \
echo "Removing build directory: $$pybuilddir" ;\
rm -r "$$pybuilddir"
#################################################################
# Shell
#################################################################
$(shellscripts): binaries/%: %
cp $< $@
#################################################################
# Docs
#################################################################
# How to prepare the PDF files to be packaged. Note that we can generate PDF
# from other source if desirable.
binaries/%.pdf : %.pdf
cp "$<" "$@"
#################################################################
# DEPENDENCIES
#################################################################
#
# NOTENOTENOTENOTENOTENOTENOTENOTENOTENOTENOTENOTE
# Files from this section need to be generally cleaned up
# to avoid cluttering the source directory.
# NOTENOTENOTENOTENOTENOTENOTENOTENOTENOTENOTENOTE
#
# This is a process to acquire all of the below dependencies into the current
# directory through another means. Note that this breaks dependency checking,
# which means that if the 'download' value is set for $(deps_from), the
# binaries will be rebuilt _every_time_ because deps_download does not exist.
deps_download: $(download_cache)/kSNP3.1_Linux_package.zip $(download_cache)/jellyfish $(download_cache)/FastTreeMP
cp $(download_cache)/jellyfish . && chmod a+x jellyfish
cp $(download_cache)/FastTreeMP . && chmod a+x FastTreeMP
unzip -j -o $(download_cache)/kSNP3.1_Linux_package.zip kSNP3.1_Linux_package/kSNP3/mummer kSNP3.1_Linux_package/kSNP3/consense \
kSNP3.1_Linux_package/kSNP3/ kSNP3.1_Linux_package/kSNP3/parsimonator
# This triggers rules below.
deps_source: consense mummer jellyfish FastTreeMP parsimonator
echo "Built dependent binaries from source"
deps: $(dependencies)
echo "Dependencies are in place."
$(dependencies): deps_$(deps_from)
cp `basename $@` binaries/
#
# Some (all?) of these dependencies can come from the distro the user is using.
#
# See: apt-get install phylip jellyfish fasttree mummer
#
# Note that consense is not available.
#
# FastTreeMP
# See: http://www.microbesonline.org/fasttree/
FastTreeMP: $(download_cache)/FastTree.c
gcc -DOPENMP -fopenmp -O3 -finline-functions -funroll-loops -Wall -o $@ $< -lm
$(download_cache)/FastTree.c:
mkdir -p $(download_cache)
curl -L "http://www.microbesonline.org/fasttree/FastTree.c" > $@
$(download_cache)/FastTreeMP:
mkdir -p $(download_cache)
curl -L "http://www.microbesonline.org/fasttree/FastTreeMP" > $@
# Jellyfish
# This is available as a package from Debian with the version available on
# GitHub here: https://github.com/gmarcais/Jellyfish/releases/tag/v2.3.0
# It is also available in binary form from GitHub, as well as source. The
# source doesn't build for me, so punting on rebuilding something that we can
# get more easily two other ways.
# Consense
# More info available here: https://evolution.genetics.washington.edu/phylip.html
# See testing here: https://evolution.gs.washington.edu/phylip/doc/consense.html
consense_build = phylip-3.697
consense: $(download_cache)/phylip-3.697.tar.gz
tar -xzf $<
# Patch consense to permit build and to permit longer (200 char in this case) names.
patch -p 0 < consense.patch
cd $(consense_build)/src && make -f Makefile.unx consense
cp $(consense_build)/src/consense binaries/
$(download_cache)/phylip-3.697.tar.gz:
mkdir -p $(download_cache)
curl -L "http://evolution.gs.washington.edu/phylip/download/phylip-3.697.tar.gz" > $@
# Mummer
mummer_build = mummer-4.0.0rc1
mummer: $(download_cache)/mummer-src.tgz
tar -xzf $<
cd $(mummer_build) && autoreconf -fi && ./configure && make mummer
cp $(mummer_build)/.libs/mummer binaries/mummer-bin
cp $(mummer_build)/.libs/libumdmummer.so.0.0.0 binaries/libumdmummer.so.0
echo '#!/bin/bash\nLD_LIBRARY_PATH=`dirname "$${0}"`:$${LD_LIBRARY_PATH} `dirname "$${0}"`/mummer-bin "$${@}"' > "$@"
chmod a+x "$@"
# This is a release candidate, guessing that's why the build doesn't make the standalone binary?
$(download_cache)/mummer-src.tgz:
mkdir -p $(download_cache)
curl -L "https://github.com/mummer4/mummer/releases/download/v4.0.0rc1/mummer-4.0.0rc1.tar.gz" > $@
# Parsimonator
parsimonator_build=Parsimonator-1.0.2-master
parsimonator: $(download_cache)/parsimonator-src.zip
unzip $<
cd $(parsimonator_build)/ && make -f Makefile.gcc
cp $(parsimonator_build)/parsimonator binaries/
rm -r $(parsimonator_build)
$(download_cache)/parsimonator-src.zip:
mkdir -p $(download_cache)
curl -L "https://github.com/stamatak/Parsimonator-1.0.2/archive/refs/heads/master.zip" >$@
jellyfish_build=Jellyfish-2.3.0
jellyfish: $(download_cache)/jellyfish-src.tgz
tar -xf $<
cd $(jellyfish_build) && autoreconf -i && ./configure && make -j 4
cp $(jellyfish_build)/bin/.libs/jellyfish $@
$(download_cache)/jellyfish-src.tgz:
mkdir -p $(download_cache)
curl -L "https://github.com/gmarcais/Jellyfish/releases/download/v2.2.10/jellyfish-2.2.10.tar.gz" >$@
$(download_cache)/jellyfish:
mkdir -p $(download_cache)
curl -L "https://github.com/gmarcais/Jellyfish/releases/download/v2.2.10/jellyfish-linux" >$@
Examples: $(download_cache)/Examples.zip
unzip "$<"
rm -r __MACOSX/
Examples.zip: $(download_cache)/Examples.zip
cp $< $@
$(download_cache)/Examples.zip:
mkdir -p $(download_cache)
curl -L "https://downloads.sourceforge.net/project/ksnp/Examples.zip" >$@
$(download_cache)/kSNP3.1_Linux_package.zip:
mkdir -p $(download_cache)
curl -L "https://downloads.sourceforge.net/project/ksnp/kSNP3.1_Linux_package.zip" >$@
#################################################################
# CLEANLINESS
#################################################################
clean:
rm binaries/* || true
rm $(all_products) || true
rm $(dependencies) || true
rm kSNP$(ver)_Source.zip kSNP$(ver).zip || true
rm -r kSNP$(ver)_Source $(packagedir) || true
distclean: clean
rm parsimonator-src.zip mummer-src.tgz mummer-bin parsimonator consense jellyfish libumdmummer.so.0 mummer phylip-3.697.tar.gz jellyfish-src.tgz FastTree.c Examples.zip || true
rm -r $(mummer_build) $(parsimonator_build) $(consense_build) $(jellyfish_build) __MACOSX Examples __pycache__ || true