#!/usr/bin/env bash # Build the runtime dependencies OSRM needs, from source, no sudo, no # conan: bzip2, lua 5.2 (static), oneTBB, boost (b2, with hand-rolled # CMake config files — boost release tarballs ship no CMake support). # # Artifacts: $W (default /tmp/osm-build), installed into $W/prefix. # Idempotent: each dep is skipped when its .done- marker exists. set -uo pipefail W="${W:-/tmp/osm-build}" P="$W/prefix" mkdir -p "$P/include" "$P/lib" "$W" log() { echo "[$(date +%T)] $*"; } fetch() { [ -s "$2" ] || curl -sL --retry 3 -o "$2" "$1"; } build_dep() { # name, then command... local name=$1; shift [ -f "$W/.done-$name" ] && { log "$name: already done"; return; } log "$name: building" if "$@" > "$W/$name.log" 2>&1; then touch "$W/.done-$name" else log "$name: FAILED (see $W/$name.log)"; exit 1 fi } # --- sources --- fetch "https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz" "$W/bzip2.tgz" [ -d "$W/bzip2-1.0.8" ] || tar -C "$W" -xzf "$W/bzip2.tgz" fetch "https://www.lua.org/ftp/lua-5.2.4.tar.gz" "$W/lua.tgz" [ -d "$W/lua-5.2.4" ] || tar -C "$W" -xzf "$W/lua.tgz" fetch "https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.13.0.tar.gz" "$W/tbb.tgz" [ -d "$W/oneTBB-2021.13.0" ] || tar -C "$W" -xzf "$W/tbb.tgz" fetch "https://archives.boost.io/release/1.84.0/source/boost_1_84_0.tar.gz" "$W/boost.tgz" [ -d "$W/boost_1_84_0" ] || tar -C "$W" -xzf "$W/boost.tgz" # --- bzip2 --- build_dep bzip2 bash -c " cd $W/bzip2-1.0.8 && make -s -j16 CFLAGS='-O2 -fPIC' cp bzlib.h $P/include/ && cp libbz2.a $P/lib/" # --- lua 5.2 (library only; the interactive REPL needs readline dev # headers, which we stub — we only link liblua.a into osrm-extract) --- build_dep lua bash -c " mkdir -p $W/local/include/readline $W/local/lib cat > $W/local/include/readline/readline.h <<'HDR' #ifndef READLINE_STUB_H #define READLINE_STUB_H char *readline(const char *prompt); void add_history(const char *line); #endif HDR cat > $W/local/include/readline/history.h <<'HDR' #ifndef HISTORY_STUB_H #define HISTORY_STUB_H void using_history(void); void clear_history(void); #endif HDR ln -sf /usr/lib/x86_64-linux-gnu/libreadline.so.8 $W/local/lib/libreadline.so cd $W/lua-5.2.4/src && make -s clean >/dev/null 2>&1 make -s -j16 linux MYCFLAGS='-I$W/local/include' MYLDFLAGS='-L$W/local/lib' cp lua.h luaconf.h lualib.h lauxlib.h lua.hpp $P/include/ cp liblua.a $P/lib/" # --- nlohmann/json (single header; needed by osmium-tool) --- if [ ! -f "$P/include/nlohmann/json.hpp" ]; then log "nlohmann-json: fetching single header" mkdir -p "$P/include/nlohmann" curl -sL -o "$P/include/nlohmann/json.hpp" \ https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp fi # --- oneTBB (CMake, installs TBBConfig.cmake) --- build_dep tbb bash -c " cmake -S $W/oneTBB-2021.13.0 -B $W/tbb-build -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$P -DTBB_TEST=OFF -DTBB_STRICT=OFF cmake --build $W/tbb-build -j16 cmake --install $W/tbb-build" # --- boost: b2 for the libs, then headers + CMake config files --- build_dep boost bash -c " cd $W/boost_1_84_0 [ -x ./b2 ] || ./bootstrap.sh ./b2 -j16 --with-date_time --with-iostreams --with-program_options \ --with-thread --with-test --with-regex \ --layout=versioned link=static cxxstd=17 rm -rf $P/include/boost && cp -r $W/boost_1_84_0/boost $P/include/boost cp -a $W/boost_1_84_0/stage/lib/libboost_*.a $P/lib/ W=$W bash $(dirname "$0")/install-boost-cmake.sh" # --- osmium-tool (PBF merging; uses OSRM's vendored libosmium/protozero) --- build_dep osmium bash -c " if [ ! -d $W/osrm-backend-26.4.1 ]; then fetch "https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v26.4.1.tar.gz" $W/osrm.tar.gz tar -C $W -xzf $W/osrm.tar.gz fi if [ ! -d $W/osmium-tool-1.19.0 ]; then fetch "https://github.com/osmcode/osmium-tool/archive/refs/tags/v1.19.0.tar.gz" $W/osmium.tgz tar -C $W -xzf $W/osmium.tgz fi rm -rf $W/osmium-build cmake -S $W/osmium-tool-1.19.0 -B $W/osmium-build -DCMAKE_BUILD_TYPE=Release \ -DOSMIUM_BUILD_PROGRAMS=ON -DOSMIUM_BUILD_TESTS=OFF \ -DCMAKE_PREFIX_PATH=$P \ -DOSMIUM_INCLUDE_DIR=$W/osrm-backend-26.4.1/third_party/libosmium/include \ -DPROTOZERO_INCLUDE_DIR=$W/osrm-backend-26.4.1/third_party/protozero/include cmake --build $W/osmium-build --target osmium -j16" log "ALL DEPS DONE"