|
|
@@ -1,6 +1,4 @@
|
|
|
#!/usr/bin/env bash
|
|
|
-# NGS build helper
|
|
|
-# Usage: ./build.sh [command] [args...]
|
|
|
set -euo pipefail
|
|
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
@@ -10,7 +8,6 @@ BUILD_DIR="${BUILD_DIR:-build}"
|
|
|
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 4)}"
|
|
|
BIN="$BUILD_DIR/ngs"
|
|
|
|
|
|
-# apt packages required to compile NGS (ylib / HPSocket are not packaged here)
|
|
|
APT_DEPS=(
|
|
|
build-essential
|
|
|
cmake
|
|
|
@@ -26,214 +23,49 @@ APT_DEPS=(
|
|
|
tar
|
|
|
)
|
|
|
|
|
|
-die() { echo "error: $*" >&2; exit 1; }
|
|
|
-info() { echo "==> $*"; }
|
|
|
+need_apt=0
|
|
|
+for c in g++ cmake make; do
|
|
|
+ command -v "$c" >/dev/null 2>&1 || need_apt=1
|
|
|
+done
|
|
|
+for pkg in "${APT_DEPS[@]}"; do
|
|
|
+ dpkg -s "$pkg" >/dev/null 2>&1 || need_apt=1
|
|
|
+done
|
|
|
|
|
|
-have_cmd() { command -v "$1" >/dev/null 2>&1; }
|
|
|
-
|
|
|
-# True only if the linker can resolve -lNAME (unversioned .so or .a).
|
|
|
-# Versioned runtime libs like libfoo.so.21 alone are NOT enough.
|
|
|
-find_lib() {
|
|
|
- local name="$1"
|
|
|
- local dir
|
|
|
- for dir in /usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib; do
|
|
|
- [[ -e "${dir}/lib${name}.so" || -e "${dir}/lib${name}.a" ]] && return 0
|
|
|
- done
|
|
|
- return 1
|
|
|
-}
|
|
|
-
|
|
|
-# Runtime .so is enough for DT_NEEDED deps of shared mysqlcppconn.
|
|
|
-find_lib_runtime() {
|
|
|
- local name="$1"
|
|
|
- local dir
|
|
|
- for dir in /usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib; do
|
|
|
- [[ -e "${dir}/lib${name}.so" || -e "${dir}/lib${name}.a" ]] && return 0
|
|
|
- compgen -G "${dir}/lib${name}.so.*" >/dev/null && return 0
|
|
|
- done
|
|
|
- ldconfig -p 2>/dev/null | grep -E -q "lib${name}\\.so(\\.|$)" && return 0
|
|
|
- return 1
|
|
|
-}
|
|
|
-
|
|
|
-cmd_help() {
|
|
|
- cat <<EOF
|
|
|
-NGS build script
|
|
|
-
|
|
|
-Usage:
|
|
|
- ./build.sh Configure + build
|
|
|
- ./build.sh build Same as above
|
|
|
- ./build.sh rebuild Clean then build
|
|
|
- ./build.sh clean Remove build directory
|
|
|
- ./build.sh deps Install apt build dependencies
|
|
|
- ./build.sh check Verify toolchain and libraries
|
|
|
- ./build.sh run [args...] Build if needed, then run ngs
|
|
|
- ./build.sh install cmake --install into /usr/local (needs sudo)
|
|
|
- ./build.sh help Show this help
|
|
|
-
|
|
|
-Env:
|
|
|
- BUILD_DIR Build directory (default: build)
|
|
|
- JOBS Parallel jobs (default: nproc)
|
|
|
-
|
|
|
-Notes:
|
|
|
- - Preinstall ylib headers/libs under /usr/local (libylib.a + headers).
|
|
|
- - Preinstall HPSocket (libhpsocket + /usr/local/include/HPSocket).
|
|
|
- - MySQL Connector/C++ (libmysqlcppconn) is required because ylib links it.
|
|
|
-EOF
|
|
|
-}
|
|
|
-
|
|
|
-cmd_deps() {
|
|
|
- have_cmd apt-get || die "apt-get not found (Debian/Ubuntu required for deps)"
|
|
|
- info "Installing apt packages: ${APT_DEPS[*]}"
|
|
|
+if [[ "$need_apt" -eq 1 ]]; then
|
|
|
+ echo "==> installing build deps"
|
|
|
sudo apt-get update
|
|
|
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${APT_DEPS[@]}"
|
|
|
- info "Done. Ensure ylib and HPSocket are installed under /usr/local."
|
|
|
-}
|
|
|
-
|
|
|
-cmd_check() {
|
|
|
- local ok=1
|
|
|
- echo "Checking build prerequisites..."
|
|
|
-
|
|
|
- for c in g++ cmake make; do
|
|
|
- if have_cmd "$c"; then
|
|
|
- echo " [OK] command: $c ($(command -v "$c"))"
|
|
|
- else
|
|
|
- echo " [MISS] command: $c"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
- done
|
|
|
-
|
|
|
- if [[ -d /usr/local/include/net && -d /usr/local/include/util ]]; then
|
|
|
- echo " [OK] ylib headers: /usr/local/include/{net,util,...}"
|
|
|
- else
|
|
|
- echo " [MISS] ylib headers under /usr/local/include (net/, util/, ...)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- if find_lib ylib; then
|
|
|
- echo " [OK] library: ylib"
|
|
|
- else
|
|
|
- echo " [MISS] library: ylib (expect /usr/local/lib/libylib.a)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- if [[ -d /usr/local/include/HPSocket || -d /usr/include/HPSocket ]]; then
|
|
|
- echo " [OK] HPSocket headers"
|
|
|
- else
|
|
|
- echo " [MISS] HPSocket headers"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- if find_lib hpsocket; then
|
|
|
- echo " [OK] library: hpsocket"
|
|
|
- else
|
|
|
- echo " [MISS] library: hpsocket"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- # Prefer shared mysqlcppconn.so so -lmysqlclient is not required at link time.
|
|
|
- if [[ -e /usr/lib/x86_64-linux-gnu/libmysqlcppconn.so \
|
|
|
- || -e /usr/local/lib/libmysqlcppconn.so \
|
|
|
- || -e /usr/lib/libmysqlcppconn.so ]]; then
|
|
|
- echo " [OK] library: mysqlcppconn (shared)"
|
|
|
- if find_lib_runtime mysqlclient; then
|
|
|
- echo " [OK] library: mysqlclient (runtime)"
|
|
|
- else
|
|
|
- echo " [MISS] library: mysqlclient runtime (libmysqlclient.so.*)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
- if find_lib mysqlclient; then
|
|
|
- echo " [OK] library: mysqlclient (linkable, optional)"
|
|
|
- else
|
|
|
- echo " [WARN] library: mysqlclient not linkable (ok with shared mysqlcppconn; install libmysqlclient-dev if link fails)"
|
|
|
+fi
|
|
|
+
|
|
|
+case "${1:-build}" in
|
|
|
+ clean)
|
|
|
+ rm -rf "$BUILD_DIR"
|
|
|
+ ;;
|
|
|
+ rebuild)
|
|
|
+ rm -rf "$BUILD_DIR"
|
|
|
+ cmake -S . -B "$BUILD_DIR"
|
|
|
+ cmake --build "$BUILD_DIR" -j"$JOBS"
|
|
|
+ echo "==> $BIN"
|
|
|
+ ;;
|
|
|
+ run)
|
|
|
+ shift || true
|
|
|
+ if [[ ! -x "$BIN" ]]; then
|
|
|
+ cmake -S . -B "$BUILD_DIR"
|
|
|
+ cmake --build "$BUILD_DIR" -j"$JOBS"
|
|
|
fi
|
|
|
- elif find_lib mysqlcppconn; then
|
|
|
- echo " [OK] library: mysqlcppconn (static)"
|
|
|
- if find_lib mysqlclient; then
|
|
|
- echo " [OK] library: mysqlclient"
|
|
|
- else
|
|
|
- echo " [MISS] library: mysqlclient (required for static mysqlcppconn; try: ./build.sh deps)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
- else
|
|
|
- echo " [MISS] library: mysqlcppconn (try: ./build.sh deps)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- for lib in sqlite3 leveldb ssl crypto z; do
|
|
|
- if find_lib "$lib"; then
|
|
|
- echo " [OK] library: $lib"
|
|
|
- else
|
|
|
- echo " [MISS] library: $lib (try: ./build.sh deps)"
|
|
|
- ok=0
|
|
|
+ exec "$BIN" "$@"
|
|
|
+ ;;
|
|
|
+ build|"")
|
|
|
+ cmake -S . -B "$BUILD_DIR"
|
|
|
+ cmake --build "$BUILD_DIR" -j"$JOBS"
|
|
|
+ echo "==> $BIN"
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ # treat as ngs args: build if needed, then run
|
|
|
+ if [[ ! -x "$BIN" ]]; then
|
|
|
+ cmake -S . -B "$BUILD_DIR"
|
|
|
+ cmake --build "$BUILD_DIR" -j"$JOBS"
|
|
|
fi
|
|
|
- done
|
|
|
-
|
|
|
- if [[ -f /usr/include/cppconn/driver.h ]]; then
|
|
|
- echo " [OK] header: cppconn/driver.h"
|
|
|
- else
|
|
|
- echo " [MISS] header: cppconn/driver.h (libmysqlcppconn-dev)"
|
|
|
- ok=0
|
|
|
- fi
|
|
|
-
|
|
|
- if [[ "$ok" -eq 1 ]]; then
|
|
|
- info "All checks passed"
|
|
|
- return 0
|
|
|
- fi
|
|
|
- die "prerequisite check failed"
|
|
|
-}
|
|
|
-
|
|
|
-cmd_clean() {
|
|
|
- info "Removing $BUILD_DIR"
|
|
|
- rm -rf "$BUILD_DIR"
|
|
|
-}
|
|
|
-
|
|
|
-cmd_build() {
|
|
|
- cmd_check
|
|
|
- info "Configuring ($BUILD_DIR)"
|
|
|
- cmake -S . -B "$BUILD_DIR"
|
|
|
- info "Building with -j$JOBS"
|
|
|
- cmake --build "$BUILD_DIR" -j"$JOBS"
|
|
|
- info "Binary: $BIN"
|
|
|
-}
|
|
|
-
|
|
|
-cmd_rebuild() {
|
|
|
- cmd_clean
|
|
|
- cmd_build
|
|
|
-}
|
|
|
-
|
|
|
-cmd_run() {
|
|
|
- if [[ ! -x "$BIN" ]]; then
|
|
|
- cmd_build
|
|
|
- fi
|
|
|
- info "Running $BIN $*"
|
|
|
- exec "$BIN" "$@"
|
|
|
-}
|
|
|
-
|
|
|
-cmd_install() {
|
|
|
- [[ -x "$BIN" ]] || cmd_build
|
|
|
- info "Installing to system prefix (sudo)"
|
|
|
- sudo cmake --install "$BUILD_DIR"
|
|
|
-}
|
|
|
-
|
|
|
-main() {
|
|
|
- local cmd="${1:-build}"
|
|
|
- if [[ $# -gt 0 ]]; then
|
|
|
- shift
|
|
|
- fi
|
|
|
-
|
|
|
- case "$cmd" in
|
|
|
- build) cmd_build ;;
|
|
|
- rebuild) cmd_rebuild ;;
|
|
|
- clean) cmd_clean ;;
|
|
|
- deps) cmd_deps ;;
|
|
|
- check) cmd_check ;;
|
|
|
- run) cmd_run "$@" ;;
|
|
|
- install) cmd_install ;;
|
|
|
- help|-h|--help) cmd_help ;;
|
|
|
- *)
|
|
|
- # Unknown first arg: treat as ngs runtime args (compat with old br.sh)
|
|
|
- cmd_run "$cmd" "$@"
|
|
|
- ;;
|
|
|
- esac
|
|
|
-}
|
|
|
-
|
|
|
-main "$@"
|
|
|
+ exec "$BIN" "$@"
|
|
|
+ ;;
|
|
|
+esac
|