photoprism/scripts/build.sh

50 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -e
2022-02-17 19:18:37 +01:00
BUILD_DATE=$(date -u +%y%m%d)
BUILD_VERSION=$(git describe --always)
if [[ -z $1 ]] || [[ -z $2 ]]; then
2022-02-17 19:18:37 +01:00
echo "Usage: build.sh [debug|race|static|prod] [filename]" 1>&2
2021-12-15 14:56:47 +01:00
exit 1
fi
if [[ $OS == "Windows_NT" ]]; then
2022-02-17 19:18:37 +01:00
BUILD_OS=win32
2021-12-15 14:56:47 +01:00
if [[ $PROCESSOR_ARCHITEW6432 == "AMD64" ]]; then
2022-02-17 19:18:37 +01:00
BUILD_ARCH=amd64
2021-12-15 14:56:47 +01:00
else
if [[ $PROCESSOR_ARCHITECTURE == "AMD64" ]]; then
2022-02-17 19:18:37 +01:00
BUILD_ARCH=amd64
fi
2021-12-15 14:56:47 +01:00
if [[ $PROCESSOR_ARCHITECTURE == "x86" ]]; then
2022-02-17 19:18:37 +01:00
BUILD_ARCH=ia32
2021-12-15 14:56:47 +01:00
fi
fi
else
2022-02-17 19:18:37 +01:00
BUILD_OS=$(uname -s)
BUILD_ARCH=$(uname -m)
fi
2022-02-17 19:18:37 +01:00
BUILD_ID=${BUILD_DATE}-${BUILD_VERSION}-${BUILD_OS}-${BUILD_ARCH}
echo "Building $1 binary..."
echo "Version: PhotoPrism CE ${BUILD_ID}"
if [[ $1 == "debug" ]]; then
2022-02-17 19:18:37 +01:00
go build -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o $2 cmd/photoprism/photoprism.go
2021-12-15 14:56:47 +01:00
du -h $2
echo "Done."
elif [[ $1 == "race" ]]; then
2022-02-17 19:18:37 +01:00
go build -race -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o $2 cmd/photoprism/photoprism.go
2021-12-15 14:56:47 +01:00
du -h $2
2019-06-22 23:14:30 +02:00
elif [[ $1 == "static" ]]; then
2022-02-17 19:18:37 +01:00
go build -a -v -ldflags "-linkmode external -extldflags \"-static -L /usr/lib -ltensorflow\" -s -w -X main.version=${BUILD_ID}" -o $2 cmd/photoprism/photoprism.go
2021-12-15 14:56:47 +01:00
du -h $2
else
2022-02-17 19:18:37 +01:00
go build -ldflags "-s -w -X main.version=${BUILD_ID}" -o $2 cmd/photoprism/photoprism.go
2021-12-15 14:56:47 +01:00
du -h $2
2019-06-22 23:14:30 +02:00
fi
2022-02-17 19:18:37 +01:00
echo "Done."