File scons-cross-build.patch of Package mingw64-libgps

From 26434a12d5e962e0da819efcb277065698cb0b39 Mon Sep 17 00:00:00 2001
From: Rob Norris <rw_norris@hotmail.com>
Date: Fri, 25 Mar 2016 13:20:37 +0000
Subject: [PATCH] Hacks to cross build for Windows

---
 SConstruct | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/SConstruct b/SConstruct
index 9626c09..df80227 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1128,6 +1128,18 @@ if not env["shared"]:
         env.Install(libdir, sources)
 else:
     def Library(env, target, sources, version, parse_flags=[]):
+        # THIS SPECIFIC HACK WORKS:
+        if 'i686-w64-mingw32' in env['target'] or 'x86_64-w64-mingw32' in env['target']:
+            shlib_prefix = env.subst('$SHLIBPREFIX')
+            # w32_32 is for Windows sockets
+            # winpthread is for mingw suppling clock_gettime() which is automatically found by scons
+            #  otherwise would need to provide a Windows implementation and override scons detection
+            env.Append(LIBS=['-lws2_32','-lwinpthread'])
+            # No versioning for DLLs - otherwise can cause file naming issues when running the end application
+            # (i.e. the end application build+link seems to work, but at runtime even though libgps.dll exists but the application expects libgps.dll.22.0.0!)
+            version = []
+            env['SHLIBSUFFIX'] = '.dll'
+            env['SHLINKFLAGS'] = '-Wl,--dll -shared -Wl,--output-def,' + shlib_prefix + target + '.def -Wl,--out-implib,' + shlib_prefix + target + '.dll.a'
         # Note: We have a possibility of getting either Object or file
         # list for sources, so we run through the sources and try to make
         # them into SharedObject instances.
@@ -1215,6 +1227,9 @@ gpsmon_sources = [
 ]
 
 # Production programs
+winflags=[]
+if 'i686-w64-mingw32' in env['target'] or 'x86_64-w64-mingw32' in env['target']:
+    winflags=['-lws2_32 -lwinpthread']
 
 gpsd = env.Program('gpsd', gpsd_sources,
                    LIBS=['gpsd', 'gps_static'],
@@ -1233,13 +1248,13 @@ gpsdctl = env.Program('gpsdctl', ['gpsdctl.c'],
                       parse_flags=gpsflags)
 gpspipe = env.Program('gpspipe', ['gpspipe.c'],
                       LIBS=['gps_static'],
-                      parse_flags=gpsflags)
+                      parse_flags=gpsflags + winflags)
 gps2udp = env.Program('gps2udp', ['gps2udp.c'],
                       LIBS=['gps_static'],
                       parse_flags=gpsflags)
 gpxlogger = env.Program('gpxlogger', ['gpxlogger.c'],
                         LIBS=['gps_static'],
-                        parse_flags=gpsflags)
+                        parse_flags=gpsflags + winflags)
 lcdgps = env.Program('lcdgps', ['lcdgps.c'],
                      LIBS=['gps_static'],
                      parse_flags=gpsflags)
@@ -1288,7 +1303,7 @@ test_trig = env.Program('test_trig', ['test_trig.c'], parse_flags=["-lm"])
 # test_libgps for glibc older than 2.17
 test_libgps = env.Program('test_libgps', ['test_libgps.c'],
                           LIBS=['gps_static'],
-                          parse_flags=["-lm"] + rtlibs + dbusflags)
+                          parse_flags=["-lm"] + rtlibs + dbusflags + winflags)
 
 if not env['socket_export']:
     announce("test_json not building because socket_export is disabled")
--
libgit2 0.26.0

openSUSE Build Service is sponsored by