lon-tool/Makefile

48 lines
1.6 KiB
Makefile
Raw Normal View History

2024-06-17 18:50:47 +00:00
# Define variables
2024-06-21 12:30:09 +00:00
NAME = lon-tool
2024-06-17 18:50:47 +00:00
SRC ?= main.go
BIN_DIR ?= ./bin
2024-06-21 13:15:23 +00:00
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
2024-06-23 09:44:19 +00:00
GOFLAGS ?= -ldflags="-s -w -X git.timoxa0.su/timoxa0/lon-tool/cmd.version=$(GIT_VERSION)"
WINDOWS_GOFLAGS ?= -ldflags="-extldflags=-static -s -w -X git.timoxa0.su/timoxa0/lon-tool/cmd.version=$(GIT_VERSION)"
2024-06-17 18:50:47 +00:00
# Windows settings
2024-06-21 12:30:09 +00:00
WINDOWS_BIN = $(BIN_DIR)/$(NAME)_win_amd64.exe
2024-06-17 18:50:47 +00:00
WINDOWS_CC = x86_64-w64-mingw32-gcc
WINDOWS_CXX = x86_64-w64-mingw32-g++
2024-06-23 05:26:23 +00:00
WINDOWS_PKG_CONFIG_PATH = /usr/x86_64-w64-mingw32/lib/pkgconfig
WINDOWS_CGO_CFLAGS = -I/usr/x86_64-w64-mingw32/include
WINDOWS_CGO_LDFLAGS = -L/usr/x86_64-w64-mingw32/lib
2024-06-17 18:50:47 +00:00
# Linux settings
2024-06-21 12:30:09 +00:00
LINUX_BIN = $(BIN_DIR)/$(NAME)_lin_amd64
2024-06-17 18:50:47 +00:00
LINUX_CC = x86_64-linux-gnu-gcc
LINUX_CXX = x86_64-linux-gnu-g++
2024-06-23 05:26:23 +00:00
LINUX_PKG_CONFIG_PATH = /usr/lib/pkgconfig
LINUX_CGO_CFLAGS = -I/usr/include
LINUX_CGO_LDFLAGS = -L/usr/lib
2024-06-17 18:50:47 +00:00
# Targets
2024-06-23 05:26:23 +00:00
all: windows linux
2024-06-17 18:50:47 +00:00
windows:
2024-06-21 13:30:43 +00:00
@echo "Building windows bin"
2024-06-17 18:50:47 +00:00
@export CGO_ENABLED=1 GOARCH=amd64 GOOS=windows CC=$(WINDOWS_CC) CXX=$(WINDOWS_CXX) \
PKG_CONFIG_PATH=$(WINDOWS_PKG_CONFIG_PATH) CGO_CFLAGS=$(WINDOWS_CGO_CFLAGS) \
CGO_LDFLAGS=$(WINDOWS_CGO_LDFLAGS) && \
2024-06-21 13:15:23 +00:00
go build $(WINDOWS_GOFLAGS) -o $(WINDOWS_BIN) $(SRC) && \
2024-06-17 18:50:47 +00:00
echo "- saved to $(WINDOWS_BIN)"
linux:
2024-06-21 13:30:43 +00:00
@echo "Building linux bin"
2024-06-17 18:50:47 +00:00
@export CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CC=$(LINUX_CC) CXX=$(LINUX_CXX) \
PKG_CONFIG_PATH=$(LINUX_PKG_CONFIG_PATH) CGO_CFLAGS=$(LINUX_CGO_CFLAGS) \
CGO_LDFLAGS=$(LINUX_CGO_LDFLAGS) && \
go build $(GOFLAGS) -o $(LINUX_BIN) $(SRC) && \
echo "- saved to $(LINUX_BIN)"
clean:
rm -f $(MACOS_BIN) $(WINDOWS_BIN) $(LINUX_BIN)
.PHONY: all macos windows linux clean