This commit is contained in:
crusader 2018-09-26 21:53:26 +09:00
parent a49f704336
commit f20b7ded97
2 changed files with 78 additions and 0 deletions

50
build.bat Normal file
View File

@ -0,0 +1,50 @@
@ECHO OFF
:: =====================================================================
:: This function sets a variable from a cli arg with value
:: 1 cli argument name
:: 2 variable name
:: 3 current Argument Name
:: 4 current Argument Value
:getArgWithValue
if "%~3"=="%~1" (
if "%~4"=="" (
REM unset the variable if value is not provided
set "%~2="
exit /B 1
)
set "%~2=%~4"
exit /B 0
)
exit /B 1
goto:eof
:: =====================================================================
:: This function sets a variable to value "TRUE" from a cli "flag" argument
:: 1 cli argument name
:: 2 variable name
:: 3 current Argument Name
:getArgFlag
if "%~3"=="%~1" (
set "%~2=TRUE"
exit /B 0
)
exit /B 1
goto:eof
:parseArgs
:: asks for the -o argument and store the value in the variable FOO
call:getArgWithValue "-o" "o_os" "%~1" "%~2" && shift && shift && goto :parseArgs
:: asks for the -bar argument and store the value in the variable BAR
call:getArgWithValue "-a" "o_arch" "%~1" "%~2" && shift && shift && goto :parseArgs
:: your code here ...
echo OS: %o_os%
echo ARCH: %o_arch%
goto:eof
::SET GOOS=%o_os% SET GOARCH=%o_arch% SET CGO_ENABLED=1 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe ./cmd/main.go

28
build.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#rm ./dist
#CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe
while getopts "o:a:" option; do
case "${option}" in
o)
o_os=${OPTARG}
;;
a)
o_arch=${OPTARG}
;;
esac
done
shift $(($OPTIND - 1))
if [ -z "${o_os}" ]; then
echo "Option -o GOOS is not specified"
exit 0
fi
if [ -z "${o_arch}" ]; then
echo "Option -a GOARCH is not specified"
exit 0
fi
GOOS=${o_os} GOARCH=${o_arch} CGO_ENABLED=1 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe ./cmd/main.go