chiark / gitweb /
fixed MinGW build
authorstevenj <stevenj@alum.mit.edu>
Wed, 16 Jun 2010 23:04:11 +0000 (19:04 -0400)
committerstevenj <stevenj@alum.mit.edu>
Wed, 16 Jun 2010 23:04:11 +0000 (19:04 -0400)
darcs-hash:20100616230411-c8de0-461279310c1fc9fc5d63128cc9b25aecf41960d0.gz

BUILD-MINGW.sh [changed mode: 0644->0755]
api/deprecated.c
api/f77api.c
api/f77funcs.h
api/general.c
api/optimize.c
api/options.c

old mode 100644 (file)
new mode 100755 (executable)
index 039e772..ef284e1
@@ -1,4 +1,9 @@
-./configure --prefix=`pwd`/mingw --host=i586-mingw32msvc --enable-shared --disable-static --without-matlab --without-octave && make -j4 && make install
+#!/bin/sh
+set -e
+
+rm -rf mingw
+
+./configure --prefix=`pwd`/mingw --host=i586-mingw32msvc --enable-shared --disable-static --without-matlab --without-octave --without-python --without-guile && make -j4 && make install
 
 cd mingw/bin
 for dll in *.dll; do
@@ -21,7 +26,12 @@ command that comes with VC++.  In particular, run:
      lib /def:libnlopt-0.def
 
 To compile the Matlab plugin, use the Matlab "mex" compiler on the file
-nlopt_minimize_constrained.c (being sure to link to the libnlopt DLL).
+nlopt_optimize.c (being sure to link to the libnlopt DLL) in the matlab
+subdirectory.
+
+To build the Python plugin (assuming that you have Python and Numpy
+installed), do:
+   python setup.py build_ext --inplace
 
 They were compiled by the GNU C compiler for MinGW, specifically:
 EOF
@@ -29,8 +39,38 @@ i586-mingw32msvc-gcc --version |head -1 >> README-WINDOWS
 
 # grep -v "nlopt-util.h" octave/nlopt_minimize_constrained-mex.c > mingw/nlopt_minimize_constrained.c
 
+nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"`
+
+mkdir mingw/matlab
+cd octave
+cp `grep 'MFILES =' Makefile.am | cut -d= -f2` ../mingw/matlab
+cp `grep 'm_DATA =' Makefile.am | cut -d\) -f2` ../mingw/matlab
+cp nlopt_optimize-mex.c ../mingw/matlab/nlopt_optimize.c
+cd ..
+
+mkdir mingw/python
+cp swig/nlopt.py swig/nlopt-python.cpp mingw/python
+cat > mingw/python/setup.py <<EOF
+from distutils.core import setup, Extension
+nlopt_module = Extension('_nlopt',
+                           sources=['nlopt-python.cpp'],
+                           libraries=['libnlopt-0'],
+                           )
+setup (name = 'nlopt',
+       version = '${nlopt_vers}',
+       author      = "Steven G. Johnson",
+       description = """NLopt nonlinear-optimization library""",
+       ext_modules = [nlopt_module],
+       py_modules = ["nlopt"],
+       )
+EOF
+
 nlopt_vers=`grep PACKAGE_VERSION config.h |cut -d" " -f3 |tr -d \"`
 zip=nlopt-${nlopt_vers}-dll.zip
 rm -f $zip
 zip -vj $zip mingw/bin/*.dll mingw/bin/*.exe
-zip -vjgl $zip mingw/bin/*.def mingw/include/* README COPYING COPYRIGHT NEWS README-WINDOWS  # octave/*.m mingw/nlopt_minimize_constrained.c
+zip -vjgl $zip mingw/bin/*.def mingw/include/* mingw/python/* README COPYING COPYRIGHT NEWS README-WINDOWS
+
+cd mingw
+zip -vgl ../$zip matlab/*
+cd ..
index ecf4d2797691926d0d4e88a43552610f5c8abd0b..50b69a33220e98fe09ef38c72586dcd133bd1e9d 100644 (file)
@@ -28,6 +28,7 @@ nlopt_algorithm nlopt_local_search_alg_deriv = NLOPT_LD_MMA;
 nlopt_algorithm nlopt_local_search_alg_nonderiv = NLOPT_LN_COBYLA;
 int nlopt_local_search_maxeval = -1; /* no maximum by default */
 
