feat: add build-debug target and strip symbols for smaller default binary

This commit is contained in:
easyzoom 2026-02-15 10:11:24 +08:00
parent ddd73cad48
commit adabfafede

View file

@ -1,4 +1,4 @@
.PHONY: all build install uninstall clean help test .PHONY: all build build-debug build-all install uninstall clean help test
# Build variables # Build variables
BINARY_NAME=picoclaw BINARY_NAME=picoclaw
@ -11,7 +11,9 @@ VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT=$(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "dev") GIT_COMMIT=$(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date +%FT%T%z) BUILD_TIME=$(shell date +%FT%T%z)
GO_VERSION=$(shell $(GO) version | awk '{print $$3}') GO_VERSION=$(shell $(GO) version | awk '{print $$3}')
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)" # -s -w: strip symbol table and DWARF for smaller binary (default)
LDFLAGS=-ldflags "$(if $(DEBUG),,-s -w )-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)"
LDFLAGS_DEBUG=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)"
# Go variables # Go variables
GO?=go GO?=go
@ -78,6 +80,14 @@ build: generate
@echo "Build complete: $(BINARY_PATH)" @echo "Build complete: $(BINARY_PATH)"
@ln -sf $(BINARY_NAME)-$(PLATFORM)-$(ARCH) $(BUILD_DIR)/$(BINARY_NAME) @ln -sf $(BINARY_NAME)-$(PLATFORM)-$(ARCH) $(BUILD_DIR)/$(BINARY_NAME)
## build-debug: Build with symbol table and DWARF for debugging (larger binary)
build-debug: generate
@echo "Building $(BINARY_NAME) for $(PLATFORM)/$(ARCH) (debug, with symbols)..."
@mkdir -p $(BUILD_DIR)
@$(GO) build $(GOFLAGS) $(LDFLAGS_DEBUG) -o $(BUILD_DIR)/$(BINARY_NAME)-$(PLATFORM)-$(ARCH)-debug ./$(CMD_DIR)
@ln -sf $(BINARY_NAME)-$(PLATFORM)-$(ARCH)-debug $(BUILD_DIR)/$(BINARY_NAME)
@echo "Debug build complete: $(BUILD_DIR)/$(BINARY_NAME)"
## build-all: Build picoclaw for all platforms ## build-all: Build picoclaw for all platforms
build-all: generate build-all: generate
@echo "Building for multiple platforms..." @echo "Building for multiple platforms..."
@ -151,7 +161,8 @@ help:
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /' @grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
@echo "" @echo ""
@echo "Examples:" @echo "Examples:"
@echo " make build # Build for current platform" @echo " make build # Build for current platform (minimal size)"
@echo " make build-debug # Build with symbols for debugging"
@echo " make install # Install to ~/.local/bin" @echo " make install # Install to ~/.local/bin"
@echo " make uninstall # Remove from /usr/local/bin" @echo " make uninstall # Remove from /usr/local/bin"
@echo " make install-skills # Install skills to workspace" @echo " make install-skills # Install skills to workspace"
@ -160,6 +171,7 @@ help:
@echo " INSTALL_PREFIX # Installation prefix (default: ~/.local)" @echo " INSTALL_PREFIX # Installation prefix (default: ~/.local)"
@echo " WORKSPACE_DIR # Workspace directory (default: ~/.picoclaw/workspace)" @echo " WORKSPACE_DIR # Workspace directory (default: ~/.picoclaw/workspace)"
@echo " VERSION # Version string (default: git describe)" @echo " VERSION # Version string (default: git describe)"
@echo " DEBUG=1 # Keep symbols for debugging (make build-debug)"
@echo "" @echo ""
@echo "Current Configuration:" @echo "Current Configuration:"
@echo " Platform: $(PLATFORM)/$(ARCH)" @echo " Platform: $(PLATFORM)/$(ARCH)"