Skip to content

Improve build.sh #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 48 additions & 44 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh

set -eu

check_command() {
if ! command -v $1 &> /dev/null
if ! command -v "$1" >/dev/null
then
echo "Error: $1 could not be found. Please install it."
exit 1
echo "Error: $1 could not be found. Please install it." >&2
return 1
fi
}

Expand All @@ -13,82 +15,84 @@ check_command go
check_command 7z
check_command upx

set -x

export CGO_ENABLED=0

# Windows amd64
export GOOS=windows
export GOARCH=amd64
FILENAME="go2rtc_win64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe
GOOS=windows GOARCH=amd64 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe

# Windows 386
export GOOS=windows
export GOARCH=386
FILENAME="go2rtc_win32.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe
GOOS=windows GOARCH=386 GOTOOLCHAIN=go1.20.14 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe

# Windows arm64
export GOOS=windows
export GOARCH=arm64
FILENAME="go2rtc_win_arm64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe
GOOS=windows GOARCH=arm64 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc.exe

# Linux amd64
export GOOS=linux
export GOARCH=amd64
FILENAME="go2rtc_linux_amd64"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=amd64 \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Linux 386
export GOOS=linux
export GOARCH=386
FILENAME="go2rtc_linux_i386"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=386 \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Linux arm64
export GOOS=linux
export GOARCH=arm64
FILENAME="go2rtc_linux_arm64"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=arm64 \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Linux arm v7
export GOOS=linux
export GOARCH=arm
export GOARM=7
FILENAME="go2rtc_linux_arm"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=arm GOARM=7 \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Linux arm v6
export GOOS=linux
export GOARCH=arm
export GOARM=6
FILENAME="go2rtc_linux_armv6"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=arm GOARM=6 \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Linux mipsle
export GOOS=linux
export GOARCH=mipsle
FILENAME="go2rtc_linux_mipsel"
go build -ldflags "-s -w" -trimpath -o $FILENAME && upx --lzma --force-overwrite -q --no-progress $FILENAME
GOOS=linux GOARCH=mipsle \
go build -ldflags "-s -w" -trimpath -o $FILENAME
upx --lzma --force-overwrite -q --no-progress $FILENAME

# Darwin amd64
export GOOS=darwin
export GOARCH=amd64
FILENAME="go2rtc_mac_amd64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc
GOOS=darwin GOARCH=amd64 GOTOOLCHAIN=go1.20.14 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc

# Darwin arm64
export GOOS=darwin
export GOARCH=arm64
FILENAME="go2rtc_mac_arm64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc
GOOS=darwin GOARCH=arm64 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc

# FreeBSD amd64
export GOOS=freebsd
export GOARCH=amd64
FILENAME="go2rtc_freebsd_amd64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc
GOOS=freebsd GOARCH=amd64 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc

# FreeBSD arm64
export GOOS=freebsd
export GOARCH=arm64
FILENAME="go2rtc_freebsd_arm64.zip"
go build -ldflags "-s -w" -trimpath && 7z a -mx9 -bso0 -sdel $FILENAME go2rtc
GOOS=freebsd GOARCH=arm64 \
go build -ldflags "-s -w" -trimpath
7z a -mx9 -bso0 -sdel $FILENAME go2rtc