+NLOPT_STDCALL
 void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
                                      nlopt_algorithm *nonderiv,
                                      int *maxeval)
@@ -37,6 +38,7 @@ void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
      *maxeval = nlopt_local_search_maxeval;
 }
 
+NLOPT_STDCALL
 void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
                                      nlopt_algorithm nonderiv,
                                      int maxeval)
@@ -50,13 +52,16 @@ void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
 
 int nlopt_stochastic_population = 0;
 
+NLOPT_STDCALL
 int nlopt_get_stochastic_population(void) { 
      return nlopt_stochastic_population; }
+NLOPT_STDCALL
 void nlopt_set_stochastic_population(int pop) { 
      nlopt_stochastic_population = pop <= 0 ? 0 : (unsigned) pop; }
 
 /*************************************************************************/
 
+NLOPT_STDCALL
 nlopt_result nlopt_minimize_econstrained(
      nlopt_algorithm algorithm,
      int n, nlopt_func_old f, void *f_data,
@@ -129,6 +134,7 @@ nlopt_result nlopt_minimize_econstrained(
      return ret;
 }
 
+NLOPT_STDCALL
 nlopt_result nlopt_minimize_constrained(
      nlopt_algorithm algorithm,
      int n, nlopt_func_old f, void *f_data,
@@ -147,6 +153,7 @@ nlopt_result nlopt_minimize_constrained(
          xtol_rel, xtol_abs, ftol_rel, ftol_abs, maxeval, maxtime);
 }
 
+NLOPT_STDCALL
 nlopt_result nlopt_minimize(
      nlopt_algorithm algorithm,
      int n, nlopt_func_old f, void *f_data,
index 193d50e1835cb939a2c364fb90775b598ad54eb7..fbc8e76339af44b94a422fe726d3cf2bce9d8932 100644 (file)
@@ -81,6 +81,8 @@ static double f77_func_wrap(unsigned n, const double *x, double *grad, void *dat
    wrapper functions are so small, the library bloat of including them
    multiple times is negligible and seems well worth the benefit. */
 
+#  define F77CALL(a, A) F77(a, A)
+
 /* name + underscore is by far the most common (gfortran, g77, Intel, ...) */
 #  define F77(a, A) a ## _
 #  include "f77funcs.h"
@@ -106,5 +108,7 @@ static double f77_func_wrap(unsigned n, const double *x, double *grad, void *dat
        http://msdn.microsoft.com/library/en-us/vccore98/html/_core_mixed.2d.language_programming.3a_.overview.asp
 */
 #  undef F77
+#  undef F77CALL
 #  define F77(a, A) NLOPT_STDCALL A
+#  define F77CALL(a, A) A
 #  include "f77funcs.h"
index 62667fdf00a598d271277534ea98b1419a0d340f..a176816d5fb85ee96dd2c238493cfacb037c71d9 100644 (file)
@@ -80,7 +80,7 @@ void F77(nloptm,NLOPTM)(int *info,
                        const int *maxeval, const double *maxtime)
 {
      int m = 0;
-     F77(nloptc,NLOPTC)(info, algorithm, n, f, f_data, &m, 0, 0, 0,
+     F77CALL(nloptc,NLOPTC)(info, algorithm, n, f, f_data, &m, 0, 0, 0,
                        lb, ub, x, minf, minf_max, ftol_rel, ftol_abs,
                        xtol_rel, xtol_abs, have_xtol_abs, maxeval, maxtime);
 }
index e892bd997d8ae6f545099451bd64b619ea14bb51..2e8eefadc082353a6018b714fe55eb3f7ea91014 100644 (file)
@@ -36,7 +36,7 @@ int nlopt_isinf(double x) {
 }
 /*************************************************************************/
 
-void nlopt_version(int *major, int *minor, int *bugfix)
+NLOPT_STDCALL void nlopt_version(int *major, int *minor, int *bugfix)
 {
      *major = MAJOR_VERSION;
      *minor = MINOR_VERSION;
@@ -126,12 +126,12 @@ const char *nlopt_algorithm_name(nlopt_algorithm a)
 /*************************************************************************/
 
 static THREADLOCAL int nlopt_srand_called = 0;
-void nlopt_srand(unsigned long seed) {
+NLOPT_STDCALL void nlopt_srand(unsigned long seed) {
      nlopt_srand_called = 1;
      nlopt_init_genrand(seed);
 }
 
-void nlopt_srand_time(void) {
+NLOPT_STDCALL void nlopt_srand_time(void) {
      nlopt_srand(nlopt_time_seed() + my_gettid() * 314159);
 }
 
index a298964b19751d4a322b933e178ab87e9d2e7836..387301314003d9f410c6f2f865193c6e6f546b46 100644 (file)
@@ -543,6 +543,7 @@ static double f_max(unsigned n, const double *x, double *grad, void *data)
      return -val;
 }
 
+NLOPT_STDCALL 
 nlopt_result nlopt_optimize(nlopt_opt opt, double *x, double *opt_f)
 {
      nlopt_func f; void *f_data;
index fffa1007763103e2b144456ee8cc501806697764..5e7038ce762af73f4304369dd658bb14c404b449 100644 (file)
@@ -30,7 +30,7 @@
 
 /*************************************************************************/
 
-void nlopt_destroy(nlopt_opt opt)
+NLOPT_STDCALL void nlopt_destroy(nlopt_opt opt)
 {
      if (opt) {
          if (opt->munge_on_destroy) {
@@ -52,7 +52,7 @@ void nlopt_destroy(nlopt_opt opt)
      }
 }
 
-nlopt_opt nlopt_create(nlopt_algorithm algorithm, unsigned n)
+NLOPT_STDCALL nlopt_opt nlopt_create(nlopt_algorithm algorithm, unsigned n)
 {
      nlopt_opt opt;
 
@@ -105,7 +105,7 @@ oom:
      return NULL;
 }
 
-nlopt_opt nlopt_copy(const nlopt_opt opt)
+NLOPT_STDCALL nlopt_opt nlopt_copy(const nlopt_opt opt)
 {
      nlopt_opt nopt = NULL;
      if (opt) {
@@ -184,7 +184,7 @@ oom:
 
 /*************************************************************************/
 
-nlopt_result nlopt_set_min_objective(nlopt_opt opt, nlopt_func f, void *f_data)
+NLOPT_STDCALL nlopt_result nlopt_set_min_objective(nlopt_opt opt, nlopt_func f, void *f_data)
 {
      if (opt) {
          opt->f = f; opt->f_data = f_data;
@@ -196,7 +196,7 @@ nlopt_result nlopt_set_min_objective(nlopt_opt opt, nlopt_func f, void *f_data)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, void *f_data)
+NLOPT_STDCALL nlopt_result nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, void *f_data)
 {
      if (opt) {
          opt->f = f; opt->f_data = f_data;
@@ -210,7 +210,7 @@ nlopt_result nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, void *f_data)
 
 /*************************************************************************/
 
-nlopt_result nlopt_set_lower_bounds(nlopt_opt opt, const double *lb)
+NLOPT_STDCALL nlopt_result nlopt_set_lower_bounds(nlopt_opt opt, const double *lb)
 {
      if (opt && (opt->n == 0 || lb)) {
          memcpy(opt->lb, lb, sizeof(double) * (opt->n));
@@ -219,7 +219,7 @@ nlopt_result nlopt_set_lower_bounds(nlopt_opt opt, const double *lb)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_set_lower_bounds1(nlopt_opt opt, double lb)
+NLOPT_STDCALL nlopt_result nlopt_set_lower_bounds1(nlopt_opt opt, double lb)
 {
      if (opt) {
          unsigned i;
@@ -230,7 +230,7 @@ nlopt_result nlopt_set_lower_bounds1(nlopt_opt opt, double lb)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_get_lower_bounds(nlopt_opt opt, double *lb)
+NLOPT_STDCALL nlopt_result nlopt_get_lower_bounds(nlopt_opt opt, double *lb)
 {
      if (opt && (opt->n == 0 || lb)) {
          memcpy(lb, opt->lb, sizeof(double) * (opt->n));
@@ -239,7 +239,7 @@ nlopt_result nlopt_get_lower_bounds(nlopt_opt opt, double *lb)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_set_upper_bounds(nlopt_opt opt, const double *ub)
+NLOPT_STDCALL nlopt_result nlopt_set_upper_bounds(nlopt_opt opt, const double *ub)
 {
      if (opt && (opt->n == 0 || ub)) {
          memcpy(opt->ub, ub, sizeof(double) * (opt->n));
@@ -248,7 +248,7 @@ nlopt_result nlopt_set_upper_bounds(nlopt_opt opt, const double *ub)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_set_upper_bounds1(nlopt_opt opt, double ub)
+NLOPT_STDCALL nlopt_result nlopt_set_upper_bounds1(nlopt_opt opt, double ub)
 {
      if (opt) {
          unsigned i;
@@ -259,7 +259,7 @@ nlopt_result nlopt_set_upper_bounds1(nlopt_opt opt, double ub)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_get_upper_bounds(nlopt_opt opt, double *ub)
+NLOPT_STDCALL nlopt_result nlopt_get_upper_bounds(nlopt_opt opt, double *ub)
 {
      if (opt && (opt->n == 0 || ub)) {
          memcpy(ub, opt->ub, sizeof(double) * (opt->n));
@@ -277,7 +277,7 @@ nlopt_result nlopt_get_upper_bounds(nlopt_opt opt, double *ub)
                       (a) == NLOPT_LD_AUGLAG ||        \
                       (a) == NLOPT_LD_AUGLAG_EQ)
 
-nlopt_result nlopt_remove_inequality_constraints(nlopt_opt opt)
+NLOPT_STDCALL nlopt_result nlopt_remove_inequality_constraints(nlopt_opt opt)
 {
      if (!opt) return NLOPT_INVALID_ARGS;
      if (opt->munge_on_destroy) {
@@ -291,7 +291,7 @@ nlopt_result nlopt_remove_inequality_constraints(nlopt_opt opt)
      return NLOPT_SUCCESS;
 }
 
-static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc,
+NLOPT_STDCALL static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc,
                                   nlopt_constraint **c,
                                   nlopt_func fc, void *fc_data,
                                   double tol)
@@ -316,7 +316,7 @@ static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc,
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_add_inequality_constraint(nlopt_opt opt,
+NLOPT_STDCALL nlopt_result nlopt_add_inequality_constraint(nlopt_opt opt,
                                             nlopt_func fc, void *fc_data,
                                             double tol)
 {
@@ -335,7 +335,7 @@ nlopt_result nlopt_add_inequality_constraint(nlopt_opt opt,
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_remove_equality_constraints(nlopt_opt opt)
+NLOPT_STDCALL nlopt_result nlopt_remove_equality_constraints(nlopt_opt opt)
 {
      if (!opt) return NLOPT_INVALID_ARGS;
      if (opt->munge_on_destroy) {
@@ -349,7 +349,7 @@ nlopt_result nlopt_remove_equality_constraints(nlopt_opt opt)
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_add_equality_constraint(nlopt_opt opt,
+NLOPT_STDCALL nlopt_result nlopt_add_equality_constraint(nlopt_opt opt,
                                           nlopt_func h, void *h_data,
                                           double tol)
 {
@@ -365,19 +365,20 @@ nlopt_result nlopt_add_equality_constraint(nlopt_opt opt,
 
 /*************************************************************************/
 
-#define SET(param, T, arg)                             \
-   nlopt_result nlopt_set_##param(nlopt_opt opt, T arg)        \
-   {                                                   \
-       if (opt) {                                      \
-            opt->arg = arg;                            \
-            return NLOPT_SUCCESS;                      \
-       }                                               \
-       return NLOPT_INVALID_ARGS;                      \
+#define SET(param, T, arg)                                             \
+   NLOPT_STDCALL nlopt_result nlopt_set_##param(nlopt_opt opt, T arg)  \
+   {                                                                   \
+       if (opt) {                                                      \
+            opt->arg = arg;                                            \
+            return NLOPT_SUCCESS;                                      \
+       }                                                               \
+       return NLOPT_INVALID_ARGS;                                      \
    }
 
 
-#define GET(param, T, arg) T nlopt_get_##param(const nlopt_opt opt) {  \
-        return opt->arg;                                               \
+#define GET(param, T, arg) NLOPT_STDCALL       \
+   T nlopt_get_##param(const nlopt_opt opt) {  \
+        return opt->arg;                       \
    }
 
 #define GETSET(param, T, arg) GET(param, T, arg) SET(param, T, arg)
@@ -388,7 +389,7 @@ GETSET(ftol_rel, double, ftol_rel)
 GETSET(ftol_abs, double, ftol_abs)
 GETSET(xtol_rel, double, xtol_rel)
 
-nlopt_result nlopt_set_xtol_abs(nlopt_opt opt, const double *xtol_abs)
+NLOPT_STDCALL nlopt_result nlopt_set_xtol_abs(nlopt_opt opt, const double *xtol_abs)
 {
      if (opt) {
          memcpy(opt->xtol_abs, xtol_abs, opt->n & sizeof(double));
@@ -397,7 +398,7 @@ nlopt_result nlopt_set_xtol_abs(nlopt_opt opt, const double *xtol_abs)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_set_xtol_abs1(nlopt_opt opt, const double xtol_abs)
+NLOPT_STDCALL nlopt_result nlopt_set_xtol_abs1(nlopt_opt opt, const double xtol_abs)
 {
      if (opt) {
          unsigned i;
@@ -408,7 +409,7 @@ nlopt_result nlopt_set_xtol_abs1(nlopt_opt opt, const double xtol_abs)
      return NLOPT_INVALID_ARGS;
 }
 
-nlopt_result nlopt_get_xtol_abs(const nlopt_opt opt, double *xtol_abs)
+NLOPT_STDCALL nlopt_result nlopt_get_xtol_abs(const nlopt_opt opt, double *xtol_abs)
 {
      memcpy(xtol_abs, opt->xtol_abs, opt->n & sizeof(double));
      return NLOPT_SUCCESS;
@@ -420,7 +421,7 @@ GETSET(maxtime, double, maxtime)
 
 /*************************************************************************/
 
-nlopt_result nlopt_set_force_stop(nlopt_opt opt, int force_stop)
+NLOPT_STDCALL nlopt_result nlopt_set_force_stop(nlopt_opt opt, int force_stop)
 {
      if (opt) {
          opt->force_stop = force_stop;
@@ -432,7 +433,7 @@ nlopt_result nlopt_set_force_stop(nlopt_opt opt, int force_stop)
 }
 
 GET(force_stop, int, force_stop)
-nlopt_result nlopt_force_stop(nlopt_opt opt) { 
+NLOPT_STDCALL nlopt_result nlopt_force_stop(nlopt_opt opt) { 
      return nlopt_set_force_stop(opt, 1); 
 }
 
@@ -443,7 +444,7 @@ GET(dimension, unsigned, n)
 
 /*************************************************************************/
 
-nlopt_result nlopt_set_local_optimizer(nlopt_opt opt,
+NLOPT_STDCALL nlopt_result nlopt_set_local_optimizer(nlopt_opt opt,
                                       const nlopt_opt local_opt)
 {
      if (opt) {
@@ -470,7 +471,7 @@ GETSET(population, unsigned, stochastic_population)
 
 /*************************************************************************/
 
-nlopt_result nlopt_set_initial_step1(nlopt_opt opt, double dx)
+NLOPT_STDCALL nlopt_result nlopt_set_initial_step1(nlopt_opt opt, double dx)
 {
      unsigned i;
      if (!opt || dx == 0) return NLOPT_INVALID_ARGS;
@@ -482,7 +483,7 @@ nlopt_result nlopt_set_initial_step1(nlopt_opt opt, double dx)
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_set_initial_step(nlopt_opt opt, const double *dx)
+NLOPT_STDCALL nlopt_result nlopt_set_initial_step(nlopt_opt opt, const double *dx)
 {
      unsigned i;
      if (!opt) return NLOPT_INVALID_ARGS;
@@ -497,7 +498,7 @@ nlopt_result nlopt_set_initial_step(nlopt_opt opt, const double *dx)
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_get_initial_step(const nlopt_opt opt, const double *x, 
+NLOPT_STDCALL nlopt_result nlopt_get_initial_step(const nlopt_opt opt, const double *x, 
                                    double *dx)
 {
      if (!opt) return NLOPT_INVALID_ARGS;
@@ -514,7 +515,7 @@ nlopt_result nlopt_get_initial_step(const nlopt_opt opt, const double *x,
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_set_default_initial_step(nlopt_opt opt, const double *x)
+NLOPT_STDCALL nlopt_result nlopt_set_default_initial_step(nlopt_opt opt, const double *x)
 {
      const double *lb, *ub;
      unsigned i;
@@ -560,7 +561,7 @@ nlopt_result nlopt_set_default_initial_step(nlopt_opt opt, const double *x)
 
 /*************************************************************************/
 
-void nlopt_set_munge(nlopt_opt opt,
+NLOPT_STDCALL void nlopt_set_munge(nlopt_opt opt,
                     nlopt_munge munge_on_destroy,
                     nlopt_munge munge_on_copy) {
      if (opt) {