From ad45ad06995353a1d8decb02a9894010124734c4 Mon Sep 17 00:00:00 2001
From: Lars Kanis <lars@greiz-reinsdorf.de>
Date: Fri, 1 Jun 2012 15:58:07 +0200
Subject: [PATCH] Force static linked libgcc and libstdc++ for cross
 compilation by using g++ as linker

Don't include sys/time.h for cross compilation, this avoids the fix for incompatible types of gettimeofday()
---
 ext/fox16/extconf.rb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ext/fox16/extconf.rb b/ext/fox16/extconf.rb
index 6e5f66d..5fd92ee 100755
--- a/ext/fox16/extconf.rb
+++ b/ext/fox16/extconf.rb
@@ -80,7 +80,8 @@ def do_rake_compiler_setup
     have_library( 'winspool', 'EnumPrintersA') && append_library( $libs, 'winspool' )
 
     CONFIG['CC'] += "\nCXX=#{ENV['CROSS_PREFIX']}-g++" # Hack CXX into Makefile for cross compilation
-    $CFLAGS += " -D_SYS_TIME_H_" # fix incompatible types for gettimeofday()
+    CONFIG['LDSHARED'].gsub!('gcc', 'g++') # ensure C++ linker is used, so that libstdc++ is linked static
+    $LDFLAGS += " -static-libgcc -static-libstdc++" # mingw-w64 v4.7 defaults to dynamic linking
   elsif RUBY_PLATFORM =~ /mingw/
     $CFLAGS = $CFLAGS + " -I/usr/local/include"
     $LDFLAGS = $LDFLAGS + " -I/usr/local/lib"
@@ -92,8 +93,8 @@ def do_rake_compiler_setup
     $LDFLAGS = $LDFLAGS + " -L/usr/local/lib"   # for libjpeg and libtiff
     %w{Xft}.each {|lib| $libs = append_library($libs, lib) }
   end
-  $libs = append_library($libs, "stdc++")
-  have_header("sys/time.h") unless RUBY_PLATFORM =~ /mingw/
+  $libs = append_library($libs, "stdc++") unless RUBY_PLATFORM =~ /mingw/ || enable_config("win32-static-build")
+  have_header("sys/time.h") unless RUBY_PLATFORM =~ /mingw/ || enable_config("win32-static-build")
   have_header("signal.h")
   if have_library("z", "deflate")
     have_library("png", "png_create_read_struct")
-- 
GitLab