用Mingw-w64交叉编译aMule for Windows

hamster 2021-04-30 PM 326℃ 0条

aMule是知名的ED2K客户端eMule的跨平台版本,号称支持所有主流操作系统,比如Linux、MacOS以及BSD等,当然也包括Windows。不过aMule官方并没有为最近几个版本的aMule版本提供Window平台的可执行程序,想要使用aMule for Windows只有手动编译,其中可以使用的编译器包括MSVC和Mingw-w64。因为自己对Linux开发环境更熟悉,所以选择在Debian上安装Mingw-w64,通过交叉编译的方式生成aMule for Windows。

准备工作

使用apt安装基本开发工具

sudo apt install g++ autoconf automake make patch unzip autopoint gettext libtool flex bison p7zip-full git wget

此外,还需要安装Mingw-w64交叉编译工具链。因为这里我们希望编译32位的aMule,所以需要安装32位Mingw-w64 GCC

sudo apt install g++-mingw-w64-i686

为了方便,设置环境变量

export BUILDDIR=$HOME/amule-build
export TARGET=i686-w64-mingw32

其中BUILDDIR为工作目录,TARGET表示生成代码的目标平台。创建目录

mkdir -p $BUILDDIR
mkdir -p $BUILDDIR/tmp
mkdir -p $BUILDDIR/pkg

这里$BUILDDIR/tmp将作为第三方依赖库的安装位置,$BUILDDIR/pkg将作为aMule的安装位置。

编译zlib

下载、解压并编译

cd $BUILDDIR
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -xf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
CC=$TARGET-gcc AR="$TARGET-ar" RANLIB=$TARGET-ranlib ./configure --prefix=$BUILDDIR/tmp/zlib --static
make install

编译Crypto++

下载并解压

cd $BUILDDIR
wget http://cryptopp.com/cryptopp610.zip
mkdir cryptopp
cd cryptopp
7z x ../cryptopp610.zip

给Makefile打补丁

wget https://downloads.freehamster.org/cryptopp.patch
patch -p0 <  cryptopp.patch

编译并安装静态库

CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make static -f GNUmakefile
PREFIX=$BUILDDIR/tmp/cryptopp make -f GNUmakefile install

编译libiconv

下载、解压并编译

cd $BUILDDIR
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar -xf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --host=$TARGET --prefix=$BUILDDIR/tmp/libiconv --enable-static=yes --enable-shared=no
make install

编译gettext

下载、解压并编译

cd $BUILDDIR
wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.3.2.tar.gz
tar -xf gettext-0.18.3.2.tar.gz
cd gettext-0.18.3.2
./configure --host=$TARGET --prefix=$BUILDDIR/tmp/gettext --with-libiconv-prefix=$BUILDDIR/tmp/libiconv --enable-shared=no --enable-static=yes --enable-threads=posix
make install

编译wxwidgets

对于wxWidgets-2.8.12

cd $BUILDDIR
wget http://prdownloads.sourceforge.net/wxwindows/wxWidgets-2.8.12.tar.bz2
tar -xf wxWidgets-2.8.12.tar.bz2
cd wxWidgets-2.8.12
./configure CPPFLAGS="-I$BUILDDIR/tmp/zlib/include" LDFLAGS="-L$BUILDDIR/tmp/zlib/lib"  --host=$TARGET --prefix=$BUILDDIR/tmp/wxwidgets --with-zlib=sys --with-msw --with-libiconv-prefix=$BUILDDIR/tmp/libiconv --disable-shared --disable-debug_flag --enable-unicode
make install

对于wxWidgets-3.0.5

cd $BUILDDIR
wget https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.5/wxWidgets-3.0.5.tar.bz2
tar -xf wxWidgets-3.0.5.tar.bz2
cd wxWidgets-3.0.5
./configure CPPFLAGS="-I$BUILDDIR/tmp/zlib/include" LDFLAGS="-L$BUILDDIR/tmp/zlib/lib"  --host=$TARGET --prefix=$BUILDDIR/tmp/wxwidgets --with-zlib=sys --with-msw --with-libiconv-prefix=$BUILDDIR/tmp/libiconv --disable-shared --disable-debug_flag
make install

编译geoip

拉取代码并编译安装

cd $BUILDDIR
git clone https://github.com/maxmind/geoip-api-c.git
cd geoip-api-c
./bootstrap
./configure --host=$TARGET --prefix=$BUILDDIR/tmp/geoip --enable-shared=no
make install

编译libpng

下载、解压并安装

cd $BUILDDIR
wget https://download.sourceforge.net/libpng/libpng-1.6.37.tar.xz
tar -xf libpng-1.6.37.tar.xz
cd libpng-1.6.37
./configure CPPFLAGS="-I$BUILDDIR/tmp/zlib/include" CFLAGS="-I$BUILDDIR/tmp/zlib/include" LDFLAGS="-L$BUILDDIR/tmp/zlib/lib" --host=$TARGET --prefix=$BUILDDIR/tmp/libpng --with-zlib-prefix=$BUILDDIR/tmp/zlib --enable-shared=no 
make install

