Remove lfs-uefi.txt symlink
[linux_from_scratch_hints.git] / PREVIOUS_FORMAT / lin2win.txt
blobe6c49b5e6b21c802b049b1cf3b97b8a586e34e21
1 TITLE:                  Linux to Windows 
2 LFS VERSION:            LFS CVS [20030603]
3 AUTHOR:                 Nathan Coulson <conathan@conet.dyndns.org>
4                         Seth W. Klein <sk@sethwklein.net>
5 SYNOPSIS:
6         Ever want to compile windows programs from linux?  This hint shows
7 how to build i386-pc-mingw32, i386-pc-cygwin32, and i386-pc-msdosdjgpp
8 cross compilers.
10 VERSION:        0.1
11 CHANGELOG:
12         0.1: Text has been fixed up, updated to gcc 3.3.1  Compile libraries
13              first
15 HINT:
16         First, to cover some of the basics. To compile the libraries for
17 these compilers, you need the compilers, but to compile the compilers, you
18 need the libraries.  This circular dependency is solved by starting with
19 binary versions of the libraries.
21         I am going to define some variables for use in the commands below,
22 and you may edit them as you see fit.  PREFIX is the destination directory,
23 while TARGET is the type of compiler you wish to install.
25 i386-pc-mingw32 [binary libraries]
26 ==================================
27         MinGW is a collection of freely available and freely distributable
28 Windows specific header files and import libraries combined with GNU toolsets
29 that allow one to produce native Windows programs that do not rely on any
30 3rd-party DLLs.
32 FILES:
33         binutils-2.14.tar.bz2           [ftp://ftp.gnu.org/gnu/binutils]
34         gcc-3.3.1.tar.bz2               [ftp://ftp.gnu.org/gnu/gcc]
35         mingw-runtime-3.0.tar.bz2       [http://www.sf.net/projects/mingw]
36         w32api-2.3.tar.bz2              [http://www.sf.net/projects/mingw]
38 ENV:
39         PREFIX=/opt/cross-compile_bin
40         TARGET=i386-pc-mingw32
41         export PATH=$PREFIX/bin:$PATH
43 LIBRARIES:
45         These must be installed into the correct directories, so we use tar's
46 -C option to specify the destination.  We also make sure that the directory
47 exists
49         mkdir -p $PREFIX/$TARGET
50         tar -xjf mingw-runtime-3.0.tar.bz2 -C $PREFIX/$TARGET
51         tar -xjf w32api-2.3.tar.bz2 -C $PREFIX/$TARGET
53 BINUTILS:
54         And now for binutils.  The only difference from the LFS instructions,
55 is the --target flag.
57         tar -xjf binutils-2.13.2.tar.bz2
58         mkdir binutils-build
59         cd binutils-build
60         ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
61         make
62         make install
64 GCC:
65         We then compile GCC last, so it uses the above libraries.  You may have
66 noticed the --enable-version-specific-runtime-libs, I have added that, so that
67 libraries are installed within their own seperate folder.
69         tar -xjf gcc-3.2.3.tar.bz2
70         mkdir gcc-build
71         cd gcc-build
72         ../gcc-3.2.3/configure --prefix=$PREFIX --target=$TARGET \
73           --enable-threads=win32 --enable-languages=c,c++ \
74           --enable-version-specific-runtime-libs
75         make
76         make install
78 END:
79         To use your new cross-compiler, put $PREFIX/bin first in your PATH.
80 (It will already be there if you set the variables as above.)
82         If you want to try it out, type in the following
84         echo 'main() { puts("Hello World"); }' > test.c
85         $TARGET-gcc test.c -o test.exe
87         Copy this to a windows machine (if avaliable), and run it.  (It
88 should print "Hello World" to the screen before exiting).
90 MinGW does not require any addition files to run on windows.
92 i386-pc-mingw32 [compiled libraries]
93 ====================================
94 FILES:
95         binutils-2.13.2.tar.bz2         [ftp://ftp.gnu.org/gnu/binutils]
96         gcc-3.2.3.tar.bz2               [ftp://ftp.gnu.org/gnu/gcc]
97         mingw-runtime-3.0-src.tar.bz2   [http://www.sf.net/projects/mingw]
98         w32api-2.3-src.tar.bz2          [http://www.sf.net/projects/mingw]
99   * Note that we use the source code of the 2 libraries this time
101 ENV:
102         PREFIX=/opt/cross-compile 
103         TARGET=i386-pc-mingw32
104         export PATH=$PREFIX/bin:$PATH
105   * We have changed the prefix to /opt/cross-compile, as to make a fresh install
106   * This path adds onto the previous path for the binary version, otherwise it
107     cannot find $TARGET-gcc.
109 LIBRARIES:
110         Since we now have a i386-pc-mingw32 toolchain, we can install the
111 libraries.  We move w32api-2.3 to w32api, because mingw-runtime searches for
112 header files in ../w32api/include.  [you can watch the packages as it compiles
113 to verify this].  We install to $PREFIX/$TARGET, as the libraries do not install
114 themselves to the $TARGET directory by default, and if we installed to /usr,
115 this would overwrite our default headers.  I also had to override the programs
116 that configure uses by default on mingw-runtime, for it does not appear to use
117 the --target flag.
119         tar -xjf mingw-runtime-3.0-src.tar.bz2
120         tar -xjf w32api-2.3-src.tar.bz2
121         mv w32api-2.3 w32api
122         mkdir mingw-build
123         cd mingw-build
124         ../mingw-runtime-3.0/configure --prefix=$PREFIX/$TARGET --target=$TARGET
125         make CC="i386-pc-mingw32-gcc" DLLTOOL="i386-pc-mingw32-dlltool" \
126             AS="i386-pc-mingw32-as" AR="i386-pc-mingw32-ar" \
127             LD="i386-pc-mingw32-ld" RANLIB="i386-pc-mingw32-ranlib"
128         make install
129         cd ..
130         mkdir w32api-build
131         cd w32api-build
132         ../w32api/configure --prefix=$PREFIX/$TARGET --host==$TARGET
133         make
134         make install
135         cd ..
137 BINUTILS:
138         Compile as above.
140 GCC:
141         Compile as above.
143 END:
144         The compiled version should work the same way as the binary way.
146 i386-pc-cygwin32 [binary libraries] (Untested)
147 ===================================
148         Cygwin is a Linux-like environment for Windows.
150 FILES:
151         binutils-2.13.2.tar.bz2         [ftp://ftp.gnu.org/gnu/binutils]
152         gcc-3.2.3.tar.bz2               [ftp://ftp.gnu.org/gnu/gcc]
153         cygwin-1.3.22-1.tar.bz2         [http://www.cygwin.com/mirrors.html]
154         w32api-2.3.tar.bz2              [http://www.sf.net/projects/mingw]
155   * I got w32api-2.3 from mingw, and just used it for cygwin.  seems to work... but I
156   beleive you can also download w32api from www.cygwin.com/mirrors.html
158 ENV:
159         PREFIX=/opt/cross-compile_bin
160         TARGET=i386-pc-cygwin32
161         export PATH=$PREFIX/bin:$PATH
163 LIBRARIES:
164         I am not completely familiar with where libraries files go,  but it
165 seems good enough to compile the next part.  [If anyone has any useful
166 information, please email conathan@conet.dyndns.org].
168 mkdir -p $PREFIX/$TARGET
169 mkdir tmp
170 tar -xjf cygwin-1.3.22-1.tar.bz2 -C tmp
171 cp -a tmp/usr/include/* $PREFIX/$TARGET/include
172 cp -a tmp/usr/lib/* $PREFIX/$TARGET/lib
173 tar -xjf w32api-2.3.tar.bz2 -C $PREFIX/$TARGET
175 BINUTILS:
176         tar -xjf binutils-2.13.2.tar.bz2
177         mkdir binutils-build
178         cd binutils-build
179         ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
180         make
181         make install
183 GCC:
184         When I checked gcc -v on cygwin, it was compiled with 
185 --enable-threads=posix, so I'll use it below.
187         tar -xjf gcc-3.2.3.tar.bz2
188         mkdir gcc-build
189         cd gcc-build
190         ../gcc-3.2.3/configure --prefix=$PREFIX --target=$TARGET \
191             --enable-threads=posix --enable-languages=c,c++ \
192             --enable-version-specific-runtime-libs
193         make
194         make install
196 END:
197         To use your new cross-compiler, put $PREFIX/bin first in your PATH.
198         (It will already be there if you set the variables as above.) In
199         addition, when building a package configured with autoconf, pass
200         --host=$TARGET to the configure script.
202         If you want to try it out, type in the following
204         echo 'main() { puts("Hello World"); }' > test.c
205         $TARGET-gcc test.c -o test.exe
207         Copy this to a windows machine (if avaliable), and run it.  (It
208 should print "Hello World" to the screen before exiting).  Please note that
209 you require the cygwin environment for windows, downloadable at www.cygwin.com.
210 The advantage of cygwin over mingw, is that most linux programs could probably
211 be easly compiled for cygwin, although requiring the cygwin.dll to run.
213 i386-pc-cygwin32 [compiled libraries] (Untested)
214 ==============================================
215 FILES:
216         binutils-2.13.2.tar.bz2         [ftp://ftp.gnu.org/gnu/binutils]
217         gcc-3.2.3.tar.bz2               [ftp://ftp.gnu.org/gnu/gcc]
218         cygwin-1.3.22-1-src.tar.bz2      [http://www.cygwin.com/mirrors.html]
219         w32api-2.3-src.tar.bz2           [http://www.sf.net/projects/mingw]
220   * again, I got w32api-2.3 from mingw, and just used it for cygwin.  seems to 
221     work...
222   * This path adds onto the previous path for the binary version, otherwise it
223     cannot find $TARGET-gcc.
225 ENV:
226         PREFIX=/opt/cross-compile
227         TARGET=i386-pc-cygwin32
228         export PATH=$PREFIX/bin:$PATH
230 LIBRARIES:
231         It appears that the cygwin libraries behave better then the mingw ones
232 do, and a simple --prefix=$PREFIX should install nicely.  It even uses
233 the correct programs to recompile itself.  w32api is automatically compiled
234 when you add it to the winsup directory, and the cygwin sources will
235 not compile without it, afaik.
237         tar -xjf cygwin-1.3.22-1-src.tar.bz2
238         tar -xzf w32api-2.3-src.tar.gz
239         mv w32api-2.3 cygwin-1.3.22-1/winsup/w32api
241         mkdir cygwin-build
242         cd cygwin-build
243         ../cygwin-1.3.22-1/configure --prefix=/usr --target=$TARGET
244         make
245         make install
246         cd ..
247         rm -rf cygwin-1.3.22-1 cygwin-build
249 BINUTILS:
250         The above instructions are sufficient.
252 GCC:
253         The above instructions are sufficient.
255 END:
256         The compiled version should work the same way as the binary way
258 i386-pc-msdosdjgpp [binary libraries]
259 ==================================
260 FILES:
261         binutils-2.13.2.tar.bz2         [ftp://ftp.gnu.org/gnu/binutils]
262         gcc-3.2.3.tar.bz2               [ftp://ftp.gnu.org/gnu/gcc]
263         gcc323s2.zip                    [http://www.delorie.com/pub/djgpp/current/v2gnu/]
264         djcrx203.zip                    [http://www.delorie.com/pub/djgpp/current/v2/]
265         autoconf-2.13.tar.bz            [ftp://ftp.gnu.org/gnu/autoconf]
266         automake-1.5.tar.bz2            [ftp://ftp.gnu.org/gnu/automake]
268 ENV:
269         PREFIX=/opt/cross-compile_bin
270         TARGET=i386-pc-msdosdjgpp
271         export PATH=$PREFIX/bin:$PATH
273 LIBRARIES:
274         We use the -a on unzip, so that it automatically formats the text files
275 for linux.  Compile stubify [used for GCC I believe], and then just copy over
276 the headers and libraries.
278         mkdir -p $PREFIX/$TARGET/{bin,include,lib}
279         mkdir tmp
280         cd tmp
281         unzip -a ../../lfs.packages/djcrx203.zip
282         cp -r include/* $PREFIX/$TARGET/include
283         cp -r lib/* $PREFIX/$TARGET/lib
284         cd src/stub
285         gcc stubify.c -o $PREFIX/$TARGET/bin/stubify
286         cd ../..
287         cd ..
288         rm -rf tmp
290 BINUTILS:
291         binutils does not appear to require any libraries to compile itself, so
292 we install it first.
294         tar -xjf binutils-2.13.2.tar.bz2
295         mkdir binutils-build
296         cd binutils-build
297         ../binutils-2.13.2/configure --prefix=$PREFIX --target=$TARGET
298         make
299         make install
301 GCC:
302         GCC is harder to build then the above targets, as we have to patch the
303 sources first.  On the http://www.delorie.com/djgpp site, you can find a 
304 gcc323s.zip file, but it does not store filepermissions and therefore it is
305 easier for us to patch.
307         We require older versions of autoconf and automake to patch gcc
308 properly, as indicated on the gcc's faq.  The instructions are provided below.
310         export PATH=$PREFIX/tmp/bin:$PATH
312         mkdir -p $PREFIX/tmp
313         tar -xjf /autoconf-2.13.tar.bz2
314         cd autoconf-2.13
315         ./configure --prefix=$PREFIX/tmp
316         make
317         make install
318         cd ..
319         rm -rf autoconf-2.13
320         tar -xjf ../lfs.packages/automake-1.5.tar.bz2
321         cd automake-1.5
322         ./configure --prefix=$PREFIX/tmp
323         make
324         make install
325         cd .. 
326         rm -rf automake-1.5 
328         Now, onto patching the gcc source.  Any errors
330         mkdir gcc
331         cd gcc
332         unzip -a ../../lfs.packages/gcc323s2.zip
333         chmod 755 unpack-gcc.sh
334         ./unpack-gcc.sh ../../lfs.packages/gcc-3.2.3.tar.gz
335         cd ..
337         This has unarchived and patched the source to gcc/gnu/gcc3.23,
338 and we can finally compile it
340         cd gcc/gnu
341         mkdir gcc-build
342         cd gcc-build
343         ../gcc-3.23/configure --prefix=$PREFIX --target=$TARGET \
344           --with-headers=$PREFIX/$TARGET/include --enable-languages=c,c++ \
345           --enable-version-specific-runtime-libs
346         make
347         make install
348         cd ../../..
349         rm -rf gcc
351         We do not require the autotools anymore, so...
353         rm -rf $PREFIX/tmp
355 END:
356         To use your new cross-compiler, put $PREFIX/bin first in your PATH.
357 (It will already be there if you set the variables as above.) In addition,
358 when building a package configured with autoconf, pass --host=$TARGET to the
359 configure script.
361 TODO
362 ====
363 i386-pc-cygwin32:
364         -Test Compiled Binaries, and determine requiraments to run
365 i386-pc-msdosdjgpp: (Test, Find a way to compmile the libraries [hard])
366         -Test Instructions
367         -Figure out how to actually run the compiled programs [listed on
368 djgpp's howto page at www.delorie.com/djgpp]
369         -Compile the libraries [looks like extracting djlsr203.zip, then
370 extract djcrx203.zip into it]
371         -check --enable-threads value
374 gcc, I noticed like to stick C++ libraries under the /include directory.  I
375 dont know if that is good or not, so I used
376 --enable-version-specific-runtime-libs to counteract this.  (It was probably
377 a typo, and was my fault though.  I'll double check someday).