162 lines
4.0 KiB
Bash
Executable File
162 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# NOSTR Core Library Build Script
|
|
# Provides convenient build targets for the standalone library
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Function to show usage
|
|
show_usage() {
|
|
echo "NOSTR Core Library Build Script"
|
|
echo "==============================="
|
|
echo ""
|
|
echo "Usage: $0 [target]"
|
|
echo ""
|
|
echo "Available targets:"
|
|
echo " clean - Clean all build artifacts"
|
|
echo " lib - Build static library (default)"
|
|
echo " shared - Build shared library"
|
|
echo " all - Build both static and shared libraries"
|
|
echo " examples - Build example programs"
|
|
echo " test - Run tests"
|
|
echo " install - Install library to system"
|
|
echo " uninstall - Remove library from system"
|
|
echo " help - Show this help message"
|
|
echo ""
|
|
echo "Library outputs:"
|
|
echo " libnostr_core.a - Static library"
|
|
echo " libnostr_core.so - Shared library"
|
|
echo " examples/* - Example programs"
|
|
}
|
|
|
|
# Parse command line arguments
|
|
TARGET=${1:-lib}
|
|
|
|
case "$TARGET" in
|
|
clean)
|
|
print_status "Cleaning build artifacts..."
|
|
make clean
|
|
print_success "Clean completed"
|
|
;;
|
|
|
|
lib|library)
|
|
print_status "Building static library..."
|
|
make clean
|
|
make
|
|
if [ -f "libnostr_core.a" ]; then
|
|
SIZE=$(stat -c%s "libnostr_core.a")
|
|
print_success "Static library built successfully (${SIZE} bytes)"
|
|
ls -la libnostr_core.a
|
|
else
|
|
print_error "Failed to build static library"
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
shared)
|
|
print_status "Building shared library..."
|
|
make clean
|
|
make libnostr_core.so
|
|
if [ -f "libnostr_core.so" ]; then
|
|
SIZE=$(stat -c%s "libnostr_core.so")
|
|
print_success "Shared library built successfully (${SIZE} bytes)"
|
|
ls -la libnostr_core.so
|
|
else
|
|
print_error "Failed to build shared library"
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
all)
|
|
print_status "Building all libraries..."
|
|
make clean
|
|
make all
|
|
print_success "All libraries built successfully"
|
|
ls -la libnostr_core.*
|
|
;;
|
|
|
|
examples)
|
|
print_status "Building examples..."
|
|
make clean
|
|
make
|
|
make examples
|
|
print_success "Examples built successfully"
|
|
ls -la examples/
|
|
;;
|
|
|
|
test)
|
|
print_status "Running tests..."
|
|
make clean
|
|
make
|
|
if make test-crypto 2>/dev/null; then
|
|
print_success "All tests passed"
|
|
else
|
|
print_warning "Running simple test instead..."
|
|
make test
|
|
print_success "Basic test completed"
|
|
fi
|
|
;;
|
|
|
|
tests)
|
|
print_status "Running tests..."
|
|
make clean
|
|
make
|
|
if make test-crypto 2>/dev/null; then
|
|
print_success "All tests passed"
|
|
else
|
|
print_warning "Running simple test instead..."
|
|
make test
|
|
print_success "Basic test completed"
|
|
fi
|
|
;;
|
|
|
|
install)
|
|
print_status "Installing library to system..."
|
|
make clean
|
|
make all
|
|
sudo make install
|
|
print_success "Library installed to /usr/local"
|
|
;;
|
|
|
|
uninstall)
|
|
print_status "Uninstalling library from system..."
|
|
sudo make uninstall
|
|
print_success "Library uninstalled"
|
|
;;
|
|
|
|
help|--help|-h)
|
|
show_usage
|
|
;;
|
|
|
|
*)
|
|
print_error "Unknown target: $TARGET"
|
|
echo ""
|
|
show_usage
|
|
exit 1
|
|
;;
|
|
esac
|