Difference between revisions of "Cross-compilation for windows with mingw"
(update to current versions) |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | = Introduction = | ||
+ | |||
If you know how to compile everything on Linux, there's not much new to learn. | If you know how to compile everything on Linux, there's not much new to learn. | ||
Line 10: | Line 12: | ||
− | + | = Compilation step-by-step = | |
− | Arch | + | == Installing mingw32 == |
+ | |||
+ | === Arch === | ||
pacman -S mingw32-{binutils,gcc,runtime,w32api} | pacman -S mingw32-{binutils,gcc,runtime,w32api} | ||
− | Debian/Ubuntu | + | === Debian/Ubuntu === |
aptitude install mingw32{,-binutils,-runtime} | aptitude install mingw32{,-binutils,-runtime} | ||
+ | |||
+ | == Setting environment variables == | ||
The value for TARGET depends on mingw32, it's i486-mingw32 for arch and i586-mingw32msvc for Debian. | The value for TARGET depends on mingw32, it's i486-mingw32 for arch and i586-mingw32msvc for Debian. | ||
Line 26: | Line 32: | ||
export BUILDDIR=$HOME/mingw32 | export BUILDDIR=$HOME/mingw32 | ||
− | Prepare build directory | + | == Prepare build directory == |
mkdir -p $BUILDDIR | mkdir -p $BUILDDIR | ||
mkdir -p $BUILDDIR/tmp | mkdir -p $BUILDDIR/tmp | ||
− | Build zlib | + | == Build zlib == |
cd $BUILDDIR | cd $BUILDDIR | ||
− | wget http://www.zlib.net/zlib-1.2. | + | wget http://www.zlib.net/zlib-1.2.5.tar.gz |
− | tar xzf zlib-1.2. | + | tar xzf zlib-1.2.5.tar.gz |
− | cd zlib-1.2. | + | cd zlib-1.2.5 |
− | CC=$TARGET-gcc AR="$TARGET-ar | + | CC=$TARGET-gcc AR="$TARGET-ar" RANLIB=$TARGET-ranlib ./configure --prefix=$BUILDDIR/tmp --static |
make install | make install | ||
− | + | You have to remove the line 'cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)' from the Makefile before running make install though. | |
+ | |||
+ | == Build libiconv == | ||
cd $BUILDDIR | cd $BUILDDIR | ||
Line 49: | Line 57: | ||
make install | make install | ||
− | Build gettext (patch | + | == Build gettext == |
+ | (patch necessary) | ||
cd $BUILDDIR | cd $BUILDDIR | ||
Line 62: | Line 71: | ||
make install | make install | ||
− | Build wxwidgets | + | == Build wxwidgets == |
cd $BUILDDIR | cd $BUILDDIR | ||
− | wget http://prdownloads.sourceforge.net/wxwindows/wxWidgets-2.8. | + | wget http://prdownloads.sourceforge.net/wxwindows/wxWidgets-2.8.11.tar.bz2 |
− | tar xjf wxWidgets-2.8. | + | tar xjf wxWidgets-2.8.11.tar.bz2 |
− | cd wxWidgets-2.8. | + | cd wxWidgets-2.8.11 |
./configure --host=$TARGET --prefix=$BUILDDIR/tmp --with-libiconv-prefix=$BUILDDIR/tmp --enable-unicode --disable-shared | ./configure --host=$TARGET --prefix=$BUILDDIR/tmp --with-libiconv-prefix=$BUILDDIR/tmp --enable-unicode --disable-shared | ||
make install | make install | ||
− | Build cryptopp | + | == Build cryptopp == |
+ | quite some patching necessary | ||
cd $BUILDDIR | cd $BUILDDIR | ||
− | wget http://cryptopp.com/ | + | wget http://cryptopp.com/cryptopp561.zip |
mkdir cryptopp | mkdir cryptopp | ||
cd cryptopp | cd cryptopp | ||
− | unzip -a ../ | + | unzip -a ../cryptopp561.zip |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
echo "69d68 | echo "69d68 | ||
< LDFLAGS += -pthread" | patch GNUmakefile | < LDFLAGS += -pthread" | patch GNUmakefile | ||
Line 91: | Line 97: | ||
PREFIX=$BUILDDIR/tmp make -f GNUmakefile install | PREFIX=$BUILDDIR/tmp make -f GNUmakefile install | ||
− | + | It complains about missing .so files. No problem. | |
+ | |||
+ | == aMule == | ||
cd $BUILDDIR | cd $BUILDDIR | ||
− | wget http://prdownloads.sourceforge.net/amule/aMule-2.2. | + | wget http://prdownloads.sourceforge.net/amule/aMule-2.2.6.tar.bz2 |
− | tar xjf aMule-2.2. | + | tar xjf aMule-2.2.6.tar.bz2 |
− | cd aMule-2.2. | + | cd aMule-2.2.6 |
./configure --host=$TARGET --with-zlib=$BUILDDIR/tmp --with-wx-prefix=$BUILDDIR/tmp --with-wx-config=$BUILDDIR/tmp/bin/wx-config --with-crypto-prefix=$BUILDDIR/tmp --prefix=$BUILDDIR/tmp | ./configure --host=$TARGET --with-zlib=$BUILDDIR/tmp --with-wx-prefix=$BUILDDIR/tmp --with-wx-config=$BUILDDIR/tmp/bin/wx-config --with-crypto-prefix=$BUILDDIR/tmp --prefix=$BUILDDIR/tmp | ||
make install | make install | ||
− | Copying everything together | + | == Copying everything together == |
cd $BUILDDIR | cd $BUILDDIR | ||
Line 108: | Line 116: | ||
cp $BUILDDIR/tmp/bin/amule.exe $BUILDDIR/pkg | cp $BUILDDIR/tmp/bin/amule.exe $BUILDDIR/pkg | ||
− | Testing | + | == Testing == |
cd $BUILDDIR/pkg | cd $BUILDDIR/pkg | ||
wine amule | wine amule | ||
− | Stripping binaries | + | == Stripping binaries == |
It significantly reduces the binary sizes, but you will loose debug information! So don't do it if you need to send crash reports to the aMule developers. | It significantly reduces the binary sizes, but you will loose debug information! So don't do it if you need to send crash reports to the aMule developers. | ||
− | + | You need the cross-compile strip tool (for instance i686-mingw32-strip instead of strip). | |
− | + | ||
− | + | ||
cd $BUILDDIR/pkg | cd $BUILDDIR/pkg | ||
− | + | $TARGET-strip amule |
Latest revision as of 00:08, 28 December 2010
Contents
Introduction
If you know how to compile everything on Linux, there's not much new to learn.
Two things are important:
- use the cross-compile toolchain (i.e. i486-mingw32-gcc instead of gcc and i486-mingw32-ranlib instead of ranlib)
- use the headers and libraries for the target system
If something goes wrong, you can expect one of these two points to be the culprit. Wrong/different headers or additional libraries (like ws2_32 for sockets) are another major source of trouble.
Most software using autotools will compile using ./configure --host=i486-mingw32; other software may require further changes.
Compilation step-by-step
Installing mingw32
Arch
pacman -S mingw32-{binutils,gcc,runtime,w32api}
Debian/Ubuntu
aptitude install mingw32{,-binutils,-runtime}
Setting environment variables
The value for TARGET depends on mingw32, it's i486-mingw32 for arch and i586-mingw32msvc for Debian.
export TARGET=i486-mingw32 #export TARGET=i586-mingw32msvc
Set a directory for building aMule. These two export commands have to be once in every terminal used to execute other command blocks shown here.
export BUILDDIR=$HOME/mingw32
Prepare build directory
mkdir -p $BUILDDIR mkdir -p $BUILDDIR/tmp
Build zlib
cd $BUILDDIR wget http://www.zlib.net/zlib-1.2.5.tar.gz tar xzf zlib-1.2.5.tar.gz cd zlib-1.2.5 CC=$TARGET-gcc AR="$TARGET-ar" RANLIB=$TARGET-ranlib ./configure --prefix=$BUILDDIR/tmp --static make install
You have to remove the line 'cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)' from the Makefile before running make install though.
Build libiconv
cd $BUILDDIR wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz tar xzf libiconv-1.13.tar.gz cd libiconv-1.13 ./configure --host=$TARGET --prefix=$BUILDDIR/tmp make install
Build gettext
(patch necessary)
cd $BUILDDIR wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.17.tar.gz tar xzf gettext-0.17.tar.gz cd gettext-0.17 echo "29,30d28 < VARIABLE(rpl_optarg) < VARIABLE(rpl_optind) " | patch gettext-tools/woe32dll/gettextlib-exports.c ./configure --host=$TARGET --prefix=$BUILDDIR/tmp --with-libiconv-prefix=$BUILDDIR/tmp make install
Build wxwidgets
cd $BUILDDIR wget http://prdownloads.sourceforge.net/wxwindows/wxWidgets-2.8.11.tar.bz2 tar xjf wxWidgets-2.8.11.tar.bz2 cd wxWidgets-2.8.11 ./configure --host=$TARGET --prefix=$BUILDDIR/tmp --with-libiconv-prefix=$BUILDDIR/tmp --enable-unicode --disable-shared make install
Build cryptopp
quite some patching necessary
cd $BUILDDIR wget http://cryptopp.com/cryptopp561.zip mkdir cryptopp cd cryptopp unzip -a ../cryptopp561.zip echo "69d68 < LDFLAGS += -pthread" | patch GNUmakefile echo "9c9 < RANLIB = ranlib --- > RANLIB = $TARGET-ranlib" | patch GNUmakefile CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make -f GNUmakefile PREFIX=$BUILDDIR/tmp make -f GNUmakefile install
It complains about missing .so files. No problem.
aMule
cd $BUILDDIR wget http://prdownloads.sourceforge.net/amule/aMule-2.2.6.tar.bz2 tar xjf aMule-2.2.6.tar.bz2 cd aMule-2.2.6 ./configure --host=$TARGET --with-zlib=$BUILDDIR/tmp --with-wx-prefix=$BUILDDIR/tmp --with-wx-config=$BUILDDIR/tmp/bin/wx-config --with-crypto-prefix=$BUILDDIR/tmp --prefix=$BUILDDIR/tmp make install
Copying everything together
cd $BUILDDIR mkdir pkg cp /usr/$TARGET/bin/mingwm10.dll $BUILDDIR/pkg cp $BUILDDIR/tmp/lib/*.dll $BUILDDIR/pkg cp $BUILDDIR/tmp/bin/amule.exe $BUILDDIR/pkg
Testing
cd $BUILDDIR/pkg wine amule
Stripping binaries
It significantly reduces the binary sizes, but you will loose debug information! So don't do it if you need to send crash reports to the aMule developers.
You need the cross-compile strip tool (for instance i686-mingw32-strip instead of strip).
cd $BUILDDIR/pkg $TARGET-strip amule