44# Use bash for all shell commands (required for pipefail and other bash features)
55SHELL := /bin/bash
66
7- .PHONY : all test test-unit test-integration test-e2e format lint build build/pkg install package clean \
7+ .PHONY : all test test-unit test-integration test-e2e format lint build build-all build /pkg install package clean \
88 build-demo build-demo-grpc build-demo-http format/go format/yaml lint/go lint/yaml \
99 lint/action lint/makefile lint/license-header lint/license-header/fix lint/dockerfile actionlint yamlfmt gotestfmt ratchet ratchet/pin \
1010 ratchet/update ratchet/check golangci-lint embedmd checkmake hadolint help docs check-embed \
@@ -15,6 +15,7 @@ SHELL := /bin/bash
1515
1616# Constant variables
1717BINARY_NAME := otel
18+ PLATFORMS := darwin/amd64 linux/amd64 windows/amd64 darwin/arm64 linux/arm64
1819TOOL_DIR := tool/cmd
1920INST_PKG_GZIP = otel-pkg.gz
2021INST_PKG_TMP = pkg_temp
@@ -26,6 +27,8 @@ GOOS ?= $(shell go env GOOS)
2627VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
2728COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
2829BUILD_TIME := $(shell date -u '+% Y-% m-% d')
30+ LDFLAGS := -X main.Version=$(VERSION ) -X main.CommitHash=$(COMMIT_HASH ) -X main.BuildTime=$(BUILD_TIME )
31+ GO_BUILD_CMD := go build -trimpath -a -ldflags "$(LDFLAGS ) "
2932EXT :=
3033ifeq ($(GOOS ) ,windows)
3134 EXT = .exe
@@ -60,9 +63,24 @@ build: build/pkg package ## Build the instrumentation tool
6063 @echo " Building instrumentation tool..."
6164 @cp $(API_SYNC_SOURCE ) $(API_SYNC_TARGET )
6265 @go mod tidy
63- @go build -a -ldflags " -X main.Version= $( VERSION ) -X main.CommitHash= $( COMMIT_HASH ) -X main.BuildTime= $( BUILD_TIME ) " -o $(BINARY_NAME )$(EXT ) ./$(TOOL_DIR )
66+ @$( GO_BUILD_CMD ) -o $(BINARY_NAME )$(EXT ) ./$(TOOL_DIR )
6467 @./$(BINARY_NAME )$(EXT ) version
6568
69+ build-all : build/pkg package # # Build the instrumentation tool for all platforms
70+ @echo " Building instrumentation tool for all platforms..."
71+ @cp $(API_SYNC_SOURCE ) $(API_SYNC_TARGET )
72+ @go mod tidy
73+ @mkdir -p dist
74+ @for platform in $(PLATFORMS ) ; do \
75+ GOOS=$$ {platform%/* }; \
76+ GOARCH=$$ {platform#* /}; \
77+ echo " Building for $$ GOOS/$$ GOARCH..." ; \
78+ EXT=" " ; \
79+ if [ " $$ GOOS" = " windows" ]; then EXT=" .exe" ; fi ; \
80+ env GOOS=$$ GOOS GOARCH=$$ GOARCH $(GO_BUILD_CMD ) -o dist/$(BINARY_NAME ) -$$ GOOS-$$ GOARCH$$ EXT ./$(TOOL_DIR ) ; \
81+ done
82+ @echo " All builds completed. Artifacts in dist/"
83+
6684install : package # # Install otel to $$GOPATH/bin (auto-packages instrumentation)
6785 @echo " Installing otel..."
6886 @cp $(API_SYNC_SOURCE ) $(API_SYNC_TARGET )
@@ -339,6 +357,7 @@ test-e2e/coverage: build gotestfmt
339357
340358clean : # # Clean build artifacts
341359 @echo " Cleaning build artifacts..."
360+ rm -rf dist
342361 rm -f $(BINARY_NAME )$(EXT )
343362 rm -f demo/basic/basic
344363 rm -f demo/grpc/server/server
0 commit comments