@@ -14,25 +14,56 @@ if "%~dp0" == "%CD%\" (
1414)
1515
1616set " WIN32DIR = %WIN32DIR:\ =/ % :/:"
17- call set " WIN32DIR = %% WIN32DIR:%~x0 :/:=:/:%% "
18- call set " WIN32DIR = %% WIN32DIR:/%~n0 :/:=:/:%% "
17+ call : set " WIN32DIR=%% WIN32DIR:%~x0 :/:=:/:%% "
18+ call : set " WIN32DIR=%% WIN32DIR:/%~n0 :/:=:/:%% "
1919set " WIN32DIR = %WIN32DIR:~0 ,-3 % "
2020
2121set configure = %~0
22+ set target =
2223set optdirs =
2324set pathlist =
2425set config_make = confargs~%RANDOM% .mak
2526set confargs = %config_make:.mak =.sub %
2627set debug_configure =
2728echo> %config_make% # CONFIGURE
2829type nul > %confargs%
30+ set args = %*
31+ goto :loop
32+
33+ :shift_argv
34+ call %~dp0 shellsplit.cmd
35+ set " argv1 = %argv2% "
36+ set " argv2 = %argv% "
37+ if not defined argv1 if defined argv2 goto :shift_argv
38+ exit /b
39+
40+ :take_arg
41+ if defined arg exit /b
42+ if not defined argv2 exit /b
43+ if not " %argv2:~0 ,1 % " == " -" (set " arg=%argv2% " & call :shift_argv)
44+ exit /b
45+
46+ :set
47+ set %1
48+ exit /b
49+
2950:loop
30- if [%1 ] == [] goto :end ;
31- if " %~1 " == " " (shift & goto :loop)
32- for /f " delims== tokens=1,*" %%I in (" %~1 " ) do ((set " opt=%%I " ) && (set " arg=%%J " ))
33- set " eq = ="
34- if " %arg% " == " " if not " %~1 " == " %opt% =%arg% " (set " eq=" )
35- shift
51+ call :shift_argv
52+ if not defined argv1 goto :end
53+
54+ for /f " delims== tokens=1*" %%I in (" %argv1% " ) do ((set " opt=%%I " ) && (set " arg=%%J " ))
55+ set " opt = %opt:~1 % "
56+ set " eq = "
57+ if defined arg (
58+ set " eq = ="
59+ set " arg = %arg:~0 ,-1 % "
60+ ) else (
61+ set " opt = %opt:~0 ,-1 % "
62+ )
63+ if " %opt% " == " " (
64+ echo 1 >& 2 %configure% : assignment for empty variable name %argv1%
65+ exit /b 1
66+ )
3667 if " %opt% " == " --debug-configure" (
3768 echo on
3869 set " debug_configure = yes"
@@ -78,7 +109,7 @@ for /f "delims== tokens=1,*" %%I in ("%~1") do ((set "opt=%%I") && (set "arg=%%J
78109 )
79110goto :loop ;
80111:target
81- if " %eq% " == " " (set " arg= %~1 " & shift)
112+ if " %eq% " == " " call : take_arg
82113 if " %arg% " == " " (
83114 echo 1 >& 2 %configure% : missing argument for %opt%
84115 exit /b 1
@@ -88,7 +119,6 @@ goto :loop ;
88119 echo>> %confargs% " --target=%arg:$ =$$ % " \
89120goto :loop ;
90121:program_name
91- if " %eq% " == " " (set " arg=%~1 " & shift)
92122 for /f " delims=- tokens=1,*" %I in ("% opt%") do set "var=%%J "
93123 if " %var% " == " prefix" (set " var=PROGRAM_PREFIX" & goto :name)
94124 if " %var% " == " suffix" (set " var=PROGRAM_SUFFIX" & goto :name)
@@ -99,32 +129,37 @@ goto :loop ;
99129 )
100130goto :unknown_opt
101131:name
102- if " %eq% " == " " (set " arg= %~1 " & shift)
132+ if " %eq% " == " " call : take_arg
103133 echo>> %config_make% %var% = %arg%
104134goto :loopend ;
105135:dir
106- if " %eq% " == " " (set " arg= %~1 " & shift)
136+ if " %eq% " == " " call : take_arg
107137 echo>> %config_make% %opt:~2 % = %arg:\ =/ %
108138goto :loopend ;
109139:enable
110- echo>> %confargs% " %opt% " \
111- if %enable% == yes (set " opt=%opt:~9 % " ) else (set " opt=%opt:~10 % " )
112- if " %opt% " == " rdoc" (
140+ if %enable% == yes (
141+ if " %eq% " == " " call :take_arg
142+ set " feature = %opt:~9 % "
143+ ) else (
144+ set " feature = %opt:~10 % "
145+ )
146+ if %enable% == yes if defined arg set " enable = %arg% "
147+ if " %feature% " == " install-doc" (
113148 echo>> %config_make% RDOCTARGET = %enable:yes =r % doc
114149 )
115- if " %opt % " == " install-static-library" (
150+ if " %feature % " == " install-static-library" (
116151 echo>> %config_make% INSTALL_STATIC_LIBRARY = %enable%
117152 )
118- if " %opt % " == " debug-env" (
153+ if " %feature % " == " debug-env" (
119154 echo>> %config_make% ENABLE_DEBUG_ENV = %enable%
120155 )
121- if " %opt % " == " devel" (
156+ if " %feature % " == " devel" (
122157 echo>> %config_make% RUBY_DEVEL = %enable%
123158 )
124- if " %opt % " == " rubygems" (
125- echo>> %config_make% USE_RUBYGEMS = %enable%
159+ if " %feature % " == " rubygems" (
160+ echo>> %config_make% USE_RUBYGEMS = %enable%
126161 )
127- goto :loop ;
162+ goto :loopend ;
128163:withoutarg
129164 echo>> %confargs% " %opt% " \
130165 if " %opt% " == " --without-baseruby" goto :nobaseruby
@@ -134,7 +169,7 @@ goto :loop ;
134169goto :loop ;
135170:witharg
136171 if " %opt% " == " --with-static-linked-ext" goto :extstatic
137- if " %eq% " == " " (set " arg= %~1 " & shift)
172+ if " %eq% " == " " call : take_arg
138173 if not " %arg% " == " " (
139174 echo>> %confargs% " %opt% =%arg:$ =$$ % " \
140175 ) else (
@@ -152,25 +187,25 @@ goto :loop ;
152187:ntver
153188 :: - For version constants, see
154189 :: - https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt#remarks
155- if " %eq% " == " " (set " NTVER=%~1 " & shift ) else (set " NTVER=%arg% " )
190+ if " %eq% " == " " (set " NTVER=%~1 " & call : shift_argv ) else (set " NTVER=%arg% " )
156191 if /i not " %NTVER:~0 ,2 % " == " 0x" if /i not " %NTVER:~0 ,13 % " == " _WIN32_WINNT_" (
157192 for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
158- call set NTVER = %%N TVER:%%i =%%i %%
193+ call : set NTVER=%%N TVER:%%i =%%i %%
159194 )
160- call set NTVER = _WIN32_WINNT_%%N TVER%%
195+ call : set NTVER=_WIN32_WINNT_%%N TVER%%
161196 )
162197 echo>> %config_make% NTVER = %NTVER%
163198goto :loopend ;
164199:extout
165- if " %eq% " == " " (set " arg= %~1 " & shift)
200+ if " %eq% " == " " call : take_arg
166201 if not " %arg% " == " .ext" (echo>> %config_make% EXTOUT = %arg% )
167202goto :loopend ;
168203:path
169- if " %eq% " == " " (set " arg= %~1 " & shift)
204+ if " %eq% " == " " call : take_arg
170205 set " pathlist = %pathlist%%a rg:\ =/ % ;"
171206goto :loopend ;
172207:extstatic
173- if " %eq% " == " " (set " arg=static" & shift )
208+ if " %eq% " == " " (set " arg=static" )
174209 echo>> %config_make% EXTSTATIC = %arg%
175210goto :loopend ;
176211:baseruby
@@ -203,13 +238,16 @@ goto :loop ;
203238 exit /b 1
204239 )
205240 :optdir-loop
206- for /f " delims=; tokens=1,*" %%I in (" %arg% " ) do (set " d=%%I " & set " arg = %%J " )
207- pushd %d:/ =\ % 2 > nul && (
208- set " optdirs = %optdirs% ;%CD:\ =/ % "
241+ setlocal EnableDelayedExpansion
242+ for /f " delims=; tokens=1,*" %%I in (" %arg% " ) do ((set " d=%%I " & set " arg = %%J " )
243+ pushd !d:/ =\ ! 2 > nul
244+ if not ERRORLEVEL 1 (
245+ call :set d=%%c d%%
209246 popd
210- ) || (
211- set " optdirs = %optdirs% ;%d:\ =/ % "
212247 )
248+ call :set " optdirs=%%o ptdirs%% ;%%d :\=/%% "
249+ )
250+ endlocal & set " optdirs = %optdirs% " & set " arg = %arg% "
213251 if not " %arg% " == " " goto :optdir-loop
214252goto :loop ;
215253:help
@@ -241,7 +279,7 @@ goto :EOF
241279 exit /b 1
242280:end
243281if " %debug_configure% " == " yes" (type %confargs% )
244- if defined optdirs ( for %%I in ( " %optdirs:~ 1 % " ) do echo>> %config_make% optdirs = %%~I )
282+ if defined optdirs echo>> %config_make% optdirs = %optdirs:~ 1 %
245283(
246284 echo .
247285 echo configure_args = \
0 commit comments