用mingw建立swarm库(实际验证后的修改版)

来源:互联网 发布:网络视频课件打不开 编辑:程序博客网 时间:2024/06/03 21:43

http://www.newsmth.net/nForum/#!article/FreeBSD/47150
Building Swarm Using MinGW

This tutorial provides directions and code for compiling your own Swarm libraries for Windows. It is a bit advanced---some familiarity with compiling software from source in a Linux environment and knowledge of the UNIX command line is assumed.
 
Install Required Tools

The first step is to download and install tools required for compiling Swarm. These links provide directions:
 ? MinGW
? Emacs
? GPerf

Build Support Libraries

The next steps are to build and install the libraries that Swarm depends on. A ZIP archive containing all the source code required can be found at:
 
http://ftp.swarm.org/pub/swarm/src/swarm/Swarm-2.4.1-MinGW-sources.zip

This archive contains two subdirectories:
? sources: This folder contains the source code for each component.
? patches: This folder contains patchfiles that modfy source code so that MinGW can compile it.
 
After downloading and extracting the source code archive, open up a MinGW shell and run the following commands:
cd /path/to/where/swarm/source/was/extracted
mkdir build
The following steps will all assume your MinGW shell is operating out of the build directory. All compiled software will be installed to /c/swarm (The Windows Explorer will see the folder appear at C:\swarm).
 
ZLib

ZLib will be the first library to be built as it is a common dependency for many of the other software components. From the build directory, execute the following to build Zlib:
tar xzf ./sources/zlib-1.2.5.tar.gz
cd zlib-1.2.5
make -f win32/Makefile.gcc
And then the following commands to install ZLib to /c/swarm:
mkdir -p /c/swarm/bin
mkdir -p /c/swarm/include
mkdir -p /c/swarm/lib

cp zlib1.dll /c/swarm/bin/
cp zconf.h zlib.h /c/swarm/include/
mv libzdll.a libz.dll.a
cp *.a /c/swarm/lib

LibPNG

LibPNG will be built next as its only dependency is ZLib. From the build directory, execute the following steps to build and install LibPNG:
tar xjf ./sources/libpng-1.5.4.tar.bz2
cd libpng-1.5.4

export CPPFLAGS='-I/c/swarm/include'
export LDFLAGS='-L/c/swarm/lib'
./configure --prefix=/c/swarm --with-zlib-prefix=/c/swarm

make
make install

XPM

Starting from the build directory, the XPM library can be built and installed as follows:
tar xjf ./sources/xpm-nox-4.2.0.tar.bz2
cd xpm-nox-4.2.0
patch -p1 < ../patches/xpm-nox-4.2.0-mingw-tcl.patch

make CC=gcc
make install prefix=/c/swarm
Summary of patchfile changes:

The patchfile is inherited from the SUSE builds of XPM for MinGW and adds Makefiles and other critical components.
 
One major modification has been made to the SUSE patchfile---tcl.h is included in xpm.h. This is required in order to use XPM while Tk is installed. Conversely, this means that this build of XPM cannot be used without having Tk installed.
 
LibFFI

Starting from the build directory, LibFFI can be built and installed as follows:
tar xzf ./sources/libffi-3.0.9.tar.gz
cd libffi-3.0.9

