Skip to content

Commit 73ba845

Browse files
committed
Use switch style arch check
1 parent 8a59667 commit 73ba845

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

bin/phpsdk_setshell.bat

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,52 @@ if 14 gtr %TMP_CHK% (
4444
set PHP_SDK_VS_NUM=%TMP_CHK%
4545
set TMP_CHK=
4646

47-
if /i not "%2"=="x64" (
48-
if /i not "%2"=="x86" (
49-
if /i not "%2"=="arm64" (
50-
echo Unsupported arch "%2"
51-
goto out_error
52-
)
53-
)
47+
rem check target arch
48+
if "%2"=="x86" set PHP_SDK_ARCH=%2
49+
if "%2"=="x64" set PHP_SDK_ARCH=%2
50+
if "%2"=="x86_64" set PHP_SDK_ARCH=x64
51+
if "%2"=="amd64" set PHP_SDK_ARCH=x64
52+
if "%2"=="arm64" set PHP_SDK_ARCH=%2
53+
if "%PHP_SDK_ARCH%"=="" (
54+
echo Unsupported target arch %2 >&2
55+
goto out_error
5456
)
5557

56-
set PHP_SDK_ARCH=%2
57-
5858
rem check OS arch
59-
rem Architecture=9 meaning x86_64
60-
wmic cpu get Architecture /value | findstr "Architecture=9\>" >nul 2>nul
61-
if not errorlevel 1 (
62-
set PHP_SDK_OS_ARCH=x64
59+
rem todo: allow user choose host sdk arch (i.e. x64 target can be compiled at x64(native) or x86(cross))
60+
for /f "usebackq tokens=1*" %%i in (`wmic cpu get Architecture /value /format:table ^| findstr /r "[1234567890][1234567890]*"`) do (
61+
set PHP_SDK_OS_ARCH_NUM=%%i
6362
)
64-
rem Architecture=12 meaning arm64
65-
wmic cpu get Architecture /value | findstr "Architecture=12\>" >nul 2>nul
66-
if not errorlevel 1 (
67-
set PHP_SDK_OS_ARCH=arm64
68-
)
69-
rem Architecture=0 meaning x86
70-
wmic cpu get Architecture /value | findstr "Architecture=0\>" >nul 2>nul
71-
if not errorlevel 1 (
72-
set PHP_SDK_OS_ARCH=x86
63+
64+
goto os_arch_cases
65+
:os_arch_error
66+
echo Unsupported OS arch %PHP_SDK_OS_ARCH% >&2
67+
goto out_error
68+
69+
:os_arch_cases
70+
if "%PHP_SDK_OS_ARCH_NUM%"=="0" set PHP_SDK_OS_ARCH=x86
71+
if "%PHP_SDK_OS_ARCH_NUM%"=="1" (set PHP_SDK_OS_ARCH=mips && goto os_arch_error)
72+
if "%PHP_SDK_OS_ARCH_NUM%"=="2" (set PHP_SDK_OS_ARCH=alpha && goto os_arch_error)
73+
if "%PHP_SDK_OS_ARCH_NUM%"=="3" (set PHP_SDK_OS_ARCH=ppc && goto os_arch_error)
74+
if "%PHP_SDK_OS_ARCH_NUM%"=="4" (set PHP_SDK_OS_ARCH=shx && goto os_arch_error)
75+
if "%PHP_SDK_OS_ARCH_NUM%"=="5" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
76+
if "%PHP_SDK_OS_ARCH_NUM%"=="6" (set PHP_SDK_OS_ARCH=ia64 && goto os_arch_error)
77+
if "%PHP_SDK_OS_ARCH_NUM%"=="7" (set PHP_SDK_OS_ARCH=alpha64 && goto os_arch_error)
78+
if "%PHP_SDK_OS_ARCH_NUM%"=="8" (set PHP_SDK_OS_ARCH=msil && goto os_arch_error)
79+
if "%PHP_SDK_OS_ARCH_NUM%"=="9" set PHP_SDK_OS_ARCH=x64
80+
rem wow64
81+
if "%PHP_SDK_OS_ARCH_NUM%"=="10" set PHP_SDK_OS_ARCH=x86
82+
if "%PHP_SDK_OS_ARCH_NUM%"=="11" (set PHP_SDK_OS_ARCH=neutral && goto os_arch_error)
83+
if "%PHP_SDK_OS_ARCH_NUM%"=="12" set PHP_SDK_OS_ARCH=arm64
84+
if "%PHP_SDK_OS_ARCH_NUM%"=="13" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
85+
rem woa64
86+
if "%PHP_SDK_OS_ARCH_NUM%"=="14" set PHP_SDK_OS_ARCH=x86
87+
if "%PHP_SDK_OS_ARCH%"=="" (
88+
goto os_arch_error
7389
)
7490

91+
set PHP_SDK_OS_ARCH_NUM=
92+
7593
rem cross compile is ok, so we donot need this
7694
rem if not /i "%PHP_SDK_ARCH%"=="PHP_SDK_OS_ARCH" (
7795
rem echo 32-bit OS detected, native 64-bit toolchain is unavailable.
@@ -183,6 +201,7 @@ if 15 gtr %PHP_SDK_VS_NUM% (
183201
) else (
184202
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" !VCVARSALL_ARCH_NAME!
185203
)
204+
set VCVARSALL_ARCH_NAME=
186205

187206
rem echo Visual Studio VC path %PHP_SDK_VC_DIR%
188207
rem echo Windows SDK path %PHP_SDK_WIN_SDK_DIR%

0 commit comments

Comments
 (0)