2018-11-08 10:56:11 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-11-12 06:58:39 +01:00
|
|
|
if [[ -z $1 ]] || [[ -z $2 ]]; then
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Usage: ${0##*/} [debug|race|static|prod] [filename]" 1>&2
|
2021-12-15 14:56:47 +01:00
|
|
|
exit 1
|
2018-11-09 11:41:07 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
set -e
|
2018-11-12 06:58:39 +01:00
|
|
|
|
2022-04-07 01:18:39 +02:00
|
|
|
BUILD_OS=$(uname -s)
|
|
|
|
BUILD_ARCH=$("$(dirname "$0")/dist/arch.sh")
|
|
|
|
BUILD_DATE=$(date -u +%y%m%d)
|
2022-02-19 15:32:52 +01:00
|
|
|
BUILD_VERSION=$(git describe --always)
|
|
|
|
BUILD_TAG=${BUILD_DATE}-${BUILD_VERSION}
|
2022-04-07 01:18:39 +02:00
|
|
|
BUILD_ID=${BUILD_TAG}-${BUILD_OS}-$(echo "${BUILD_ARCH}" | tr '[:lower:]' '[:upper:]')
|
2022-05-20 15:42:33 +02:00
|
|
|
BUILD_BIN=${2:-photoprism}
|
2022-04-07 01:18:39 +02:00
|
|
|
GO_BIN=${GO_BIN:-go}
|
2022-03-01 16:54:49 +01:00
|
|
|
GO_VER=$($GO_BIN version)
|
2022-02-17 19:18:37 +01:00
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
echo "Building PhotoPrism ${BUILD_ID} ($1)..."
|
2022-02-17 19:18:37 +01:00
|
|
|
|
2018-11-12 06:58:39 +01:00
|
|
|
if [[ $1 == "debug" ]]; then
|
2022-05-20 15:42:33 +02:00
|
|
|
BUILD_CMD=("$GO_BIN" build -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o "${BUILD_BIN}" cmd/photoprism/photoprism.go)
|
2020-05-28 21:20:42 +02:00
|
|
|
elif [[ $1 == "race" ]]; then
|
2022-05-20 15:42:33 +02:00
|
|
|
BUILD_CMD=("$GO_BIN" build -race -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o "${BUILD_BIN}" cmd/photoprism/photoprism.go)
|
2019-06-22 23:14:30 +02:00
|
|
|
elif [[ $1 == "static" ]]; then
|
2022-05-20 15:42:33 +02:00
|
|
|
BUILD_CMD=("$GO_BIN" build -a -v -ldflags "-linkmode external -extldflags \"-static -L /usr/lib -ltensorflow\" -s -w -X main.version=${BUILD_ID}" -o "${BUILD_BIN}" cmd/photoprism/photoprism.go)
|
2018-11-08 10:56:11 +01:00
|
|
|
else
|
2022-05-20 15:42:33 +02:00
|
|
|
BUILD_CMD=("$GO_BIN" build -ldflags "-extldflags \"-Wl,-rpath -Wl,\$ORIGIN/../lib\" -s -w -X main.version=${BUILD_ID}" -o "${BUILD_BIN}" cmd/photoprism/photoprism.go)
|
2019-06-22 23:14:30 +02:00
|
|
|
fi
|
2022-02-17 19:18:37 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# build binary
|
2022-05-20 15:42:33 +02:00
|
|
|
echo "=> compiling \"$BUILD_BIN\" with \"${GO_VER}\""
|
2022-03-02 12:21:46 +01:00
|
|
|
echo "=> ${BUILD_CMD[*]}"
|
2022-03-01 13:55:05 +01:00
|
|
|
"${BUILD_CMD[@]}"
|
|
|
|
|
|
|
|
# show size
|
2022-05-20 15:42:33 +02:00
|
|
|
du -h "${BUILD_BIN}"
|
2022-03-01 13:55:05 +01:00
|
|
|
|
2022-04-07 01:18:39 +02:00
|
|
|
echo "Done."
|