./configure --prefix=/c/swarm
make
make install
The LibFFI headers get installed in a weird place.
mv /c/swarm/lib/libffi-3.0.9/include/*.h /c/swarm/include
rm -rf /c/swarm/lib/libffi-3.0.9
Tcl

Starting from the build directory, Tcl can be built and installed as follows:
tar xzf ./sources/tcl8.4.19-src.tar.gz
cd tcl8.4.19
patch -p1 < ../patches/tcl-8.4.19-fix-lvalues.patch
cd win

./configure --prefix=/c/swarm
make
make install
Summary of patchfile changes:

At two places in the TCL source code, an assignment is made while simultaneously performing a typecast. The typecast and the assignment had to be split into separate operations in order to be acceptable to the MinGW compilers.
 
Tk

Starting from the build directory, Tk can be built and installed as follows:
tar xzf ./sources/tk8.4.19-src.tar.gz
cd tk8.4.19/win

./configure --prefix=/c/swarm
make
make install
BLT

Starting from the build directory, BLT can be built and installed as follows:
tar xzf ./sources/BLT2.4z.tar.gz
cd blt2.4z

./configure --prefix=/c/swarm --without-x
make
make install
HDF5 (Optional)

Getting HDF5 to work with MinGW is a little tricky. It is an optional dependency, so if support for reading and writing .hdf files is not needed this section can be skipped.
 
As of version 1.8.7, HDF5 currently does not compile under MinGW. So, we must wrap pre-compiled binaries for use with MinGW. In order to wrap the binaries, we will need an additional tool called pexports. This can be installed using mingw-get:
 mingw-get install mingw-utils
Download 32-bit Windows binaries from the HDF website compiled for use with the Visual Studio compilers (these files have "VS" listed under the Compilers section). After extracting the archive, the HDF5 libraries can be wrapped for use with MinGW by executing the following commands:
 cd path/to/where/HDF5/was/extracted

for dll in `ls dll/*dll`; do
  def_file=`basename $dll .dll`.def
  lib_file=lib`basename $dll dll.dll`.a
  pexports $dll > $def_file
  dlltool -d $def_file -l lib/$lib_file
done
Next, move the libraries and header files needed to use HDF5 from C into C:\swarm:
 cp dll/hdf5dll.dll dll/szip.dll /c/swarm/bin
cp include/* /c/swarm/include
cp lib/libhdf5.a /c/swarm/lib
Finally, a patch must be applied to the HDF header file H5public.h so that it doesn't define ssize_t---a constant already defined by MinGW. The required patch is contained in the Swarm MinGW source archive:
 cd /path/to/where/swarm/source/was/extracted
patch -p1 -d /c/swarm < patches/hdf5-1.8.7-mingw.patch
Build Swarm

Finally, the Swarm libraries themselves can be built. From the build directory, execute the following
 tar xzf ../sources/swarm-2.4.1.tar.gz
cd swarm-2.4.1
patch -p1 < ../patches/swarm-2.4.1-mingw.patch

export CPPFLAGS='-I/c/swarm/include'
export LDFLAGS='-L/c/swarm/lib'
./configure --prefix=/c/swarm \
  --with-zlibdir=/c/swarm \
  --with-pngdir=/c/swarm \
  --with-xpmdir=/c/swarm \
  --with-ffidir=/c/swarm \
  --with-tcl=/c/swarm/lib \
  --with-tk=/c/swarm/lib \
  --with-bltdir=/c/swarm

cd avcall
gcc -S avcall-i386.c
cd ..

make
make install
If you wrapped HDF5 up for use with MinGW, add --with-hdf5dir=/c/swarm to the list of arguments passed to configure.
 
Summary of patchfile changes:

swarm-2.4.1-mingw.patch modifies the Swarm source code in the following ways:
? gettimeofday is no longer defined in the Swarm sources as MinGW includes this function in its standard library.
 ? Swarm GUI functions are updated to be compatible with LibPNG 1.5.
? The Swarm configure script defines DATADIR as a preprocessor macro---this conflicts with variables in the GCC Objective-C library. DATDIR is undefed in critical parts of the source code.
 ? The sleep function is aliased to usleep---which is the name of the MinGW implementation.
 ? The way in which Makefiles invoke gperf is amended so that it actually produces output.
 ? NULL checks are added to `zstrdup` in src/defobj/internal.m. Some functions in the Swarm library may attempt to call `zstrdup` on a NULL pointer. (This happens if the SWARMHOME environment variable is not set.) Failing to check for this condition can lead to segfaults. `zstrdup` now returns NULL if passed a NULL string or if `alloc` fails to allocate memory for a duplicate.
 
Full details are contained in the patchfile.

原创粉丝点击