Compare commits
2 Commits
9fd4c61df7
...
05fe1df8aa
| Author | SHA1 | Date | |
|---|---|---|---|
| 05fe1df8aa | |||
| 98a802552b |
@@ -88,6 +88,59 @@ Simply include the source files directly in your project:
|
||||
gcc your_project.c -lnostr_core -lm
|
||||
```
|
||||
|
||||
## Building the Library
|
||||
|
||||
### Using the Provided Build Script
|
||||
|
||||
The library includes an automated build script that handles all dependencies and creates a self-contained static library.
|
||||
|
||||
**IMPORTANT**: The build script must be run from within the `nostr_core_lib` directory:
|
||||
|
||||
```bash
|
||||
# Correct usage:
|
||||
cd nostr_core_lib
|
||||
./build.sh
|
||||
|
||||
# If you need to use it from your project directory:
|
||||
cd nostr_core_lib
|
||||
./build.sh
|
||||
cd ..
|
||||
gcc your_app.c nostr_core_lib/libnostr_core_x64.a -lz -ldl -lpthread -lm -o your_app
|
||||
```
|
||||
|
||||
**Common Error**: Running `./nostr_core_lib/build.sh` from outside the library directory will fail with:
|
||||
```
|
||||
[ERROR] Build script must be run from the nostr_core_lib directory
|
||||
```
|
||||
|
||||
### Build Script Options
|
||||
|
||||
```bash
|
||||
# Auto-detect NIPs from your source code
|
||||
./build.sh
|
||||
|
||||
# Force specific NIPs
|
||||
./build.sh --nips=1,6,19
|
||||
|
||||
# Build all available NIPs
|
||||
./build.sh --nips=all
|
||||
|
||||
# Build for specific architecture
|
||||
./build.sh arm64
|
||||
|
||||
# Build with tests
|
||||
./build.sh --tests
|
||||
|
||||
# Get help
|
||||
./build.sh --help
|
||||
```
|
||||
|
||||
The build script automatically:
|
||||
- Scans your `.c` files for `#include "nip*.h"` statements
|
||||
- Compiles only the needed NIPs
|
||||
- Creates a self-contained static library (`libnostr_core_x64.a`)
|
||||
- Includes all dependencies (OpenSSL, curl, secp256k1, cJSON)
|
||||
|
||||
## Basic Usage Example
|
||||
|
||||
```c
|
||||
|
||||
32
build.sh
32
build.sh
@@ -146,6 +146,27 @@ if [ "$HELP" = true ]; then
|
||||
fi
|
||||
|
||||
print_info "NOSTR Core Library - Customer Build Script"
|
||||
|
||||
# Check if we're running from the correct directory
|
||||
if [ ! -d "nostr_core" ] || [ ! -f "nostr_core/utils.c" ] || [ ! -d "secp256k1" ]; then
|
||||
print_error "Build script must be run from the nostr_core_lib directory"
|
||||
echo ""
|
||||
echo "It looks like you're trying to run this script from your project directory."
|
||||
echo "Please change to the nostr_core_lib directory first, then run the build script."
|
||||
echo ""
|
||||
echo "Correct usage:"
|
||||
echo " cd nostr_core_lib"
|
||||
echo " ./build.sh"
|
||||
echo ""
|
||||
echo "Or if nostr_core_lib is in your project directory:"
|
||||
echo " cd nostr_core_lib"
|
||||
echo " ./build.sh"
|
||||
echo " cd .."
|
||||
echo " gcc your_app.c nostr_core_lib/libnostr_core_x64.a -lz -ldl -lpthread -lm -o your_app"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_info "Auto-detecting needed NIPs from your source code..."
|
||||
|
||||
|
||||
@@ -367,6 +388,9 @@ done
|
||||
###########################################################################################
|
||||
print_info "Creating self-contained static library: $OUTPUT"
|
||||
|
||||
# Store the build directory to ensure correct paths when extracting from subdirectories
|
||||
BUILD_DIR=$(pwd)
|
||||
|
||||
# Create temporary directories for extracting objects
|
||||
TMP_SECP256K1=".tmp_secp256k1_$$"
|
||||
TMP_OPENSSL=".tmp_openssl_$$"
|
||||
@@ -379,21 +403,21 @@ if [ -f "$SECP256K1_LIB" ]; then
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Extracting secp256k1 objects..."
|
||||
fi
|
||||
(cd "$TMP_SECP256K1" && ar x "../$SECP256K1_LIB")
|
||||
(cd "$TMP_SECP256K1" && ar x "$BUILD_DIR/$SECP256K1_LIB")
|
||||
fi
|
||||
|
||||
# Extract OpenSSL objects
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Extracting OpenSSL objects..."
|
||||
fi
|
||||
(cd "$TMP_OPENSSL" && ar x "../openssl-install/lib64/libssl.a")
|
||||
(cd "$TMP_OPENSSL" && ar x "../openssl-install/lib64/libcrypto.a")
|
||||
(cd "$TMP_OPENSSL" && ar x "$BUILD_DIR/openssl-install/lib64/libssl.a")
|
||||
(cd "$TMP_OPENSSL" && ar x "$BUILD_DIR/openssl-install/lib64/libcrypto.a")
|
||||
|
||||
# Extract curl objects
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
print_info "Extracting curl objects..."
|
||||
fi
|
||||
(cd "$TMP_CURL" && ar x "../curl-install/lib/libcurl.a")
|
||||
(cd "$TMP_CURL" && ar x "$BUILD_DIR/curl-install/lib/libcurl.a")
|
||||
|
||||
# Combine all objects into final library
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
|
||||
Reference in New Issue
Block a user