Makefile raw

   1  .PHONY: test build clean examples install-deps check fmt vet lint
   2  
   3  # Test the package
   4  test:
   5  	go test -v ./...
   6  
   7  # Run benchmarks
   8  bench:
   9  	go test -bench=. -benchmem ./...
  10  
  11  # Build examples
  12  build: examples
  13  
  14  examples:
  15  	@echo "Building examples..."
  16  	@mkdir -p bin
  17  	@go build -o bin/ecdsa-example ./examples/ecdsa
  18  	@go build -o bin/schnorr-example ./examples/schnorr
  19  	@go build -o bin/ecdh-example ./examples/ecdh
  20  	@go build -o bin/recovery-example ./examples/recovery
  21  	@echo "Examples built in bin/"
  22  
  23  # Run all examples
  24  run-examples: examples
  25  	@echo "\n=== ECDSA Example ==="
  26  	@./bin/ecdsa-example
  27  	@echo "\n=== Schnorr Example ==="
  28  	@./bin/schnorr-example || echo "Schnorr module not available"
  29  	@echo "\n=== ECDH Example ==="
  30  	@./bin/ecdh-example || echo "ECDH module not available"
  31  	@echo "\n=== Recovery Example ==="
  32  	@./bin/recovery-example || echo "Recovery module not available"
  33  
  34  # Clean build artifacts
  35  clean:
  36  	@rm -rf bin/
  37  	@go clean
  38  
  39  # Install dependencies
  40  install-deps:
  41  	go get -u ./...
  42  	go mod tidy
  43  
  44  # Check code
  45  check: fmt vet
  46  
  47  # Format code
  48  fmt:
  49  	go fmt ./...
  50  
  51  # Run go vet
  52  vet:
  53  	go vet ./...
  54  
  55  # Run linter (requires golangci-lint)
  56  lint:
  57  	@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install from https://golangci-lint.run/usage/install/"; exit 1)
  58  	golangci-lint run
  59  
  60  # Show module information
  61  info:
  62  	@echo "Module: p8k.mleku.dev"
  63  	@echo "Go version: $(shell go version)"
  64  	@echo "Dependencies:"
  65  	@go list -m all
  66  
  67  # Download and build libsecp256k1 from source (Linux/macOS)
  68  install-secp256k1:
  69  	@echo "Downloading and building libsecp256k1..."
  70  	@rm -rf /tmp/secp256k1
  71  	@git clone https://github.com/bitcoin-core/secp256k1 /tmp/secp256k1
  72  	@cd /tmp/secp256k1 && ./autogen.sh
  73  	@cd /tmp/secp256k1 && ./configure --enable-module-recovery --enable-module-schnorrsig --enable-module-ecdh --enable-module-extrakeys
  74  	@cd /tmp/secp256k1 && make
  75  	@cd /tmp/secp256k1 && sudo make install
  76  	@sudo ldconfig || true
  77  	@echo "libsecp256k1 installed successfully"
  78  
  79  # Help
  80  help:
  81  	@echo "Available targets:"
  82  	@echo "  test              - Run tests"
  83  	@echo "  bench             - Run benchmarks"
  84  	@echo "  build             - Build examples"
  85  	@echo "  examples          - Build examples (alias for build)"
  86  	@echo "  run-examples      - Build and run all examples"
  87  	@echo "  clean             - Clean build artifacts"
  88  	@echo "  install-deps      - Install Go dependencies"
  89  	@echo "  check             - Run fmt and vet"
  90  	@echo "  fmt               - Format code"
  91  	@echo "  vet               - Run go vet"
  92  	@echo "  lint              - Run golangci-lint"
  93  	@echo "  info              - Show module information"
  94  	@echo "  install-secp256k1 - Download and build libsecp256k1 from source"
  95  	@echo "  help              - Show this help message"
  96  
  97