Posted to tcl by patthoyts at Wed Apr 20 08:04:14 GMT 2011view raw

  1. From fc8bcccb56137c25154d213838e4b0a508762476 Mon Sep 17 00:00:00 2001
  2. From: Pat Thoyts <patthoyts@users.sourceforge.net>
  3. Date: Wed, 20 Apr 2011 01:40:51 +0100
  4. Subject: [PATCH] Support cross-compilation to x64 from ix86 hosts.
  5.  
  6. Part of the build uses tclsh to generate files. Ensure we can specify
  7. a runnable executable using TCLSH_NATIVE when cross-compiling.
  8. This patch also gets smarter about finding the compiler version,
  9. the compiler target architecture and the native architecture.
  10.  
  11. Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
  12. ---
  13. win/makefile.vc | 13 +++++++-
  14. win/rules.vc | 88 ++++++++++++++++++++++++++++--------------------------
  15. 2 files changed, 57 insertions(+), 44 deletions(-)
  16.  
  17. diff --git a/win/makefile.vc b/win/makefile.vc
  18. index 35aef18..7dc96b7 100644
  19. --- a/win/makefile.vc
  20. +++ b/win/makefile.vc
  21. @@ -208,6 +208,15 @@ TCLDDELIB = $(OUT_DIR)\$(TCLDDELIBNAME)
  22. TCLTEST = $(OUT_DIR)\$(PROJECT)test.exe
  23. CAT32 = $(OUT_DIR)\cat32.exe
  24.  
  25. +# Can we run what we build? IX86 runs on all architectures.
  26. +!ifndef TCLSH_NATIVE
  27. +!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
  28. +TCLSH_NATIVE = $(TCLSH)
  29. +!else
  30. +!error You must explicitly set TCLSH_NATIVE for cross-compilation
  31. +!endif
  32. +!endif
  33. +
  34. ### Make sure we use backslash only.
  35. LIB_INSTALL_DIR = $(_INSTALLDIR)\lib
  36. BIN_INSTALL_DIR = $(_INSTALLDIR)\bin
  37. @@ -1015,13 +1024,13 @@ install-libraries: tclConfig install-msgs install-tzdata
  38. install-tzdata:
  39. @echo Installing time zone data
  40. @set TCL_LIBRARY=$(ROOT)/library
  41. - @$(TCLSH) "$(ROOT)/tools/installData.tcl" \
  42. + @$(TCLSH_NATIVE) "$(ROOT)/tools/installData.tcl" \
  43. "$(ROOT)/library/tzdata" "$(SCRIPT_INSTALL_DIR)/tzdata"
  44.  
  45. install-msgs:
  46. @echo Installing message catalogs
  47. @set TCL_LIBRARY=$(ROOT)/library
  48. - @$(TCLSH) "$(ROOT)/tools/installData.tcl" \
  49. + @$(TCLSH_NATIVE) "$(ROOT)/tools/installData.tcl" \
  50. "$(ROOT)/library/msgs" "$(SCRIPT_INSTALL_DIR)/msgs"
  51.  
  52. #---------------------------------------------------------------------
  53. diff --git a/win/rules.vc b/win/rules.vc
  54. index 865b10d..c30b1cd 100644
  55. --- a/win/rules.vc
  56. +++ b/win/rules.vc
  57. @@ -27,18 +27,6 @@ _INSTALLDIR = C:\Program Files\Tcl
  58. _INSTALLDIR = $(INSTALLDIR:/=\)
  59. !endif
  60.  
  61. -!ifndef MACHINE
  62. -!if "$(CPU)" == "" || "$(CPU)" == "i386"
  63. -MACHINE = IX86
  64. -!else
  65. -MACHINE = $(CPU)
  66. -!endif
  67. -!endif
  68. -
  69. -!ifndef CFG_ENCODING
  70. -CFG_ENCODING = \"cp1252\"
  71. -!endif
  72. -
  73. #----------------------------------------------------------
  74. # Set the proper copy method to avoid overwrite questions
  75. # to the user when copying files and selecting the right
  76. @@ -64,6 +52,51 @@ ERRNULL = >NUL # Win9x shell cannot redirect stderr
  77. !endif
  78. MKDIR = mkdir
  79.  
  80. +#------------------------------------------------------------------------------
  81. +# Determine the host and target architectures and compiler version.
  82. +#------------------------------------------------------------------------------
  83. +
  84. +_HASH=^#
  85. +_VC_MANIFEST_EMBED_EXE=
  86. +_VC_MANIFEST_EMBED_DLL=
  87. +VCVER=0
  88. +!if ![echo VCVERSION=_MSC_VER > vercl.x] \
  89. + && ![echo $(_HASH)if defined(_M_IX86) >> vercl.x] \
  90. + && ![echo ARCH=IX86 >> vercl.x] \
  91. + && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
  92. + && ![echo ARCH=AMD64 >> vercl.x] \
  93. + && ![echo $(_HASH)endif >> vercl.x] \
  94. + && ![echo VCVERSION=_MSC_VER >> vercl.x] \
  95. + && ![cl -nologo -TC -P vercl.x $(ERRNULL)]
  96. +!include vercl.i
  97. +!if ![echo VCVER= ^\> vercl.vc] \
  98. + && ![set /a $(VCVERSION) / 100 - 6 >> vercl.vc]
  99. +!include vercl.vc
  100. +!endif
  101. +!endif
  102. +!if ![del /q/f vercl.x vercl.i vercl.vc]
  103. +!endif
  104. +
  105. +!if ![reg query HKLM\Hardware\Description\System\CentralProcessor\0 /v Identifier | findstr /i x86]
  106. +NATIVE_ARCH=IX86
  107. +!else
  108. +NATIVE_ARCH=AMD64
  109. +!endif
  110. +
  111. +# Since MSVC8 we must deal with manifest resources.
  112. +!if $(VCVERSION) >= 1400
  113. +_VC_MANIFEST_EMBED_EXE=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;1
  114. +_VC_MANIFEST_EMBED_DLL=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
  115. +!endif
  116. +
  117. +!ifndef MACHINE
  118. +MACHINE=$(ARCH)
  119. +!endif
  120. +
  121. +!ifndef CFG_ENCODING
  122. +CFG_ENCODING = \"cp1252\"
  123. +!endif
  124. +
  125. !message ===============================================================================
  126.  
  127. #----------------------------------------------------------
  128. @@ -176,36 +209,6 @@ LINKERFLAGS =-ltcg
  129. !endif
  130.  
  131. #----------------------------------------------------------
  132. -# MSVC8 (ships with Visual Studio 2005) generates a manifest
  133. -# file that we should link into the binaries. This is how.
  134. -#----------------------------------------------------------
  135. -
  136. -_VC_MANIFEST_EMBED_EXE=
  137. -_VC_MANIFEST_EMBED_DLL=
  138. -VCVER=0
  139. -!if ![echo VCVERSION=_MSC_VER > vercl.x] \
  140. - && ![cl -nologo -TC -P vercl.x $(ERRNULL)]
  141. -!include vercl.i
  142. -!if $(VCVERSION) >= 1600
  143. -VCVER=10
  144. -!elseif $(VCVERSION) >= 1500
  145. -VCVER=9
  146. -!elseif $(VCVERSION) >= 1400
  147. -VCVER=8
  148. -!elseif $(VCVERSION) >= 1300
  149. -VCVER=7
  150. -!elseif $(VCVERSION) >= 1200
  151. -VCVER=6
  152. -!endif
  153. -!endif
  154. -
  155. -# Since MSVC8 we must deal with manifest resources.
  156. -!if $(VCVERSION) >= 1400
  157. -_VC_MANIFEST_EMBED_EXE=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;1
  158. -_VC_MANIFEST_EMBED_DLL=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
  159. -!endif
  160. -
  161. -#----------------------------------------------------------
  162. # Decode the options requested.
  163. #----------------------------------------------------------
  164.  
  165. @@ -667,6 +670,7 @@ TK_INCLUDES = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
  166. !message *** Suffix for binaries will be '$(SUFX)'
  167. !message *** Optional defines are '$(OPTDEFINES)'
  168. !message *** Compiler version $(VCVER). Target machine is $(MACHINE)
  169. +!message *** Host architecture is $(NATIVE_ARCH)
  170. !message *** Compiler options '$(COMPILERFLAGS) $(OPTIMIZATIONS) $(DEBUGFLAGS) $(WARNINGS)'
  171. !message *** Link options '$(LINKERFLAGS)'
  172.  
  173. --
  174. 1.7.4.msysgit.0