# NOSTR Core Library Makefile # Standalone library build system CC = gcc AR = ar CFLAGS = -Wall -Wextra -std=c99 -fPIC -O2 DEBUG_CFLAGS = -Wall -Wextra -std=c99 -fPIC -g -DDEBUG STATIC_CFLAGS = -Wall -Wextra -std=c99 -O2 -static # Logging compile flags LOGGING_FLAGS ?= -DENABLE_FILE_LOGGING -DENABLE_WEBSOCKET_LOGGING -DENABLE_DEBUG_LOGGING ifneq ($(ENABLE_LOGGING),) LOGGING_FLAGS += -DENABLE_FILE_LOGGING -DENABLE_WEBSOCKET_LOGGING -DENABLE_DEBUG_LOGGING endif # Include paths INCLUDES = -I. -Inostr_core -Icjson -Isecp256k1/include # Library source files LIB_SOURCES = nostr_core/core.c nostr_core/core_relays.c nostr_core/nostr_crypto.c nostr_core/nostr_secp256k1.c nostr_core/nostr_aes.c nostr_core/nostr_chacha20.c cjson/cJSON.c LIB_OBJECTS = $(LIB_SOURCES:.c=.o) ARM64_LIB_OBJECTS = $(LIB_SOURCES:.c=.arm64.o) # Library outputs (static only) STATIC_LIB = libnostr_core.a ARM64_STATIC_LIB = libnostr_core_arm64.a # Example files EXAMPLE_SOURCES = $(wildcard examples/*.c) EXAMPLE_TARGETS = $(EXAMPLE_SOURCES:.c=) # Default target - build static library default: $(STATIC_LIB) # Build all targets (static only) all: $(STATIC_LIB) examples # Static library $(STATIC_LIB): $(LIB_OBJECTS) @echo "Creating static library: $@" $(AR) rcs $@ $^ # ARM64 cross-compilation settings ARM64_CC = aarch64-linux-gnu-gcc ARM64_AR = aarch64-linux-gnu-ar ARM64_INCLUDES = -I. -Inostr_core -Icjson # ARM64 static library $(ARM64_STATIC_LIB): $(ARM64_LIB_OBJECTS) @echo "Creating ARM64 static library: $@" $(ARM64_AR) rcs $@ $^ # Object files (x86_64) %.o: %.c @echo "Compiling: $<" $(CC) $(CFLAGS) $(LOGGING_FLAGS) $(INCLUDES) -c $< -o $@ # ARM64 object files %.arm64.o: %.c @echo "Compiling for ARM64: $<" $(ARM64_CC) $(CFLAGS) $(LOGGING_FLAGS) $(ARM64_INCLUDES) -c $< -o $@ # Examples examples: $(EXAMPLE_TARGETS) examples/%: examples/%.c $(STATIC_LIB) @echo "Building example: $@" $(CC) $(STATIC_CFLAGS) $(LOGGING_FLAGS) $(INCLUDES) $< -o $@ ./libnostr_core.a ./secp256k1/.libs/libsecp256k1.a -lm # ARM64 targets arm64: $(ARM64_STATIC_LIB) arm64-all: $(ARM64_STATIC_LIB) # Debug build debug: CFLAGS = $(DEBUG_CFLAGS) debug: clean default # Install library to system (static only) install: $(STATIC_LIB) @echo "Installing static library..." sudo cp $(STATIC_LIB) /usr/local/lib/ sudo cp nostr_core/nostr_core.h /usr/local/include/ sudo cp nostr_core/nostr_crypto.h /usr/local/include/ # Uninstall library uninstall: @echo "Uninstalling library..." sudo rm -f /usr/local/lib/$(STATIC_LIB) sudo rm -f /usr/local/include/nostr_core.h sudo rm -f /usr/local/include/nostr_crypto.h # Test the library test: examples/simple_keygen @echo "Running simple key generation test..." ./examples/simple_keygen # Run crypto tests test-crypto: @echo "Running comprehensive crypto test suite..." cd tests && make test # Clean build artifacts clean: @echo "Cleaning build artifacts..." rm -f $(LIB_OBJECTS) $(ARM64_LIB_OBJECTS) rm -f $(STATIC_LIB) $(ARM64_STATIC_LIB) rm -f $(EXAMPLE_TARGETS) # Create distribution package dist: clean @echo "Creating distribution package..." mkdir -p dist/nostr_core cp -r *.h *.c Makefile examples/ tests/ README.md LICENSE dist/nostr_core/ 2>/dev/null || true cd dist && tar -czf nostr_core.tar.gz nostr_core/ @echo "Distribution package created: dist/nostr_core.tar.gz" # Help help: @echo "NOSTR Core Library Build System" @echo "===============================" @echo "" @echo "Available targets:" @echo " default - Build static library (recommended)" @echo " all - Build static library and examples" @echo " arm64 - Build ARM64 static library" @echo " arm64-all - Build ARM64 static library" @echo " debug - Build with debug symbols" @echo " examples - Build example programs" @echo " test - Run simple test" @echo " test-crypto - Run comprehensive crypto test suite" @echo " install - Install static library to system (/usr/local)" @echo " uninstall - Remove library from system" @echo " clean - Remove build artifacts" @echo " dist - Create distribution package" @echo " help - Show this help" @echo "" @echo "Library outputs (static only):" @echo " $(STATIC_LIB) - x86_64 static library" @echo " $(ARM64_STATIC_LIB) - ARM64 static library" .PHONY: default all arm64 arm64-all debug examples test test-crypto install uninstall clean dist help