diff --git a/.gitignore b/.gitignore index 4255469..19c1f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ nips/ build/ relay.log Trash/ +src/version.h diff --git a/Makefile b/Makefile index d0d5b05..69ee8e4 100644 --- a/Makefile +++ b/Makefile @@ -36,19 +36,68 @@ $(NOSTR_CORE_LIB): @echo "Building nostr_core_lib..." cd nostr_core_lib && ./build.sh +# Generate version.h from git tags +src/version.h: + @if [ -d .git ]; then \ + echo "Generating version.h from git tags..."; \ + VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "unknown"); \ + if echo "$$VERSION" | grep -q "^v[0-9]"; then \ + CLEAN_VERSION=$$(echo "$$VERSION" | sed 's/^v//'); \ + MAJOR=$$(echo "$$CLEAN_VERSION" | cut -d. -f1); \ + MINOR=$$(echo "$$CLEAN_VERSION" | cut -d. -f2); \ + PATCH=$$(echo "$$CLEAN_VERSION" | cut -d. -f3 | cut -d- -f1); \ + else \ + CLEAN_VERSION="0.0.0-$$VERSION"; \ + MAJOR=0; MINOR=0; PATCH=0; \ + fi; \ + echo "/* Auto-generated version information */" > src/version.h; \ + echo "#ifndef VERSION_H" >> src/version.h; \ + echo "#define VERSION_H" >> src/version.h; \ + echo "" >> src/version.h; \ + echo "#define VERSION \"$$VERSION\"" >> src/version.h; \ + echo "#define VERSION_MAJOR $$MAJOR" >> src/version.h; \ + echo "#define VERSION_MINOR $$MINOR" >> src/version.h; \ + echo "#define VERSION_PATCH $$PATCH" >> src/version.h; \ + echo "" >> src/version.h; \ + echo "#endif /* VERSION_H */" >> src/version.h; \ + echo "Generated version.h with version: $$VERSION"; \ + elif [ ! -f src/version.h ]; then \ + echo "Git not available and version.h missing, creating fallback version.h..."; \ + VERSION="unknown"; \ + echo "/* Auto-generated version information */" > src/version.h; \ + echo "#ifndef VERSION_H" >> src/version.h; \ + echo "#define VERSION_H" >> src/version.h; \ + echo "" >> src/version.h; \ + echo "#define VERSION \"$$VERSION\"" >> src/version.h; \ + echo "#define VERSION_MAJOR 0" >> src/version.h; \ + echo "#define VERSION_MINOR 0" >> src/version.h; \ + echo "#define VERSION_PATCH 0" >> src/version.h; \ + echo "" >> src/version.h; \ + echo "#endif /* VERSION_H */" >> src/version.h; \ + echo "Created fallback version.h with version: $$VERSION"; \ + else \ + echo "Git not available, preserving existing version.h"; \ + fi + +# Force version.h regeneration (useful for development) +force-version: + @echo "Force regenerating version.h..." + @rm -f src/version.h + @$(MAKE) src/version.h + # Build the relay -$(TARGET): $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB) +$(TARGET): $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB) @echo "Compiling C-Relay for architecture: $(ARCH)" $(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS) @echo "Build complete: $(TARGET)" # Build for specific architectures -x86: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB) +x86: $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB) @echo "Building C-Relay for x86_64..." $(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_x86 $(NOSTR_CORE_LIB) $(LIBS) @echo "Build complete: $(BUILD_DIR)/c_relay_x86" -arm64: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB) +arm64: $(BUILD_DIR) src/version.h $(MAIN_SRC) $(NOSTR_CORE_LIB) @echo "Cross-compiling C-Relay for ARM64..." @if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \ echo "ERROR: ARM64 cross-compiler not found."; \ @@ -120,6 +169,7 @@ init-db: # Clean build artifacts clean: rm -rf $(BUILD_DIR) + rm -f src/version.h @echo "Clean complete" # Clean everything including nostr_core_lib @@ -158,5 +208,6 @@ help: @echo " make check-toolchain # Check what compilers are available" @echo " make test # Run tests" @echo " make init-db # Set up database" + @echo " make force-version # Force regenerate version.h from git" -.PHONY: all x86 arm64 test init-db clean clean-all install-deps install-cross-tools install-arm64-deps check-toolchain help \ No newline at end of file +.PHONY: all x86 arm64 test init-db clean clean-all install-deps install-cross-tools install-arm64-deps check-toolchain help force-version \ No newline at end of file diff --git a/build_output.log b/build_output.log deleted file mode 100644 index 66e0a59..0000000 --- a/build_output.log +++ /dev/null @@ -1,28 +0,0 @@ -=== C Nostr Relay Build and Restart Script === -Removing old configuration file to trigger regeneration... -✓ Configuration file removed - will be regenerated with latest database values -Building project... -rm -rf build -Clean complete -mkdir -p build -Compiling C-Relay for architecture: x86_64 -gcc -Wall -Wextra -std=c99 -g -O2 -I. -Inostr_core_lib -Inostr_core_lib/nostr_core -Inostr_core_lib/cjson -Inostr_core_lib/nostr_websocket src/main.c src/config.c -o build/c_relay_x86 nostr_core_lib/libnostr_core_x64.a -lsqlite3 -lwebsockets -lz -ldl -lpthread -lm -L/usr/local/lib -lsecp256k1 -lssl -lcrypto -L/usr/local/lib -lcurl -Build complete: build/c_relay_x86 -Build successful. Proceeding with relay restart... -Stopping any existing relay servers... -No existing relay found -Starting relay server... -Debug: Current processes: None -Started with PID: 786684 -Relay started successfully! -PID: 786684 -WebSocket endpoint: ws://127.0.0.1:8888 -Log file: relay.log - -=== Relay server running in background === -To kill relay: pkill -f 'c_relay_' -To check status: ps aux | grep c_relay_ -To view logs: tail -f relay.log -Binary: ./build/c_relay_x86 -Ready for Nostr client connections! - diff --git a/src/config.c b/src/config.c index 3bac140..42bf8ad 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,5 @@ #include "config.h" +#include "version.h" #include #include #include @@ -734,7 +735,7 @@ cJSON* create_config_nostr_event(const char* privkey_hex) { {"relay_contact", ""}, {"relay_pubkey", ""}, {"relay_software", "https://git.laantungir.net/laantungir/c-relay.git"}, - {"relay_version", "0.2.0"}, + {"relay_version", VERSION}, // NIP-13 Proof of Work {"pow_enabled", "true"},