This commit is contained in:
2025-08-09 11:07:11 -04:00
parent ca6b4754f9
commit e137560d64
10 changed files with 395 additions and 135 deletions

117
build.sh
View File

@@ -2,6 +2,7 @@
# NOSTR Core Library Build Script
# Provides convenient build targets for the standalone library
# Automatically increments patch version with each build
set -e # Exit on any error
@@ -29,6 +30,117 @@ print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to automatically increment version
increment_version() {
print_status "Incrementing version..."
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_warning "Not in a git repository - skipping version increment"
return 0
fi
# Get the highest version tag (not necessarily the most recent chronologically)
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n 1 || echo "v0.1.0")
if [[ -z "$LATEST_TAG" ]]; then
LATEST_TAG="v0.1.0"
fi
# Extract version components (remove 'v' prefix if present)
VERSION=${LATEST_TAG#v}
# Parse major.minor.patch
if [[ $VERSION =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
else
print_error "Invalid version format in tag: $LATEST_TAG"
print_error "Expected format: v0.1.0"
return 1
fi
# Increment patch version
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="v${MAJOR}.${MINOR}.${NEW_PATCH}"
print_status "Current version: $LATEST_TAG"
print_status "New version: $NEW_VERSION"
# Create new git tag
if git tag "$NEW_VERSION" 2>/dev/null; then
print_success "Created new version tag: $NEW_VERSION"
# Generate version.h header file
cat > nostr_core/version.h << EOF
/*
* NOSTR Core Library - Auto-Generated Version Header
* DO NOT EDIT THIS FILE MANUALLY - Generated by build.sh
*/
#ifndef NOSTR_VERSION_H
#define NOSTR_VERSION_H
#define VERSION_MAJOR ${MAJOR}
#define VERSION_MINOR ${MINOR}
#define VERSION_PATCH ${NEW_PATCH}
#define VERSION_STRING "${MAJOR}.${MINOR}.${NEW_PATCH}"
#define VERSION_TAG "${NEW_VERSION}"
/* Build information */
#define BUILD_DATE "$(date +%Y-%m-%d)"
#define BUILD_TIME "$(date +%H:%M:%S)"
#define BUILD_TIMESTAMP "$(date '+%Y-%m-%d %H:%M:%S')"
/* Git information */
#define GIT_HASH "$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
#define GIT_BRANCH "$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')"
/* Display versions */
#define VERSION_DISPLAY "${NEW_VERSION}"
#define VERSION_FULL_DISPLAY "${NEW_VERSION} ($(date '+%Y-%m-%d %H:%M:%S'), $(git rev-parse --short HEAD 2>/dev/null || echo 'unknown'))"
/* Version API functions */
const char* nostr_core_get_version(void);
const char* nostr_core_get_version_full(void);
const char* nostr_core_get_build_info(void);
#endif /* NOSTR_VERSION_H */
EOF
# Generate version.c implementation file
cat > nostr_core/version.c << EOF
/*
* NOSTR Core Library - Auto-Generated Version Implementation
* DO NOT EDIT THIS FILE MANUALLY - Generated by build.sh
*/
#include "version.h"
const char* nostr_core_get_version(void) {
return VERSION_TAG;
}
const char* nostr_core_get_version_full(void) {
return VERSION_FULL_DISPLAY;
}
const char* nostr_core_get_build_info(void) {
return "Built on " BUILD_DATE " at " BUILD_TIME " from commit " GIT_HASH " on branch " GIT_BRANCH;
}
EOF
print_success "Generated version.h and version.c"
else
print_warning "Tag $NEW_VERSION already exists - using existing version"
NEW_VERSION=$LATEST_TAG
fi
# Update VERSION file for compatibility
echo "${NEW_VERSION#v}" > VERSION
print_success "Updated VERSION file to ${NEW_VERSION#v}"
}
# Function to show usage
show_usage() {
echo "NOSTR Core Library Build Script"
@@ -64,6 +176,7 @@ case "$TARGET" in
;;
lib|library)
increment_version
print_status "Building static library..."
make clean
make
@@ -78,6 +191,7 @@ case "$TARGET" in
;;
shared)
increment_version
print_status "Building shared library..."
make clean
make libnostr_core.so
@@ -92,6 +206,7 @@ case "$TARGET" in
;;
all)
increment_version
print_status "Building all libraries..."
make clean
make all
@@ -100,6 +215,7 @@ case "$TARGET" in
;;
examples)
increment_version
print_status "Building examples..."
make clean
make
@@ -135,6 +251,7 @@ case "$TARGET" in
;;
install)
increment_version
print_status "Installing library to system..."
make clean
make all