tools: Add --ldflags to go-compile
This flags allows passing additional ldflags to the build.
It is primarily there to pass -C arguments to specify values
of variables at compile time.
@@ -26,6 +26,10 @@ do
package="$2"
shift
;;
+ --ldflags)
+ ldflags="$2"
+ shift
+ ;;
*)
echo "Unknown option $1"
exit 1
@@ -60,10 +64,15 @@ test -z $(find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.*
>&2 echo "go build..."
if [ "$GOOS" = "darwin" ]
+then
+ if [ -z "$ldflags" ]
then
go build -o $out "$package"
else
- go build -o $out -buildmode pie --ldflags '-s -w -extldflags "-static"' "$package"
+ go build -o $out -ldflags "${ldflags}" "$package"
+ fi
+else
+ go build -o $out -buildmode pie -ldflags "-s -w ${ldflags} -extldflags \"-static\"" "$package"
fi
tar cf - $out
