This commit is contained in:
crusader 2018-09-26 22:10:01 +09:00
parent f20b7ded97
commit afe6fbad16
2 changed files with 22 additions and 44 deletions

View File

@ -1,50 +1,28 @@
@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
:: build.bat -o windows -a amd64
set o=windows
set a=amd64
:initial
if "%1"=="" goto done
echo %1
set aux=%1
if "%aux:~0,1%"=="-" (
set nome=%aux:~1,250%
) else (
set "%nome%=%1"
set nome=
)
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
shift
goto initial
:done
:: your code here ...
echo OS: %o_os%
echo ARCH: %o_arch%
echo OS: %o%
echo ARCH: %a%
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
::SET GOOS=%o% SET GOARCH=%a% SET CGO_ENABLED=1 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe ./cmd/main.go

View File

@ -1,7 +1,6 @@
#!/bin/bash
#rm ./dist
#CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe
# ./build.sh -o linux -a amd64
while getopts "o:a:" option; do
case "${option}" in
@ -25,4 +24,5 @@ if [ -z "${o_arch}" ]; then
exit 0
fi
rm ./dist
GOOS=${o_os} GOARCH=${o_arch} CGO_ENABLED=1 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe ./cmd/main.go