-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
66 lines (57 loc) · 2.34 KB
/
Copy pathbuild.sh
File metadata and controls
66 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Cross-platform build script for operatorlm.
#
# Detects the target OS/arch (or honours GOOS/GOARCH from the environment) and
# builds with the right linker flags. On Windows it forces -H=windowsgui so no
# console window appears at launch (logs go to ~/.operatorlm/operatorlm.log via
# setupLogging in main.go). On Linux/macOS it produces a normal binary.
#
# Usage:
# ./build.sh # build for the host
# GOOS=linux GOARCH=arm64 ./build.sh # cross-compile
# GOOS=windows ./build.sh # produces operatorlm.exe
set -euo pipefail
cd "$(dirname "$0")"
target_os="${GOOS:-$(go env GOOS)}"
target_arch="${GOARCH:-$(go env GOARCH)}"
# -s -w: strip symbol/debug info (smaller binary, fewer AV false positives on
# Windows). Applied on every OS — debug symbols aren't needed for releases.
ldflags="-s -w"
output="operatorlm"
case "$target_os" in
windows)
ldflags="-H=windowsgui $ldflags"
output="OperatorLM.exe"
;;
linux|darwin)
: # CGO is required by getlantern/systray; rely on the toolchain default.
;;
*)
echo "warning: untested GOOS=$target_os; proceeding with defaults" >&2
;;
esac
# Inject the build-time version so the OTA updater can compare against the
# latest GitHub release. Honour $VERSION from the environment, otherwise fall
# back to `git describe`. An empty result means "dev build" and the updater
# will refuse to self-update.
version="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || true)}"
if [ -n "$version" ]; then
ver_flag="-X github.com/aralde/operatorlm/internal/version.Version=$version"
if [ -n "$ldflags" ]; then
ldflags="$ldflags $ver_flag"
else
ldflags="$ver_flag"
fi
fi
# getlantern/systray requires CGO on every platform.
export CGO_ENABLED="${CGO_ENABLED:-1}"
echo "Building $output for $target_os/$target_arch (CGO_ENABLED=$CGO_ENABLED, version=${version:-dev})"
# -trimpath / -buildvcs=false: strip local paths and VCS stamps so the binary
# is reproducible and doesn't leak $HOME — also reduces SmartScreen/Defender
# false positives on fresh Go binaries.
if [ -n "$ldflags" ]; then
GOOS="$target_os" GOARCH="$target_arch" go build -trimpath -buildvcs=false -ldflags="$ldflags" -o "$output" .
else
GOOS="$target_os" GOARCH="$target_arch" go build -trimpath -buildvcs=false -o "$output" .
fi
echo "Built $output"