From beb99d98cdda587cc8341e0891e3be6ef6c98d4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 6 Nov 2018 12:14:49 +0100
Subject: [PATCH] Build system improvements for MSYS2

On Windows/MinGW, use the -static linking flag. This enforces static linking of
Boost libraries, which is needed on MSYS2.

Also, use AM_CXXFLAGS and AM_LDFLAGS variables for changing flags, since
CXXFLAGS and LDFLAGS are user variables.
---
 configure.ac    | 11 +++++------
 src/Makefile.am |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 700889a8..2ccc980a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,23 +30,22 @@ AX_CXX_COMPILE_STDCXX_14
 AC_CANONICAL_HOST
 case ${host_os} in
   *mingw32*)
-    # On mingw32, we don't want dynamic libgcc
-    # Note that static-libstdc++ is only supported since GCC 4.5 (but generates no error on older versions)
-    LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -static-libgfortran"
-    have_windows="yes"
+    # On Windows, we don't want dynamic linking
+    AM_LDFLAGS="-static"
+    AC_SUBST([AM_LDFLAGS])
     ;;
   *cygwin*)
     AC_MSG_WARN([You are compiling for the Cygwin target. This means that the preprocessor will])
     AC_MSG_WARN([not run from MATLAB unless you add the Cygwin DLL to the path.])
     AC_MSG_WARN([This is probably not what you want. Consider using a MinGW cross-compiler.])
-    have_windows="yes"
     ;;
 esac
 
 # Use C++ for testing headers
 AC_LANG([C++])
 
-CXXFLAGS="$CXXFLAGS -Wall -Wno-parentheses"
+AM_CXXFLAGS="-Wall -Wno-parentheses"
+AC_SUBST([AM_CXXFLAGS])
 
 # If default 'ar' is not available, try to find one with a host prefix (see ticket #145)
 AC_CHECK_PROGS([AR], [ar ${host_alias}-ar])
diff --git a/src/Makefile.am b/src/Makefile.am
index 1756b921..71099dcb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,7 +65,7 @@ EXTRA_DIST = \
 
 # The -I. is for <FlexLexer.h>
 dynare_m_CPPFLAGS = $(BOOST_CPPFLAGS) -I.
-dynare_m_LDFLAGS = $(BOOST_LDFLAGS)
+dynare_m_LDFLAGS = $(AM_LDFLAGS) $(BOOST_LDFLAGS)
 dynare_m_LDADD = macro/libmacro.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB)
 
 DynareFlex.cc FlexLexer.h: DynareFlex.ll
-- 
GitLab