为了避免后面编译aMule时出现链接错误,需要修改libpng-config

sed -i 's/libs="-lpng16"/libs="-lpng16 -lz"/g'  $BUILDDIR/tmp/libpng/bin/libpng-config

编译aMule

下载并解压

cd $BUILDDIR
wget http://prdownloads.sourceforge.net/amule/aMule-2.3.3.tar.xz
tar -xf aMule-2.3.3.tar.xz
cd aMule-2.3.3

配置编译选项

./configure CPPFLAGS="-I$BUILDDIR/tmp/zlib/include -I$BUILDDIR/tmp/libpng/include" LDFLAGS="-L$BUILDDIR/tmp/zlib/lib -L$BUILDDIR/tmp/libpng/lib"  --prefix=$BUILDDIR/pkg --host=$TARGET --enable-amule-daemon --enable-webserver --enable-amulecmd --enable-amule-gui --enable-cas --enable-wxcas --enable-alc --enable-alcc --enable-fileview --enable-static --enable-geoip --disable-debug --enable-optimize --enable-mmap --with-zlib=$BUILDDIR/tmp/zlib  --with-wx-prefix=$BUILDDIR/tmp/wxwidgets --with-wx-config=$BUILDDIR/tmp/wxwidgets/bin/wx-config --with-crypto-prefix=$BUILDDIR/tmp/cryptopp --with-libintl-prefix=$BUILDDIR/tmp/gettext --with-libiconv-prefix=$BUILDDIR/tmp/libiconv --with-geoip-static -with-geoip-lib=$BUILDDIR/tmp/geoip/lib --with-geoip-headers=$BUILDDIR/tmp/geoip/include  --with-libpng-prefix=$BUILDDIR/tmp/libpng --with-libpng-config=$BUILDDIR/tmp/libpng/bin/libpng-config

编译安装

make install

编译得到的可执行文件位于路径$BUILDDIR/pkg/bin下。我们发现可执行文件的体积较大

-rwxr-xr-x 1 cat cat 3.8M 5月 24 22:51 alcc.exe
-rwxr-xr-x 1 cat cat 8.4M 5月 24 22:51 alc.exe
-rwxr-xr-x 1 cat cat 4.4M 5月 24 22:52 amulecmd.exe
-rwxr-xr-x 1 cat cat 28M 5月 24 22:52 amuled.exe
-rwxr-xr-x 1 cat cat 36M 5月 24 22:52 amule.exe
-rwxr-xr-x 1 cat cat 14M 5月 24 22:52 amulegui.exe
-rwxr-xr-x 1 cat cat 6.5M 5月 24 22:52 amuleweb.exe
-rwxr-xr-x 1 cat cat 79K 5月 24 22:51 cas.exe
-rwxr-xr-x 1 cat cat 1.8M 5月 24 22:52 ed2k.exe
-rwxr-xr-x 1 cat cat 8.9M 5月 24 22:51 wxcas.exe

strip缩减体积

$TARGET-strip $BUILDDIR/pkg/bin/*

体积缩减效果明显

-rwxr-xr-x 1 cat cat 2.4M 5月 24 22:59 alcc.exe
-rwxr-xr-x 1 cat cat 5.8M 5月 24 22:59 alc.exe
-rwxr-xr-x 1 cat cat 2.9M 5月 24 22:59 amulecmd.exe
-rwxr-xr-x 1 cat cat 6.1M 5月 24 22:59 amuled.exe
-rwxr-xr-x 1 cat cat 13M 5月 24 22:59 amule.exe
-rwxr-xr-x 1 cat cat 9.7M 5月 24 22:59 amulegui.exe
-rwxr-xr-x 1 cat cat 4.3M 5月 24 22:59 amuleweb.exe
-rwxr-xr-x 1 cat cat 45K 5月 24 22:59 cas.exe
-rwxr-xr-x 1 cat cat 914K 5月 24 22:59 ed2k.exe
-rwxr-xr-x 1 cat cat 6.2M 5月 24 22:59 wxcas.exe

用7-Zip打包

cd $BUILDDIR
mkdir amule-2.3.3
cp pkg/bin/*.exe amule-2.3.3
cp -r pkg/share/locale/ amule-2.3.3
cp -r pkg/share/amule/* amule-2.3.3
mkdir amule-2.3.3/docs
cp pkg/share/doc/amule/* amule-2.3.3/docs
7z a amule-2.3.3-win32.7z amule-2.3.3

最后放一个发布地址:https://github.com/minnyres/amule-win32/releases

标签: aMule, GCC, Mingw-w64

非特殊说明,本博所有文章均为博主原创。

评论啦~