crosscompile.tcl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #
  2. # Run this Tcl script to generate the crosscompile.html file.
  3. #
  4. set rcsid {$Id: crosscompile.tcl,v 1.5 2001/11/24 13:23:05 drh Exp $}
  5. puts {<html>
  6. <head>
  7. <title>Notes On How To Compile SQLite Using The MinGW Cross-Compiler</title>
  8. </head>
  9. <body bgcolor=white>
  10. <h1 align=center>
  11. Notes On How To Compile SQLite Using The MinGW Cross-Compiler
  12. </h1>}
  13. puts "<p align=center>
  14. (This page was last modified on [lrange $rcsid 3 4] UTC)
  15. </p>"
  16. puts {
  17. <p><a href="http://www.mingw.org/">MinGW</a> or
  18. <a href="http://www.mingw.org/">Minimalist GNU For Windows</a>
  19. is a version of the popular GCC compiler that builds Win95/Win98/WinNT
  20. binaries. See the website for details.</p>
  21. <p>This page describes how you can use MinGW configured as a
  22. cross-compiler running under RedHat 6.0 Linux to generate a
  23. binary for SQLite that runs under WinNT.
  24. Some additional steps (described <a href="#win95">below</a>)
  25. are needed to target Win95/98.</p>
  26. }
  27. proc Code {body} {
  28. puts {<blockquote><pre>}
  29. regsub -all {&} [string trim $body] {\&amp;} body
  30. regsub -all {>} $body {\&gt;} body
  31. regsub -all {<} $body {\&lt;} body
  32. regsub -all {\(\(\(} $body {<font color="#00671f"><u>} body
  33. regsub -all {\)\)\)} $body {</u></font>} body
  34. puts $body
  35. puts {</pre></blockquote>}
  36. }
  37. puts {
  38. <p>Here are the steps:</p>
  39. <ol>
  40. <li>
  41. <p>Get a copy of the MinGW compiler and all
  42. its associated tools that run under Linux. No binary versions of
  43. MinGW in this configuration are available for net downloads, as far
  44. as I know. You will probably have to download the source code and
  45. compile it all yourself.
  46. A <a href="mingw.html">separate bulletin</a> describes how this
  47. can be done.
  48. When you are done, make sure the compiler and all its associated tools
  49. are located somewhere on your PATH environment variable.
  50. </p>
  51. </li>
  52. <li>
  53. <p>
  54. Download the Win32 port of GDBM from <a href="http://www.roth.net/libs/gdbm/">
  55. Roth Consulting</a>. You can FTP a ZIP archive of the sources directly
  56. from <a href="ftp://ftp.roth.net/pub/ntperl/gdbm/source/Win32_GDBM_Source.zip">
  57. ftp://ftp.roth.net/pub/ntperl/gdbm/source/Win32_GDBM_Source.zip</a>.
  58. </p>
  59. </li>
  60. <li>
  61. <p>Make a directory and unpack the Win32 port of GDBM.</p>
  62. <blockquote><pre>
  63. mkdir roth
  64. cd roth
  65. unzip ../Win32_GDBM_Source.zip
  66. </pre></blockquote>
  67. </li>
  68. <li>
  69. <p>Manually build the GDBM library as follows:</p>
  70. <blockquote><pre>
  71. i386-mingw32-gcc -DWIN32=1 -O2 -c *.c
  72. i386-mingw32-ar cr libgdbm.a *.o
  73. i386-mingw32-ranlib libgdbm.a
  74. cd ..
  75. </pre></blockquote>
  76. </li>
  77. <li>
  78. <p>
  79. Download the SQLite tarball from
  80. <a href="http://www.hwaci.com/sw/sqlite/sqlite.tar.gz">
  81. http://www.hwaci.com/sw/sqlite/sqlite.tar.gz</a>.
  82. Unpack the tarball and create a separate directory in which
  83. to build the executable and library.
  84. </p>
  85. <blockquote><pre>
  86. tar xzf sqlite.tar.gz
  87. mkdir sqlite-bld
  88. cd sqlite-bld
  89. </pre></blockquote>
  90. </li>
  91. <li>
  92. <p>
  93. Create a "hints" file that will tell the SQLite configuration script
  94. to use the MinGW cross-compiler rather than the native linux compiler.
  95. The hints file should looks something like this:</p>
  96. <blockquote><pre>
  97. cat >mingw.hints <<\END
  98. config_TARGET_CC=i386-mingw32-gcc
  99. config_TARGET_CFLAGS='-O2'
  100. config_TARGET_GDBM_LIBS=../roth/libgdbm.a
  101. config_TARGET_GDBM_INC=-I../roth
  102. config_TARGET_AR='i386-mingw32-ar cr'
  103. config_TARGET_RANLIB=i386-mingw32-ranlib
  104. config_TARGET_EXEEXT='.exe'
  105. END
  106. </pre></blockquote>
  107. </li>
  108. <li>
  109. <p>Configure and build SQLite:</p>
  110. <blockquote><pre>
  111. ../sqlite/configure --with-hints=./mingw.hints
  112. make
  113. </pre></blockquote>
  114. </li>
  115. </ol>
  116. <a name="win95">
  117. <h2>Targetting Windows95/98 instead of WindowsNT</h2>
  118. <p>A small amount of additional work is needed to get SQLite running
  119. under Windows95/98. The first problem is that the LockFile() and
  120. UnlockFile() API that the Roth GDBM port uses does not work under
  121. Windows95. The easiest workaround is to just disable file locking
  122. in the GDBM library. You can do so by appending a few lines of code
  123. to the end of one of the GDBM source files and compiling the library
  124. using a special command-line option. Replace step (4) above as
  125. follows:</p>
  126. <ol>
  127. <li value="4"><p>
  128. Append text to the <b>systems.h</b> source file as follows:</p>
  129. <blockquote><pre>
  130. cat &gt;&gt;systems.h &lt;&lt;\END
  131. #ifdef NO_LOCKS
  132. #undef UNLOCK_FILE
  133. #define UNLOCK_FILE(x)
  134. #undef READLOCK_FILE
  135. #define READLOCK_FILE(x) lock_val=0;
  136. #undef WRITELOCK_FILE
  137. #define WRITELOCK_FILE(x) lock_val=0;
  138. #endif
  139. END
  140. </pre></blockquote>
  141. <p>Then manually build the GDBM library with the extra
  142. "NO_LOCKS" define as follows:</p>
  143. <blockquote><pre>
  144. i386-mingw32-gcc -DWIN32=1 -DNO_LOCKS -O2 -c *.c
  145. i386-mingw32-ar cr libgdbm.a *.o
  146. i386-mingw32-ranlib libgdbm.a
  147. cd ..
  148. </pre></blockquote>
  149. </p></li>
  150. </ol>
  151. <p>Note that the locking problem has been reported and may actually
  152. be fixed in the Roth GDBM distribution by the time you read this.
  153. You should probably check before you make the above changes.</p>
  154. <p>The above is all you have to do to get SQLite to work on Windows95.
  155. But one more step is required to get it to work <i>well</i>. It
  156. turns out that SQLite make heavy use of <b>malloc()</b> and
  157. <b>free()</b> and the implementation of this functions
  158. on Windows95 is particular poor. Large database queries will run
  159. more than 10 times faster if you substitute a better memory allocator
  160. such as the one by
  161. <a href="http://g.oswego.edu/dl/html/malloc.html">Doug Lea</a>.
  162. A copy of Doug's allocator is included in the <b>contrib</b>
  163. directory of the source tree. Speed improvements are also reported
  164. on WindowsNT when alternative memory allocators are used, though
  165. the speedup is not as dramatic as it is with WIndows95.</p>
  166. }
  167. puts {
  168. <p><hr /></p>
  169. <p><a href="index.html"><img src="/goback.jpg" border=0 />
  170. Back to the SQLite Home Page</a>
  171. </p>
  172. </body></html>}