aboutsummaryrefslogtreecommitdiff
path: root/utils/gpsd/patches/003_sconscript-cross-platform-build-support.patch
blob: 68613de9e52104cb4c938a810dd4e0239945ebac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Backported from:

https://gitlab.com/gpsd/gpsd/-/commit/28fb46ac70059d3b0eb64041c35ef83027bd8506
https://gitlab.com/gpsd/gpsd/-/commit/c5ed9736d859fed0682e60e899e9617ac67da11b

From c2b4d3fb9a9e011bdc2fb891b78c6ce13f0c7101 Mon Sep 17 00:00:00 2001
From: "Sergey V. Lobanov" <sergey@lobanov.in>
Date: Mon, 24 Jan 2022 16:01:54 -0800
Subject: [PATCH] SConscript: Add target_platform config option.

This patch adds an ability to redefine target platform using config
optiont target_platform=<platform> to support cross-platform compilation.

This allows cross cimpileg for openWRT (target_platform=linux) on
osX (sys.platform() == darwin)

Signed-off-by: Gary E. Miller <gem@rellim.com>
---
 SConscript | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

--- a/SConscript
+++ b/SConscript
@@ -52,6 +52,7 @@ EnsurePythonVersion(2, 6)
 # e.g. "scons-3" on CentOS 8.
 scons_executable_name = os.path.basename(sys.argv[0]) or 'scons'
 
+
 # Have scons rebuild an existing target when the source(s) MD5 changes
 # Do not use time to prevent rebuilding when sources, like gpsd_config.h,
 # are rebuilt, but with no changes.
@@ -351,6 +352,7 @@ boolopts = (
     ("gpsdclients",   True,  "gspd client programs"),
     ("gpsd",          True,  "gpsd itself"),
     ("implicit_link", imloads, "implicit linkage is supported in shared libs"),
+    # FIXME: should check for Pi, not for "linux"
     ("magic_hat", sys.platform.startswith('linux'),
      "special Linux PPS hack for Raspberry Pi et al"),
     ("minimal", False, "turn off every option not set on the command line"),
@@ -410,6 +412,10 @@ nonboolopts = (
      "Prefix to the binary tools to use (gcc, ld, etc.)\n"
      "For cross-compiling, or building with multiple local toolchains.\n"
      ),
+    # If build and target platform are different, then redefining target
+    # platform might be necessary to use better build flags
+    ("target_platform", sys.platform,
+     "target platform for cross-compiling (linux, darwin, etc.)"),
     ("target_python",  def_target_python,  "target Python version as command"),
 )
 
@@ -878,13 +884,16 @@ have_valgrind = False
 # per SCons 4.0.1 doc: Section 23.9. Not Configuring When Cleaning Targets
 if not cleaning and not helping:
     # OS X aliases gcc to clang
+    if (sys.platform != config.env['target_platform']):
+        announce("Target system is: %s" % config.env['target_platform'])
+
     announce("cc is %s, version %s" % (env['CC'], env['CCVERSION']))
     # clang accepts -pthread, then warns it is unused.
     if not config.CheckCC():
         announce("ERROR: CC doesn't work")
 
     if ((config.CheckCompilerOption("-pthread") and
-         not sys.platform.startswith('darwin'))):
+         not config.env['target_platform'].startswith('darwin'))):
         config.env.MergeFlags("-pthread")
 
     confdefs = ["/* gpsd_config.h generated by scons, do not hand-hack. */\n"]
@@ -935,7 +944,7 @@ if not cleaning and not helping:
     # confdefs.append('#endif\n')
     # Reinstated for FreeBSD (below) 16-Aug-2019
 
-    if sys.platform.startswith('linux'):
+    if config.env['target_platform'].startswith('linux'):
         # for cfmakeraw(), strsep(), etc. on CentOS 7
         # glibc 2.19 and before
         # sets __USE_MISC
@@ -947,7 +956,7 @@ if not cleaning and not helping:
         confdefs.append('#if !defined(_GNU_SOURCE)')
         confdefs.append('#define _GNU_SOURCE 1')
         confdefs.append('#endif\n')
