From ca10b01fb0d771f05757c12d6b7d51aed36a4612 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Fri, 31 Oct 2025 18:41:32 +0100 Subject: [PATCH] Update makefile --- Makefile | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- README.md | 30 ++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2fd4a6b..fffc93d 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,83 @@ EXEC=entity-maker +BUILD_DIR=./build +CMD_DIR=./cmd/entity-maker + +# Build variables +GOOS ?= linux +GOARCH ?= amd64 +LDFLAGS=-s -w .PHONY: build build: - @go build -ldflags "-s -w" -o ./build/${EXEC} ./cmd/entity-maker/main.go + @echo "Building ${EXEC} for ${GOOS}/${GOARCH}..." + @mkdir -p ${BUILD_DIR} + @CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build \ + -ldflags "${LDFLAGS}" \ + -trimpath \ + -o ${BUILD_DIR}/${EXEC} \ + ${CMD_DIR} + @echo "✓ Binary created: ${BUILD_DIR}/${EXEC}" + @ls -lh ${BUILD_DIR}/${EXEC} +.PHONY: build-dev +build-dev: + @echo "Building ${EXEC} (development mode)..." + @mkdir -p ${BUILD_DIR} + @go build -o ${BUILD_DIR}/${EXEC} ${CMD_DIR} + @echo "✓ Binary created: ${BUILD_DIR}/${EXEC}" + + +.PHONY: install +install: build + @echo "Installing ${EXEC} to /usr/local/bin..." + @sudo cp ${BUILD_DIR}/${EXEC} /usr/local/bin/${EXEC} + @echo "✓ Installed successfully" + + +.PHONY: clean +clean: + @echo "Cleaning build artifacts..." + @rm -rf ${BUILD_DIR} + @rm -f ${EXEC} + @echo "✓ Clean complete" + + +.PHONY: test +test: + @echo "Running tests..." + @go test -v ./... + + +.PHONY: verify-static +verify-static: build + @echo "Verifying binary is statically linked..." + @file ${BUILD_DIR}/${EXEC} + @ldd ${BUILD_DIR}/${EXEC} 2>&1 || echo "✓ Binary is statically linked" + + +.PHONY: upgrade-packages upgrade-packages: + @echo "Upgrading Go packages..." @go get -u ./... + @go mod tidy + @echo "✓ Packages upgraded" + + +.PHONY: help +help: + @echo "Entity Maker - Makefile targets:" + @echo "" + @echo " build Build static binary for Linux (default)" + @echo " build-dev Build development binary with debug symbols" + @echo " install Install binary to /usr/local/bin" + @echo " clean Remove build artifacts" + @echo " test Run tests" + @echo " verify-static Verify binary has no dynamic dependencies" + @echo " upgrade-packages Update Go dependencies" + @echo " help Show this help message" + @echo "" + @echo "Build options:" + @echo " GOOS=linux GOARCH=amd64 make build (default)" + @echo "" diff --git a/README.md b/README.md index 7c14ce8..e94c0b2 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,40 @@ A command-line tool for generating SQLAlchemy entities from PostgreSQL database ### Build from source +Using Makefile (recommended): + ```bash +# Build static binary (production-ready, fully portable) +make build + +# Build with debug symbols (development) +make build-dev + +# Install to /usr/local/bin +make install + +# Clean build artifacts +make clean + +# Verify binary has no dependencies +make verify-static + +# Show all available targets +make help +``` + +Or using Go directly: + +```bash +# Static binary (portable across all Linux x86-64 systems) +CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o ./build/entity-maker ./cmd/entity-maker + +# Development binary with debug symbols go build -o entity-maker ./cmd/entity-maker ``` +The static binary (`make build`) is **fully portable** and will run on any Linux x86-64 system without external dependencies. + ## Usage ### Interactive Mode