Updated build.sh to build curl, openssl, and 256k1 if needed
This commit is contained in:
189
build.sh
189
build.sh
@@ -202,7 +202,7 @@ else
|
||||
# Check for nostr_core.h (includes everything)
|
||||
if grep -q '#include[[:space:]]*["\<]nostr_core\.h["\>]' *.c 2>/dev/null; then
|
||||
print_info "Found #include \"nostr_core.h\" - building all NIPs"
|
||||
NEEDED_NIPS="001 005 006 011 013 019 044"
|
||||
NEEDED_NIPS="001 004 005 006 011 013 019 044"
|
||||
elif [ -n "$DETECTED" ]; then
|
||||
NEEDED_NIPS="$DETECTED"
|
||||
print_success "Auto-detected NIPs: $(echo $NEEDED_NIPS | tr ' ' ',')"
|
||||
@@ -220,7 +220,7 @@ fi
|
||||
|
||||
# If building tests, include all NIPs to ensure test compatibility
|
||||
if [ "$BUILD_TESTS" = true ] && [ -z "$FORCE_NIPS" ]; then
|
||||
NEEDED_NIPS="001 005 006 011 013 019 044"
|
||||
NEEDED_NIPS="001 004 005 006 011 013 019 044"
|
||||
print_info "Building tests - including all available NIPs for test compatibility"
|
||||
fi
|
||||
|
||||
@@ -284,6 +284,169 @@ fi
|
||||
|
||||
|
||||
|
||||
###########################################################################################
|
||||
###########################################################################################
|
||||
############ CHECK AND BUILD DEPENDENCIES BASED ON NEEDED NIPS
|
||||
###########################################################################################
|
||||
###########################################################################################
|
||||
|
||||
print_info "Checking dependencies based on needed NIPs..."
|
||||
|
||||
# Set secp256k1 library path based on architecture
|
||||
case $ARCHITECTURE in
|
||||
x64)
|
||||
SECP256K1_LIB="secp256k1/.libs/libsecp256k1.a"
|
||||
;;
|
||||
arm64)
|
||||
SECP256K1_LIB="secp256k1/.libs/libsecp256k1_arm64.a"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Determine which dependencies are needed based on NIPs
|
||||
NEED_SECP256K1=false
|
||||
NEED_OPENSSL=false
|
||||
NEED_CURL=false
|
||||
|
||||
# secp256k1 is always needed (core cryptography for NIP-001)
|
||||
NEED_SECP256K1=true
|
||||
|
||||
# Check if network-dependent NIPs are included
|
||||
NETWORK_NIPS="005 011" # NIP-005 (DNS), NIP-011 (Relay info)
|
||||
for nip in $NEEDED_NIPS; do
|
||||
case $nip in
|
||||
005|011)
|
||||
NEED_CURL=true
|
||||
print_info "NIP-$nip requires HTTP functionality - curl needed"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if WebSocket functionality is needed (always included currently)
|
||||
# Since nostr_websocket/nostr_websocket_openssl.c is always compiled
|
||||
NEED_OPENSSL=true
|
||||
NEED_CURL=true
|
||||
print_info "WebSocket functionality enabled - OpenSSL and curl needed"
|
||||
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Dependency requirements:"
|
||||
[ "$NEED_SECP256K1" = true ] && echo " ✓ secp256k1 (core crypto)"
|
||||
[ "$NEED_OPENSSL" = true ] && echo " ✓ OpenSSL (TLS/WebSocket)"
|
||||
[ "$NEED_CURL" = true ] && echo " ✓ curl (HTTP requests)"
|
||||
fi
|
||||
|
||||
# Function to build secp256k1 if needed and missing
|
||||
build_secp256k1() {
|
||||
if [ "$NEED_SECP256K1" != true ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -f "$SECP256K1_LIB" ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_success "secp256k1 already available"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_info "Building secp256k1..."
|
||||
if [ ! -d "secp256k1" ]; then
|
||||
print_error "secp256k1 source directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Force clean build if .libs exists but no library
|
||||
if [ -d "secp256k1/.libs" ] && [ ! -f "$SECP256K1_LIB" ]; then
|
||||
print_info "Cleaning previous secp256k1 build..."
|
||||
(cd secp256k1 && make clean) || true
|
||||
fi
|
||||
|
||||
(cd secp256k1 && \
|
||||
./autogen.sh && \
|
||||
./configure --enable-static --disable-shared --enable-module-recovery && \
|
||||
make clean && \
|
||||
make -j$(nproc)) || { print_error "Failed to build secp256k1"; exit 1; }
|
||||
|
||||
# Verify the library was actually created
|
||||
if [ ! -f "$SECP256K1_LIB" ]; then
|
||||
print_error "secp256k1 library not created: $SECP256K1_LIB"
|
||||
print_error "Check if secp256k1 source files are present"
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Checking secp256k1 directory contents:"
|
||||
ls -la secp256k1/.libs/ 2>/dev/null || print_warning "No .libs directory found"
|
||||
ls -la secp256k1/src/ 2>/dev/null || print_warning "No src directory found"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "secp256k1 built successfully"
|
||||
}
|
||||
|
||||
# Function to build OpenSSL if needed and missing
|
||||
build_openssl() {
|
||||
if [ "$NEED_OPENSSL" != true ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -f "openssl-install/lib64/libssl.a" ] && [ -f "openssl-install/lib64/libcrypto.a" ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_success "OpenSSL already available"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_info "Building OpenSSL (this may take 5-10 minutes)..."
|
||||
if [ ! -d "openssl-3.4.2" ]; then
|
||||
print_error "openssl-3.4.2 source directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(cd openssl-3.4.2 && \
|
||||
./Configure linux-x86_64 no-shared --prefix="$(pwd)/../openssl-install" && \
|
||||
make -j$(nproc) && \
|
||||
make install) || { print_error "Failed to build OpenSSL"; exit 1; }
|
||||
|
||||
print_success "OpenSSL built successfully"
|
||||
}
|
||||
|
||||
# Function to build curl if needed and missing
|
||||
build_curl() {
|
||||
if [ "$NEED_CURL" != true ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -f "curl-install/lib/libcurl.a" ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_success "curl already available"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_info "Building curl..."
|
||||
if [ ! -d "curl-8.15.0/curl-8.15.0" ]; then
|
||||
print_error "curl-8.15.0/curl-8.15.0 source directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(cd curl-8.15.0/curl-8.15.0 && \
|
||||
./configure --disable-shared --enable-static \
|
||||
--with-openssl="$(pwd)/../../openssl-install" \
|
||||
--without-libpsl --without-brotli \
|
||||
--disable-ldap --disable-ldaps --disable-rtsp --disable-proxy \
|
||||
--disable-dict --disable-telnet --disable-tftp --disable-pop3 \
|
||||
--disable-imap --disable-smb --disable-smtp --disable-gopher \
|
||||
--disable-manual \
|
||||
--prefix="$(pwd)/../../curl-install" && \
|
||||
make -j$(nproc) && \
|
||||
make install) || { print_error "Failed to build curl"; exit 1; }
|
||||
|
||||
print_success "curl built successfully"
|
||||
}
|
||||
|
||||
# Build only the needed dependencies
|
||||
build_secp256k1
|
||||
build_openssl
|
||||
build_curl
|
||||
|
||||
|
||||
###########################################################################################
|
||||
###########################################################################################
|
||||
############ ADD CORE DEPENDENCIES THAT NEED TO BE BUILT TO THE $SOURCES VARIABLE
|
||||
@@ -299,15 +462,6 @@ SOURCES="$SOURCES nostr_core/nostr_common.c"
|
||||
SOURCES="$SOURCES nostr_core/core_relays.c"
|
||||
SOURCES="$SOURCES nostr_websocket/nostr_websocket_openssl.c"
|
||||
|
||||
# Add secp256k1 library path based on architecture
|
||||
case $ARCHITECTURE in
|
||||
x64)
|
||||
SECP256K1_LIB="secp256k1/.libs/libsecp256k1.a"
|
||||
;;
|
||||
arm64)
|
||||
SECP256K1_LIB="secp256k1/.libs/libsecp256k1_arm64.a"
|
||||
;;
|
||||
esac
|
||||
NIP_DESCRIPTIONS=""
|
||||
|
||||
for nip in $NEEDED_NIPS; do
|
||||
@@ -401,12 +555,16 @@ TMP_CURL=".tmp_curl_$$"
|
||||
|
||||
mkdir -p "$TMP_SECP256K1" "$TMP_OPENSSL" "$TMP_CURL"
|
||||
|
||||
# Extract secp256k1 objects
|
||||
# Extract secp256k1 objects (if library exists)
|
||||
SECP256K1_OBJECTS=""
|
||||
if [ -f "$SECP256K1_LIB" ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Extracting secp256k1 objects..."
|
||||
fi
|
||||
(cd "$TMP_SECP256K1" && ar x "$BUILD_DIR/$SECP256K1_LIB")
|
||||
SECP256K1_OBJECTS="$TMP_SECP256K1/*.o"
|
||||
else
|
||||
print_warning "secp256k1 library not found: $SECP256K1_LIB - skipping secp256k1 objects"
|
||||
fi
|
||||
|
||||
# Extract OpenSSL objects
|
||||
@@ -427,11 +585,14 @@ if [ "$VERBOSE" = true ]; then
|
||||
print_info "Combining all objects into self-contained library..."
|
||||
fi
|
||||
|
||||
|
||||
#########################################################
|
||||
### THE ACTUAL COMMAND TO LINK .o FILES INTO A .a FILE
|
||||
#########################################################
|
||||
ar rcs "$OUTPUT" $OBJECTS "$TMP_SECP256K1"/*.o "$TMP_OPENSSL"/*.o "$TMP_CURL"/*.o
|
||||
if [ -n "$SECP256K1_OBJECTS" ]; then
|
||||
ar rcs "$OUTPUT" $OBJECTS $SECP256K1_OBJECTS "$TMP_OPENSSL"/*.o "$TMP_CURL"/*.o
|
||||
else
|
||||
ar rcs "$OUTPUT" $OBJECTS "$TMP_OPENSSL"/*.o "$TMP_CURL"/*.o
|
||||
fi
|
||||
AR_RESULT=$?
|
||||
|
||||
# Cleanup temporary directories
|
||||
|
||||
Reference in New Issue
Block a user