-    elif sys.platform.startswith('darwin'):
+    elif config.env['target_platform'].startswith('darwin'):
         # strlcpy() and SIGWINCH need _DARWIN_C_SOURCE
         confdefs.append('#if !defined(_DARWIN_C_SOURCE)')
         confdefs.append('#define _DARWIN_C_SOURCE 1\n')
@@ -962,7 +971,7 @@ if not cleaning and not helping:
                         "-Wl,-compatibility_version,%s" % libgps_version,
                         "-Wl,-install_name,%s/$TARGET.srcpath" %
                         installdir('libdir', add_destdir=False)]
-    elif sys.platform.startswith('freebsd'):
+    elif config.env['target_platform'].startswith('freebsd'):
         # for isascii(), putenv(), nice(), strptime()
         confdefs.append('#if !defined(_XOPEN_SOURCE)')
         confdefs.append('#define _XOPEN_SOURCE 700')
@@ -975,7 +984,7 @@ if not cleaning and not helping:
         confdefs.append('#if !defined(__BSD_VISIBLE)')
         confdefs.append("#define __BSD_VISIBLE 1\n")
         confdefs.append('#endif\n')
-    elif sys.platform.startswith('openbsd'):
+    elif config.env['target_platform'].startswith('openbsd'):
         # required to define u_int in sys/time.h
         confdefs.append('#if !defined(_BSD_SOURCE)')
         confdefs.append("#define _BSD_SOURCE 1\n")
@@ -984,12 +993,12 @@ if not cleaning and not helping:
         confdefs.append('#if !defined(__BSD_VISIBLE)')
         confdefs.append("#define __BSD_VISIBLE 1\n")
         confdefs.append('#endif\n')
-    elif sys.platform.startswith('netbsd'):
+    elif config.env['target_platform'].startswith('netbsd'):
         # required to get strlcpy(), and more, from string.h
         confdefs.append('#if !defined(_NETBSD_SOURCE)')
         confdefs.append("#define _NETBSD_SOURCE 1\n")
         confdefs.append('#endif\n')
-    elif sys.platform.startswith('sunos5'):
+    elif config.env['target_platform'].startswith('sunos5'):
         # tested with gcc-5.5 on slowlaris 10
         # required to get isascii(), and more, from ctype.h
         confdefs.append('#if !defined(__XPG4_CHAR_CLASS__)')
@@ -1044,11 +1053,11 @@ if not cleaning and not helping:
             ncurseslibs = ['!ncurses5-config --libs --cflags']
         elif WhereIs('ncursesw5-config'):
             ncurseslibs = ['!ncursesw5-config --libs --cflags']
-        elif sys.platform.startswith('freebsd'):
+        elif config.env['target_platform'].startswith('freebsd'):
             ncurseslibs = ['-lncurses']
-        elif (sys.platform.startswith('darwin') or
-              sys.platform.startswith('openbsd') or
-              sys.platform.startswith('sunos5')):
+        elif (config.env['target_platform'].startswith('darwin') or
+              config.env['target_platform'].startswith('openbsd') or
+              config.env['target_platform'].startswith('sunos5')):
             ncurseslibs = ['-lcurses']
         else:
             announce('Turning off ncurses support, library not found.')
@@ -1064,7 +1073,8 @@ if not cleaning and not helping:
                 announce("pkg_config is confused about the state "
                          "of libusb-1.0.")
                 usbflags = []
-        elif sys.platform.startswith("freebsd"):
+        elif config.env['target_platform'].startswith('freebsd'):
+            # FIXME: shold directly test for libusb existence.
             confdefs.append("#define HAVE_LIBUSB 1\n")
             usbflags = ["-lusb"]
         else:
@@ -2498,8 +2508,11 @@ if qt_env:
     binaryinstall.append(GPSLibraryInstall(qt_env, installdir('libdir'),
                                            compiled_qgpsmmlib, libgps_version))
 
-if ((not env['debug'] and not env['debug_opt'] and not env['profiling'] and
-     not env['nostrip'] and not sys.platform.startswith('darwin'))):
+if ((not env['debug'] and
+     not env['debug_opt'] and
+     not env['profiling'] and
+     not env['nostrip'] and
+     not env['target_platform'].startswith('darwin'))):
     env.AddPostAction(binaryinstall, '$STRIP $TARGET')
 
 binaryinstall.append(env.Install(installdir('bindir'), bin_scripts))