forked from dscho/fiji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.sh
executable file
·215 lines (197 loc) · 4.56 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
#!/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
CWD="$(dirname "$0")" || {
echo "Huh? Cannot cd to $(dirname "$0")" >&2
exit 1
}
dirname () {
case "$1" in
*/*)
echo ${1%/*}
;;
*\\*)
echo ${1%\\*}
;;
*)
echo .
;;
esac
}
look_for_tools_jar () {
for d in "$@"
do
test -d "$d" || continue
for j in java default-java
do
test -f "$d/$j/lib/tools.jar" || continue
export TOOLS_JAR="$d/$j/lib/tools.jar"
return
done
done
}
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
}
need_to_build_fake () {
(cd "$CWD" &&
test -f jars/fake.jar || {
echo YesPlease
return
}
for source in $(find src-plugins/fake/ -name \*.java)
do
test "$source" -nt jars/fake.jar && {
echo YesPlease
return
}
done)
return
}
ensure_fake_is_built () {
# test whether we need to build it
test -z "$(need_to_build_fake)" && return
(cd "$CWD" &&
: blow previous builds away
rm -rf src-plugins/fake/target/classes &&
mkdir -p src-plugins/fake/target/classes &&
: compile classes
java -jar precompiled/javac.jar -source 1.5 -target 1.5 -classpath precompiled/javac.jar -d src-plugins/fake/target/classes $(find src-plugins/fake/ -name \*.java) &&
: compile .jar using Fiji Build
java -classpath src-plugins/fake/target/classes"$PATHSEP"precompiled/javac.jar fiji.build.Fake jars/fake.jar-rebuild)
}
PATHSEP=:
UNAME_S="$(uname -s)"
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=;;
Linux)
case "$(uname -m)" in
x86_64)
platform=linux64
java_submodule=linux-amd64
look_for_tools_jar /usr/lib64/jvm /usr/lib/jvm
;;
*) platform=linux32
java_submodule=linux
look_for_tools_jar /usr/lib/jvm
;;
esac; exe=;;
MINGW*|CYGWIN*)
CWD="$(cd "$CWD" && pwd)"
PATHSEP=\;
case "$PROCESSOR_ARCHITEW6432" in
'') platform=win32; java_submodule=$platform;;
*) platform=win64; java_submodule=$platform;;
esac
exe=.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
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
contrib@fiji.sc:/srv/git/*)
URL="git://fiji.sc/${URL#contrib@fiji.sc:/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
: build fake.jar, making sure javac is in the PATH
PATH="$PATH:$(get_java_home)/bin:$(get_java_home)/../bin" \
ensure_fake_is_built || {
echo "Could not build Fiji Build" >&2
exit 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)"
;;
CYGWIN*)
export JAVA_HOME="$(cygpath -d "$JAVA_HOME")"
;;
esac
sh "$CWD/bin/ImageJ.sh" --build "$@"