2015-10-31 13:13:38 +01:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
2020-05-27 22:57:32 +02:00
|
|
|
|
export GO111MODULE=on
|
2016-02-22 22:56:59 +01:00
|
|
|
|
|
2017-12-06 20:22:55 +01:00
|
|
|
|
if [ -d $GOOS ]; then OS=$(go env GOOS); else OS=$GOOS; fi
|
2023-03-01 20:38:30 +01:00
|
|
|
|
if [ -d $CGO_ENABLED ]; then CGO_ENABLED=$(go env CGO_ENABLED); else OS=$CGO_ENABLED; fi
|
2017-12-06 20:22:55 +01:00
|
|
|
|
|
2015-10-31 13:13:38 +01:00
|
|
|
|
GITREV=$(git rev-parse --short HEAD)
|
2021-08-12 22:26:39 -06:00
|
|
|
|
VERSION=$(grep "Version =" internal/buildinfo/VERSION.go|cut -d '"' -f2)
|
2016-02-22 21:54:32 +01:00
|
|
|
|
|
2023-10-18 20:48:07 +02:00
|
|
|
|
# Go 1.19 or later is required
|
2018-02-17 21:36:54 +01:00
|
|
|
|
GO_POINT_VERSION=$(go version| perl -ne 'm/go1\.(\d+)/; print $1;')
|
2023-10-18 20:48:07 +02:00
|
|
|
|
[ "$GO_POINT_VERSION" -lt "19" ] && echo "Go 1.19 or later required" && exit 1;
|
2015-10-31 13:13:38 +01:00
|
|
|
|
|
2018-04-21 11:51:17 +02:00
|
|
|
|
AX25VERSION="0.0.12-rc4"
|
|
|
|
|
|
AX25DIST="libax25-${AX25VERSION}"
|
|
|
|
|
|
AX25DIST_URL="http://http.debian.net/debian/pool/main/liba/libax25/libax25_${AX25VERSION}.orig.tar.gz"
|
2017-08-12 00:41:35 +02:00
|
|
|
|
function install_libax25 {
|
|
|
|
|
|
mkdir -p .build && cd .build
|
2018-04-21 11:51:17 +02:00
|
|
|
|
[[ -f "${AX25DIST}" ]] || curl -LSsf "${AX25DIST_URL}" | tar zx
|
|
|
|
|
|
cd "${AX25DIST}/" && ./configure --prefix=/ && make && cd ../../
|
2017-08-12 00:41:35 +02:00
|
|
|
|
}
|
2022-03-18 11:34:37 -06:00
|
|
|
|
function build_web {
|
|
|
|
|
|
cd web
|
2022-04-04 21:14:54 -06:00
|
|
|
|
if [ -d $NVM_DIR ]; then
|
|
|
|
|
|
source $NVM_DIR/nvm.sh
|
2023-05-22 12:43:10 +02:00
|
|
|
|
nvm install
|
2022-04-04 21:14:54 -06:00
|
|
|
|
nvm use
|
|
|
|
|
|
fi
|
2022-03-18 11:34:37 -06:00
|
|
|
|
npm install
|
|
|
|
|
|
npm run production
|
|
|
|
|
|
}
|
2017-08-12 00:41:35 +02:00
|
|
|
|
|
|
|
|
|
|
[[ "$1" == "libax25" ]] && install_libax25 && exit 0;
|
2022-03-18 11:34:37 -06:00
|
|
|
|
[[ "$1" == "web" ]] && build_web && exit 0;
|
2017-08-12 00:41:35 +02:00
|
|
|
|
|
2016-09-19 20:04:54 +02:00
|
|
|
|
# Link against libax25 (statically) on Linux
|
2023-03-01 20:38:30 +01:00
|
|
|
|
if [[ "$OS" == "linux"* ]] && [[ "$CGO_ENABLED" == "1" ]]; then
|
2017-08-12 00:41:35 +02:00
|
|
|
|
TAGS="libax25 $TAGS"
|
|
|
|
|
|
LIB=".build/${AX25DIST}/.libs/libax25.a"
|
|
|
|
|
|
if [[ -z "$CGO_LDFLAGS" ]] && [[ -f "$LIB" ]]; then
|
|
|
|
|
|
export CGO_CFLAGS="-I$(pwd)/.build/${AX25DIST}"
|
|
|
|
|
|
export CGO_LDFLAGS="$(pwd)/${LIB}"
|
|
|
|
|
|
fi
|
|
|
|
|
|
if [[ -z "$CGO_LDFLAGS" ]]; then
|
|
|
|
|
|
echo "WARNING: No static libax25 library available."
|
|
|
|
|
|
echo " Linking against shared library instead. To fix"
|
|
|
|
|
|
echo " this issue, set CGO_LDFLAGS to the full path of"
|
|
|
|
|
|
echo " libax25.a, or run 'make.bash libax25' to download"
|
|
|
|
|
|
echo " and compile ${AX25DIST} in .build/"
|
2016-09-19 20:03:17 +02:00
|
|
|
|
else
|
2017-08-12 00:41:35 +02:00
|
|
|
|
TAGS="static $TAGS"
|
2016-09-19 20:03:17 +02:00
|
|
|
|
fi
|
2023-03-01 20:38:30 +01:00
|
|
|
|
else
|
|
|
|
|
|
if [[ "$OS" == "linux"* ]]; then
|
|
|
|
|
|
echo "WARNING: CGO unavailable. libax25 (ax25+linux) will not be supported with this build."
|
|
|
|
|
|
fi
|
2016-09-19 20:03:17 +02:00
|
|
|
|
fi
|
2015-11-01 21:56:16 +01:00
|
|
|
|
|
2020-05-27 22:57:32 +02:00
|
|
|
|
echo -e "Downloading Go dependencies..."
|
|
|
|
|
|
go mod download
|
2016-05-07 22:10:47 +02:00
|
|
|
|
|
2016-09-19 20:03:17 +02:00
|
|
|
|
echo "Running tests..."
|
2021-10-24 14:01:32 +02:00
|
|
|
|
if [[ "$SKIP_TESTS" == "1" ]]; then
|
|
|
|
|
|
echo "Skipping."
|
|
|
|
|
|
else
|
|
|
|
|
|
go test -tags "$TAGS" ./... github.com/la5nta/wl2k-go/...
|
|
|
|
|
|
fi
|
2016-09-19 20:03:17 +02:00
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
|
|
echo "Building Pat v$VERSION..."
|
2021-08-12 22:26:39 -06:00
|
|
|
|
go build -tags "$TAGS" -ldflags "-X \"github.com/la5nta/pat/internal/buildinfo.GitRev=$GITREV\"" $(go list .)
|
2016-09-12 18:23:16 +02:00
|
|
|
|
|
2022-03-22 17:49:11 -06:00
|
|
|
|
# Build macOS pkg
|
2017-12-06 20:22:55 +01:00
|
|
|
|
if [[ "$OS" == "darwin"* ]] && command -v packagesbuild >/dev/null 2>&1; then
|
2022-03-22 17:49:11 -06:00
|
|
|
|
ARCH=$(go env GOARCH)
|
2016-09-19 20:03:17 +02:00
|
|
|
|
echo "Generating macOS installer package..."
|
2016-09-12 18:23:16 +02:00
|
|
|
|
packagesbuild osx/pat.pkgproj
|
2022-03-22 17:49:11 -06:00
|
|
|
|
mv 'Pat :: A Modern Winlink Client.pkg' "pat_${VERSION}_darwin_${ARCH}_unsigned.pkg"
|
2016-09-12 18:23:16 +02:00
|
|
|
|
fi
|
2016-09-19 20:03:17 +02:00
|
|
|
|
|
|
|
|
|
|
echo -e "Enjoy!"
|