-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·191 lines (154 loc) · 3.66 KB
/
make.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
#!/bin/sh
# Copyright 2019 Michael J. Walsh
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Functions
compile_java()
{
echo Running Java Compiler...
mkdir -p build && javac -d ./build Lemmini.java
if [ "$?" != "0" ]; then
echo Build Failed
exit 1
fi
}
make_jar()
{
if [ -f Lemmini.jar ]; then
rm Lemmini.jar
fi
if ! [ -d build ]; then
compile_java
fi
echo Making Jar File...
jar cfe Lemmini.jar Lemmini -C build . -C . background.gif crc.ini disclaimer.htm extract.ini lemmini.png LemminiIcon.png patch
if [ "$?" != "0" ]; then
echo Failed to make jar
exit 1
fi
}
run_java()
{
if ! [ -d build ]; then
compile_java
fi
echo Running Java Code...
java -cp ".:build" Lemmini
}
make_mac_app()
{
if [ -d Lemmini.app ]; then
rm -fR Lemmini.app
fi
if [ -d tmpapp ]; then
rm -fR tmpapp
fi
if ! [ -f Lemmini.jar ]; then
if ! [ -f build/Lemmini.class ]; then
compile_java
fi
make_jar
fi
echo Making Mac App...
mkdir -p tmpapp/Contents/MacOS
mkdir tmpapp/Contents/Resources
cp Info.plist tmpapp/Contents/
cp Lemmini.icns tmpapp/Contents/Resources/
mv Lemmini.jar tmpapp/Contents/Resources/
cat <<'EOF' > tmpapp/Contents/MacOS/Lemmini
#!/bin/sh
FOO=$(dirname "$0")
cd "$FOO/../Resources"
msg=$(java "-Xdock:icon=Lemmini.icns" -jar Lemmini.jar 2>&1 )
if [ $? -eq 0 ]
then
exit 0
fi
osascript - "$msg" <<'EOS'
on run argv
display alert (item 1 of argv) as critical buttons {"Ok"}
end run
EOS
exit 1
EOF
chmod 755 tmpapp/Contents/MacOS/Lemmini
mv tmpapp Lemmini.app
}
install_mac_app()
{
if ! [ -d Lemmini.app ]; then
make_mac_app
fi
echo Installing Mac App...
mv Lemmini.app /Applications/ || echo Failed to move app to /Applications/
}
make_clean()
{
echo Cleaning Install directory...
if [ -d build ]; then rm -fR build; fi
if [ -f Lemmini.jar ]; then rm Lemmini.jar; fi
if [ -d Lemmini.app ]; then rm -fR Lemmini.app; fi
if [ -d tmpapp ]; then rm -fR tmpapp; fi
}
print_usage()
{
cat << EOF
Usage: ./make.sh command
All commands complete any required earlier steps, with the effect that a
./make install will compile the java code, make a jar file, put it in an
app wrapper and move the app to the Applications folder.
Main Commands:
compile Compile the java code
jar Make a jar file
clean Delete the files and folders creeated by this script (if any)
Non including the installed application.
Mac Commands:
app Make a simple mac app wrapper for the jar
install Move the app to the /Applications folder
Other Commands:
test Delete the existing build, compile and run
run Compile (if necessary) and run
EOF
}
# main
system=`uname`
if [ "$#" = "0" ]; then
print_usage
exit 0
fi
if [ "$1" = "run" ]; then
run_java
elif [ "$1" = "jar" ]; then
make_jar
elif [ "$1" = "app" ]; then
if [ "$system" = "Darwin" ]; then
make_mac_app
else
echo This function is only supported on Mac
fi
elif [ "$1" = "compile" ]; then
compile_java
elif [ "$1" = "test" ]; then
compile_java
run_java
elif [ "$1" = "clean" ]; then
make_clean
elif [ "$1" = "install" ]; then
if [ "$system" = "Darwin" ]; then
install_mac_app
else
echo This function is only supported on Mac
fi
else
print_usage
fi