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 @ECHO OFF
:: ===================================================================== :: build.bat -o windows -a amd64
:: This function sets a variable from a cli arg with value
:: 1 cli argument name set o=windows
:: 2 variable name set a=amd64
:: 3 current Argument Name
:: 4 current Argument Value :initial
:getArgWithValue if "%1"=="" goto done
if "%~3"=="%~1" ( echo %1
if "%~4"=="" ( set aux=%1
REM unset the variable if value is not provided if "%aux:~0,1%"=="-" (
set "%~2=" set nome=%aux:~1,250%
exit /B 1 ) else (
) set "%nome%=%1"
set "%~2=%~4" set nome=
exit /B 0
) )
exit /B 1 shift
goto:eof goto initial
:done
:: =====================================================================
:: 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 ... :: your code here ...
echo OS: %o_os% echo OS: %o%
echo ARCH: %o_arch% echo ARCH: %a%
goto:eof 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 #!/bin/bash
#rm ./dist # ./build.sh -o linux -a amd64
#CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe
while getopts "o:a:" option; do while getopts "o:a:" option; do
case "${option}" in case "${option}" in
@ -25,4 +24,5 @@ if [ -z "${o_arch}" ]; then
exit 0 exit 0
fi 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 GOOS=${o_os} GOARCH=${o_arch} CGO_ENABLED=1 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/probe ./cmd/main.go