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