Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
diana:windows:building:environment [2009-11-12 12:45:50] dages glib and pkg-config |
diana:windows:building:environment [2022-05-31 09:29:31] (current) |
====== Setting up the build environment on Windows ====== | ====== Setting up the build environment on Windows ====== |
| |
Assuming Windows XP 32. | Assuming Windows XP 32. We will use MinGW to build the libraries and application and MSYS as a working environment. |
| |
| The distinction between MinGW and MSYS is very important: MinGW is a set of compilers and libraries you use to build Windows applications, while MSYS is an emulated GNU environment similar to (and, in fact, based on) Cygwin. You can //not// use MSYS libraries in your Windows application. This means that you will sometimes have two copies of a particular library: an MSYS version used by MSYS tools, and a native version built with MinGW and used by MinGW tools and / or your application. |
| |
| ===== Directories ===== |
| |
| We will install MinGW into ''C:\MinGW'' and MSYS into ''C:\MSYS''. |
| |
| MSYS maps Unix-like paths to Windows paths: ''/'' translates to ''C:\MSYS'' and ''/mingw'' translates to ''C:\MinGW''. In addition, all Windows drives will show up as ''/x'', where ''x'' corresponds to the drive letter, so ''/c/windows'' translates to ''C:\windows'', etc. |
| |
| We will install our libraries and applications into ''C:\met.no''. You should start by creating that directory and the required subdirectories: |
| |
| C:\> mkdir met.no |
| C:\> mkdir met.no\bin |
| C:\> mkdir met.no\include |
| C:\> mkdir met.no\lib |
| C:\> mkdir met.no\share |
| C:\> mkdir met.no\copyright |
| |
===== Subversion ===== | ===== Subversion ===== |
Doesn't really matter which one. Certified binaries of The Real McCoy are available at http://www.collab.net/downloads/subversion/ (command-line only) if you have an account (or are willing to register). There are other (non-certified) sources such as SlikSVN (http://www.sliksvn.com/en/download, command-line only) and TortoiseSVN (http://tortoisesvn.net/downloads, with Windows Explorer integration, which is really neat). | Doesn't really matter which one. Certified binaries of The Real McCoy are available at http://www.collab.net/downloads/subversion/ (command-line only) if you have an account (or are willing to register). There are other (non-certified) sources such as SlikSVN (http://www.sliksvn.com/en/download, command-line only) and TortoiseSVN (http://tortoisesvn.net/downloads, with Windows Explorer integration, which is really neat). |
| |
===== MSYS ===== | ===== MinGW ===== |
| |
Download the MSYS Base System installer from http://downloads.sourceforge.net/project/mingw/MSYS%20Base%20System/msys-1.0.11/MSYS-1.0.11.exe and run it. If it asks, tell it you don't have MinGW installed. | Download and the latest automated installer from http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/ and run it. Ask for the //current// version (not //previous// or //candidate//). Select these components //and these components only//: base tools, g++ compiler, g77 compiler. |
| |
Now that MSYS is installed, you can start the "MSYS (rxvt)" shortcut it installed, and it'll be almost like you were home on the Unix farm. | As of 2009-11-20, the current MinGW version is 5.1.6, which includes GCC 3.4.5. |
| |
===== MinGW ===== | //tip: move the installer into an empty directory before starting it; it will download all the MinGW distribution files into that directory.// |
| |
As of November 2009, the automated installer is useless; it installs gcc 3 instead of 4. You'll have to install MinGW manually using MSYS. | At this point, you may want to download bsdtar from http://sourceforge.net/projects/mingw/files/MinGW%20Utilities/basic%20bsdtar/bsdtar-2.7.900a_r1628-20091110/ and install ''bsdtar.exe'' as ''/mingw/bin/tar''. It supports a wider range of archive formats and compression algorithms than GNU tar, and automatically detects which one to use. |
| |
The following command will create and mount a directory for MinGW: | You may want to install InfoZip's ''zip'' utility as well, since ''bsdtar'' can //extract// zip files but not //create// them: download the source code from http://sourceforge.net/projects/infozip/files/, extract it, and run the following commands in the source directory: |
| |
mount C:/MinGW /mingw | $ make -f win32/makefile.gcc |
| $ cp zip.exe /mingw/bin |
| |
Next, download the packages you will need. | ===== MSYS ===== |
| |
| Download the MSYS installer from |
| http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/ and run it (you will need administrator privileges). Accept the default answer to all questions. |
| |
* GCC: http://downloads.sourceforge.net/project/mingw/GCC%20Version%204/Current%20Release_%20gcc-4.4.0/gcc-full-4.4.0-mingw32-bin-2.tar.lzma | As of 2009-11-20, the latest MSYS version is 1.0.11. |
* BinUtils: http://downloads.sourceforge.net/project/mingw/GNU%20Binutils/binutils-2.20/binutils-2.20-1-mingw32-bin.tar.gz | |
* MinGW API: http://downloads.sourceforge.net/project/mingw/MinGW%20API%20for%20MS-Windows/Current%20Release_%20w32api-3.13/w32api-3.13-mingw32-dev.tar.gz | |
* MinGW Runtime: http://downloads.sourceforge.net/project/mingw/MinGW%20Runtime/mingwrt-3.16/mingwrt-3.16-mingw32-dev.tar.gz and http://downloads.sourceforge.net/project/mingw/MinGW%20Runtime/mingwrt-3.16/mingwrt-3.16-mingw32-dll.tar.gz | |
| |
Then extract everything: | ===== Testing the toolchain ===== |
| |
$ for f in *tar.gz ; do tar zxvf $f -C /mingw ; done | |
$ for f in *tar.lzma ; do tar --lzma -xvf $f -C /mingw ; done | |
| |
Let's see if our C compiler works: | Let's see if our C compiler works: |
$ which gcc | $ which gcc |
/mingw/bin/gcc.exe | /mingw/bin/gcc.exe |
| $ gcc --version |
| gcc.exe (GCC) 3.4.5 (mingw-vista special r3) |
| Copyright (C) 2004 Free Software Foundation, Inc. |
| This is free software; see the source for copying conditions. There is NO |
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
$ cat >hello.c | $ cat >hello.c |
#include <stdio.h> | #include <stdio.h> |
$ which g++ | $ which g++ |
/mingw/bin/g++.exe | /mingw/bin/g++.exe |
| $ g++ --version |
| g++.exe (GCC) 3.4.5 (mingw-vista special r3) |
| Copyright (C) 2004 Free Software Foundation, Inc. |
| This is free software; see the source for copying conditions. There is NO |
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
$ cat >hello.cc | $ cat >hello.cc |
#include <iostream> | #include <iostream> |
Hello, C++ world! | Hello, C++ world! |
| |
And Fortran 90: | And Fortran 77: |
| |
$ which gfortran | $ which g77 |
/mingw/bin/gfortran.exe | /mingw/bin/g77.exe |
$ cat >hello.f90 | $ g77 --version |
PROGRAM HelloWorld | GNU Fortran (GCC) 3.4.5 (mingw-vista special r3) |
PRINT *, "Hello, Fortran world!" | Copyright (C) 2004 Free Software Foundation, Inc. |
END PROGRAM HelloWorld | |
| GNU Fortran comes with NO WARRANTY, to the extent permitted by law. |
| You may redistribute copies of GNU Fortran |
| under the terms of the GNU General Public License. |
| For more information about these matters, see the file named COPYING |
| or type the command `info -f g77 Copying'. |
| $ cat >hello.f |
| PROGRAM HELLOW |
| WRITE(UNIT=*, FMT=*) 'Hello, Fortran world!' |
| END |
^D | ^D |
$ gfortran -o hello hello.f90 | $ g77 -o hello hello.f |
$ ./hello.exe | $ ./hello.exe |
Hello, Fortran world! | Hello, Fortran world! |
| |
===== Perl ===== | ===== lex & yacc ===== |
| |
The GNU Autotools, which we will install next, require Perl. Download http://downloads.sourceforge.net/project/mingw/MSYS%20perl/perl-5.6.1_2-1/perl-5.6.1_2-1-msys-1.0.11-bin.tar.lzma and install it: | |
| |
$ tar --lzma -xvf perl-5.6.1_2-1-msys-1.0.11-bin.tar.lzma -C / | |
| |
===== GNU Autotools ===== | |
| |
==== Download ==== | |
| |
=== Autoconf === | |
| |
http://downloads.sourceforge.net/project/mingw/MinGW%20autoconf/autoconf2.5/autoconf2.5-2.64-1/autoconf2.5-2.64-1-mingw32-bin.tar.lzma | |
and | |
http://downloads.sourceforge.net/project/mingw/MinGW%20autoconf/wrapper/autoconf-7-1/autoconf-7-1-mingw32-bin.tar.lzma | |
| |
=== Automake === | |
| |
http://downloads.sourceforge.net/project/mingw/MinGW%20automake/automake1.11/automake1.11-1.11-1/automake1.11-1.11-1-mingw32-bin.tar.lzma | |
and | |
http://downloads.sourceforge.net/project/mingw/MinGW%20automake/wrapper/automake-4-1/automake-4-1-mingw32-bin.tar.lzma | |
| |
=== Libtool === | |
| |
http://downloads.sourceforge.net/project/mingw/MinGW%20libtool/libtool-2.2.7a-1/libtool-2.2.7a-1-mingw32-bin.tar.lzma | |
| |
You do //not// need any of the ''libltdl'' tarballs. | |
| |
==== Install ==== | |
| |
$ for f in *tar.gz ; do tar zxvf $f -C /mingw ; done | |
$ for f in *tar.lzma ; do tar --lzma -xvf $f -C /mingw ; done | |
| |
===== pkg-config ===== | |
| |
There are no MinGW or MSYS binaries for pkg-config, and building it from source is non-trivial due to a circular dependency on glib (you need pkg-config to build glib). However, the Gnome project distribute Windows binaries of both glib and pkg-config, which you can download from http://www.gtk.org/download-windows.html. They come in zip files, so you can just double-click them in Windows Explorer and copy the contents to your MSYS root (''C:\MSYS''). | |
| |
===== Boost jam ===== | |
| |
This utility is used to [[boost|compile the Boost libraries]]. We're going to build it from source, so this is our baptism of MinGW fire... | |
| |
Get the source tarball from http://downloads.sourceforge.net/project/boost/boost-jam/3.1.17/boost-jam-3.1.17.tgz; once you have it, it's a simple matter of running the build script (which will automatically detect MinGW) and installing the resulting executable: | |
| |
$ tar zxf boost-jam-3.1.17.tgz | Or rather, in our brave GNU world, flex and bison. There is a problem here: you can't use the MSYS versions, because they're not just build tools—bison includes a runtime library (''liby''). Hence we need native versions of both tools. We can get those from [[http://sourceforge.net/projects/gnuwin32|GnuWin32]]. |
$ cd boost-jam-3.1.17 | |
$ sh ./build.sh | |
$ mkdir -p /usr/local/bin | |
$ cp bin.ntx86/bjam.exe /usr/local/bin | |
$ which bjam | |
/usr/local/bin/bjam.exe | |
$ bjam -v | |
Boost.Jam Version 3.1.17. OS=NT. | |
Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. | |
Copyright 2001 David Turner. | |
Copyright 2001-2004 David Abrahams. | |
Copyright 2002-2008 Rene Rivera. | |
Copyright 2003-2008 Vladimir Prus. | |
| |
It's alive! | Download the following files from http://sourceforge.net/projects/gnuwin32/files/: |
| |
===== Additional Unix utilities ===== | * the ''bin'', ''lib'' and ''dep'' zipfiles for the latest bison release (the ''dep'' zipfile contains a few libraries that bison needs, so you won't have to install them separately) |
| * the ''bin'' and ''lib'' zipfiles for the latest flex release |
| |
You may want to install other programs, such as: | For some unfathomable reason, both the flex and bison ''lib'' zipfiles contain incorrect copies of ''<unistd.h>''. Either make a backup copy of ''/MinGW/include/unistd.h'' before you unpack them, or tell ''unzip'' (or ''bsdtar'') not to overwrite existing files: |
| |
* OpenSSL (http://downloads.sourceforge.net/project/mingw/MSYS%20openssl/openssl-0.9.8k-1/libopenssl-0.9.8k-1-msys-1.0.11-dll-098.tar.lzma and http://downloads.sourceforge.net/project/mingw/MSYS%20openssl/openssl-0.9.8k-1/openssl-0.9.8k-1-msys-1.0.11-bin.tar.lzma) | $ tar -kxf bison-2.4.1-lib.zip -C /MinGW |
* libbz2 (http://downloads.sourceforge.net/project/mingw/MinGW%20bzip2/release%201.0.5-2/libbz2-1.0.5-2-mingw32-dll-2.tar.gz) and bzip2 (http://downloads.sourceforge.net/project/mingw/MinGW%20bzip2/release%201.0.5-2/bzip2-1.0.5-2-mingw32-bin.tar.gz) | |
* libz (http://downloads.sourceforge.net/project/mingw/MinGW%20zlib/zlib-1.2.3-1-mingw32/libz-1.2.3-1-mingw32-dll-1.tar.gz and http://downloads.sourceforge.net/project/mingw/MSYS%20zlib/zlib-1.2.3-1/zlib-1.2.3-1-msys-1.0.11-dll.tar.gz) and gzip (http://downloads.sourceforge.net/project/mingw/MSYS%20gzip/gzip-1.3.12-1/gzip-1.3.12-1-msys-1.0.11-bin.tar.lzma) | |
* liblzma (http://downloads.sourceforge.net/project/mingw/MSYS%20xz/xz-4.999.9beta-1/liblzma-4.999.9beta-1-msys-1.0.11-dll-1.tar.gz) and xz (http://downloads.sourceforge.net/project/mingw/MSYS%20xz/xz-4.999.9beta-1/xz-4.999.9beta-1-msys-1.0.11-bin.tar.gz) | |
* libarchive (http://downloads.sourceforge.net/project/mingw/MSYS%20libarchive/libarchive-2.7.1-1/libarchive-2.7.1-1-msys-1.0.11-dll-2.tar.lzma) and bsdtar (http://downloads.sourceforge.net/project/mingw/MSYS%20libarchive/libarchive-2.7.1-1/bsdtar-2.7.1-1-msys-1.0.11-bin.tar.lzma) | |
* vim (http://downloads.sourceforge.net/project/mingw/MSYS%20vim/vim-7.2-1/vim-7.2-1-msys-1.0.11-bin.tar.lzma) | |
* GNU coreutils (http://downloads.sourceforge.net/project/mingw/MSYS%20coreutils/coreutils-5.97-2/coreutils-5.97-2-msys-1.0.11-bin.tar.lzma and http://downloads.sourceforge.net/project/mingw/MSYS%20coreutils/coreutils-5.97-2/coreutils-5.97-2-msys-1.0.11-ext.tar.lzma) | |
* minires (http://downloads.sourceforge.net/project/mingw/MSYS%20minires/minires-1.02_1-1/libminires-1.02_1-1-msys-1.0.11-dll.tar.lzma and http://downloads.sourceforge.net/project/mingw/MSYS%20minires/minires-1.02_1-1/minires-1.02_1-1-msys-1.0.11-bin.tar.lzma) | |
* OpenSSH (http://downloads.sourceforge.net/project/mingw/MSYS%20openssh/openssh-4.7p1-2/openssh-4.7p1-2-msys-1.0.11-bin.tar.lzma) | |
Note that you should install ''*-mingw32-*'' in ''/mingw'' and ''*-msys-*'' in ''/'': | |
| |
$ for f in *-mingw32-*tar.lzma ; do tar --lzma -xvf $f -C /mingw ; done | This will install a shell script called ''/MinGW/bin/yacc'' which incorrectly redirects to ''c:/progra~1/bison/bin/bison''. Edit it so the entire script looks like this: |
$ for f in *-msys-*tar.lzma ; do tar --lzma -xvf $f -C / ; done | |
| |
Some tarballs are compressed with ''xz'' (''*.lzma''), some with ''bzip2'' (''*.bz2''), some with ''gzip'' (''*.gz''). Take care to use the correct tar options (''--lzma'', ''--bzip2'' or ''--gzip'') according to file type. However, once you've installed OpenSSL, all the compression libraries, libarchive and bsdtar, you can use bsdtar instead of GNU tar; bsdtar automatically detects the file type, so regardless of compression algorithm, you can just use ''bsdtar xvf <tarball> -C <destdir>''. | #! /bin/sh |
| exec /mingw/bin/bison -y "$@" |
| |
===== WiX ===== | ===== WiX ===== |