summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile.sub275
-rw-r--r--[-rwxr-xr-x]win32/configure.bat479
-rw-r--r--win32/enc-setup.mak4
-rw-r--r--win32/file.c4
-rwxr-xr-xwin32/ifchange.bat117
-rwxr-xr-xwin32/install-buildtools.cmd14
-rwxr-xr-xwin32/install-msys-packages.cmd29
-rwxr-xr-xwin32/lastrev.bat30
-rwxr-xr-xwin32/makedirs.bat2
-rwxr-xr-xwin32/mkexports.rb13
-rwxr-xr-xwin32/rm.bat70
-rwxr-xr-xwin32/rmdirs.bat8
-rwxr-xr-xwin32/rtname.cmd71
-rw-r--r--win32/setup.mak100
-rw-r--r--win32/shellsplit.cmd114
-rw-r--r--win32/test_shellsplit.cmd28
-rwxr-xr-xwin32/vssetup.cmd56
-rw-r--r--win32/win32.c362
18 files changed, 992 insertions, 784 deletions
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 36d8f34e9a..47837c42ad 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -13,22 +13,28 @@ PWD = $(MAKEDIR)
empty =
tooldir = $(srcdir)/tool
+PROMPT = +$$S
+
+MAKEFLAGS = l$(MAKEFLAGS)
+
!ifndef MFLAGS
MFLAGS=-l
!endif
-!if "$(BASERUBY)" == ""
+!if "$(HAVE_BASERUBY)" == "no"
+BASERUBY =
+!else if "$(BASERUBY)" == ""
# After `nmake`, just built `ruby.exe` exists in the build directory,
# and is searched first prior to $PATH. Assume that no ruby
# executable in $(tooldir).
! if [cd $(tooldir) && ruby missing-baseruby.bat 2> nul]
! else if [(cd $(tooldir) && for %I in (ruby.exe) do @echo BASERUBY = %~s$$PATH:I) > baseruby.mk]
-! else
+! else if exist(baseruby.mk)
! include baseruby.mk
! endif
-! if [del baseruby.mk]
+! if [del baseruby.mk 2> nul]
! endif
-!else if "$(BASERUBY)" == "no" || [($(BASERUBY) -eexit) > nul 2> nul]
+!else if [($(BASERUBY) $(tooldir)/missing-baseruby.bat) > nul 2> nul]
BASERUBY =
!endif
!if "$(BASERUBY)" == ""
@@ -115,22 +121,24 @@ IFCHANGE = $(COMSPEC) /C $(srcdir:/=\)\win32\ifchange.bat
RM = $(COMSPEC) /C $(srcdir:/=\)\win32\rm.bat
RM1 = del
RMDIR = $(COMSPEC) /C $(srcdir:/=\)\win32\rmdirs.bat
-RMDIRS = $(COMSPEC) /C $(srcdir:/=\)\win32\rmdirs.bat
+RMDIRS = $(COMSPEC) /C $(srcdir:/=\)\win32\rmdirs.bat -p
RMALL = $(COMSPEC) /C $(srcdir:/=\)\win32\rm.bat -f -r
MAKEDIRS = $(COMSPEC) /E:ON /C $(srcdir:/=\)\win32\makedirs.bat
TOUCH = $(BASERUBY) -run -e touch --
CP = copy > nul
MV = move > nul
RM1 = del /f /q
-!if !defined(BASERUBY)
-BASERUBY = ruby
-!endif
!if !defined(TEST_RUNNABLE)
TEST_RUNNABLE = yes
!endif
CAT_DEPEND = type
+!if !defined(MSC_VER)
+! error MSC_VER not defined. Retry from configure pass.
+!else if $(MSC_VER) < 1900
+! error MSVC $(MSC_VER) is not supported
+!endif
!if !defined(MACHINE)
MACHINE = x86
!endif
@@ -141,9 +149,6 @@ PROCESSOR_LEVEL = 5
!if 6 < $(PROCESSOR_LEVEL)
PROCESSOR_LEVEL = 6
!endif
-!if $(MSC_VER) < 1400
-PROCESSOR_FLAG = -G$(PROCESSOR_LEVEL)
-!endif
CPU = i$(PROCESSOR_LEVEL)86
ARCH = i386
!else
@@ -160,15 +165,9 @@ XCFLAGS = $(XCFLAGS) -DRUBY_DEVEL=1
XCFLAGS = $(XCFLAGS) -Dmodular_gc_dir="$(modular_gc_dir)"
!endif
!if !defined(OPTFLAGS)
-!if $(MSC_VER) < 1400
-OPTFLAGS = -O2b2xg-
-!else
OPTFLAGS = -O2sy-
!endif
-!endif
-!if $(MSC_VER) >= 1900
OPTFLAGS = $(OPTFLAGS) -Zc:inline
-!endif
!if !defined(incflags)
incflags =
!endif
@@ -177,6 +176,8 @@ PLATFORM = mswin32
!endif
!if !defined(RT)
!error RT not defined. Retry from configure pass.
+!else if $(RT_VER) < 140
+! error Runtime library $(RT_VER) is not supported
!endif
!ifndef NTVER
NTVER = _WIN32_WINNT_WIN8
@@ -263,11 +264,7 @@ OUTFLAG = -Fe
COUTFLAG = -Fo
!endif
!if !defined(CPPOUTFLAG)
-! if $(MSC_VER) < 1600
-CPPOUTFLAG = >
-! else
CPPOUTFLAG = -Fi
-! endif
!endif
!if !defined(CSRCFLAG)
CSRCFLAG = -Tc
@@ -279,12 +276,12 @@ RUNTIMEFLAG = -MD
COMPILERFLAG = -Zm600
!endif
!if !defined(WARNFLAGS)
-!if $(MSC_VER) >= 1400
WARNFLAGS = -W2 -wd4100 -wd4127 -wd4210 -wd4214 -wd4255 -wd4574 \
-wd4668 -wd4710 -wd4711 -wd4820 -wd4996 \
-we4028 -we4142 -we4047 -we4013
-!else
-WARNFLAGS = -W2
+!if $(MSC_VER) >= 1944
+# https://developercommunity.visualstudio.com/t/warning-C5287:-operands-are-different-e/10877942
+WARNFLAGS = $(WARNFLAGS) -wd5287
!endif
!endif
WERRORFLAG = -WX
@@ -315,9 +312,7 @@ EXTSOLIBS =
!endif
!if !defined(LIBS)
LIBS = user32.lib advapi32.lib shell32.lib ws2_32.lib
-!if $(MSC_VER) >= 1400
LIBS = $(LIBS) iphlpapi.lib
-!endif
!if defined(USE_GMP)
LIBS = $(LIBS) gmp.lib
!endif
@@ -325,9 +320,6 @@ LIBS = $(LIBS) imagehlp.lib shlwapi.lib bcrypt.lib $(EXTLIBS)
!endif
!if !defined(MISSING)
MISSING = crypt.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj win32/win32.obj win32/file.obj setproctitle.obj
-!if $(RT_VER) < 120
-MISSING = $(MISSING) acosh.obj cbrt.obj erf.obj nan.obj tgamma.obj
-!endif
MISSING = $(MISSING) explicit_bzero.obj
!endif
DLNOBJ = dln.obj
@@ -350,15 +342,7 @@ ARFLAGS = -machine:$(MACHINE) -out:
LD = $(CC)
LDSHARED = $(LD) -LD
XCFLAGS = -DRUBY_EXPORT $(INCFLAGS) $(XCFLAGS) $(XINCFLAGS)
-!if $(MSC_VER) >= 1800
LDFLAGS = $(LDFLAGS) -manifest:embed,ID=2
-!elseif $(MSC_VER) >= 1400
-# Prevents VC++ 2005 (cl ver 14) warnings
-MANIFESTTOOL = mt -nologo
-LDSHARED_0 = @if exist $(@).manifest $(MINIRUBY) -run -e wait_writable -- -n 10 $@
-LDSHARED_1 = @if exist $(@).manifest $(MANIFESTTOOL) -manifest $(@).manifest -outputresource:$(@);2
-LDSHARED_2 = @if exist $(@).manifest @$(RM) $(@:/=\).manifest
-!endif
CPPFLAGS = $(DEFS) $(ARCHDEFS) $(CPPFLAGS)
!if "$(USE_RUBYGEMS)" == "no"
CPPFLAGS = -DDISABLE_RUBYGEMS $(CPPFLAGS)
@@ -370,16 +354,15 @@ MAINLIBS = $(LIBS)
SOLIBS =
RCFILES = $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc
!ifndef RCFLAGS
-!if $(MSC_VER) >= 1600
RCFLAGS=-nologo
!endif
-!endif
ENABLE_SHARED = yes
LIBRUBY_LDSHARED = $(LDSHARED)
LIBRUBY_DLDFLAGS = $(EXTLDFLAGS) -implib:dummy.lib -def:$(RUBYDEF)
EXEEXT = .exe
+BUILD_EXEEXT = $(EXEEXT)
EXECUTABLE_EXTS = ".exe",".com",".cmd",".bat"
!if !defined(PROGRAM)
PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT)
@@ -457,9 +440,11 @@ EXTSTATIC =
OBJEXT = obj
ASMEXT = asm
+DLEXT = so
INSTALLED_LIST= .installed.list
+HASH_SIGN = ^#
SRC_FILE = $(<:\=/)
OS_SRC_FILE = $(<:/=\)
DEST_FILE = $(@:\=/)
@@ -493,7 +478,8 @@ ENCOBJS = dmyenc.$(OBJEXT)
EXTOBJS = dmyext.$(OBJEXT)
!endif
-arch_hdrdir = $(EXTOUT)/include/$(arch)
+ext_hdrdir = $(EXTOUT)/include
+arch_hdrdir = $(ext_hdrdir)/$(arch)
top_srcdir = $(srcdir)
hdrdir = $(srcdir)/include
VPATH = $(arch_hdrdir)/ruby;$(hdrdir)/ruby;$(srcdir);$(srcdir)/missing;$(win_srcdir)
@@ -517,6 +503,15 @@ HAVE_GIT = yes
HAVE_GIT = no
! endif
!endif
+!if "$(HAVE_GIT)" == "no"
+!else if [for /f "tokens=3" %I in ('git --version') do @(\
+ for /f "delims=. tokens=1-2" %I in ("%I") do @(\
+ if %I lss 2 (exit 1) else if %I gtr 2 (exit 0) \
+ else if %J lss 10 (exit 1) else (exit 0)\
+ )\
+ )]
+HAVE_GIT = no
+!endif
!if defined(VCS)
!else if exist($(srcdir)/.git)
@@ -532,9 +527,10 @@ MESSAGE_END = ) do @echo.%~I)
ECHO_BEGIN = @echo.
ECHO_END =
-all: $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub $(srcdir)/common.mk
+all: $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub $(srcdir)/common.mk $(srcdir)/depend
prog: config
+# The default non-transformed names without $(EXEEXT).
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)
stub: $(STUBPROGRAM)
@@ -563,6 +559,13 @@ ACTIONS_ENDGROUP = @::
ABI_VERSION_HDR = $(hdrdir)/ruby/internal/abi.h
+!if defined(DUMP_AST)
+DUMP_AST_TARGET = $(empty)
+!else
+DUMP_AST = dump_ast$(BUILD_EXEEXT)
+DUMP_AST_TARGET = $(DUMP_AST)
+!endif
+
!include $(srcdir)/common.mk
!ifdef SCRIPTPROGRAMS
@@ -643,7 +646,8 @@ config.status: nul
guard = INCLUDE_RUBY_CONFIG_H
-$(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
+$(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub \
+ $(ABI_VERSION_HDR)
@echo Creating config.h
!if !exist("$(arch_hdrdir)")
@md $(arch_hdrdir:/=\)
@@ -671,9 +675,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
-!if $(MSC_VER) >= 1800
#define HAVE_STDBOOL_H 1
-!endif
#define HAVE_STDLIB_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STRING_H 1
@@ -681,11 +683,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
!if $(MSC_VER) >= 1920
#define HAVE_AFUNIX_H 1
!endif
-!if $(MSC_VER) >= 1400
#define HAVE_LONG_LONG 1
-!else
-#define ULL_TO_DOUBLE(n) ((double)(unsigned long)((n)>>32) * (1I64 << 32) + (unsigned long)(n))
-!endif
#define HAVE_OFF_T 1
#define rb_off_t __int64
#define SIGNEDNESS_OF_OFF_T -1
@@ -694,11 +692,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define SIZEOF_INT 4
#define SIZEOF_SHORT 2
#define SIZEOF_LONG 4
-!if $(MSC_VER) >= 1400
#define SIZEOF_LONG_LONG 8
-!else
-#define SIZEOF_LONG_LONG 0
-!endif
#define SIZEOF___INT64 8
#ifndef _INTEGRAL_MAX_BITS
#define _INTEGRAL_MAX_BITS 64
@@ -713,15 +707,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define SIZEOF_DOUBLE 8
#define SIGNEDNESS_OF_TIME_T -1
#define NEGATIVE_TIME_T 1
-!if $(RT_VER) >= 80
#define SIZEOF_TIME_T 8
#define TIMET2NUM(v) LL2NUM(v)
#define NUM2TIMET(v) NUM2LL(v)
-!else
-#define SIZEOF_TIME_T 4
-#define TIMET2NUM(v) LONG2NUM(v)
-#define NUM2TIMET(v) NUM2LONG(v)
-!endif
#define CLOCKID2NUM(v) INT2NUM(v)
#define NUM2CLOCKID(v) NUM2INT(v)
#define SIZEOF_CLOCK_T 4
@@ -737,22 +725,11 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define SIZEOF_INTPTR_T 4
#define SIZEOF_UINTPTR_T 4
!endif
-!if $(MSC_VER) < 1400
-#define SIZE_MAX UINT_MAX
-!endif
-!if $(MSC_VER) >= 1800
#define HAVE_VA_COPY 1
-!else
-#define HAVE_VA_COPY_VIA_STRUCT_ASSIGNMENT 1
-!endif
-!if $(MSC_VER) > 1100
#define NORETURN(x) __declspec(noreturn) x
-!endif
-!if $(MSC_VER) >= 1300
#define DEPRECATED(x) __declspec(deprecated) x
#define RUBY_CXX_DEPRECATED(mesg) __declspec(deprecated(mesg))
#define NOINLINE(x) __declspec(noinline) x
-!endif
#define ALWAYS_INLINE(x) __forceinline x
#define WARN_UNUSED_RESULT(x) x
#define MAYBE_UNUSED(x) x
@@ -760,11 +737,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define FUNC_STDCALL(x) __stdcall x
#define FUNC_CDECL(x) __cdecl x
#define FUNC_FASTCALL(x) __fastcall x
-!if $(MSC_VER) >= 1500
#define RUBY_FUNCTION_NAME_STRING __FUNCTION__
#define RBIMPL_ATTR_PACKED_STRUCT_BEGIN() __pragma(pack(push, 1))
#define RBIMPL_ATTR_PACKED_STRUCT_END() __pragma(pack(pop))
-!endif
#define RUBY_EXTERN extern __declspec(dllimport)
#define RUBY_FUNC_EXPORTED extern __declspec(dllexport)
#define RUBY_ALIGNAS(n) __declspec(align(n))
@@ -780,34 +755,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define rb_uid_t int
#define HAVE_STRUCT_STAT_ST_RDEV 1
#define HAVE_STRUCT_TIMEVAL 1
-!if $(MSC_VER) >= 1900
#define HAVE_STRUCT_TIMESPEC
-!endif
-!if $(MSC_VER) >= 1600
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
-!else
-#define int8_t signed char
-#define uint8_t unsigned char
-#define int16_t short
-#define uint16_t unsigned short
-#define int32_t int
-#define uint32_t unsigned int
-#define int64_t __int64
-#define uint64_t unsigned __int64
-#define INT8_MIN _I8_MIN
-#define INT8_MAX _I8_MAX
-#define UINT8_MAX _UI8_MAX
-#define INT16_MIN _I16_MIN
-#define INT16_MAX _I16_MAX
-#define UINT16_MAX _UI16_MAX
-#define INT32_MIN _I32_MIN
-#define INT32_MAX _I32_MAX
-#define UINT32_MAX _UI32_MAX
-#define INT64_MIN _I64_MIN
-#define INT64_MAX _I64_MAX
-#define UINT64_MAX _UI64_MAX
-!endif
#define HAVE_INT8_T 1
#define HAVE_UINT8_T 1
#define SIZEOF_INT8_T 1
@@ -838,7 +788,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define PRI_PIDT_PREFIX PRI_INT_PREFIX
#define GETGROUPS_T int
#define TYPEOF_TIMEVAL_TV_SEC long
-!if $(RT_VER) >= 120
#define HAVE_ACOSH 1
#define HAVE_ASINH 1
#define HAVE_ATANH 1
@@ -850,7 +799,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define HAVE_ROUND 1
#define HAVE_TGAMMA 1
#define HAVE_NEXTAFTER 1
-!endif
#define HAVE_ALLOCA 1
#define HAVE_DUP2 1
#define HAVE_MEMCMP 1
@@ -867,14 +815,10 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define HAVE_STRCHR 1
#define HAVE_STRSTR 1
#define HAVE_FLOCK 1
-!if $(MSC_VER) >= 1800
#define HAVE_ISINF 1
-!endif
#define HAVE_ISNAN 1
#define HAVE_FINITE 1
-!if $(RT_VER) >= 120
#define HAVE_NAN 1
-!endif
#define HAVE_HYPOT 1
#define HAVE_FMOD 1
#define HAVE_FREXP 1
@@ -920,13 +864,9 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define HAVE_SYSTEM 1
#define HAVE_TZSET 1
#define HAVE_UMASK 1
-!if $(RT_VER) > 120
#define HAVE_QSORT_S
-!endif
#define HAVE_TYPE_NET_LUID 1
-!if $(MSC_VER) >= 1600
#define HAVE_NULLPTR 1
-!endif
#define SETPGRP_VOID 1
#define RSHIFT(x,y) ((x)>>(int)y)
#define HAVE_RB_FD_INIT 1
@@ -935,11 +875,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define RUBY_JMP_BUF jmp_buf
#ifndef __cplusplus
#define inline __inline
-!if $(MSC_VER) >= 1800
#define restrict __restrict
-!else
-#define restrict /* not supported */
-!endif
#endif
#define NEED_IO_SEEK_BETWEEN_RW 1
!if "$(MACHINE)" == "x86" || "$(ARCH)" == "x64"
@@ -949,7 +885,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define THREAD_IMPL_H "$(THREAD_IMPL_H)"
#define THREAD_IMPL_SRC "$(THREAD_IMPL_SRC)"
#define LOAD_RELATIVE 1
-#define DLEXT ".so"
+#define DLEXT ".$(DLEXT)"
!if "$(libdir_basename)" != "lib"
#define LIBDIR_BASENAME "$(libdir_basename)"
!endif
@@ -1044,7 +980,7 @@ s,@LN_S@,$(LN_S),;t t
s,@SET_MAKE@,MFLAGS = -$$(MAKEFLAGS),;t t
s,@RM@,$$(COMSPEC) /C $$(top_srcdir:/=\)\win32\rm.bat,;t t
s,@RMDIR@,$$(COMSPEC) /C $$(top_srcdir:/=\)\win32\rmdirs.bat,:t t
-s,@RMDIRS@,$$(COMSPEC) /C $$(top_srcdir:/=\)\win32\rmdirs.bat,;t t
+s,@RMDIRS@,$$(COMSPEC) /C $$(top_srcdir:/=\)\win32\rmdirs.bat -p,;t t
s,@RMALL@,$$(COMSPEC) /C $$(top_srcdir:/=\)\win32\rm.bat -f -r,:t t
s,@MAKEDIRS@,$$(COMSPEC) /E:ON /C $$(top_srcdir:/=\)\win32\makedirs.bat,;t t
s,@LIBOBJS@,$(LIBOBJS),;t t
@@ -1062,7 +998,7 @@ s,@STATIC@,$(STATIC),;t t
s,@CCDLFLAGS@,,;t t
s,@LDSHARED@,$(LDSHARED),;t t
s,@SOEXT@,dll,;t t
-s,@DLEXT@,so,;t t
+s,@DLEXT@,$(DLEXT),;t t
s,@LIBEXT@,lib,;t t
s,@STRIP@,$(STRIP),;t t
s,@ENCSTATIC@,$(ENCSTATIC),;t t
@@ -1103,11 +1039,6 @@ s,@LIBPATHFLAG@,-libpath:%s,;t t
s,@RPATHFLAG@,,;t t
s,@LIBARG@,%s.lib,;t t
s,@LINK_SO@,$$(LDSHARED) -Fe$$(@) $$(OBJS) $$(LIBS) $$(LOCAL_LIBS) -link $$(DLDFLAGS) -implib:$$(*F:.so=)-$$(arch).lib -pdb:$$(*F:.so=)-$$(arch).pdb -def:$$(DEFFILE),;t t
-!if $(MSC_VER) >= 1400 && $(MSC_VER) < 1800
-s,@LINK_SO@,@if exist $$(@).manifest $$(RUBY) -run -e wait_writable -- -n 10 $$(@),;t t
-s,@LINK_SO@,@if exist $$(@).manifest $(MANIFESTTOOL) -manifest $$(@).manifest -outputresource:$$(@);2,;t t
-s,@LINK_SO@,@if exist $$(@).manifest $$(RM) $$(@:/=\).manifest,;t t
-!endif
s,@COMPILE_C@,$$(CC) $$(INCFLAGS) $$(CFLAGS) $$(CPPFLAGS) $$(COUTFLAG)$$(@) -c $$(CSRCFLAG)$$(<:\=/),;t t
s,@COMPILE_CXX@,$$(CXX) $$(INCFLAGS) $$(CXXFLAGS) $$(CPPFLAGS) $$(COUTFLAG)$$(@) -c -Tp$$(<:\=/),;t t
s,@ASSEMBLE_C@,$$(CC) $$(CFLAGS) $$(CPPFLAGS) -Fa$$(@) -c $$(CSRCFLAG)$$(<:\=/),;t t
@@ -1189,11 +1120,6 @@ $(PROGRAM): $(MAINOBJ) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res
$(ECHO) linking $(@:\=/)
$(Q) $(PURIFY) $(CC) $(MAINOBJ) $(EXTOBJS) $(RUBY_INSTALL_NAME).res \
$(OUTFLAG)$@ $(LIBRUBYARG) -link $(LDFLAGS) $(XLDFLAGS)
-! if defined(LDSHARED_0)
- $(Q) $(LDSHARED_0)
- $(Q) $(LDSHARED_1)
- $(Q) $(LDSHARED_2)
-! endif
!endif
!if "$(WPROGRAM)" != ""
@@ -1202,11 +1128,6 @@ $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $(LIBRUBY_SO) $(RUBYW_INSTALL_NAME).res
$(Q) $(PURIFY) $(CC) $(MAINOBJ) $(WINMAINOBJ) \
$(RUBYW_INSTALL_NAME).res $(OUTFLAG)$@ $(LIBRUBYARG) \
-link $(LDFLAGS) $(XLDFLAGS) -subsystem:Windows
-! if defined(LDSHARED_0)
- $(Q) $(LDSHARED_0)
- $(Q) $(LDSHARED_1)
- $(Q) $(LDSHARED_2)
-! endif
!endif
!if "$(STUBPROGRAM)" != ""
@@ -1214,11 +1135,6 @@ $(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME)
$(ECHO) linking $(@:\=/)
$(Q) $(PURIFY) $(CC) rubystub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \
$(OUTFLAG)$@ $(LIBRUBYARG) -link $(LDFLAGS) $(XLDFLAGS)
-! if defined(LDSHARED_0)
- $(Q) $(LDSHARED_0)
- $(Q) $(LDSHARED_1)
- $(Q) $(LDSHARED_2)
-! endif
!endif
!if "$(LIBRUBY_SO_UPDATE)" == ""
@@ -1249,12 +1165,6 @@ $(LIBRUBY_SO): $(LIBRUBY_A) $(DLDOBJS) $(RUBYDEF) $(RUBY_SO_NAME).res
$(OUTFLAG)$@ -link $(LDFLAGS) $(XLDFLAGS) \
$(LIBRUBY_DLDFLAGS)
@$(RM) dummy.lib dummy.exp
-!if defined(LDSHARED_0)
- $(Q) $(LDSHARED_0)
- $(Q) $(LDSHARED_1)
- $(Q) $(LDSHARED_2)
-# | findstr -v -c:LNK4049 -c:LNK4217
-!endif
$(RUBYDEF): $(LIBRUBY_A) $(RBCONFIG)
$(ECHO) generating $(@:\=/)
@@ -1268,14 +1178,44 @@ clean-local::
$(Q)$(RM) $(WINMAINOBJ) ext\extinit.c ext\extinit.$(OBJEXT) ext\vc*.pdb miniruby.lib
$(Q)$(RM) $(RUBY_INSTALL_NAME).res $(RUBYW_INSTALL_NAME).res $(RUBY_SO_NAME).res
$(Q)$(RM) miniruby.rc $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc
- $(Q)$(RM) *.map *.pdb *.ilk *.exp $(RUBYDEF) ext\ripper\y.output
+ $(Q)$(RM) *.map *.pdb *.ilk *.exp *.dll $(RUBYDEF) ext\ripper\y.output
+
+clean-local:: clean-prism
+
+clean-prism:
+ @for /R $(PRISM_BUILD_DIR:/=\) %I in (.time) do @(del /q %I && $(RMDIRS) %~pI) 2> nul || $(NULLCMD)
distclean-local::
- $(Q)$(RM) ext\config.cache $(RBCONFIG:/=\) $(CONFIG_H:/=\)
+ $(Q)$(RM) ext\config.cache $(RBCONFIG:/=\) $(CONFIG_H:/=\) miniprelude.c
-$(Q)$(RM) $(INSTALLED_LIST:/=\) $(arch_hdrdir:/=\)\ruby\config.h verconf.h
-$(Q)$(RMDIRS) $(arch_hdrdir:/=\)\ruby
-$(Q)$(RMDIR) win32
+distclean-local:: clean-srcs-local
+distclean-ext:: clean-srcs-ext
+
+distclean-local:: distclean-prism
+
+distclean-prism: clean-prism
+!if "$(srcdir)" != "."
+ $(Q)for %I in ( \
+ $(PRISM_SRCDIR:/=\)\templates\ext\prism\*.c.erb \
+ $(PRISM_SRCDIR:/=\)\templates\include\prism\*.h.erb \
+ $(PRISM_SRCDIR:/=\)\templates\src\*.c.erb \
+ ) do $(Q)(del /q prism\%~nI 2> nul || $(NULLCMD))
+ $(Q)for /D %I in (prism\*) do $(Q)$(RMDIRS) %I
+ $(Q)$(RMDIRS) prism
+!endif
+
+realclean-prism: distclean-prism
+!if "$(srcdir)" == "."
+ $(Q)for %I in ( \
+ $(PRISM_SRCDIR:/=\)\templates\ext\prism\*.c.erb \
+ $(PRISM_SRCDIR:/=\)\templates\include\prism\*.h.erb \
+ $(PRISM_SRCDIR:/=\)\templates\src\*.c.erb \
+ ) do $(Q)(del /q $(PRISM_SRCDIR:/=\)\%~nI 2> nul || $(NULLCMD))
+!endif
+
.bundle/clean:: .bundle/clean.sub
.bundle/distclean:: .bundle/distclean.sub
.bundle/realclean:: .bundle/realclean.sub
@@ -1285,7 +1225,7 @@ distclean-local::
.bundle/realclean.sub:: ext/realclean.mk
ext/clean.mk ext/distclean.mk ext/realclean.mk::
- $(Q)if exist $(EXTS_MK) $(MAKE) -k -f $(EXTS_MK) top_srcdir=$(srcdir) $(*F)
+ $(Q)if exist $(EXTS_MK) $(MAKE) $(MFLAGS) -k -f $(EXTS_MK) top_srcdir=$(srcdir) $(*F)
ext/clean.sub ext/distclean.sub ext/realclean.sub \
.bundle/clean.sub .bundle/distclean.sub .bundle/realclean.sub::
@@ -1295,16 +1235,18 @@ ext/clean.sub ext/distclean.sub ext/realclean.sub \
call set n=%I && \
call set n=%n:%CD%\$(@D)\=% && \
call set n=%n:\.=% && \
- call echo $(@F)ing %n:\=/% & \
- $(MAKE) $(MFLAGS) $(@F) & \
+ call echo $(@F:.sub=)ing %n:\=/% & \
+ $(MAKE) $(MFLAGS) $(@F:.sub=) & \
cd %CD% & \
$(RMDIRS) %I \
- ))) || @
+ ))) || $(NULLCMD)
ext/distclean ext/realclean .bundle/distclean .bundle/realclean::
- $(Q)cd $(@D) 2>nul && (for /R $(EXTS) %I in (exts.mk*) \
- do $(Q)(del %I & rmdir %~dpI)) || @
- -$(Q)rmdir $(@D) 2> nul || @
+ $(Q)(for /D /R $(@D) %I in (.) do $(Q)$(RMDIRS) %I) || $(NULLCMD)
+
+.bundle/distclean .bundle/realclean::
+ $(Q)for /D %I in ($(@D)\*) do $(Q)$(RMDIRS) %I || $(NULLCMD)
+ -$(Q)rmdir $(@D) 2> nul || $(NULLCMD)
.bundle/realclean::
@$(RMALL) $(tooldir)/bunlder/*.lock $(srcdir)/.bundle
@@ -1329,7 +1271,7 @@ $(RCFILES): $(RBCONFIG) $(srcdir)/revision.h $(srcdir)/win32/resource.rb
update-benchmark-driver:
$(GIT) clone https://github.com/benchmark-driver/benchmark-driver $(srcdir)/benchmark/benchmark-driver || \
- $(GIT) -C $(srcdir)/benchmark/benchmark-driver pull origin master
+ $(GIT_IN_SRC)/benchmark/benchmark-driver pull origin master
$(ruby_pc): $(RBCONFIG)
@$(BOOTSTRAPRUBY) $(tooldir)/expand-config.rb \
@@ -1468,8 +1410,20 @@ loadpath: verconf.h
sed -e '1,/^const char ruby_initial_load_paths/d;/;/,$$d' \
-e '/^^ /!d;s/ *"\\\\0"$$//;s/" *"//g'
-RUBYSPEC_CAPIEXT_SRCDIR = $(srcdir)/$(RUBYSPEC_CAPIEXT)
-RUBYSPEC_CAPIEXT_DEPS = $(RUBYSPEC_CAPIEXT_SRCDIR)/rubyspec.h $(RUBY_H_INCLUDES) $(LIBRUBY)
+!if [exit > rbincs.mk]
+!else if [for %I in ($(BUILTIN_RB_SRCS)) do \
+ @for %J in (\
+"%~nI.rbinc: %I $$(tooldir)/mk_builtin_loader.rb $$(DUMP_AST_TARGET)" \
+" $$(ECHO) making $$@" \
+" $$(Q) $$(BASERUBY) $$(tooldir)/mk_builtin_loader.rb $$(DUMP_AST) %I" \
+"" \
+) do @echo.%~J>>rbincs.mk]
+!else
+! include rbincs.mk
+! if [del rbincs.mk > nul]
+! endif
+!endif
+
RUBYSPEC_CAPIEXT_EXTS =
!if [echo>rubyspec-capiext.mk RUBYSPEC_CAPIEXT_EXTS = \]
@@ -1484,23 +1438,16 @@ RUBYSPEC_CAPIEXT_EXTS =
$(RUBYSPEC_CAPIEXT_EXTS): $(RUBYSPEC_CAPIEXT_DEPS)
rubyspec-capiext: $(RUBYSPEC_CAPIEXT_EXTS)
- @ $(NULLCMD)
{$(RUBYSPEC_CAPIEXT_SRCDIR)}.c{$(RUBYSPEC_CAPIEXT)}.so:
$(ECHO) building $(@F)
$(Q)$(MAKEDIRS) $(@D)
- $(Q)echo> $*.def EXPORTS
- $(Q)echo>> $*.def Init_$(*F)
- $(Q)$(LDSHARED) -Fe$(@) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) $< $(LIBRUBYARG) -link $(DLDFLAGS) $(XLDFLAGS) $(LIBS) $(LOCAL_LIBS) -implib:$*.lib -pdb:$*.pdb -def:$*.def
-!if defined(LDSHARED_0)
- $(Q)$(LDSHARED_0)
- $(Q)$(LDSHARED_1)
- $(Q)$(LDSHARED_2)
-!endif
-
-exts: rubyspec-capiext
+ $(Q)(echo EXPORTS&&echo Init_$(*F))> $*.def
+ $(Q)$(LDSHARED) -Fe$(@) -Fo$(*).obj $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) $< $(LIBRUBYARG) -link $(DLDFLAGS) $(XLDFLAGS) $(LIBS) $(LOCAL_LIBS) -implib:$*.lib -pdb:$*.pdb -def:$*.def
+ $(Q)$(RM) $*.def $*.exp $*.lib $*.obj $*.pdb
yesterday:
+ (set TZ=UTC-9) && \
for /f "usebackq" %H in \
- (`$(GIT) -C $(srcdir) log -1 "--before=00:00+0900" "--format=%H"`) do \
- $(GIT) -C $(srcdir) reset --hard %%H
+ (`$(GIT_LOG_FORMAT)%H -1 "--before=00:00"`) do \
+ $(GIT_IN_SRC) reset --hard %%H
diff --git a/win32/configure.bat b/win32/configure.bat
index bad09cd3f5..e8d6b5f95b 100755..100644
--- a/win32/configure.bat
+++ b/win32/configure.bat
@@ -1,272 +1,260 @@
@echo off
-@setlocal disabledelayedexpansion
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
set PROMPT=$E[94m+$E[m$S
-set witharg=
+goto :main
-for %%I in (%0) do if /%%~dpI/ == /%CD%\/ (
+:set
+set %*
+exit /b
+
+:shift
+call %~dp0shellsplit.cmd
+set "argv1=%argv2%"
+set "argv2=%argv%"
+if not defined argv1 if defined argv2 goto :shift
+exit /b
+
+:take_arg
+if defined arg exit /b
+if not defined argv2 exit /b
+if not "%argv2:~0,1%"=="-" (set "arg=%argv2%" & call :shift)
+exit /b
+
+:main
+if "%~dp0" == "%CD%\" (
echo don't run in win32 directory.
exit /b 999
+) else if "%~0" == "%~nx0" (
+ set "WIN32DIR=%~$PATH:0"
+) else if "%~0" == "%~n0" (
+ set "WIN32DIR=%~$PATH:0"
+) else (
+ set "WIN32DIR=%~0"
)
-set XINCFLAGS=
-set XLDFLAGS=
+set "WIN32DIR=%WIN32DIR:\=/%:/:"
+call :set "WIN32DIR=%%WIN32DIR:%~x0:/:=:/:%%"
+call :set "WIN32DIR=%%WIN32DIR:/%~n0:/:=:/:%%"
+set "WIN32DIR=%WIN32DIR:~0,-3%"
-set conf=%0
+set configure=%~0
+set args=%*
+set target=
+set optdirs=
set pathlist=
set config_make=confargs~%RANDOM%.mak
-set confargs=%config_make:.mak=.c%
+set confargs=%config_make:.mak=.sub%
+set debug_configure=
echo>%config_make% # CONFIGURE
-(
- echo #define $ $$ //
- echo !ifndef CONFIGURE_ARGS
- echo #define CONFIGURE_ARGS \
-) >%confargs%
+type nul > %confargs%
:loop
-set opt=%1
-if "%1" == "" goto :end
-if "%1" == "--debug-configure" (echo on & shift & goto :loop)
-if "%1" == "--no-debug-configure" (echo off & shift & goto :loop)
-if "%1" == "--prefix" goto :prefix
-if "%1" == "--srcdir" goto :srcdir
-if "%1" == "srcdir" goto :srcdir
-if "%1" == "--target" goto :target
-if "%1" == "target" goto :target
-if "%1" == "--with-static-linked-ext" goto :extstatic
-if "%1" == "--program-prefix" goto :pprefix
-if "%1" == "--program-suffix" goto :suffix
-if "%1" == "--program-transform-name" goto :transform_name
-if "%1" == "--program-name" goto :installname
-if "%1" == "--install-name" goto :installname
-if "%1" == "--so-name" goto :soname
-if "%1" == "--enable-install-doc" goto :enable-rdoc
-if "%1" == "--disable-install-doc" goto :disable-rdoc
-if "%1" == "--enable-install-static-library" goto :enable-lib
-if "%1" == "--disable-install-static-library" goto :disable-lib
-if "%1" == "--enable-debug-env" goto :enable-debug-env
-if "%1" == "--disable-debug-env" goto :disable-debug-env
-if "%1" == "--enable-devel" goto :enable-devel
-if "%1" == "--disable-devel" goto :disable-devel
-if "%1" == "--enable-rubygems" goto :enable-rubygems
-if "%1" == "--disable-rubygems" goto :disable-rubygems
-if "%1" == "--extout" goto :extout
-if "%1" == "--path" goto :path
-if "%1" == "--with-baseruby" goto :baseruby
-if "%1" == "--without-baseruby" goto :baseruby
-if "%1" == "--with-ntver" goto :ntver
-if "%1" == "--with-libdir" goto :libdir
-if "%1" == "--with-git" goto :git
-if "%1" == "--without-git" goto :nogit
-if "%1" == "--without-ext" goto :witharg
-if "%1" == "--without-extensions" goto :witharg
-if "%1" == "--with-opt-dir" goto :opt-dir
-if "%1" == "--with-gmp" goto :gmp
-if "%1" == "--with-gmp-dir" goto :gmp-dir
-if "%opt:~0,10%" == "--without-" goto :withoutarg
-if "%opt:~0,7%" == "--with-" goto :witharg
-if "%1" == "-h" goto :help
-if "%1" == "--help" goto :help
+call :shift
+if not defined argv1 goto :end
+for /f "delims== tokens=1,*" %%I in (" %argv1% ") do ((set "opt=%%I") && (set "arg=%%J"))
+ set "opt=%opt:~1%"
+ if defined arg (
+ set "eq=="
+ set "arg=%arg:~0,-1%"
+ ) else (
+ set "eq="
+ set "opt=%opt:~0,-1%"
+ )
+ if "%opt%"=="" (
+ echo 1>&2 %configure%: assignment for empty variable name %argv1%
+ exit /b 1
+ )
+ if "%opt%" == "--debug-configure" (
+ echo on
+ set "debug_configure=yes"
+ goto :loop ;
+ )
+ if "%opt%" == "--no-debug-configure" (
+ echo off
+ set "debug_configure="
+ goto :loop ;
+ )
+ if "%opt%" == "--prefix" goto :dir
+ if "%opt%" == "srcdir" set "opt=--srcdir"
+ if "%opt%" == "--srcdir" goto :dir
+ if "%opt%" == "--target" goto :target
+ if "%opt%" == "target" goto :target
+ if "%opt:~0,10%" == "--program-" goto :program_name
+ if "%opt%" == "--install-name" (set "var=RUBY_INSTALL_NAME" & goto :name)
+ if "%opt%" == "--so-name" (set "var=RUBY_SO_NAME" & goto :name)
+ if "%opt%" == "--extout" goto :extout
+ if "%opt%" == "--path" goto :path
+ if "%opt:~0,9%" == "--enable-" (set "enable=yes" & goto :enable)
+ if "%opt:~0,10%" == "--disable-" (set "enable=no" & goto :enable)
+ if "%opt:~0,10%" == "--without-" goto :withoutarg
+ if "%opt:~0,7%" == "--with-" goto :witharg
+ if "%opt%" == "-h" goto :help
+ if "%opt%" == "--help" goto :help
if "%opt:~0,1%" == "-" (
- echo>>%confargs% %1 \
- set witharg=
- ) else if "%witharg%" == "" (
- echo>>%confargs% %1 \
+ goto :unknown_opt
+ )
+ if "%eq%" == "=" (
+ set "var=%opt%"
+ goto :name
+ )
+ set "arg=%opt%"
+ set "eq=="
+ set "opt=--target"
+ set "target=%arg%"
+:loopend
+ if not "%arg%" == "" (
+ echo>>%confargs% "%opt%=%arg:$=$$%" \
) else (
- echo>>%confargs% ,%1\
+ echo>>%confargs% "%opt%%eq%" \
)
- shift
-goto :loop ;
-:srcdir
- echo>> %config_make% srcdir = %~2
- echo>>%confargs% --srcdir=%2 \
- shift
- shift
-goto :loop ;
-:prefix
- echo>> %config_make% prefix = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
-:pprefix
- echo>> %config_make% PROGRAM_PREFIX = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
-:suffix
- echo>> %config_make% PROGRAM_SUFFIX = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
-:installname
- echo>> %config_make% RUBY_INSTALL_NAME = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
-:soname
- echo>> %config_make% RUBY_SO_NAME = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
-:transform_name
-
- shift
- shift
goto :loop ;
:target
- echo>> %config_make% target = %~2
- echo>>%confargs% --target=%2 \
- if "%~2" == "x64-mswin64" (
- echo>> %config_make% TARGET_OS = mswin64
+ if "%eq%" == "" call :take_arg
+ if "%arg%" == "" (
+ echo 1>&2 %configure%: missing argument for %opt%
+ exit /b 1
)
- shift
- shift
-goto :loop ;
-:extstatic
- echo>> %config_make% EXTSTATIC = static
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:enable-rdoc
- echo>> %config_make% RDOCTARGET = rdoc
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:disable-rdoc
- echo>> %config_make% RDOCTARGET = nodoc
- echo>>%confargs% %1 \
- shift
+ set "target=%arg%"
+ set "opt=--target"
+ echo>>%confargs% "--target=%arg:$=$$%" \
goto :loop ;
-:enable-lib
- echo>> %config_make% INSTALL_STATIC_LIBRARY = yes
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:disable-lib
- echo>> %config_make% INSTALL_STATIC_LIBRARY = no
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:enable-debug-env
- echo>> %config_make% ENABLE_DEBUG_ENV = yes
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:disable-debug-env
- echo>> %config_make% ENABLE_DEBUG_ENV = no
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:enable-devel
- echo>> %config_make% RUBY_DEVEL = yes
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:disable-devel
- echo>> %config_make% RUBY_DEVEL = no
- echo>>%confargs% %1 \
- shift
-goto :loop ;
-:enable-rubygems
- echo>> %config_make% USE_RUBYGEMS = yes
- echo>>%confargs% %1 \
- shift
+:program_name
+ for /f "delims=- tokens=1,*" %I in ("%opt%") do set "var=%%J"
+ if "%var%" == "prefix" (set "var=PROGRAM_PREFIX" & goto :name)
+ if "%var%" == "suffix" (set "var=PROGRAM_SUFFIX" & goto :name)
+ if "%var%" == "name" (set "var=RUBY_INSTALL_NAME" & goto :name)
+ if "%var%" == "transform-name" (
+ echo.1>&2 %configure%: --program-transform-name option is not supported
+ exit /b 1
+ )
+goto :unknown_opt
+:name
+ if "%eq%" == "" call :take_arg
+ echo>> %config_make% %var% = %arg%
+goto :loopend ;
+:dir
+ if "%eq%" == "" call :take_arg
+ if defined arg set "arg=%arg:\=/%"
+ echo>> %config_make% %opt:~2% = %arg%
+goto :loopend ;
+:enable
+ if %enable% == yes (
+ if "%eq%" == "" call :take_arg
+ set "feature=%opt:~9%"
+ ) else (
+ set "feature=%opt:~10%"
+ )
+ if %enable% == yes if defined arg (set "enable=%arg%")
+ if "%feature%" == "install-doc" (
+ echo>> %config_make% RDOCTARGET = %enable:yes=r%doc
+ )
+ if "%feature%" == "install-static-library" (
+ echo>> %config_make% INSTALL_STATIC_LIBRARY = %enable%
+ )
+ if "%feature%" == "debug-env" (
+ echo>> %config_make% ENABLE_DEBUG_ENV = %enable%
+ )
+ if "%feature%" == "devel" (
+ echo>> %config_make% RUBY_DEVEL = %enable%
+ )
+ if "%feature%" == "rubygems" (
+ echo>> %config_make% USE_RUBYGEMS = %enable%
+ )
+goto :loopend ;
+:withoutarg
+ echo>>%confargs% "%opt%" \
+ if "%opt%" == "--without-baseruby" goto :nobaseruby
+ if "%opt%" == "--without-git" goto :nogit
+ if "%opt%" == "--without-ext" goto :witharg
+ if "%opt%" == "--without-extensions" goto :witharg
goto :loop ;
-:disable-rubygems
- echo>> %config_make% USE_RUBYGEMS = no
- echo>>%confargs% %1 \
- shift
+:witharg
+ if "%opt%" == "--with-static-linked-ext" goto :extstatic
+ if "%eq%" == "" call :take_arg
+ if not "%arg%" == "" (
+ echo>>%confargs% "%opt%=%arg:$=$$%" \
+ ) else (
+ echo>>%confargs% "%opt%%eq%" \
+ )
+ if "%opt%" == "--with-baseruby" goto :baseruby
+ if "%opt%" == "--with-ntver" goto :ntver
+ if "%opt%" == "--with-libdir" goto :libdir
+ if "%opt%" == "--with-git" goto :git
+ if "%opt%" == "--with-opt-dir" goto :opt-dir
+ if "%opt%" == "--with-gmp-dir" goto :opt-dir
+ if "%opt%" == "--with-gmp" goto :gmp
+ if "%opt%" == "--with-destdir" goto :destdir
+ if "%opt%" == "--with-dump-ast" goto :dump-ast
goto :loop ;
:ntver
::- For version constants, see
::- https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt#remarks
- set NTVER=%~2
+ if "%eq%" == "" (set "NTVER=%~1" & call :shift) else (set "NTVER=%arg%")
if /i not "%NTVER:~0,2%" == "0x" if /i not "%NTVER:~0,13%" == "_WIN32_WINNT_" (
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 (
- call set NTVER=%%NTVER:%%i=%%i%%
+ call :set NTVER=%%NTVER:%%i=%%i%%
)
- call set NTVER=_WIN32_WINNT_%%NTVER%%
+ call :set NTVER=_WIN32_WINNT_%%NTVER%%
)
echo>> %config_make% NTVER = %NTVER%
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
+goto :loopend ;
:extout
- if not "%~2" == ".ext" (echo>> %config_make% EXTOUT = %~2)
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
+ if "%eq%" == "" call :take_arg
+ if not "%arg%" == ".ext" (echo>> %config_make% EXTOUT = %arg%)
+goto :loopend ;
:path
- set pathlist=%pathlist%%~2;
- echo>>%confargs% %1=%2 \
- shift
- shift
-goto :loop ;
+ if "%eq%" == "" call :take_arg
+ set "pathlist=%pathlist%%arg:\=/%;"
+goto :loopend ;
+:extstatic
+ if "%eq%" == "" (set "arg=static")
+ echo>> %config_make% EXTSTATIC = %arg%
+goto :loopend ;
:baseruby
- echo>> %config_make% BASERUBY = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
+ echo>> %config_make% HAVE_BASERUBY = yes
+ echo>> %config_make% BASERUBY = %arg%
goto :loop ;
:nobaseruby
echo>> %config_make% HAVE_BASERUBY = no
- echo>>%confargs% %1=%2 \
- shift
+ echo>> %config_make% BASERUBY =
goto :loop ;
:libdir
- echo>> %config_make% libdir_basename = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
+ echo>> %config_make% libdir_basename = %arg%
goto :loop ;
:git
- echo>> %config_make% GIT = %~2
- echo>>%confargs% %1=%2 \
- shift
- shift
+ echo>> %config_make% GIT = %arg%
goto :loop ;
:nogit
echo>> %config_make% GIT = never-use
echo>> %config_make% HAVE_GIT = no
- echo>>%confargs% %1 \
- shift
goto :loop ;
:gmp
echo>> %config_make% WITH_GMP = yes
- echo>>%confargs% %1=1 \
- shift
- shift
goto :loop ;
-:gmp-dir
+:destdir
+ echo>> %config_make% DESTDIR = %arg%
+goto :loop ;
+:dump-ast
+ echo>> %config_make% DUMP_AST = %arg%
+goto :loop ;
:opt-dir
- set opt=%~2
- for %%I in (%opt:;= %) do (
- set d=%%I
- call pushd %%d:/=\%% && (
- call set XINCFLAGS=%%XINCFLAGS%% -I%%CD:\=/%%/include
- call set XLDFLAGS=%%XLDFLAGS%% -libpath:%%CD:\=/%%/lib
+ if "%arg%" == "" (
+ echo 1>&2 %configure%: missing argument for %opt%
+ exit /b 1
+ )
+ :optdir-loop
+ for /f "delims=; tokens=1,*" %%I in ("%arg%") do (set "d=%%I" & set "arg=%%J")
+ pushd %d:/=\% 2> nul && (
+ call :set "optdirs=%optdirs%;%%CD:\=/%%"
popd
+ ) || (
+ set "optdirs=%optdirs%;%d:\=/%"
)
- )
-:witharg
- echo>>%confargs% %1=%2\
- set witharg=1
- shift
- shift
-goto :loop ;
-:withoutarg
- echo>>%confargs% %1 \
- shift
+ if not "%arg%" == "" goto :optdir-loop
goto :loop ;
:help
echo Configuration:
echo --help display this help
- echo --srcdir=DIR find the sources in DIR [configure dir or `..']
+ echo --srcdir=DIR find the sources in DIR [configure dir or '..']
echo Installation directories:
echo --prefix=PREFIX install files in PREFIX [/usr]
echo System types:
@@ -276,47 +264,50 @@ goto :loop ;
echo --with-static-linked-ext link external modules statically
echo --with-ext="a,b,..." use extensions a, b, ...
echo --without-ext="a,b,..." ignore extensions a, b, ...
- echo --with-opt-dir="DIR-LIST" add optional headers and libraries directories separated by `;'
+ echo --with-opt-dir="DIR-LIST" add optional headers and libraries directories separated by ';'
echo --disable-install-doc do not install rdoc indexes during install
echo --with-ntver=0xXXXX target NT version (shouldn't use with old SDK)
echo --with-ntver=_WIN32_WINNT_XXXX
echo --with-ntver=XXXX same as --with-ntver=_WIN32_WINNT_XXXX
- echo Note that `,' and `;' need to be enclosed within double quotes in batch file command line.
+ echo Note that parameters containing spaces must be enclosed within double quotes.
del %confargs% %config_make%
-goto :exit
+goto :EOF
+:unknown_opt
+ (
+ echo %configure%: unknown option %opt%
+ echo Try --help option.
+ ) 1>&2
+ exit /b 1
:end
+if "%debug_configure%" == "yes" (type %confargs%)
+if defined optdirs (echo>>%config_make% optdirs = %optdirs:~1%)
(
- echo //
- echo configure_args = CONFIGURE_ARGS
- echo !endif
- echo #undef $
-) >> %confargs%
-(
- cl -EP %confargs% 2>nul | findstr "! ="
echo.
- if NOT "%XINCFLAGS%" == "" echo XINCFLAGS = %XINCFLAGS%
- if NOT "%XLDFLAGS%" == "" echo XLDFLAGS = %XLDFLAGS%
- if NOT "%pathlist%" == "" (
+ echo configure_args = \
+ type %confargs%
+ echo # configure_args
+
+ echo.
+ echo !if "$(optdirs)" != ""
+ for %%I in ("$(optdirs:\=/)" "$(optdirs:/;=;)") do @echo optdirs = %%~I
+ echo XINCFLAGS = -I"$(optdirs:;=/include" -I")/include"
+ echo XLDFLAGS = -libpath:"$(optdirs:;=/lib" -libpath:")/lib"
+ echo !endif
+
+ if not "%pathlist%" == "" (
+ echo.
call echo PATH = %%pathlist:;=/bin;%%$^(PATH^)
call echo INCLUDE = %%pathlist:;=/include;%%$^(INCLUDE^)
call echo LIB = %%pathlist:;=/lib;%%$^(LIB^)
)
) >> %config_make%
-del %confargs% > nul
-set setup_make=%config_make:confargs=setup%
-(
- echo #### -*- makefile -*-
- echo conf = %conf%
- echo $^(conf^): nul
- echo @del %setup_make%
- echo @$^(MAKE^) -l$^(MAKEFLAGS^) -f $^(@D^)/setup.mak \
- echo WIN32DIR=$^(@D:\=/^) config_make=%config_make%
- echo -@move /y Makefile Makefile.old ^> nul 2^> nul
- echo @ren Makefile.new Makefile
-) > %setup_make%
-nmake -alf %setup_make% MAKEFILE=Makefile.new
+del %confargs%
+if "%debug_configure%" == "yes" (type %config_make%)
-exit /b %ERRORLEVEL%
-:exit
-@endlocal
+nmake -al -f %WIN32DIR%/setup.mak "WIN32DIR=%WIN32DIR%" ^
+ config_make=%config_make% ^
+ MAKEFILE=Makefile.new MAKEFILE_BACK=Makefile.old MAKEFILE_NEW=Makefile ^
+ %target%
+set error=%ERRORLEVEL%
+if exist %config_make% del /q %config_make%
diff --git a/win32/enc-setup.mak b/win32/enc-setup.mak
index 44345a2f45..b012161e32 100644
--- a/win32/enc-setup.mak
+++ b/win32/enc-setup.mak
@@ -4,7 +4,7 @@ BUILTIN_ENCOBJS BUILTIN_TRANSOBJS: $(srcdir)/enc/Makefile.in
!include $(srcdir)/enc/Makefile.in
BUILTIN_ENCOBJS:
- @echo BUILTIN_ENCOBJS = $(BUILTIN_ENCS:.c=.obj) >> $(MAKEFILE)
+ @echo>> $(MAKEFILE) BUILTIN_ENCOBJS = $(BUILTIN_ENCS:.c=.obj)
BUILTIN_TRANSOBJS:
- @echo BUILTIN_TRANSOBJS = $(BUILTIN_TRANSES:.trans=.obj) >> $(MAKEFILE)
+ @echo>> $(MAKEFILE) BUILTIN_TRANSOBJS = $(BUILTIN_TRANSES:.trans=.obj)
diff --git a/win32/file.c b/win32/file.c
index f137f04c43..26b99715cd 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -629,14 +629,10 @@ rb_freopen(VALUE fname, const char *mode, FILE *file)
len = MultiByteToWideChar(CP_UTF8, 0, name, n, wname, len);
wname[len] = L'\0';
RB_GC_GUARD(fname);
-#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S)
- e = _wfreopen(wname, wmode, file) ? 0 : errno;
-#else
{
FILE *newfp = 0;
e = _wfreopen_s(&newfp, wname, wmode, file);
}
-#endif
ALLOCV_END(wtmp);
return e;
}
diff --git a/win32/ifchange.bat b/win32/ifchange.bat
index 1de98f9990..f3fc9ea37c 100755
--- a/win32/ifchange.bat
+++ b/win32/ifchange.bat
@@ -1,54 +1,80 @@
@echo off
:: usage: ifchange target temporary
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+
+:: @set PROMPT=$T:$S
for %%I in (%0) do set progname=%%~nI
set timestamp=
set keepsuffix=
set empty=
set color=auto
:optloop
+set optarg=
+:optnext
for %%I in (%1) do set opt=%%~I
-if "%opt%" == "--" (
- shift
-) else if "%opt%" == "--timestamp" (
- set timestamp=.
- shift
- goto :optloop
-) else if "%opt:~0,12%" == "--timestamp=" (
- set timestamp=%opt:~12%
- shift
- goto :optloop
-) else if "%opt%" == "--keep" (
- set keepsuffix=.old
- shift
- goto :optloop
-) else if "%opt:~0,7%" == "--keep=" (
- set keepsuffix=%opt:~7%
- shift
- goto :optloop
-) else if "%opt%" == "--empty" (
- set empty=yes
- shift
- goto :optloop
-) else if "%opt%" == "--color" (
- set color=always
- shift
- goto :optloop
-) else if "%opt:~0,8%" == "--color=" (
- set color=%opt:~8%
- shift
- goto :optloop
-) else if "%opt%" == "--debug" (
- shift
- echo on
- goto :optloop
-) else if "%opt%" == "--help" (
- call :help
- exit /b
-) else if "%opt:~0,2%" == "--" (
+ if not "%opt:~0,2%" == "--" (
+ if not "%optarg%" == "" (
+ call set %optarg%=%%opt%%
+ shift
+ goto :optloop
+ )
+ goto :optend
+ )
+ if "%opt%" == "--" (
+ shift
+ goto :optend
+ )
+ if "%opt%" == "--timestamp" (
+ set timestamp=.
+ set optarg=timestamp
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,12%" == "--timestamp=" (
+ set timestamp=%opt:~12%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--keep" (
+ set keepsuffix=.old
+ set optarg=keep
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,7%" == "--keep=" (
+ set keepsuffix=%opt:~7%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--empty" (
+ set empty=yes
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--color" (
+ set color=always
+ set optarg=color
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,8%" == "--color=" (
+ set color=%opt:~8%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--debug" (
+ shift
+ echo on
+ goto :optloop
+ )
+ if "%opt%" == "--help" (
+ call :help
+ exit /b
+ )
echo %progname%: unknown option: %1 1>&2
exit /b 1
-)
+:optend
if "%2" == "" (
call :help 1>&2
@@ -60,6 +86,19 @@ set src=%2
set dest=%dest:/=\%
set src=%src:/=\%
+if not "%src%" == "-" goto :srcfile
+ if not "%TMPDIR%" == "" (
+ set src=%TMPDIR%\ifchange%RANDOM%.tmp
+ ) else if not "%TEMP%" == "" (
+ set src=%TEMP%\ifchange%RANDOM%.tmp
+ ) else if not "%TMP%" == "" (
+ set src=%TMP%\ifchange%RANDOM%.tmp
+ ) else (
+ set src=.\ifchange%RANDOM%.tmp
+ )
+ findstr -r -c:"^" > "%src%"
+:srcfile
+
if exist %dest% (
if not exist %src% goto :nt_unchanged1
if not "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged
diff --git a/win32/install-buildtools.cmd b/win32/install-buildtools.cmd
new file mode 100755
index 0000000000..7f5e20293b
--- /dev/null
+++ b/win32/install-buildtools.cmd
@@ -0,0 +1,14 @@
+@echo off
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+
+set components=VC.Tools.x86.x64 VC.Redist.14.Latest CoreBuildTools
+set components=%components% Windows11SDK.26100
+if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (
+ set components=%components% VC.Tools.ARM64 VC.Tools.ARM64EC
+)
+set override=--passive
+for %%I in (%components%) do (
+ call set override=%%override%% --add Microsoft.VisualStudio.Component.%%I
+)
+echo on
+winget install --id Microsoft.VisualStudio.2022.BuildTools --override "%override%"
diff --git a/win32/install-msys-packages.cmd b/win32/install-msys-packages.cmd
new file mode 100755
index 0000000000..f388de5692
--- /dev/null
+++ b/win32/install-msys-packages.cmd
@@ -0,0 +1,29 @@
+::- Install msys packages for rubygems
+::- The dependencies are taken from vcpkg.json to share the common info.
+
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b - 1
+@set PROMPT=$h$e[96m$g$e[39m$s
+@set script=%0
+@call set "srcdir=%%script:\win32\%~nx0=%%"
+
+@if not defined MINGW_PACKAGE_PREFIX (
+ ::- Enable msys environment by ridk (from RubyInstaller-DevKit)
+ where ridk >nul 2>&1 || (
+ (echo MINGW_PACKAGE_PREFIX is not set, you have to enable development environment.) 1>&2
+ exit /b 1
+ )
+ call ridk enable %*
+ echo:
+) else if not "%1" == "" (
+ ::- Switch msys environment by ridk (from RubyInstaller-DevKit)
+ call ridk enable %*
+ echo:
+)
+
+@set pkgs=
+@(
+ for /f %%I in ('powershell -c "(ConvertFrom-Json $input).dependencies"') do @(
+ call set "pkgs=%%pkgs%% %%MINGW_PACKAGE_PREFIX%%-%%%%I"
+ )
+) < "%srcdir%\vcpkg.json"
+pacman -S --needed --noconfirm %pkgs:~1%
diff --git a/win32/lastrev.bat b/win32/lastrev.bat
new file mode 100755
index 0000000000..48e5750c6e
--- /dev/null
+++ b/win32/lastrev.bat
@@ -0,0 +1,30 @@
+@echo off
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+
+if "%1" == "" (set gitdir=.) else (set gitdir=%1)
+set TZ=UTC
+for /f "usebackq tokens=1-3" %%I in (
+ `git -C "%gitdir%" log -1 --no-show-signature "--date=format-local:%%F %%T" "--format=%%H %%cd" HEAD`
+) do (
+ set rev=%%I
+ set dt=%%J
+ set tm=%%K
+)
+if not "%dt%" == "" (
+ set /a yy=%dt:-=% / 10000
+ set /a mm=%dt:-=% / 100 %% 100
+ set /a dd=%dt:-=% %% 100
+)
+for /f "usebackq tokens=1" %%I in (
+ `git -C "%gitdir%" symbolic-ref --short HEAD`
+) do set branch=%%I
+if not "%rev%" == "" (
+ echo #define RUBY_REVISION "%rev:~,10%"
+ echo #define RUBY_FULL_REVISION "%rev%"
+ echo #define RUBY_BRANCH_NAME "%branch%"
+ echo #define RUBY_RELEASE_DATETIME "%dt%T%tm%Z"
+ echo #define RUBY_RELEASE_YEAR %yy%
+ echo #define RUBY_RELEASE_MONTH %mm%
+ echo #define RUBY_RELEASE_DAY %dd%
+)
+@endlocal
diff --git a/win32/makedirs.bat b/win32/makedirs.bat
index 13740d8778..8c06d94041 100755
--- a/win32/makedirs.bat
+++ b/win32/makedirs.bat
@@ -1,3 +1,3 @@
@echo off
-setlocal EnableExtensions
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
for %%I in (%*) do if not exist "%%~I/." mkdir "%%~I"
diff --git a/win32/mkexports.rb b/win32/mkexports.rb
index 1a37c7ee91..44bda94990 100755
--- a/win32/mkexports.rb
+++ b/win32/mkexports.rb
@@ -110,6 +110,7 @@ class Exports::Mswin < Exports
case filetype
when /OBJECT/, /LIBRARY/
l.chomp!
+ next if (/^ .*\(pick any\)$/ =~ l)...true
next if /^[[:xdigit:]]+ 0+ UNDEF / =~ l
next unless /External/ =~ l
next if /(?:_local_stdio_printf_options|v(f|sn?)printf(_s)?_l)\Z/ =~ l
@@ -137,7 +138,11 @@ end
class Exports::Cygwin < Exports
def self.nm
- @@nm ||= RbConfig::CONFIG["NM"]
+ @@nm ||=
+ begin
+ require 'shellwords'
+ RbConfig::CONFIG["NM"].shellsplit
+ end
end
def exports(*)
@@ -145,7 +150,9 @@ class Exports::Cygwin < Exports
end
def each_line(objs, &block)
- IO.foreach("|#{self.class.nm} --extern-only --defined-only #{objs.join(' ')}", &block)
+ IO.popen([*self.class.nm, *%w[--extern-only --defined-only], *objs]) do |f|
+ f.each(&block)
+ end
end
def each_export(objs)
@@ -154,7 +161,7 @@ class Exports::Cygwin < Exports
re = /\s(?:(T)|[[:upper:]])\s#{symprefix}((?!#{PrivateNames}).*)$/
objdump(objs) do |l|
next if /@.*@/ =~ l
- yield $2, !$1 if re =~ l
+ yield $2.strip, !$1 if re =~ l
end
end
end
diff --git a/win32/rm.bat b/win32/rm.bat
index fefc030545..c41ebfa5ee 100755
--- a/win32/rm.bat
+++ b/win32/rm.bat
@@ -1,18 +1,64 @@
@echo off
-setlocal
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+
+set prog=%~n0
+set dryrun=
set recursive=
+set debug=
+set error=0
+set parent=
+
:optloop
if "%1" == "-f" shift
-if "%1" == "-r" (shift & set "recursive=1" & goto :optloop)
-if "%1" == "--debug" (shift & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop)
+if "%1" == "-n" (shift & set "dryrun=%1" & goto :optloop)
+if "%1" == "-r" (shift & set "recursive=%1" & goto :optloop)
+if "%1" == "--debug" (shift & set "debug=%1" & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop)
:begin
-if "%1" == "" goto :end
-set p=%1
-set p=%p:/=\%
-if exist "%p%" del /q "%p%" > nul
-if "%recursive%" == "1" for /D %%I in (%p%) do (
- rd /s /q %%I
-)
-shift
+if "%1" == "" goto :EOF
+ set p=%1
+ shift
+ set p=%p:/=\%
+ call :remove %p%
goto :begin
-:end
+
+:remove
+setlocal
+
+::- Split %1 by '?' and '*', wildcard characters
+for /f "usebackq delims=?* tokens=1*" %%I in ('%1') do (set "par=%%I" & set "sub=%%J")
+if "%sub%" == "" goto :remove_plain
+if "%sub:\=%" == "%sub%" goto :remove_plain
+ ::- Extract the first wildcard
+ set "q=%1"
+ call set "q=%%q:%par%=%%"
+ set q=%q:~0,1%
+
+ ::- `delims` chars at the beginning are removed in `for`
+ if "%sub:~0,1%" == "\" (
+ set "sub=%sub:~1%"
+ set "par=%par%%q%"
+ ) else (
+ for /f "usebackq delims=\\ tokens=1*" %%I in ('%sub%') do (set "par=%par%%q%%%I" & set "sub=%%J")
+ )
+
+ ::- Recursive search
+ for /d %%D in (%par%) do (
+ call :remove %sub% %2%%D\
+ )
+goto :remove_end
+:remove_plain
+ set p=%2%1
+ if not exist "%1" goto :remove_end
+ if not "%dryrun%" == "" (
+ echo Removing %p:\=/%
+ goto :remove_end
+ )
+ ::- Try `rd` first for symlink to a directory; `del` attemps to remove all
+ ::- files under the target directory, instead of the symlink itself.
+ (rd /q "%p%" || del /q "%p%") 2> nul && goto :remove_end
+
+ if "%recursive%" == "-r" for /D %%I in (%p%) do (
+ rd /s /q %%I || call set error=%%ERRORLEVEL%%
+ )
+:remove_end
+endlocal & set "error=%error%" & goto :EOF
diff --git a/win32/rmdirs.bat b/win32/rmdirs.bat
index 308b648322..a8abebd383 100755
--- a/win32/rmdirs.bat
+++ b/win32/rmdirs.bat
@@ -1,6 +1,9 @@
-::-*- batch -*-
@echo off
-if "%1" == "-p" shift
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+set parents=1
+:optloop
+if "%1" == "--debug" (shift & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop)
+if "%1" == "-p" (shift & (set parents=1) & goto :optloop)
:begin
if "%1" == "" goto :end
set dir=%1
@@ -12,6 +15,7 @@ if "%1" == "" goto :end
if "%dir%" == "." goto :begin
if "%dir%" == ".." goto :begin
rd "%dir%" 2> nul || goto :begin
+ if "%parents%" == "" goto :begin
:trim_sep
if not /%dir:~-1%/ == /\/ goto :trim_base
set dir=%dir:~0,-1%
diff --git a/win32/rtname.cmd b/win32/rtname.cmd
index 775e81681a..b85c6a0c7c 100755
--- a/win32/rtname.cmd
+++ b/win32/rtname.cmd
@@ -1,35 +1,36 @@
-@echo off
-set rt=
-set rtver=
-set osver=
-for /f "usebackq" %%I in (`
- dumpbin -dependents %1 ^|
- findstr -r -i -c:"\<vcruntime.*\.dll$" -c:"\<msvcr.*\.dll$"
-`) do (
- set rt=%%~nI
-)
-
-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 @(
- ::- downcase
- call set rt=%%rt:%%i=%%i%%
-)
-
-if "%rt%" == "msvcrt" (
- call set rtver=60
-) else if "%rt:~0,5%" == "msvcr" (
- call set rtver=%%rt:msvcr=%%
- call set osver=_%%rtver%%
-) else if "%rt:~0,9%" == "vcruntime" (
- call set rtver=%%rt:vcruntime=%%
- call set osver=_%%rtver%%
-) else (
- (echo %0: %1 is not linked to msvcrt nor vcruntime) 1>&2
- exit 1
-)
-for %%I in (
- "PLATFORM = $(TARGET_OS)%osver%"
- "RT = %rt%"
- "RT_VER = %rtver%"
-) do @(
- echo %%~I
-)
+@echo off
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+set rt=
+set rtver=
+set osver=
+for /f "usebackq" %%I in (`
+ dumpbin -dependents %1 ^|
+ findstr -r -i -c:"\<vcruntime.*\.dll$" -c:"\<msvcr.*\.dll$"
+`) do (
+ set rt=%%~nI
+)
+
+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 @(
+ ::- downcase
+ call set rt=%%rt:%%i=%%i%%
+)
+
+if "%rt%" == "msvcrt" (
+ call set rtver=60
+) else if "%rt:~0,5%" == "msvcr" (
+ call set rtver=%%rt:msvcr=%%
+ call set osver=_%%rtver%%
+) else if "%rt:~0,9%" == "vcruntime" (
+ call set rtver=%%rt:vcruntime=%%
+ call set osver=_%%rtver%%
+) else (
+ (echo %0: %1 is not linked to msvcrt nor vcruntime) 1>&2
+ exit 1
+)
+for %%I in (
+ "PLATFORM = $(TARGET_OS)%osver%"
+ "RT = %rt%"
+ "RT_VER = %rtver%"
+) do @(
+ echo %%~I
+)
diff --git a/win32/setup.mak b/win32/setup.mak
index 275ccda3bb..19ace3445c 100644
--- a/win32/setup.mak
+++ b/win32/setup.mak
@@ -24,6 +24,9 @@ MAKEFILE = Makefile
CPU = PROCESSOR_LEVEL
CC = $(CC) -nologo
CPP = $(CC) -EP
+!if "$(HAVE_BASERUBY)" != "no" && "$(BASERUBY)" == ""
+BASERUBY = ruby
+!endif
all: -prologue- -generic- -epilogue-
i386-mswin32: -prologue- -i386- -epilogue-
@@ -32,13 +35,14 @@ i586-mswin32: -prologue- -i586- -epilogue-
i686-mswin32: -prologue- -i686- -epilogue-
alpha-mswin32: -prologue- -alpha- -epilogue-
x64-mswin64: -prologue- -x64- -epilogue-
+arm64-mswin64: -prologue- -arm64- -epilogue-
--prologue-: -basic-vars-
+-prologue-: -basic-vars- -baseruby- -gmp-
-generic-: -osname-
-basic-vars-: nul
- @type << > $(MAKEFILE)
-### Makefile for ruby $(TARGET_OS) ###
+ @rem <<$(MAKEFILE)
+### Makefile for ruby ###
MAKE = nmake
srcdir = $(srcdir:\=/)
prefix = $(prefix:\=/)
@@ -46,9 +50,13 @@ prefix = $(prefix:\=/)
<<
@type $(config_make) >>$(MAKEFILE)
@del $(config_make) > nul
-!if defined(BASERUBY)
- $(BASERUBY:/=\) "$(srcdir)/tool/missing-baseruby.bat"
+
+-baseruby-: nul
+!if "$(HAVE_BASERUBY)" != "no"
+ @cd $(srcdir:/=\)\tool && $(BASERUBY:/=\) missing-baseruby.bat --verbose || exit $(HAVE_BASERUBY:yes=non-)0
!endif
+
+-gmp-:
!if "$(WITH_GMP)" != "no"
@($(CC) $(XINCFLAGS) <<conftest.c -link $(XLDFLAGS) gmp.lib > nul && (echo USE_GMP = yes) || exit /b 0) >>$(MAKEFILE)
#include <gmp.h>
@@ -63,20 +71,31 @@ int main(void) {mpz_init(x); return 0;}
@echo # TARGET>>$(MAKEFILE)
-osname32-: -osname-section-
- @echo TARGET_OS = mswin32>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if target OS is 32bit" >>$(MAKEFILE)
+#ifdef _WIN64
+#error
+#else
+TARGET_OS = mswin32
+#endif
+<<
-osname64-: -osname-section-
- @echo TARGET_OS = mswin64>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if target OS is 64bit" >>$(MAKEFILE)
+#ifndef _WIN64
+#error
+#else
+TARGET_OS = mswin64
+#endif
+<<
-osname-: -osname-section-
- @echo !ifndef TARGET_OS>>$(MAKEFILE)
- @($(CC) -c <<conftest.c > nul && (echo TARGET_OS = mswin32) || (echo TARGET_OS = mswin64)) >>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking for target OS" 2>nul | findstr = >>$(MAKEFILE)
#ifdef _WIN64
-#error
+TARGET_OS = mswin64
+#else
+TARGET_OS = mswin32
#endif
<<
- @echo !endif>>$(MAKEFILE)
- @$(WIN32DIR:/=\)\rm.bat conftest.*
-compiler-: -compiler-section- -version- -runtime- -headers-
@@ -143,8 +162,8 @@ main(void)
<<
@( \
$(CC) -O2 $@.c && .\$@ || \
- set bug=%ERRORLEVEL% \
- echo This compiler has an optimization bug \
+ (set bug=%ERRORLEVEL% & \
+ echo This compiler has an optimization bug) \
) & $(WIN32DIR:/=\)\rm.bat $@.* & exit /b %bug%
-version-: nul verconf.mk
@@ -188,39 +207,70 @@ echo TEENY = RUBY_VERSION_TEENY
echo ABI_VERSION = RUBY_ABI_VERSION
#endif
set /a MSC_VER = _MSC_VER
-#if _MSC_VER >= 1920
+#ifndef _MSC_VER
+# error _MSC_VER not defined
+#elif _MSC_VER >= 1920
set /a MSC_VER_LOWER = MSC_VER/20*20+0
set /a MSC_VER_UPPER = MSC_VER/20*20+19
#elif _MSC_VER >= 1900
set /a MSC_VER_LOWER = MSC_VER/10*10+0
set /a MSC_VER_UPPER = MSC_VER/10*10+9
+#elif _MSC_VER < 1400
+# error Unsupported VC++ compiler
#endif
set MSC_VER
del %0 & exit
<<
-generic-: nul
- @$(CPP) <<conftest.c 2>nul | findstr = >>$(MAKEFILE)
+ @$(CPP) -Tc <<checking-target 2>nul | findstr = >>$(MAKEFILE)
#if defined _M_ARM64
MACHINE = arm64
#elif defined _M_X64
MACHINE = x64
#else
MACHINE = x86
-#endif
-<<
!if defined($(CPU))
- @echo>>$(MAKEFILE) $(CPU) = $(PROCESSOR_LEVEL)
+$(CPU) = $(PROCESSOR_LEVEL)
!endif
+#endif
-alpha-: -osname32-
- @echo MACHINE = alpha>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
+#ifndef _M_ALPHA
+#error Not compiler for $(@:-=)
+#else
+MACHINE = $(@:-=)
+#endif
+<<
+
-x64-: -osname64-
- @echo MACHINE = x64>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
+#ifndef _M_AMD64
+#error Not compiler for $(@:-=)
+#else
+MACHINE = $(@:-=)
+#endif
+<<
+
-ix86-: -osname32-
- @echo MACHINE = x86>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
+#ifndef _M_IX86
+#error Not compiler for $(@:-=)
+#else
+#define ix86 x86
+MACHINE = $(@:-=)
+#endif
+<<
+
-arm64-: -osname64-
- @echo MACHINE = arm64>>$(MAKEFILE)
+ @$(CPP) -Tc <<"checking if compiler is for $(@:-=)" >>$(MAKEFILE)
+#ifndef _M_ARM64
+#error Not compiler for $(@:-=)
+#else
+MACHINE = $(@:-=)
+#endif
+<<
-i386-: -ix86-
@echo $(CPU) = 3>>$(MAKEFILE)
@@ -250,7 +300,7 @@ MACHINE = x86
# XLDFLAGS =
# RFLAGS = -r
# EXTLIBS =
-CC = $(CC)
+CC = $(CC) -source-charset:utf-8
!if "$(AS)" != "ml64"
AS = $(AS) -nologo
!endif
@@ -265,4 +315,6 @@ AS = $(AS) -nologo
$(BANG)include $$(srcdir)/win32/Makefile.sub
<<
@$(COMSPEC) /C $(srcdir:/=\)\win32\rm.bat config.h config.status
+ -@move /y $(MAKEFILE_NEW) $(MAKEFILE_BACK) > nul 2> nul
+ @move /y $(MAKEFILE) $(MAKEFILE_NEW) > nul
@echo type 'nmake' to make ruby.
diff --git a/win32/shellsplit.cmd b/win32/shellsplit.cmd
new file mode 100644
index 0000000000..0594f22df1
--- /dev/null
+++ b/win32/shellsplit.cmd
@@ -0,0 +1,114 @@
+setlocal EnableExtensions DisableDelayedExpansion
+if not defined V set V=0
+if not defined args (
+ goto :return_arg
+)
+set INPUT=%args%
+set OUTBUF=
+set UNQ=
+set QTD=
+
+set INPUT=%INPUT:#=#35%
+set INPUT=%INPUT:@=#64%
+set "PENDING=%INPUT:"=@sep%" &:: escape double quotes and split consecutive marks
+
+::#### split into unquoted part, quoted part, remains
+:loop
+
+for /F "tokens=1,2* delims=@" %%I in (" %PENDING%") do (
+ set "UNQ=%%I"
+ set "QTD=%%J"
+ set "PENDING=%%K"
+)
+set "UNQ=%UNQ:~1%"
+
+if %V%==1 (
+ echo unquoted:
+ (echo UNQ :"%UNQ%")&(echo QTD :"%QTD%")&(echo REST:"%PENDING%")&(if defined OUTBUF echo OUTBUF:"%OUTBUF%")
+)
+
+if defined QTD (set "QTD=%QTD:~3%")
+if defined PENDING (set "PENDING=%PENDING:~3%")
+
+if %V%==1 (
+ (echo QTD :"%QTD%")&(echo REST:"%PENDING%")
+)
+
+if not defined UNQ if defined OUTBUF (
+ set concat_next=true
+ goto :process_unquote
+)
+
+set concat_prev=
+set concat_check=
+if defined UNQ (set "concat_check=%UNQ:~0,1%")
+if not "%concat_check%"==" " (set concat_prev=true)
+
+set concat_next=
+set concat_check=
+if defined UNQ (set "concat_check=%UNQ:~-1%")
+if not "%concat_check%"==" " (set concat_next=true)
+
+if not defined concat_prev if defined OUTBUF (
+ goto :return_arg
+)
+
+::#### process unquoted part
+:process_unquote
+
+if defined UNQ if "%UNQ: =%"=="" (set UNQ=)
+if not defined UNQ goto :process_quoted
+
+for /F "tokens=1* eol=" %%I in ("%UNQ%") do (
+ set "token=%%I"
+ set "UNQ=%%J"
+)
+
+if %V%==1 (
+ (echo unq :"%token%")&(echo UNQ :"%UNQ%")
+)
+
+set "OUTBUF=%OUTBUF%%token%"
+if defined UNQ (
+ goto :return_arg
+) else (
+ if not defined concat_next (
+ goto :return_arg
+ )
+)
+
+::#### process quoted part
+:process_quoted
+
+if %V%==1 (
+ echo quoted:
+ (echo UNQ :"%UNQ%")&(echo QTD :"%QTD%")&(echo REST:"%PENDING%")&(if defined OUTBUF echo OUTBUF:"%OUTBUF%")
+)
+
+set "OUTBUF=%OUTBUF%%QTD%"
+set QTD=
+
+if not defined PENDING (
+ goto :return_arg
+)
+goto :loop
+
+::#### return splitted argv
+:return_arg
+
+set "argv=%OUTBUF%"
+if defined argv (set "argv=%argv:#64=@%")
+if defined argv (set "argv=%argv:#35=#%")
+
+if defined QTD (set QTD="%QTD%")
+
+:: special handling is required because they may contain double quotes
+
+if defined PENDING set PENDING=%PENDING:@sep="%
+set args=%UNQ%%QTD%%PENDING%
+if defined args set args=%args:#64=@%
+if defined args set args=%args:#35=#%
+
+endlocal & set "argv=%argv%" & set args=%args%
+
+exit /b
diff --git a/win32/test_shellsplit.cmd b/win32/test_shellsplit.cmd
new file mode 100644
index 0000000000..8a2e8ec8f4
--- /dev/null
+++ b/win32/test_shellsplit.cmd
@@ -0,0 +1,28 @@
+@echo off & if not [%1]==[] goto :process
+
+echo.
+echo This script demonstrates how shellsplit.cmd works.
+echo usage: %0 arg1 arg2...
+echo.
+echo Prints separated arguments as (arg1)(arg2)...
+echo - splits commandline with spaces/tabs. cmd.exe standard rule is ignored.
+echo - you can use double quotes to contain spaces/tabs into an argument.
+echo - you can not escape double quote.
+echo - solitary "" is ignored since cmd.exe variables cannot represent empty value.
+exit /b 0
+
+:process
+setlocal
+set V=0
+
+:: %* can contain meta character inside quote. do not use set "args=%*" here.
+set args=%*
+
+:loop
+call %~dp0\shellsplit.cmd
+if not defined argv goto :end
+set /p "tmp=(%argv%)"<NUL
+goto :loop
+
+:end
+endlocal & exit /b 0
diff --git a/win32/vssetup.cmd b/win32/vssetup.cmd
new file mode 100755
index 0000000000..f9f49fb276
--- /dev/null
+++ b/win32/vssetup.cmd
@@ -0,0 +1,56 @@
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+::- do not `echo off` that affects the called batch files
+
+::- check for vswhere
+@set vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
+@if not exist "%vswhere%" (
+ echo 1>&2 vswhere.exe not found
+ exit /b 1
+)
+
+::- find the latest build tool and its setup batch file.
+@set VSDEVCMD=
+@set VSDEV_ARGS=
+@set where_opt=
+@set arch=
+:argloop
+@(set arg=%1) & if defined arg (shift) else (goto :argend)
+ @if "%arg%" == "-prerelease" (
+ set where_opt=-prerelease
+ goto :argloop
+ )
+ @if /i "%arg%" == "-arch" (
+ set arch=%1
+ shift
+ goto :argloop
+ )
+ @if /i "%arg:~0,6%" == "-arch=" (
+ set arch=%arg:~6%
+ goto :argloop
+ )
+
+ @set VSDEV_ARGS=%VSDEV_ARGS% %arg%
+ @goto :argloop
+:argend
+@if defined VSDEV_ARGS set VSDEV_ARGS=%VSDEV_ARGS:~1%
+
+@for /f "delims=" %%I in ('"%vswhere%" -products * -latest -property installationPath %where_opt%') do @(
+ set VSDEVCMD=%%I\Common7\Tools\VsDevCmd.bat
+)
+@if not defined VSDEVCMD (
+ echo 1>&2 Visual Studio not found
+ exit /b 1
+)
+
+::- default to the current processor.
+@set host_arch=%PROCESSOR_ARCHITECTURE%
+@if not defined arch set arch=%PROCESSOR_ARCHITECTURE%
+::- `vsdevcmd.bat` requires arch names to be lowercase
+@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 @(
+ call set arch=%%arch:%%i=%%i%%
+ call set host_arch=%%host_arch:%%i=%%i%%
+)
+@if "%arch%" == "x86_64" set arch=amd64
+
+::- chain to `vsdevcmd.bat`
+@(endlocal && "%VSDEVCMD%" -arch=%arch% -host_arch=%host_arch% %VSDEV_ARGS%)
diff --git a/win32/win32.c b/win32/win32.c
index 784c150393..e3a3df71f6 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -21,6 +21,10 @@
#undef __STRICT_ANSI__
+/* Visual C++ 2015 (14.0):
+ * - _MSC_VER: 1900
+ * - MSVCRT_VERSION: 140
+ */
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "ruby/io.h"
@@ -42,7 +46,7 @@
#include <shlobj.h>
#include <mbstring.h>
#include <shlwapi.h>
-#if defined _MSC_VER && _MSC_VER >= 1400
+#if defined _MSC_VER
#include <crtdbg.h>
#include <rtcapi.h>
#endif
@@ -65,10 +69,6 @@
#include "encindex.h"
#define isdirsep(x) ((x) == '/' || (x) == '\\')
-#if defined _MSC_VER && _MSC_VER <= 1200
-# define CharNextExA(cp, p, flags) CharNextExA((WORD)(cp), (p), (flags))
-#endif
-
static int w32_wopen(const WCHAR *file, int oflag, int perm);
static int w32_stati128(const char *path, struct stati128 *st, UINT cp, BOOL lstat);
static char *w32_getenv(const char *name, UINT cp);
@@ -113,10 +113,8 @@ static char *w32_getenv(const char *name, UINT cp);
#undef dup2
#undef strdup
-#if RUBY_MSVCRT_VERSION >= 140
-# define _filbuf _fgetc_nolock
-# define _flsbuf _fputc_nolock
-#endif
+#define _filbuf _fgetc_nolock
+#define _flsbuf _fputc_nolock
#define enough_to_get(n) (--(n) >= 0)
#define enough_to_put(n) (--(n) >= 0)
@@ -316,15 +314,6 @@ get_version(void)
GetVersionEx(&osver);
}
-#ifdef _M_IX86
-/* License: Artistic or GPL */
-DWORD
-rb_w32_osid(void)
-{
- return osver.dwPlatformId;
-}
-#endif
-
/* License: Artistic or GPL */
DWORD
rb_w32_osver(void)
@@ -503,11 +492,6 @@ rb_w32_special_folder(int type)
return rb_w32_conv_from_wchar(path, rb_filesystem_encoding());
}
-#if defined _MSC_VER && _MSC_VER <= 1200
-/* License: Ruby's */
-#define GetSystemWindowsDirectoryW GetWindowsDirectoryW
-#endif
-
/* License: Ruby's */
UINT
rb_w32_system_tmpdir(WCHAR *path, UINT len)
@@ -629,7 +613,6 @@ init_env(void)
static void init_stdhandle(void);
-#if RUBY_MSVCRT_VERSION >= 80
/* License: Ruby's */
static void
invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t dummy)
@@ -639,7 +622,7 @@ invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file,
int ruby_w32_rtc_error;
-# ifndef __MINGW32__
+#ifndef __MINGW32__
/* License: Ruby's */
RBIMPL_ATTR_NONNULL((5))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 5, 6)
@@ -658,7 +641,6 @@ rtc_error_handler(int e, const char *src, int line, const char *exe, const char
rb_write_error2(RSTRING_PTR(str), RSTRING_LEN(str));
return 0;
}
-# endif
#endif
static CRITICAL_SECTION select_mutex;
@@ -852,13 +834,11 @@ socklist_delete(SOCKET *sockp, int *flagp)
return ret;
}
-#if RUBY_MSVCRT_VERSION >= 80
# ifdef __MINGW32__
# define _CrtSetReportMode(type,mode) ((void)0)
# define _RTC_SetErrorFunc(func) ((void)0)
# endif
static void set_pioinfo_extra(void);
-#endif
static int w32_cmdvector(const WCHAR *, char ***, UINT, rb_encoding *);
//
// Initialization stuff
@@ -867,13 +847,10 @@ static int w32_cmdvector(const WCHAR *, char ***, UINT, rb_encoding *);
void
rb_w32_sysinit(int *argc, char ***argv)
{
-#if RUBY_MSVCRT_VERSION >= 80
-
_CrtSetReportMode(_CRT_ASSERT, 0);
_set_invalid_parameter_handler(invalid_parameter);
_RTC_SetErrorFunc(rtc_error_handler);
set_pioinfo_extra();
-#endif
SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
get_version();
@@ -2413,7 +2390,6 @@ rb_w32_closedir(DIR *dirp)
return 0;
}
-#if RUBY_MSVCRT_VERSION >= 140
typedef struct {
union
{
@@ -2433,14 +2409,8 @@ typedef struct {
#define FILE_COUNT(stream) ((vcruntime_file*)stream)->_cnt
#define FILE_READPTR(stream) ((vcruntime_file*)stream)->_ptr
#define FILE_FILENO(stream) ((vcruntime_file*)stream)->_file
-#else
-#define FILE_COUNT(stream) stream->_cnt
-#define FILE_READPTR(stream) stream->_ptr
-#define FILE_FILENO(stream) stream->_file
-#endif
/* License: Ruby's */
-#if RUBY_MSVCRT_VERSION >= 140
typedef char lowio_text_mode;
typedef char lowio_pipe_lookahead[3];
@@ -2457,32 +2427,14 @@ typedef struct {
uint8_t dbcsBufferUsed : 1; // Is the dbcsBuffer in use?
char dbcsBuffer; // Buffer for the lead byte of DBCS when converting from DBCS to Unicode
} ioinfo;
-#else
-typedef struct {
- intptr_t osfhnd; /* underlying OS file HANDLE */
- char osfile; /* attributes of file (e.g., open in text mode?) */
- char pipech; /* one char buffer for handles opened on pipes */
- int lockinitflag;
- CRITICAL_SECTION lock;
-#if RUBY_MSVCRT_VERSION >= 80
- char textmode;
- char pipech2[2];
-#endif
-} ioinfo;
-#endif
#if !defined _CRTIMP || defined __MINGW32__
#undef _CRTIMP
#define _CRTIMP __declspec(dllimport)
#endif
-#if RUBY_MSVCRT_VERSION >= 140
static ioinfo ** __pioinfo = NULL;
#define IOINFO_L2E 6
-#else
-EXTERN_C _CRTIMP ioinfo * __pioinfo[];
-#define IOINFO_L2E 5
-#endif
static inline ioinfo* _pioinfo(int);
@@ -2492,20 +2444,18 @@ static inline ioinfo* _pioinfo(int);
#define rb_acrt_lowio_lock_fh(i) EnterCriticalSection(&_pioinfo(i)->lock)
#define rb_acrt_lowio_unlock_fh(i) LeaveCriticalSection(&_pioinfo(i)->lock)
-#if RUBY_MSVCRT_VERSION >= 80
static size_t pioinfo_extra = 0; /* workaround for VC++8 SP1 */
/* License: Ruby's */
static void
set_pioinfo_extra(void)
{
-#if RUBY_MSVCRT_VERSION >= 140
-# define FUNCTION_RET 0xc3 /* ret */
-# ifdef _DEBUG
-# define UCRTBASE "ucrtbased.dll"
-# else
-# define UCRTBASE "ucrtbase.dll"
-# endif
+#define FUNCTION_RET 0xc3 /* ret */
+#ifdef _DEBUG
+# define UCRTBASE "ucrtbased.dll"
+#else
+# define UCRTBASE "ucrtbase.dll"
+#endif
/* get __pioinfo addr with _isatty */
/*
* Why Ruby depends to _pioinfo is
@@ -2640,7 +2590,6 @@ set_pioinfo_extra(void)
__pioinfo = *(ioinfo***)(p);
#endif
#endif /* _M_ARM64 */
-#endif /* RUBY_MSVCRT_VERSION */
int fd;
fd = _open("NUL", O_RDONLY);
@@ -2656,9 +2605,6 @@ set_pioinfo_extra(void)
pioinfo_extra = 0;
}
}
-#else
-#define pioinfo_extra 0
-#endif
static inline ioinfo*
_pioinfo(int fd)
@@ -2805,11 +2751,11 @@ rb_w32_strerror(int e)
DWORD source = 0;
char *p;
- if (e < 0 || e > sys_nerr) {
- if (e < 0)
- e = GetLastError();
+ if (e < 0)
+ strlcpy(buffer, "Unknown Error", sizeof(buffer));
+ else if (e > sys_nerr) {
#if WSAEWOULDBLOCK != EWOULDBLOCK
- else if (e >= EADDRINUSE && e <= EWOULDBLOCK) {
+ if (e >= EADDRINUSE && e <= EWOULDBLOCK) {
static int s = -1;
int i;
if (s < 0)
@@ -4235,7 +4181,6 @@ socketpair(int af, int type, int protocol, int *sv)
return 0;
}
-#if !defined(_MSC_VER) || _MSC_VER >= 1400
/* License: Ruby's */
static void
str2guid(const char *str, GUID *guid)
@@ -4361,7 +4306,6 @@ freeifaddrs(struct ifaddrs *ifp)
ifp = next;
}
}
-#endif
#if 0 // Have never been used
//
@@ -4725,26 +4669,35 @@ waitpid(rb_pid_t pid, int *stat_loc, int options)
#include <sys/timeb.h>
/* License: Ruby's */
+#define filetime_unit (10UL * 1000 * 1000)
+#define filetime_diff_days ((1970-1601)*3652425UL/10000)
+#define filetime_diff_secs (filetime_diff_days * (24ULL * 60 * 60))
+#define unix_to_filetime(sec) (((sec) + filetime_diff_secs) * filetime_unit)
+#define filetime_unix_offset unix_to_filetime(0ULL)
+
+/* License: Ruby's */
+typedef union {
+ /* FILETIME and ULARGE_INTEGER::u are the same layout */
+ FILETIME ft;
+ ULARGE_INTEGER i;
+} FILETIME_INTEGER;
+
+/* License: Ruby's */
/* split FILETIME value into UNIX time and sub-seconds in NT ticks */
static time_t
filetime_split(const FILETIME* ft, long *subsec)
{
- ULARGE_INTEGER tmp;
- unsigned LONG_LONG lt;
- const unsigned LONG_LONG subsec_unit = (unsigned LONG_LONG)10 * 1000 * 1000;
-
- tmp.LowPart = ft->dwLowDateTime;
- tmp.HighPart = ft->dwHighDateTime;
- lt = tmp.QuadPart;
+ FILETIME_INTEGER fi = {.ft = *ft};
+ ULONGLONG lt = fi.i.QuadPart;
/* lt is now 100-nanosec intervals since 1601/01/01 00:00:00 UTC,
convert it into UNIX time (since 1970/01/01 00:00:00 UTC).
the first leap second is at 1972/06/30, so we doesn't need to think
about it. */
- lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * subsec_unit;
+ lt -= unix_to_filetime(0);
- *subsec = (long)(lt % subsec_unit);
- return (time_t)(lt / subsec_unit);
+ *subsec = (long)(lt % filetime_unit);
+ return (time_t)(lt / filetime_unit);
}
/* License: Ruby's */
@@ -4762,37 +4715,67 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
}
/* License: Ruby's */
+static void
+filetime_to_timespec(FILETIME ft, struct timespec *sp)
+{
+ long subsec;
+ sp->tv_sec = filetime_split(&ft, &subsec);
+ sp->tv_nsec = subsec * 100;
+}
+
+/* License: Ruby's */
+static const long secs_in_ns = 1000000000;
+
+/* License: Ruby's */
int
clock_gettime(clockid_t clock_id, struct timespec *sp)
{
switch (clock_id) {
case CLOCK_REALTIME:
+ case CLOCK_REALTIME_COARSE:
{
FILETIME ft;
- long subsec;
GetSystemTimePreciseAsFileTime(&ft);
- sp->tv_sec = filetime_split(&ft, &subsec);
- sp->tv_nsec = subsec * 100;
+ filetime_to_timespec(ft, sp);
return 0;
}
case CLOCK_MONOTONIC:
{
LARGE_INTEGER freq;
LARGE_INTEGER count;
- if (!QueryPerformanceFrequency(&freq)) {
+ if (UNLIKELY(!QueryPerformanceFrequency(&freq))) {
errno = map_errno(GetLastError());
return -1;
}
- if (!QueryPerformanceCounter(&count)) {
+ if (UNLIKELY(!QueryPerformanceCounter(&count))) {
errno = map_errno(GetLastError());
return -1;
}
sp->tv_sec = count.QuadPart / freq.QuadPart;
- if (freq.QuadPart < 1000000000)
- sp->tv_nsec = (count.QuadPart % freq.QuadPart) * 1000000000 / freq.QuadPart;
+ if (freq.QuadPart < secs_in_ns)
+ sp->tv_nsec = (count.QuadPart % freq.QuadPart) * secs_in_ns / freq.QuadPart;
else
- sp->tv_nsec = (long)((count.QuadPart % freq.QuadPart) * (1000000000.0 / freq.QuadPart));
+ sp->tv_nsec = (long)((count.QuadPart % freq.QuadPart) * ((double)secs_in_ns / freq.QuadPart));
+ return 0;
+ }
+ case CLOCK_PROCESS_CPUTIME_ID:
+ case CLOCK_THREAD_CPUTIME_ID:
+ {
+ FILETIME_INTEGER c, e, k, u, total;
+ BOOL ok;
+ if (clock_id == CLOCK_PROCESS_CPUTIME_ID) {
+ ok = GetProcessTimes(GetCurrentProcess(), &c.ft, &e.ft, &k.ft, &u.ft);
+ }
+ else {
+ ok = GetThreadTimes(GetCurrentThread(), &c.ft, &e.ft, &k.ft, &u.ft);
+ }
+ if (UNLIKELY(!ok)) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ total.i.QuadPart = k.i.QuadPart + u.i.QuadPart;
+ filetime_to_timespec(total.ft, sp);
return 0;
}
default:
@@ -4807,6 +4790,7 @@ clock_getres(clockid_t clock_id, struct timespec *sp)
{
switch (clock_id) {
case CLOCK_REALTIME:
+ case CLOCK_REALTIME_COARSE:
{
sp->tv_sec = 0;
sp->tv_nsec = 1000;
@@ -4820,7 +4804,15 @@ clock_getres(clockid_t clock_id, struct timespec *sp)
return -1;
}
sp->tv_sec = 0;
- sp->tv_nsec = (long)(1000000000.0 / freq.QuadPart);
+ sp->tv_nsec = (long)((double)secs_in_ns / freq.QuadPart);
+ return 0;
+ }
+ case CLOCK_PROCESS_CPUTIME_ID:
+ case CLOCK_THREAD_CPUTIME_ID:
+ {
+ const int frames_in_sec = 60;
+ sp->tv_sec = 0;
+ sp->tv_nsec = (long)(secs_in_ns / frames_in_sec);
return 0;
}
default:
@@ -6611,7 +6603,7 @@ rb_w32_pipe(int fds[2])
memcpy(name, prefix, width_of_prefix);
snprintf(name + width_of_prefix, width_of_ids, "%.*"PRI_PIDT_PREFIX"x-%.*lx",
- width_of_pid, rb_w32_getpid(), width_of_serial, InterlockedIncrement(&serial)-1);
+ width_of_pid, rb_w32_getpid(), width_of_serial, (unsigned long)(InterlockedIncrement(&serial)-1));
sec.nLength = sizeof(sec);
sec.lpSecurityDescriptor = NULL;
@@ -6745,20 +6737,6 @@ constat_handle(HANDLE h)
return p;
}
-/* License: Ruby's */
-static void
-constat_reset(HANDLE h)
-{
- st_data_t data;
- struct constat *p;
- thread_exclusive(conlist) {
- if (!conlist || conlist == conlist_disabled) continue;
- if (!st_lookup(conlist, (st_data_t)h, &data)) continue;
- p = (struct constat *)data;
- p->vt100.state = constat_init;
- }
-}
-
#define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
#define BACKGROUND_MASK (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
@@ -6789,47 +6767,54 @@ constat_attr(int count, const int *seq, WORD attr, WORD default_attr, int *rever
case 1:
bold = FOREGROUND_INTENSITY;
break;
+ case 22:
+ bold = 0;
+ break;
case 4:
#ifndef COMMON_LVB_UNDERSCORE
#define COMMON_LVB_UNDERSCORE 0x8000
#endif
attr |= COMMON_LVB_UNDERSCORE;
break;
+ case 24:
+ attr &= ~COMMON_LVB_UNDERSCORE;
+ break;
case 7:
rev = 1;
break;
+ case 27:
+ rev = 0;
+ break;
case 30:
attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
break;
- case 17:
case 31:
attr = (attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN)) | FOREGROUND_RED;
break;
- case 18:
case 32:
attr = (attr & ~(FOREGROUND_BLUE | FOREGROUND_RED)) | FOREGROUND_GREEN;
break;
- case 19:
case 33:
attr = (attr & ~FOREGROUND_BLUE) | FOREGROUND_GREEN | FOREGROUND_RED;
break;
- case 20:
case 34:
attr = (attr & ~(FOREGROUND_GREEN | FOREGROUND_RED)) | FOREGROUND_BLUE;
break;
- case 21:
case 35:
attr = (attr & ~FOREGROUND_GREEN) | FOREGROUND_BLUE | FOREGROUND_RED;
break;
- case 22:
case 36:
attr = (attr & ~FOREGROUND_RED) | FOREGROUND_BLUE | FOREGROUND_GREEN;
break;
- case 23:
case 37:
attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
break;
+ case 38: /* 256-color or true color; N/A on old Command Prompt */
+ break;
+ case 39:
+ attr = (attr & ~FOREGROUND_MASK) | (default_attr & FOREGROUND_MASK);
+ break;
case 40:
attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
@@ -6855,6 +6840,11 @@ constat_attr(int count, const int *seq, WORD attr, WORD default_attr, int *rever
case 47:
attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
break;
+ case 48: /* 256-color or true color; N/A on old Command Prompt */
+ break;
+ case 49:
+ attr = (attr & ~BACKGROUND_MASK) | (default_attr & BACKGROUND_MASK);
+ break;
}
}
attr |= bold;
@@ -7210,9 +7200,6 @@ rb_w32_read_internal(int fd, void *buf, size_t size, rb_off_t *offset)
size_t len;
size_t ret;
OVERLAPPED ol;
- BOOL isconsole;
- BOOL islineinput = FALSE;
- int start = 0;
if (is_socket(sock))
return rb_w32_recv(fd, buf, size, 0);
@@ -7235,25 +7222,8 @@ rb_w32_read_internal(int fd, void *buf, size_t size, rb_off_t *offset)
}
ret = 0;
- isconsole = is_console(_osfhnd(fd)) && (osver.dwMajorVersion < 6 || (osver.dwMajorVersion == 6 && osver.dwMinorVersion < 2));
- if (isconsole) {
- DWORD mode;
- GetConsoleMode((HANDLE)_osfhnd(fd),&mode);
- islineinput = (mode & ENABLE_LINE_INPUT) != 0;
- }
retry:
- /* get rid of console reading bug */
- if (isconsole) {
- constat_reset((HANDLE)_osfhnd(fd));
- if (start)
- len = 1;
- else {
- len = 0;
- start = 1;
- }
- }
- else
- len = size;
+ len = size;
size -= len;
if (setup_overlapped(&ol, fd, FALSE, offset)) {
@@ -7324,8 +7294,7 @@ rb_w32_read_internal(int fd, void *buf, size_t size, rb_off_t *offset)
ret += read;
if (read >= len) {
buf = (char *)buf + read;
- if (err != ERROR_OPERATION_ABORTED &&
- !(isconsole && len == 1 && (!islineinput || *((char *)buf - 1) == '\n')) && size > 0)
+ if (err != ERROR_OPERATION_ABORTED && size > 0)
goto retry;
}
if (read == 0)
@@ -7532,27 +7501,13 @@ rb_w32_write_console(uintptr_t strarg, int fd)
return (long)reslen;
}
-#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__GMTIME64_S)
-/* License: Ruby's */
-static int
-unixtime_to_filetime(time_t time, FILETIME *ft)
-{
- ULARGE_INTEGER tmp;
-
- tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
- ft->dwLowDateTime = tmp.LowPart;
- ft->dwHighDateTime = tmp.HighPart;
- return 0;
-}
-#endif
-
/* License: Ruby's */
static int
timespec_to_filetime(const struct timespec *ts, FILETIME *ft)
{
ULARGE_INTEGER tmp;
- tmp.QuadPart = ((LONG_LONG)ts->tv_sec + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
+ tmp.QuadPart = unix_to_filetime((ULONGLONG)ts->tv_sec);
tmp.QuadPart += ts->tv_nsec / 100;
ft->dwLowDateTime = tmp.LowPart;
ft->dwHighDateTime = tmp.HighPart;
@@ -7922,23 +7877,6 @@ rb_w32_isatty(int fd)
return 1;
}
-#if defined(_MSC_VER) && RUBY_MSVCRT_VERSION <= 60
-extern long _ftol(double);
-/* License: Ruby's */
-long
-_ftol2(double d)
-{
- return _ftol(d);
-}
-
-/* License: Ruby's */
-long
-_ftol2_sse(double d)
-{
- return _ftol(d);
-}
-#endif
-
#ifndef signbit
/* License: Ruby's */
int
@@ -7970,68 +7908,6 @@ rb_w32_fd_is_text(int fd)
return _osfile(fd) & FTEXT;
}
-#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__GMTIME64_S)
-/* License: Ruby's */
-static int
-unixtime_to_systemtime(const time_t t, SYSTEMTIME *st)
-{
- FILETIME ft;
- if (unixtime_to_filetime(t, &ft)) return -1;
- if (!FileTimeToSystemTime(&ft, st)) return -1;
- return 0;
-}
-
-/* License: Ruby's */
-static void
-systemtime_to_tm(const SYSTEMTIME *st, struct tm *t)
-{
- int y = st->wYear, m = st->wMonth, d = st->wDay;
- t->tm_sec = st->wSecond;
- t->tm_min = st->wMinute;
- t->tm_hour = st->wHour;
- t->tm_mday = st->wDay;
- t->tm_mon = st->wMonth - 1;
- t->tm_year = y - 1900;
- t->tm_wday = st->wDayOfWeek;
- switch (m) {
- case 1:
- break;
- case 2:
- d += 31;
- break;
- default:
- d += 31 + 28 + (!(y % 4) && ((y % 100) || !(y % 400)));
- d += ((m - 3) * 153 + 2) / 5;
- break;
- }
- t->tm_yday = d - 1;
-}
-
-/* License: Ruby's */
-static int
-systemtime_to_localtime(TIME_ZONE_INFORMATION *tz, SYSTEMTIME *gst, SYSTEMTIME *lst)
-{
- TIME_ZONE_INFORMATION stdtz;
- SYSTEMTIME sst;
-
- if (!SystemTimeToTzSpecificLocalTime(tz, gst, lst)) return -1;
- if (!tz) {
- GetTimeZoneInformation(&stdtz);
- tz = &stdtz;
- }
- if (tz->StandardBias == tz->DaylightBias) return 0;
- if (!tz->StandardDate.wMonth) return 0;
- if (!tz->DaylightDate.wMonth) return 0;
- if (tz != &stdtz) stdtz = *tz;
-
- stdtz.StandardDate.wMonth = stdtz.DaylightDate.wMonth = 0;
- if (!SystemTimeToTzSpecificLocalTime(&stdtz, gst, &sst)) return 0;
- if (lst->wMinute == sst.wMinute && lst->wHour == sst.wHour)
- return 0;
- return 1;
-}
-#endif
-
#ifdef HAVE__GMTIME64_S
# ifndef HAVE__LOCALTIME64_S
/* assume same as _gmtime64_s() */
@@ -8055,17 +7931,8 @@ gmtime_r(const time_t *tp, struct tm *rp)
errno = e;
return NULL;
}
-#if RUBY_MSVCRT_VERSION >= 80 || defined(HAVE__GMTIME64_S)
e = gmtime_s(rp, tp);
if (e != 0) goto error;
-#else
- {
- SYSTEMTIME st;
- if (unixtime_to_systemtime(*tp, &st)) goto error;
- rp->tm_isdst = 0;
- systemtime_to_tm(&st, rp);
- }
-#endif
return rp;
}
@@ -8079,17 +7946,8 @@ localtime_r(const time_t *tp, struct tm *rp)
errno = e;
return NULL;
}
-#if RUBY_MSVCRT_VERSION >= 80 || defined(HAVE__LOCALTIME64_S)
e = localtime_s(rp, tp);
if (e) goto error;
-#else
- {
- SYSTEMTIME gst, lst;
- if (unixtime_to_systemtime(*tp, &gst)) goto error;
- rp->tm_isdst = systemtime_to_localtime(NULL, &gst, &lst);
- systemtime_to_tm(&lst, rp);
- }
-#endif
return rp;
}
@@ -8306,10 +8164,6 @@ rb_w32_set_thread_description_str(HANDLE th, VALUE name)
VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE) = rb_f_notimplement;
-#if RUBY_MSVCRT_VERSION < 120
-#include "missing/nextafter.c"
-#endif
-
void *
rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, rb_off_t offset)
{