diff --git a/.gitignore b/.gitignore index b491846..cd87336 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ dist/ # Nightly python remake tools/ + +# build files +bin/ diff --git a/Makefile b/Makefile index bb257e3..6122476 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,12 @@ BINARY_NAME := chatlog GO := go + +# Embed version into binary ifeq ($(VERSION),) - VERSION := $(shell git describe --tags --always --dirty="-dev") + VERSION := $(shell git describe --tags --always --dirty="-dev" 2>/dev/null) +endif +ifeq ($(VERSION),) + VERSION := dev endif LDFLAGS := -ldflags '-X "github.com/sjzar/chatlog/pkg/version.Version=$(VERSION)" -w -s' @@ -19,7 +24,7 @@ UPX_PLATFORMS := \ linux/arm64 \ windows/amd64 -.PHONY: all clean lint tidy test build crossbuild upx +.PHONY: all clean lint tidy test build upx all: clean lint tidy test build @@ -41,20 +46,25 @@ test: build: @echo "🔨 Building for current platform..." + @mkdir -p bin CGO_ENABLED=1 $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go -crossbuild: clean - @echo "🌍 Building for multiple platforms..." - for platform in $(PLATFORMS); do \ - os=$$(echo $$platform | cut -d/ -f1); \ - arch=$$(echo $$platform | cut -d/ -f2); \ - float=$$(echo $$platform | cut -d/ -f3); \ - output_name=bin/chatlog_$${os}_$${arch}; \ - [ "$$float" != "" ] && output_name=$$output_name_$$float; \ - echo "🔨 Building for $$os/$$arch..."; \ - echo "🔨 Building for $$output_name..."; \ - GOOS=$$os GOARCH=$$arch CGO_ENABLED=1 GOARM=$$float $(GO) build -trimpath $(LDFLAGS) -o $$output_name main.go ; \ - if [ "$(ENABLE_UPX)" = "1" ] && echo "$(UPX_PLATFORMS)" | grep -q "$$os/$$arch"; then \ - echo "⚙️ Compressing binary $$output_name..." && upx --best $$output_name; \ +build-windows: + @echo "🪟 Cross-compiling for Windows amd64..." + @mkdir -p bin + @if [ "$(OS)" = "Windows_NT" ]; then \ + # On Windows host, don't force CC; rely on local toolchain (e.g. MSYS2 mingw64). \ + echo "🧭 Host detected: Windows"; \ + GOOS=windows GOARCH=amd64 CGO_ENABLED=1 $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME)_windows_amd64.exe main.go; \ + else \ + # Non-Windows host: require mingw-w64 cross compiler. Use fallback if CC_WIN_AMD64 is empty. \ + ccbin=$${CC_WIN_AMD64:-x86_64-w64-mingw32-gcc}; \ + echo "🛠 Resolving MinGW: $$ccbin"; \ + if ! command -v "$$ccbin" >/dev/null 2>&1; then \ + echo "❌ $$ccbin not found in PATH."; \ + echo " Arch Linux: sudo pacman -S --needed mingw-w64-gcc"; \ + exit 1; \ fi; \ - done \ No newline at end of file + echo "⚙️ Using CC=$$ccbin"; \ + env CC="$$ccbin" GOOS=windows GOARCH=amd64 CGO_ENABLED=1 $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME)_windows_amd64.exe main.go; \ + fi \ No newline at end of file diff --git a/chatlog b/chatlog deleted file mode 100644 index b9a6bd8..0000000 Binary files a/chatlog and /dev/null differ