forked from Project-OSRM/node-osrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·190 lines (167 loc) · 5.51 KB
/
bootstrap.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
#!/bin/bash
set -e
# we pin the mason version to avoid changes in mason breaking builds
MASON_VERSION="3e0cc5a"
if [[ `which pkg-config` ]]; then
echo "Success: Found pkg-config";
else
echo "echo you need pkg-config installed";
exit 1;
fi;
if [[ `which node` ]]; then
echo "Success: Found node";
else
echo "echo you need node installed";
exit 1;
fi;
function dep() {
./.mason/mason install $1 $2
./.mason/mason link $1 $2
}
# Set 'osrm_release' to a branch, tag, or gitsha in package.json
export OSRM_RELEASE=$(node -e "console.log(require('./package.json').osrm_release)")
export CXX=${CXX:-clang++}
export BUILD_TYPE=${BUILD_TYPE:-Release}
export TARGET_DIR=${TARGET_DIR:-$(pwd)/lib/binding}
export OSRM_REPO=${OSRM_REPO:-"https://github.com/Project-OSRM/osrm-backend.git"}
export OSRM_DIR=$(pwd)/deps/osrm-backend-${BUILD_TYPE}
echo
echo "*******************"
echo -e "OSRM_RELEASE set to: \033[1m\033[36m ${OSRM_RELEASE}\033[0m"
echo -e "BUILD_TYPE set to: \033[1m\033[36m ${BUILD_TYPE}\033[0m"
echo -e "CXX set to: \033[1m\033[36m ${CXX}\033[0m"
echo "*******************"
echo
echo
function all_deps() {
dep cmake 3.2.2 &
dep lua 5.3.0 &
dep luabind e414c57bcb687bb3091b7c55bbff6947f052e46b &
dep boost 1.61.0 &
dep boost_libsystem 1.61.0 &
dep boost_libthread 1.61.0 &
dep boost_libfilesystem 1.61.0 &
dep boost_libprogram_options 1.61.0 &
dep boost_libregex 1.61.0 &
dep boost_libiostreams 1.61.0 &
dep boost_libtest 1.61.0 &
dep boost_libdate_time 1.61.0 &
dep expat 2.1.0 &
dep stxxl 1.4.1 &
dep bzip2 1.0.6 &
dep zlib system &
dep tbb 43_20150316 &
wait
}
function move_tools() {
cp -r ${MASON_HOME}/bin/osrm-* "${TARGET_DIR}/"
}
function copy_tbb() {
if [[ `uname -s` == 'Darwin' ]]; then
cp ${MASON_HOME}/lib/libtbb.dylib ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc.dylib ${TARGET_DIR}/
else
cp ${MASON_HOME}/lib/libtbb.so.2 ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc.so.2 ${TARGET_DIR}/
cp ${MASON_HOME}/lib/libtbbmalloc_proxy.so.2 ${TARGET_DIR}/
fi
}
function localize() {
mkdir -p ${TARGET_DIR}
copy_tbb
cp ${MASON_HOME}/bin/lua ${TARGET_DIR}
move_tools
}
function build_osrm() {
if [[ ! -d ${OSRM_DIR} ]]; then
echo "Fresh clone."
mkdir -p ${OSRM_DIR}
git clone ${OSRM_REPO} ${OSRM_DIR}
pushd ${OSRM_DIR}
else
echo "Already cloned, fetching."
pushd ${OSRM_DIR}
git fetch
fi
git checkout ${OSRM_RELEASE}
OSRM_HASH=$(git rev-parse HEAD)
echo
echo "*******************"
echo -e "Using osrm-backend \033[1m\033[36m ${OSRM_HASH}\033[0m"
echo "*******************"
echo
mkdir -p build
pushd build
# put mason installed ccache on PATH
# then osrm-backend will pick it up automatically
export CCACHE_VERSION="3.2.4"
${MASON_DIR}/mason install ccache ${CCACHE_VERSION}
export PATH=$(${MASON_DIR}/mason prefix ccache ${CCACHE_VERSION})/bin:${PATH}
CMAKE_EXTRA_ARGS=""
if [[ ${AR:-false} != false ]]; then
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_AR=${AR}"
fi
if [[ ${RANLIB:-false} != false ]]; then
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_RANLIB=${RANLIB}"
fi
if [[ ${NM:-false} != false ]]; then
CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_NM=${NM}"
fi
${MASON_HOME}/bin/cmake ../ -DCMAKE_INSTALL_PREFIX=${MASON_HOME} \
-DCMAKE_CXX_COMPILER="$CXX" \
-DBoost_NO_SYSTEM_PATHS=ON \
-DTBB_INSTALL_DIR=${MASON_HOME} \
-DCMAKE_INCLUDE_PATH=${MASON_HOME}/include \
-DCMAKE_LIBRARY_PATH=${MASON_HOME}/lib \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_EXE_LINKER_FLAGS="${LINK_FLAGS}" \
-DBoost_USE_STATIC_LIBS=ON \
${CMAKE_EXTRA_ARGS}
make -j${JOBS} VERBOSE=1 && make install
ccache -s
popd
popd
}
function setup_mason() {
if [[ ! -d ./.mason ]]; then
git clone https://github.com/mapbox/mason.git ./.mason
(cd ./.mason && git checkout ${MASON_VERSION})
else
echo "Updating to latest mason"
(cd ./.mason && git fetch && git checkout ${MASON_VERSION})
fi
export MASON_DIR=$(pwd)/.mason
export MASON_HOME=$(pwd)/mason_packages/.link
export PATH=$(pwd)/.mason:$PATH
export CXX=${CXX:-clang++}
export CC=${CC:-clang}
}
function main() {
setup_mason
all_deps
# fix install name of tbb
if [[ `uname -s` == 'Darwin' ]]; then
install_name_tool -id @loader_path/libtbb.dylib ${MASON_HOME}/lib/libtbb.dylib
install_name_tool -id @loader_path/libtbb.dylib ${MASON_HOME}/lib/libtbbmalloc.dylib
fi
export PKG_CONFIG_PATH=${MASON_HOME}/lib/pkgconfig
# environment variables to tell the compiler and linker
# to prefer mason paths over other paths when finding
# headers and libraries. This should allow the build to
# work even when conflicting versions of dependencies
# exist on global paths
# stopgap until c++17 :) (http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4214.pdf)
export C_INCLUDE_PATH="${MASON_HOME}/include"
export CPLUS_INCLUDE_PATH="${MASON_HOME}/include"
export LIBRARY_PATH="${MASON_HOME}/lib"
LINK_FLAGS=""
if [[ $(uname -s) == 'Linux' ]]; then
LINK_FLAGS="${LINK_FLAGS} "'-Wl,-z,origin -Wl,-rpath=\$ORIGIN'
# ensure rpath is picked up by node-osrm build
export LDFLAGS='-Wl,-z,origin -Wl,-rpath=\$$ORIGIN '${LDFLAGS}
fi
build_osrm
localize
}
main
set +e