-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.sh
executable file
·408 lines (373 loc) · 8.16 KB
/
Build.sh
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/bin/sh
# This script is the entry point for the Fiji Build
#
# Call it without parameters to build everything or
# with the filenames of the .jar files to be built
set -a
unset CDPATH
CWD="$(dirname "$0")" || {
echo "Huh? Cannot cd to $(dirname "$0")" >&2
exit 1
}
# MinGW does not necessarily have dirname.exe
dirname () {
case "$1" in
*/*)
echo ${1%/*}
;;
*\\*)
echo ${1%\\*}
;;
*)
echo .
;;
esac
}
get_java_home () {
if test -d "$JAVA_HOME"
then
echo "$JAVA_HOME"
else
if test -n "$java_submodule" && test -d "$CWD/java/$java_submodule"
then
echo "$CWD/java/$java_submodule/$(ls -t "$CWD/java/$java_submodule" | head -n 1)/jre"
fi
fi
}
# platform-specific stuff
PATHSEP=:
UNAME_S="$(uname -s)"
LAUNCHER=bin/ImageJ.sh
FIJILAUNCHER=
case "$UNAME_S" in
Darwin)
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
java_submodule=macosx-java3d
case "$(uname -r)" in
8.*) platform=tiger;;
*) platform=macosx;;
esac
exe=
LAUNCHER=Contents/MacOS/ImageJ-$platform
FIJILAUNCHER=Contents/MacOS/fiji-$platform
;;
Linux)
case "$(uname -m)" in
x86_64)
platform=linux64
java_submodule=linux-amd64
;;
*) platform=linux32
java_submodule=linux
;;
esac
exe=
LAUNCHER=ImageJ-$platform
FIJILAUNCHER=fiji-$platform
FIJILAUNCHER=${FIJILAUNCHER%32}
;;
MINGW*|CYGWIN*)
CWD="$(cd "$CWD" && pwd)"
PATHSEP=\;
case "$PROCESSOR_ARCHITEW6432" in
'') platform=win32; java_submodule=$platform;;
*) platform=win64; java_submodule=$platform;;
esac
exe=.exe
LAUNCHER=ImageJ-$platform.exe
FIJILAUNCHER=fiji-$platform.exe
;;
FreeBSD)
platform=freebsd
if test -z "$JAVA_HOME"
then
JAVA_HOME=/usr/local/jdk1.6.0/jre
export JAVA_HOME
fi
if ! test -f "$JAVA_HOME/jre/lib/ext/vecmath.jar" &&
! test -f "$JAVA_HOME/lib/ext/vecmath.jar"
then
echo "You are missing Java3D. Please install with"
echo ""
echo " sudo portinstall java3d"
echo ""
echo "(This requires some time)"
exit 1
fi
;;
*)
platform=
TOOLS_JAR="$(ls -t /usr/jdk*/lib/tools.jar \
/usr/local/jdk*/lib/tools.jar 2> /dev/null |
head -n 1)"
test -z "$TOOLS_JAR" ||
export TOOLS_JAR
;;
esac
# Java
test -n "$platform" &&
test -z "$JAVA_HOME" &&
JAVA_HOME="$(get_java_home)"
# need to clone java submodule
test -z "$platform" ||
test -f "$JAVA_HOME/lib/tools.jar" || test -f "$JAVA_HOME/../lib/tools.jar" ||
test -f "$CWD"/java/"$java_submodule"/Home/lib/ext/vecmath.jar || {
echo "No JDK found; cloning it"
JAVA_SUBMODULE=java/$java_submodule
: jump through hoops to enable a shallow clone of the JDK
git submodule init "$JAVA_SUBMODULE" && (
URL="$(git config submodule."$JAVA_SUBMODULE".url)" &&
case "$URL" in
[email protected]:/srv/git/*)
URL="git://fiji.sc/${URL#[email protected]:/srv/git/}"
;;
esac &&
mkdir -p "$JAVA_SUBMODULE" &&
cd "$JAVA_SUBMODULE" &&
git init &&
git remote add -t master origin "$URL" &&
git fetch --depth 1 &&
git reset --hard origin/master
) || {
echo "Could not clone JDK" >&2
exit 1
}
}
case "$JAVA_HOME" in
[A-Z]:*)
# assume this is MSys
JAVA_HOME="$(cd "$JAVA_HOME" && pwd)" ||
unset JAVA_HOME
;;
esac
test -n "$JAVA_HOME" &&
test -d "$JAVA_HOME" ||
for d in java/$java_submodule/*
do
test "$d/jre" || continue
if test -z "$JAVA_HOME" || test "$d" -nt "$JAVA_HOME"
then
JAVA_HOME="$CWD/$d/jre"
fi
done
if test -d "$JAVA_HOME"
then
if test -d "$JAVA_HOME/jre"
then
JAVA_HOME="$JAVA_HOME/jre"
fi
export PATH="$JAVA_HOME/bin:$PATH"
fi
# make sure java is in the PATH
PATH="$PATH:$(get_java_home)/bin:$(get_java_home)/../bin"
export PATH
# Thanks, MacOSX (or for that matter, BSD), and Windows, for easy, standard
# ways to get the mtime of a file.
get_mtime () {
stat -c %Y "$1"
}
# JAVA_HOME needs to be a DOS path for Windows from here on
case "$UNAME_S" in
MINGW*)
export JAVA_HOME="$(cd "$JAVA_HOME" && pwd -W)"
get_mtime () {
date -r "$1" +%s
}
;;
CYGWIN*)
export JAVA_HOME="$(cygpath -d "$JAVA_HOME")"
;;
Darwin*)
get_mtime () {
stat -f %m "$1"
}
;;
esac
# Figure out whether $2 (the destination) is newer than $1 (the source).
# If $2 is a SNAPSHOT .jar, must not be older than a day, either.
#
# This function is mainly used to test whether something is older than
# Build.sh and hence needs to be updated.
uptodate () {
test -s "$2" &&
test "$2" -nt "$1" &&
case "$2" in
*-SNAPSHOT.jar)
test "$(($(get_mtime "$2")-$(date +%s)))" -gt -86400
;;
esac
}
# we need an absolute CWD from now on
case "$CWD" in
[A-Z]:*|/*)
# is already absolute
;;
*)
CWD="$(cd "$CWD" && pwd)"
;;
esac
# pseudo-Maven (thanks to SciJava's maven-helper)
ARGV0="$CWD/$0"
MAVEN_HELPER="$CWD/bin/maven-helper.sh"
MAVEN_HELPER_URL="https://raw.github.com/scijava/scijava-scripts/master/maven-helper.sh"
force_update=
maven_helper () {
uptodate "$ARGV0" "$MAVEN_HELPER" || {
force_update=t
if ! curl -fsL "$MAVEN_HELPER_URL" > "$MAVEN_HELPER"
then
rm "$MAVEN_HELPER"
echo "Could not find $MAVEN_HELPER!" >&2
exit 1
fi
}
test $# = 0 ||
sh -$- "$MAVEN_HELPER" "$@"
}
maven_update () {
for gav in "$@"
do
artifactId="${gav#*:}"
version="${artifactId#*:}"
artifactId="${artifactId%%:*}"
path="jars/$artifactId-$version.jar"
test -z "$force_update" ||
rm -f "$path"
(cd "$CWD"
test -f jars/"$artifactId".jar && rm jars/"$artifactId".jar
for file in jars/"$artifactId"-[0-9]*.jar
do
test "a$file" = a"$path" && continue
test -f "$file" || continue
rm "$file"
done
uptodate "$ARGV0" "$path" && continue
echo "Downloading $gav" >&2
(cd jars/ && maven_helper install "$gav") || exit
if test ! -f "$path"
then
echo "Failure to download $path" >&2
exit 1
fi
uptodate "$ARGV0" "$path" ||
touch "$path")
done
}
update_launcher () {
case "$LAUNCHER" in
bin/ImageJ.sh)
test -z "$exe" || rm -f "$CWD/fiji$exe"
uptodate "$ARGV0" "$CWD/fiji" || {
cat > "$CWD/fiji" << EOF
#!/bin/sh
exec "$CWD/$LAUNCHER" "$@"
EOF
chmod a+x "$CWD/fiji"
}
;;
*)
uptodate "$ARGV0" "$CWD/$LAUNCHER" ||
(cd $CWD &&
sh -$- bin/download-launchers.sh release $platform)
;;
esac
test -z "$FIJILAUNCHER" ||
test ! -f "$CWD/$FIJILAUNCHER" ||
rm "$CWD/$FIJILAUNCHER"
}
# make sure that javac and minimaven are up-to-date
JAVAC_VERSION="$(maven_helper latest-version sc.fiji:javac)" || exit
SCIJAVA_COMMON_VERSION="$(maven_helper \
property-from-pom "$CWD/pom.xml" scijava-common.version)" || exit
MINIMAVEN_VERSION="$(maven_helper \
property-from-pom "$CWD/pom.xml" minimaven.version)" || exit
maven_update sc.fiji:javac:$JAVAC_VERSION \
org.scijava:scijava-common:$SCIJAVA_COMMON_VERSION \
org.scijava:minimaven:$MINIMAVEN_VERSION
# Avoid confusing ij-minimaven (obsolete) with minimaven (current)
for f in "$CWD"/jars/ij-minimaven-*.jar
do
test ! -f "$f" || rm "$f"
done
# command-line options
OPTIONS="-Dimagej.app.directory=\"$CWD\""
while test $# -gt 0
do
case "$1" in
verbose=*)
OPTIONS="$OPTIONS -Dminimaven.verbose=true"
;;
-D*)
OPTIONS="$OPTIONS $1"
;;
*=*)
OPTIONS="$OPTIONS -D$1"
;;
--)
shift
break
;;
-*)
echo "Invalid option: $1" >&2
exit 1
;;
*)
break
;;
esac
shift
done
# handle targets
if test $# = 0 || test "run" = "$*"
then
eval sh -$- "$CWD/bin/ImageJ.sh" --mini-maven "$OPTIONS" install ||
exit
update_launcher
for name in fiji ImageJ
do
uptodate "$LAUNCHER" "$name$exe" ||
cp "$LAUNCHER" "$name$exe"
done
else
for name in "$@"
do
case "$name" in
fiji|ImageJ)
update_launcher ||
exit
uptodate "$LAUNCHER" "$name$exe" ||
cp "$LAUNCHER" "$name$exe"
continue
;;
misc/headless.jar)
sh -$- "$CWD/bin/ImageJ.sh" \
"$CWD/bin/write-headless-jar.bsh" \
"$CWD/misc/headless.jar" ||
exit
continue
;;
clean)
eval sh -$- \"$CWD/bin/ImageJ.sh\" --mini-maven \
"$OPTIONS" clean ||
exit
continue
;;
esac
artifactId="${name##*/}"
artifactId="${artifactId%.jar}"
artifactId="${artifactId%%-[0-9]*}"
case "$name" in
*-rebuild)
artifactId=${artifactId%-rebuild}
artifactId="${artifactId%.jar}"
eval sh -$- "$CWD/bin/ImageJ.sh" --mini-maven \
"$OPTIONS" -DartifactId="$artifactId" \
-- clean ||
exit
;;
esac
eval sh -$- "$CWD/bin/ImageJ.sh" --mini-maven \
"$OPTIONS" -DartifactId="$artifactId" -- install ||
exit
done
fi