chiark / gitweb /
lcc doesn't support dllimport, thanks to Laurent Vanbeylen for the bug report
[nlopt.git] / BUILD-MINGW.sh
1 #!/bin/sh
2 set -e
3
4 rm -rf mingw
5
6 ./configure --prefix=`pwd`/mingw --host=i586-mingw32msvc --enable-shared --disable-static --without-matlab --without-octave --without-python --without-guile --without-threadlocal && make -j4 && make install
7
8 cd mingw/bin
9 for dll in *.dll; do
10     def=`basename $dll .dll`.def
11     echo "LIBRARY $dll" > $def
12     echo EXPORTS >> $def
13     i586-mingw32msvc-nm $dll | grep ' T _' | sed 's/.* T _//' | egrep 'nlopt|nlo_' >> $def
14 done
15 cd ../..
16
17 perl -pi -e 's,^ * #define NLOPT_DLL,*/\n#define NLOPT_DLL\n/*,' mingw/include/nlopt.h
18
19 cat > README-WINDOWS <<EOF
20 This .zip archive contains DLL libraries and the associated header (.h)
21 and module-definition (.def) files of NLopt compiled for Win32.
22
23 In order to link to this .dll files from Visual C++, you need to
24 create a .lib "import libraries" for it, and can do so with the "lib"
25 command that comes with VC++.  In particular, run:
26      lib /def:libnlopt-0.def
27
28 To compile the Matlab plugin, use the Matlab "mex" compiler on the file
29 nlopt_optimize.c (being sure to link to the libnlopt DLL) in the matlab
30 subdirectory.
31
32 To build the Python plugin (assuming that you have Python and Numpy
33 installed), do:
34    python setup.py build_ext --inplace
35
36 They were compiled by the GNU C compiler for MinGW, specifically:
37 EOF
38 i586-mingw32msvc-gcc --version |head -1 >> README-WINDOWS
39
40 # grep -v "nlopt-util.h" octave/nlopt_minimize_constrained-mex.c > mingw/nlopt_minimize_constrained.c
41
42 nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"`
43
44 mkdir mingw/matlab
45 cd octave
46 cp `grep 'MFILES =' Makefile.am | cut -d= -f2` ../mingw/matlab
47 cp `grep 'm_DATA =' Makefile.am | cut -d\) -f2` ../mingw/matlab
48 cp nlopt_optimize-mex.c ../mingw/matlab/nlopt_optimize.c
49 cd ..
50
51 mkdir mingw/python
52 cp swig/nlopt.py swig/nlopt-python.cpp mingw/python
53 cat > mingw/python/setup.py <<EOF
54 from distutils.core import setup, Extension
55 nlopt_module = Extension('_nlopt',
56                            sources=['nlopt-python.cpp'],
57                            libraries=['libnlopt-0'],
58                            )
59 setup (name = 'nlopt',
60        version = '${nlopt_vers}',
61        author      = "Steven G. Johnson",
62        description = """NLopt nonlinear-optimization library""",
63        ext_modules = [nlopt_module],
64        py_modules = ["nlopt"],
65        )
66 EOF
67
68 nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"`
69 zip=nlopt-${nlopt_vers}-dll.zip
70 rm -f $zip
71 zip -vj $zip mingw/bin/*.dll mingw/bin/*.exe
72 zip -vjgl $zip mingw/bin/*.def mingw/include/* mingw/python/* README COPYING COPYRIGHT NEWS README-WINDOWS
73
74 cd mingw
75 zip -vgl ../$zip matlab/*
76 cd ..