add autoscaler and build for go code
This commit is contained in:
parent
7912242231
commit
cf1dbdc07a
4 changed files with 144 additions and 0 deletions
102
src/tools/go_build
Executable file
102
src/tools/go_build
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ "x$DEBUG" = "x" ]; then
|
||||
:
|
||||
else
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [ "x$BUILDTYPE" = "xdebug" ]; then
|
||||
CGO_CFLAGS="$CGO_CFLAGS -DWITH_DEBUG=1 -Og -ggdb "
|
||||
CGO_LDFLAGS="$CGO_LDFLAGS -Og -ggdb "
|
||||
GO_FLAGS=' -gcflags "all=-N -l"'
|
||||
|
||||
export CGO_CFLAGS CGO_LDFLAGS GO_FLAGS
|
||||
fi
|
||||
|
||||
fix_env() {
|
||||
local _n _x _cmd _v
|
||||
|
||||
_n="$1"
|
||||
shift
|
||||
_cmd="sed "
|
||||
for _x in $*; do
|
||||
_v=$(eval $(echo "echo \$$_x") | sed -s 's@"@@g')
|
||||
_cmd="$_cmd -e s|@$_x@|$_v|g "
|
||||
done
|
||||
_v=$(eval $(echo "echo \$$_n"))
|
||||
_cmd="$_n=\"$(echo $_v | $_cmd)\"; export $_n"
|
||||
eval "$_cmd"
|
||||
}
|
||||
|
||||
# fix value of environment variable by realpath
|
||||
# of it
|
||||
fix_input_envs() {
|
||||
local _n _v _cmd
|
||||
|
||||
for _n in CURRENT_SOURCE_DIR BUILD_ROOT; do
|
||||
_v=$(eval $(echo "echo \$$_n") | sed -e 's@"@@g')
|
||||
_v=$(realpath $_v)
|
||||
_cmd="$_n=$_v; export $_n"
|
||||
eval "$_cmd"
|
||||
done
|
||||
}
|
||||
|
||||
# fix dependencies, by:
|
||||
# for math just add -lmath
|
||||
# for thread by add -pthread
|
||||
# otherwise using
|
||||
# pkg-config --cflags/ pkg-config --libs
|
||||
fix_dependencies() {
|
||||
local _x _cflags _ldflags
|
||||
|
||||
for _x in $DEPENDENCIES; do
|
||||
case "$_x" in
|
||||
math)
|
||||
_cflags=""
|
||||
_ldflags="-lm"
|
||||
;;
|
||||
thread)
|
||||
_cflags="-pthread"
|
||||
_ldflags="-pthread"
|
||||
;;
|
||||
*)
|
||||
_cflags=$(pkg-config --cflags "$_x")
|
||||
_ldflags=$(pkg-config --libs "$_x")
|
||||
;;
|
||||
esac
|
||||
|
||||
CGO_CFLAGS="$CGO_CFLAGS $_cflags"
|
||||
CGO_LDFLAGS="$CGO_LDFLAGS $_ldflags"
|
||||
done
|
||||
|
||||
export CGO_CFLAGS CGO_LDFLAGS
|
||||
}
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo go_build sfile dest
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_sfile=$(realpath "$1")
|
||||
_sdir=$(dirname "$_sfile")
|
||||
_dfile=$(realpath "$2")
|
||||
|
||||
fix_input_envs
|
||||
fix_dependencies
|
||||
|
||||
if [ -z "$HOME" -o ! -w "$HOME" ]; then
|
||||
HOME=$TMPDIR
|
||||
export HOME
|
||||
fi
|
||||
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
export GOPATH="$TMPDIR/go"
|
||||
|
||||
for _n in $FIX_ENVARS; do
|
||||
fix_env $_n $ENVARS;
|
||||
done
|
||||
|
||||
export GOPROXY=https://goproxy.cn
|
||||
|
||||
(cd $_sdir; go build -gcflags "all=-N -l" -o "$_dfile" "$_sfile")
|
||||
Loading…
Add table
Add a link
Reference in a new issue