From 82a9972be74fe7188977e94b12bbd35d980d7551 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Fri, 13 Mar 2026 11:59:00 +0100 Subject: [PATCH] Add parallel compilation support and improve Makefile/install script robustness - Add .DEFAULT_GOAL := all to Makefile for consistent default target - Document -j/--jobs option in README.md to allow parallel compilation - Add JOBS variable and -j/--jobs argument to install script (default: 1) - Replace fragile mkdir/cp commands with robust error handling and clear diagnostics - Add build directory preservation on copy failure for manual recovery - Pass -j option to make during compilation to enable parallel builds --- Makefile | 2 ++ README.md | 6 +++++- install_obitools.sh | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index d9fb833..1801300 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ #export GOBIN=$(GOPATH)/bin #export PATH=$(GOBIN):$(shell echo $${PATH}) +.DEFAULT_GOAL := all + GREEN := \033[0;32m YELLOW := \033[0;33m BLUE := \033[0;34m diff --git a/README.md b/README.md index c6294fb..9327135 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,12 @@ The installation script offers several options: > > -p, --obitools-prefix Prefix added to the obitools command names if you > want to have several versions of obitools at the -> same time on your system (as example `-p g` will produce +> same time on your system (as example `-p g` will produce > `gobigrep` command instead of `obigrep`). +> +> -j, --jobs Number of parallel jobs used for compilation +> (default: 1). Increase this value to speed up +> compilation on multi-core systems (e.g., `-j 4`). ### Examples diff --git a/install_obitools.sh b/install_obitools.sh index 07cf571..ffb9652 100755 --- a/install_obitools.sh +++ b/install_obitools.sh @@ -7,6 +7,7 @@ INSTALL_DIR="/usr/local" OBITOOLS_PREFIX="" VERSION="" LIST_VERSIONS=false +JOBS=1 # Help message function display_help { @@ -21,6 +22,7 @@ function display_help { echo " gobigrep command instead of obigrep)." echo " -v, --version Install a specific version (e.g., 4.4.8)." echo " If not specified, installs the latest version." + echo " -j, --jobs Number of parallel jobs for compilation (default: 1)." echo " -l, --list List all available versions and exit." echo " -h, --help Display this help message." echo "" @@ -65,6 +67,10 @@ while [ "$#" -gt 0 ]; do VERSION="$2" shift 2 ;; + -j|--jobs) + JOBS="$2" + shift 2 + ;; -l|--list) LIST_VERSIONS=true shift @@ -122,9 +128,15 @@ mkdir -p "${WORK_DIR}/cache" \ exit 1) # Create installation directory -mkdir -p "${INSTALL_DIR}/bin" 2> /dev/null \ - || (echo "Please enter your password for installing obitools in ${INSTALL_DIR}" 1>&2 - sudo mkdir -p "${INSTALL_DIR}/bin") +if ! mkdir -p "${INSTALL_DIR}/bin" 2>/dev/null; then + if [ ! -w "$(dirname "${INSTALL_DIR}")" ] && [ ! -w "${INSTALL_DIR}" ]; then + echo "Please enter your password for installing obitools in ${INSTALL_DIR}" 1>&2 + sudo mkdir -p "${INSTALL_DIR}/bin" + else + echo "Error: Could not create ${INSTALL_DIR}/bin (check path or disk space)" 1>&2 + exit 1 + fi +fi if [[ ! -d "${INSTALL_DIR}/bin" ]]; then echo "Could not create ${INSTALL_DIR}/bin directory for installing obitools" 1>&2 @@ -208,16 +220,29 @@ mkdir -p vendor # Build with or without prefix if [[ -z "$OBITOOLS_PREFIX" ]] ; then - make GOFLAGS="-buildvcs=false" + make -j"${JOBS}" obitools GOFLAGS="-buildvcs=false" else - make GOFLAGS="-buildvcs=false" OBITOOLS_PREFIX="${OBITOOLS_PREFIX}" + make -j"${JOBS}" obitools GOFLAGS="-buildvcs=false" OBITOOLS_PREFIX="${OBITOOLS_PREFIX}" fi # Install binaries echo "Installing binaries to ${INSTALL_DIR}/bin..." 1>&2 -(cp build/* "${INSTALL_DIR}/bin" 2> /dev/null) \ - || (echo "Please enter your password for installing obitools in ${INSTALL_DIR}" 1>&2 - sudo cp build/* "${INSTALL_DIR}/bin") +if ! cp build/* "${INSTALL_DIR}/bin" 2>/dev/null; then + if [ ! -w "${INSTALL_DIR}/bin" ]; then + echo "Please enter your password for installing obitools in ${INSTALL_DIR}" 1>&2 + sudo cp build/* "${INSTALL_DIR}/bin" + else + echo "Error: Could not copy binaries to ${INSTALL_DIR}/bin" 1>&2 + echo " Source files: $(ls build/ 2>/dev/null || echo 'none found')" 1>&2 + echo "" 1>&2 + echo "The build directory has been preserved for manual recovery:" 1>&2 + echo " $(pwd)/build/" 1>&2 + echo "You can install manually with:" 1>&2 + echo " cp $(pwd)/build/* ${INSTALL_DIR}/bin/" 1>&2 + popd > /dev/null || true + exit 1 + fi +fi popd > /dev/null || exit