-
Notifications
You must be signed in to change notification settings - Fork 7
/
maker_java_v1.2.sh
153 lines (122 loc) · 3.49 KB
/
maker_java_v1.2.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
#!/data/data/com.termux/files/usr/bin/bash
#which java compiler to use
compiler="ecj"
#java launcher to use
launcher="java2"
# name of final binary: put your desired name here
# without extension ".jar", also edit following variables that should not be empty, according to your project
app_name="" #==========must not be empty
main_class="" #========name of java class
#with main(String [] arg) method,
#must not be emty
#verbose flags
dexflag=false
#--no-strict : do not check for java package structure,
#0=enable|otherwise disable
dx_nostrict=0
#run program after build
run_prog=1
project_home_dir='' #points to root dir of project
#must not be empty
#jar libs: colon separated list of java libbraries
#make sure no spaces appear below.
jarlibs=""
#in case if project depends on a nativeLibrary add its path below:
#colon separated paths to shared libs
nativeLibPath=""
#arrays for program arguments and input files
dxargs=( )
compilerargs=( )
launcherargs=( )
sourcefiles=( )
classfiles=( )
#variable to store return values of commands
ret=
#check if ret is non-zero and bail
chkret ( ) {
if [ $ret != 0 ]
then
echo -e "\n\terror occured at $1,abort!"
exit 1
fi
}
#this forces the output to be suppressed
#do SILENT=[non-zero value] to disable redirection
redirect_cmd( ) {
if [ -n "$SILENT" ]; then
"$@" > /dev/null
else
"$@"
fi
}
#go to project_home_dir for processing
#in case if script is called from other dirs
if [ -d "$project_home_dir" ]
then
cd $project_home_dir
else
echo -e "\n===================\tcould not read $project_home_dir \nplz set variables properly"
exit 1
fi
#clean up previous binaries
rm -rf ./bin/*
mkdir ./bin/classes
#process command line args
if [ $# -ne 0 ]
then
while getopts "djlnrsv" option
do
case $option in
j) compilerargs+=( -verbose ) ;;
d) dxargs+=( --verbose ) ;;
n) dx_nostrict=1 ;;
l) launcherargs+=( --verbose ) ;;
s) SILENT=1 ;;
v)
compilerargs+=( -verbose )
dxargs+=( --verbose )
launcherargs+=( --verbose ) ;;
r) run_prog=0 ;;
esac
done
fi
#compile the sourcefiles
cd src
#set up java compiler arguments
compilerargs+=( -d ../bin/classes/ )
compilerargs+=( -warn:none )
#add any jarlib if exists
[[ ! -z $jarlibs ]] && \
compilerargs+=( -classpath "$jarlibs" )
sourcefiles+=( `find . -name '[A-Za-z0-9]*.java' -type f` )
$compiler "${compilerargs[@]}" "${sourcefiles[@]}"
ret=$?
chkret "$compiler : compile time error"
#calling dx : set up arguments
cd ../bin/classes/
#find any classfiles and dirs(expected to be java package stucture)
num_dirs=0
num_dirs=`ls -l|grep ^d|wc -l`
(( $num_dirs > 0 )) && \
classfiles+=(
`find . -maxdepth 1 -type d|cut -d$'\n' -f 2-` ) ||
classfiles+=( `find . -type f -name '*.class'` )
#set up dx arguments
dxargs+=( --dex )
dxargs+=( --output=../"$app_name.jar" )
(( dx_nostrict == 0 )) && dxargs+=( --no-strict )
#dx requires space as delimeter
[[ ! -z $jarlibs ]] && classfiles+=( ${jarlibs//:/ } )
#call it with redirect_cmd to suppress usual
# "processing xyz class" output
redirect_cmd dx "${dxargs[@]}" "${classfiles[@]}"
# if run_prog is non-zero then exit
(( run_prog != 0 )) && exit
#go to project_home_dir -in case if called from other dirs
cd $project_home_dir
#set up launcherargs and call it.
[[ $launcher == "java2" && ! -z $nativeLibPath ]] && \
launcherargs+=( -nlp=$nativeLibPath )
launcherargs+=( -jar ./bin/$app_name.jar )
launcherargs+=( $main_class )
$launcher "${launcherargs[@]}" this_is_an_argument_to_java_program