diff --git a/configure b/configure index ba0142c..dc32361 100755 --- a/configure +++ b/configure @@ -1,5 +1,96 @@ -#!/bin/sh +#!/bin/bash +# Configure script for R package with htslib integration + +# Exit on any error +set -e HTSLIB_DIR="src/htslib-1.21" echo "Configuring HTSlib in $HTSLIB_DIR" -cd $HTSLIB_DIR && ./configure --without-libdeflate && make libhts.a +# cd $HTSLIB_DIR && ./configure --without-libdeflate && make libhts.a + +# Determine the package source directory +PKG_SOURCE_DIR=$(pwd) + +# Create a directory for htslib build +HTSLIB_BUILD_DIR="${PKG_SOURCE_DIR}/src/htslib_build" +mkdir -p "${HTSLIB_BUILD_DIR}" + +# Function to check for compilation tools +check_tools() { + # Check for essential build tools + command -v gcc >/dev/null 2>&1 || { + echo "Error: GCC compiler not found" >&2 + exit 1 + } + command -v make >/dev/null 2>&1 || { + echo "Error: Make not found" >&2 + exit 1 + } +} + +# Function to configure and build htslib +build_htslib() { + echo "Configuring htslib..." + + # Go to the htslib source directory + cd "${PKG_SOURCE_DIR}/${HTSLIB_DIR}" + + # Clean any previous builds + make clean || true + + # Configure htslib + # Customize these options as needed + ./configure \ + --disable-shared \ + --enable-static \ + --prefix="${HTSLIB_BUILD_DIR}" \ + CFLAGS="-O2 -fPIC" + + # Build htslib + make + make install +} + +# Function to create Makevars files +create_makevars() { + echo "Creating Makevars files..." + + # Unix Makevars + cat > "${PKG_SOURCE_DIR}/src/Makevars" << EOL +# Paths and flags for htslib +PKG_CPPFLAGS = -I${HTSLIB_BUILD_DIR}/include -I${PKG_SOURCE_DIR}/inst/include +PKG_LIBS = -L${HTSLIB_BUILD_DIR}/lib -lhts -lz + +# Ensure static linking +STATICALLY_LINKED_LIBS = ${HTSLIB_BUILD_DIR}/lib/libhts.a +EOL + + # Windows Makevars + cat > "${PKG_SOURCE_DIR}/src/Makevars.win" << EOL +# Windows-specific paths and flags for htslib +PKG_CPPFLAGS = -I${HTSLIB_BUILD_DIR}/include -I${PKG_SOURCE_DIR}/inst/include +PKG_LIBS = -L${HTSLIB_BUILD_DIR}/lib -lhts -lz + +# Ensure static linking +STATICALLY_LINKED_LIBS = ${HTSLIB_BUILD_DIR}/lib/libhts.a +EOL +} + +# Main script execution +main() { + # Check for necessary build tools + check_tools + + # Build htslib + build_htslib + + # Create Makevars files + # create_makevars + + echo "htslib configuration complete." + exit 0 +} + +# Run the main function +main +