forked from apple/turicreate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·192 lines (152 loc) · 4.83 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
#!/bin/bash -e
function print_help {
echo "Configures and builds a specified target."
echo
echo "Usage: ./build.sh <target> [options] "
echo
echo "Values for <target>: "
echo
echo " python-egg Build python egg (default)."
echo
echo "Common Options:"
echo " --target-dir, -t The target directory to install artifacts to."
echo " default: `pwd`/targets."
echo
echo " --release,-r Build in release mode."
echo " --debug,-d Build in debug mode (default)."
echo
echo " --jobs,-j The number of parallel jobs to run."
echo
echo " --cleanup,-c Clean up everything before building."
echo
echo " --skip-configure,-s Skip running ./configure."
echo
echo " -C <option> Option passed to the configure script."
echo
echo " -D <cmake option> Option passed through to the CMake build."
echo
echo "python-egg options"
echo "------------------------------------------------------------------------"
echo
echo " --build-number Set build number. "
echo " Defaults to part of git commit hash. "
echo
echo "Example: ./build.sh python-framework && cp -R targets/TuriCore.framework."
echo
exit 1
} # end of print help
function unknown_target {
echo "Unrecognized target: $1"
echo "To get help, run ./configure --help"
exit 1
} # end of unknown option
function unknown_option {
echo "Unrecognized option: $1"
echo "To get help, run ./configure --help"
exit 1
} # end of unknown option
if [[ ${OSTYPE} == darwin* ]] ; then
apple=1
else
apple=0
fi
# command flag options
target="python-egg"
cleanup=0
skip_configure=0
jobs=4
configure_options=""
cmake_options=""
build_mode="debug"
target_dir=`pwd`/targets
install_sysroot=""
no_sudo=0
copy_links=0
build_number=`git rev-parse --short HEAD || echo "NULL"`
###############################################################################
#
# Parse command line configure flags ------------------------------------------
#
while [ $# -gt 0 ]
do case $1 in
python) target="python";;
python-egg) target="python-egg";;
--cleanup|-c) cleanup=1;;
--skip-configure|-s) skip_configure=1;;
--copy-links) copy_links=1;;
--no-sudo) no_sudo=1 ;;
--build-number=*) build_number=${1##--build-number=} ;;
--build-number) build_number="$2"; shift;;
--target-dir=*) target_dir="${1##--target-dir=}" ;;
--target-dir|-t) target_dir="$2"; shift ;;
--jobs=*) jobs=${1##--jobs=} ;;
--jobs|-j) jobs=$2; shift ;;
--help) print_help; exit 0;;
-C) configure_options="${configure_options} $2"; shift ;;
-D) configure_options="${configure_options} -D $2"; shift ;;
*) unknown_option $1 ;;
esac
shift
done
build_dir=`pwd`/${build_mode}
src_dir=`pwd`
echo "Setting up build:"
echo "build_mode = ${build_mode}"
echo "target_dir = ${target_dir}"
echo "target = ${target}"
echo "build_dir = ${build_dir}"
function run_cleanup {
./configure --cleanup --yes || exit 1
}
function run_configure {
if [[ ${skip_configure} -eq 0 ]] ; then
./configure ${configure_options} $@ || exit 1
else
echo "Skipping configure script as requested."
fi
}
if [[ ${cleanup} -eq 1 ]]; then
run_cleanup
exit 0
fi
function build_python_egg {
run_configure --with-python
install_dir=${target_dir}/python
rm -rf ${target_dir}/python
mkdir -p ${target_dir}/python
bash scripts/make_wheel.sh --skip_test --skip_cpp_test --build_number="$build_number" --num_procs=${jobs} --${build_mode} --target-dir="${install_dir}"
pushd ${build_mode}/src
if [[ $apple -eq 1 ]]; then
find . \(-type f -name '*.dylib' -o -name '*.so'\) -print0 | xargs -0 strip -x -
else
find . -type f -name '*.so' -print0 | xargs -0 strip -s
fi
find . \(-type f -name '*.dylib' -o -name '*.so'\) -print0 | xargs -0 tar cvzf ${install_dir}/shared_objects.tar.gz
}
function prepare_install_directory {
inst_dir=$1
if [[ ! -d $inst_dir ]] ; then
>&2 echo "Install sysroot \"${inst_dir}\" not a valid destination; creating."
mkdir -p ${inst_dir}
if [[ $? -ne 0 ]] ; then
echo "Failure creating destination ${inst_dir}."
exit 1
fi
echo ""
return
fi
if [[ $no_sudo -eq 1 ]] ; then
echo ""
return
fi
_dst_owner=`ls -ld ${inst_dir} | awk '{ print $3 }' || echo ""`
if [[ $_dst_owner == `whoami` ]] ; then
echo ""
else
echo "sudo"
fi
}
case $target in
python-egg) build_python_egg;;
*) echo "NOT IMPLEMENTED" && exit 1;;
esac