Skip to content

Commit b5ecfd1

Browse files
committed
Win32: Refactor target detection
Previously, Visual C++ had only one toolchain for the x86 family, and the only option was to select the target processor level. In recent versions, there are multiple toolchains with the same command name for each host/target platform combination, so it is no longer possible to select the target with a command-line option. Also, configure.bat assumes that the toolchain has been configured before it is executed, so selecting it from this batch file is meaningless. Therefore, the only possible check is whether the specified target and compiler match.
1 parent 6cc2096 commit b5ecfd1

File tree

2 files changed

+71
-28
lines changed

2 files changed

+71
-28
lines changed

win32/configure.bat

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,18 @@ for /f "delims== tokens=1,*" %%I in ("%~1") do ((set "opt=%%I") && (set "arg=%%J
6666
set "var=%opt%"
6767
goto :name
6868
)
69-
set "eq=="
69+
set "target=%opt%"
70+
echo>>%confargs% "--target=%opt:$=$$%" \
71+
goto :loop ;
7072
:target
7173
if "%eq%" == "" (set "arg=%~1" & shift)
72-
echo>> %config_make% target = %arg%
73-
echo>>%confargs% "--target=%arg:$=$$%" \
74-
if "%arg%" == "x64-mswin64" (
75-
echo>> %config_make% TARGET_OS = mswin64
74+
if "%arg%" == "" (
75+
echo 1>&2 %configure%: missing argument for %opt%
76+
exit /b 1
7677
)
77-
goto :loop
78+
set "target=%arg%"
79+
echo>>%confargs% "--target=%arg:$=$$%" \
80+
goto :loop ;
7881
:program_name
7982
if "%eq%" == "" (set "arg=%~1" & shift)
8083
for /f "delims=- tokens=1,*" %I in ("%opt%") do set "var=%%J"
@@ -220,7 +223,7 @@ goto :loop ;
220223
echo --with-ntver=XXXX same as --with-ntver=_WIN32_WINNT_XXXX
221224
echo Note that '=,;' need to be enclosed within double quotes in batch file command line.
222225
del %confargs% %config_make%
223-
goto :exit
226+
goto :EOF
224227
:unknown_opt
225228
(
226229
echo %configure%: unknown option %opt%
@@ -256,6 +259,7 @@ if "%debug_configure%" == "yes" (type %config_make%)
256259

257260
nmake -al -f %WIN32DIR%/setup.mak "WIN32DIR=%WIN32DIR%" ^
258261
config_make=%config_make% ^
259-
MAKEFILE=Makefile.new MAKEFILE_BACK=Makefile.old MAKEFILE_NEW=Makefile
260-
:exit
261-
@endlocal
262+
MAKEFILE=Makefile.new MAKEFILE_BACK=Makefile.old MAKEFILE_NEW=Makefile ^
263+
%target%
264+
set error=%ERRORLEVEL%
265+
if exist %config_make% del /q %config_make%

win32/setup.mak

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MAKE = $(MAKE) -f $(MAKEFILE)
2222
MAKEFILE = Makefile
2323
!endif
2424
CPU = PROCESSOR_LEVEL
25-
CC = $(CC) -nologo -source-charset:utf-8
25+
CC = $(CC) -nologo
2626
CPP = $(CC) -EP
2727
!if "$(HAVE_BASERUBY)" != "no" && "$(BASERUBY)" == ""
2828
BASERUBY = ruby
@@ -35,13 +35,14 @@ i586-mswin32: -prologue- -i586- -epilogue-
3535
i686-mswin32: -prologue- -i686- -epilogue-
3636
alpha-mswin32: -prologue- -alpha- -epilogue-
3737
x64-mswin64: -prologue- -x64- -epilogue-
38+
arm64-mswin64: -prologue- -arm64- -epilogue-
3839

3940
-prologue-: -basic-vars- -baseruby- -gmp-
4041
-generic-: -osname-
4142

4243
-basic-vars-: nul
4344
@rem <<$(MAKEFILE)
44-
### Makefile for ruby $(TARGET_OS) ###
45+
### Makefile for ruby ###
4546
MAKE = nmake
4647
srcdir = $(srcdir:\=/)
4748
prefix = $(prefix:\=/)
@@ -70,20 +71,31 @@ int main(void) {mpz_init(x); return 0;}
7071
@echo # TARGET>>$(MAKEFILE)
7172

7273
-osname32-: -osname-section-
73-
@echo TARGET_OS = mswin32>>$(MAKEFILE)
74+
@$(CPP) -Tc <<"checking if target OS is 32bit" >>$(MAKEFILE)
75+
#ifdef _WIN64
76+
#error
77+
#else
78+
TARGET_OS = mswin32
79+
#endif
80+
<<
7481

7582
-osname64-: -osname-section-
76-
@echo TARGET_OS = mswin64>>$(MAKEFILE)
83+
@$(CPP) -Tc <<"checking if target OS is 64bit" >>$(MAKEFILE)
84+
#ifndef _WIN64
85+
#error
86+
#else
87+
TARGET_OS = mswin64
88+
#endif
89+
<<
7790

7891
-osname-: -osname-section-
79-
@echo !ifndef TARGET_OS>>$(MAKEFILE)
80-
@($(CC) -c <<conftest.c > nul && (echo TARGET_OS = mswin32) || (echo TARGET_OS = mswin64)) >>$(MAKEFILE)
92+
@$(CPP) -Tc <<"checking for target OS" 2>nul | findstr = >>$(MAKEFILE)
8193
#ifdef _WIN64
82-
#error
94+
TARGET_OS = mswin64
95+
#else
96+
TARGET_OS = mswin32
8397
#endif
8498
<<
85-
@echo !endif>>$(MAKEFILE)
86-
@$(WIN32DIR:/=\)\rm.bat conftest.*
8799

88100
-compiler-: -compiler-section- -version- -runtime- -headers-
89101

@@ -211,27 +223,54 @@ del %0 & exit
211223
<<
212224

213225
-generic-: nul
214-
@$(CPP) <<conftest.c 2>nul | findstr = >>$(MAKEFILE)
226+
@$(CPP) -Tc <<checking-target 2>nul | findstr = >>$(MAKEFILE)
215227
#if defined _M_ARM64
216228
MACHINE = arm64
217229
#elif defined _M_X64
218230
MACHINE = x64
219231
#else
220232
MACHINE = x86
221-
#endif
222-
<<
223233
!if defined($(CPU))
224-
@echo>>$(MAKEFILE) $(CPU) = $(PROCESSOR_LEVEL)
234+
$(CPU) = $(PROCESSOR_LEVEL)
225235
!endif
236+
#endif
226237

227238
-alpha-: -osname32-
228-
@echo MACHINE = alpha>>$(MAKEFILE)
239+
@$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
240+
#ifndef _M_ALPHA
241+
#error Not compiler for $(@:-=)
242+
#else
243+
MACHINE = $(@:-=)
244+
#endif
245+
<<
246+
229247
-x64-: -osname64-
230-
@echo MACHINE = x64>>$(MAKEFILE)
248+
@$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
249+
#ifndef _M_AMD64
250+
#error Not compiler for $(@:-=)
251+
#else
252+
MACHINE = $(@:-=)
253+
#endif
254+
<<
255+
231256
-ix86-: -osname32-
232-
@echo MACHINE = x86>>$(MAKEFILE)
257+
@$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
258+
#ifndef _M_IX86
259+
#error Not compiler for $(@:-=)
260+
#else
261+
#define ix86 x86
262+
MACHINE = $(@:-=)
263+
#endif
264+
<<
265+
233266
-arm64-: -osname64-
234-
@echo MACHINE = arm64>>$(MAKEFILE)
267+
@$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
268+
#ifndef _M_ARM64
269+
#error Not compiler for $(@:-=)
270+
#else
271+
MACHINE = $(@:-=)
272+
#endif
273+
<<
235274

236275
-i386-: -ix86-
237276
@echo $(CPU) = 3>>$(MAKEFILE)
@@ -261,7 +300,7 @@ MACHINE = x86
261300
# XLDFLAGS =
262301
# RFLAGS = -r
263302
# EXTLIBS =
264-
CC = $(CC)
303+
CC = $(CC) -source-charset:utf-8
265304
!if "$(AS)" != "ml64"
266305
AS = $(AS) -nologo
267306
!endif

0 commit comments

Comments
 (0)