Files
hfsutils/configure.standalone
Pablo Lezaeta Reyes e929252b6e update small
2025-10-31 22:44:24 -03:00

236 lines
5.2 KiB
Bash

#!/bin/bash
# Simple configure script for standalone HFS utilities
set -e
# Default values
PREFIX="/usr/local"
SBINDIR=""
CC="gcc"
CFLAGS="-g -O2"
ENABLE_DEBUG="no"
ENABLE_STATIC="no"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
log_info() {
echo -e "${BLUE}INFO:${NC} $1"
}
log_success() {
echo -e "${GREEN}SUCCESS:${NC} $1"
}
log_warning() {
echo -e "${YELLOW}WARNING:${NC} $1"
}
log_error() {
echo -e "${RED}ERROR:${NC} $1"
}
# Show help
show_help() {
cat << EOF
Configure script for standalone HFS utilities
Usage: $0 [OPTIONS]
Options:
--help Show this help message
--prefix=DIR Installation prefix (default: /usr/local)
--sbindir=DIR System binary directory (default: PREFIX/sbin)
--cc=COMPILER C compiler to use (default: gcc)
--cflags=FLAGS Additional C compiler flags
--enable-debug Enable debug build
--enable-static Enable static linking
--disable-tests Disable test suite
Examples:
$0 # Default configuration
$0 --prefix=/usr --sbindir=/usr/bin # System installation
$0 --enable-debug # Debug build
$0 --cc=clang # Use clang compiler
EOF
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--help)
show_help
exit 0
;;
--prefix=*)
PREFIX="${1#*=}"
shift
;;
--sbindir=*)
SBINDIR="${1#*=}"
shift
;;
--cc=*)
CC="${1#*=}"
shift
;;
--cflags=*)
CFLAGS="$CFLAGS ${1#*=}"
shift
;;
--enable-debug)
ENABLE_DEBUG="yes"
shift
;;
--enable-static)
ENABLE_STATIC="yes"
shift
;;
--disable-tests)
ENABLE_TESTS="no"
shift
;;
*)
log_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Set default SBINDIR if not specified
if [[ -z "$SBINDIR" ]]; then
SBINDIR="$PREFIX/sbin"
fi
# Adjust flags for debug build
if [[ "$ENABLE_DEBUG" == "yes" ]]; then
CFLAGS="$CFLAGS -DDEBUG -g3 -O0"
log_info "Debug build enabled"
else
CFLAGS="$CFLAGS -DNDEBUG"
fi
# Adjust flags for static build
if [[ "$ENABLE_STATIC" == "yes" ]]; then
CFLAGS="$CFLAGS -static"
log_info "Static linking enabled"
fi
log_info "Configuring standalone HFS utilities..."
# Check for required tools
log_info "Checking build environment..."
# Check for C compiler
if ! command -v "$CC" >/dev/null 2>&1; then
log_error "C compiler '$CC' not found"
log_info "Please install a C compiler (gcc, clang, etc.)"
exit 1
fi
# Test compiler
log_info "Testing C compiler..."
cat > conftest.c << 'EOF'
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
int main() {
printf("Compiler test OK\n");
return 0;
}
EOF
if ! $CC $CFLAGS -o conftest conftest.c 2>/dev/null; then
log_error "C compiler test failed"
rm -f conftest.c conftest
exit 1
fi
if ! ./conftest >/dev/null 2>&1; then
log_error "Compiled test program failed to run"
rm -f conftest.c conftest
exit 1
fi
rm -f conftest.c conftest
log_success "C compiler works"
# Check for required headers
log_info "Checking for required headers..."
REQUIRED_HEADERS="stdio.h stdlib.h string.h unistd.h fcntl.h errno.h sys/stat.h time.h stdint.h getopt.h"
for header in $REQUIRED_HEADERS; do
cat > conftest.c << EOF
#include <$header>
int main() { return 0; }
EOF
if ! $CC $CFLAGS -c conftest.c -o conftest.o 2>/dev/null; then
log_error "Required header '$header' not found"
rm -f conftest.c conftest.o
exit 1
fi
rm -f conftest.c conftest.o
done
log_success "All required headers found"
# Check for make
if ! command -v make >/dev/null 2>&1; then
log_warning "make not found - you'll need to compile manually"
else
log_success "make found"
fi
# Create config.mk
log_info "Creating configuration..."
cat > config.mk << EOF
# Generated by configure.standalone
# $(date)
# Installation directories
PREFIX = $PREFIX
SBINDIR = $SBINDIR
# Build tools
CC = $CC
CFLAGS = $CFLAGS
# Build options
ENABLE_DEBUG = $ENABLE_DEBUG
ENABLE_STATIC = $ENABLE_STATIC
EOF
# Create simple Makefile if it doesn't exist
if [[ ! -f Makefile ]]; then
log_info "Creating Makefile..."
cp Makefile.standalone Makefile
fi
# Show configuration summary
log_success "Configuration complete!"
echo
echo "Configuration Summary:"
echo " Installation prefix: $PREFIX"
echo " System binary dir: $SBINDIR"
echo " C compiler: $CC"
echo " C flags: $CFLAGS"
echo " Debug build: $ENABLE_DEBUG"
echo " Static linking: $ENABLE_STATIC"
echo
echo "Next steps:"
echo " make # Build utilities"
echo " make test # Run tests"
echo " make install # Install utilities"
echo " make clean # Clean build files"
echo
log_info "You can now run 'make' to build the utilities"