Merge pull request #17303 from CarlosDerSeher/feature_bt_agent
[feed/packages.git] / utils / gpsd / patches / 003_sconscript-cross-platform-build-support.patch
1 Backported from:
2
3 https://gitlab.com/gpsd/gpsd/-/commit/28fb46ac70059d3b0eb64041c35ef83027bd8506
4 https://gitlab.com/gpsd/gpsd/-/commit/c5ed9736d859fed0682e60e899e9617ac67da11b
5
6 From c2b4d3fb9a9e011bdc2fb891b78c6ce13f0c7101 Mon Sep 17 00:00:00 2001
7 From: "Sergey V. Lobanov" <sergey@lobanov.in>
8 Date: Mon, 24 Jan 2022 16:01:54 -0800
9 Subject: [PATCH] SConscript: Add target_platform config option.
10
11 This patch adds an ability to redefine target platform using config
12 optiont target_platform=<platform> to support cross-platform compilation.
13
14 This allows cross cimpileg for openWRT (target_platform=linux) on
15 osX (sys.platform() == darwin)
16
17 Signed-off-by: Gary E. Miller <gem@rellim.com>
18 ---
19 SConscript | 41 +++++++++++++++++++++++++++--------------
20 1 file changed, 27 insertions(+), 14 deletions(-)
21
22 --- a/SConscript
23 +++ b/SConscript
24 @@ -52,6 +52,7 @@ EnsurePythonVersion(2, 6)
25 # e.g. "scons-3" on CentOS 8.
26 scons_executable_name = os.path.basename(sys.argv[0]) or 'scons'
27
28 +
29 # Have scons rebuild an existing target when the source(s) MD5 changes
30 # Do not use time to prevent rebuilding when sources, like gpsd_config.h,
31 # are rebuilt, but with no changes.
32 @@ -351,6 +352,7 @@ boolopts = (
33 ("gpsdclients", True, "gspd client programs"),
34 ("gpsd", True, "gpsd itself"),
35 ("implicit_link", imloads, "implicit linkage is supported in shared libs"),
36 + # FIXME: should check for Pi, not for "linux"
37 ("magic_hat", sys.platform.startswith('linux'),
38 "special Linux PPS hack for Raspberry Pi et al"),
39 ("minimal", False, "turn off every option not set on the command line"),
40 @@ -410,6 +412,10 @@ nonboolopts = (
41 "Prefix to the binary tools to use (gcc, ld, etc.)\n"
42 "For cross-compiling, or building with multiple local toolchains.\n"
43 ),
44 + # If build and target platform are different, then redefining target
45 + # platform might be necessary to use better build flags
46 + ("target_platform", sys.platform,
47 + "target platform for cross-compiling (linux, darwin, etc.)"),
48 ("target_python", def_target_python, "target Python version as command"),
49 )
50
51 @@ -878,13 +884,16 @@ have_valgrind = False
52 # per SCons 4.0.1 doc: Section 23.9. Not Configuring When Cleaning Targets
53 if not cleaning and not helping:
54 # OS X aliases gcc to clang
55 + if (sys.platform != config.env['target_platform']):
56 + announce("Target system is: %s" % config.env['target_platform'])
57 +
58 announce("cc is %s, version %s" % (env['CC'], env['CCVERSION']))
59 # clang accepts -pthread, then warns it is unused.
60 if not config.CheckCC():
61 announce("ERROR: CC doesn't work")
62
63 if ((config.CheckCompilerOption("-pthread") and
64 - not sys.platform.startswith('darwin'))):
65 + not config.env['target_platform'].startswith('darwin'))):
66 config.env.MergeFlags("-pthread")
67
68 confdefs = ["/* gpsd_config.h generated by scons, do not hand-hack. */\n"]
69 @@ -935,7 +944,7 @@ if not cleaning and not helping:
70 # confdefs.append('#endif\n')
71 # Reinstated for FreeBSD (below) 16-Aug-2019
72
73 - if sys.platform.startswith('linux'):
74 + if config.env['target_platform'].startswith('linux'):
75 # for cfmakeraw(), strsep(), etc. on CentOS 7
76 # glibc 2.19 and before
77 # sets __USE_MISC
78 @@ -947,7 +956,7 @@ if not cleaning and not helping:
79 confdefs.append('#if !defined(_GNU_SOURCE)')
80 confdefs.append('#define _GNU_SOURCE 1')
81 confdefs.append('#endif\n')
82 - elif sys.platform.startswith('darwin'):
83 + elif config.env['target_platform'].startswith('darwin'):
84 # strlcpy() and SIGWINCH need _DARWIN_C_SOURCE
85 confdefs.append('#if !defined(_DARWIN_C_SOURCE)')
86 confdefs.append('#define _DARWIN_C_SOURCE 1\n')
87 @@ -962,7 +971,7 @@ if not cleaning and not helping:
88 "-Wl,-compatibility_version,%s" % libgps_version,
89 "-Wl,-install_name,%s/$TARGET.srcpath" %
90 installdir('libdir', add_destdir=False)]
91 - elif sys.platform.startswith('freebsd'):
92 + elif config.env['target_platform'].startswith('freebsd'):
93 # for isascii(), putenv(), nice(), strptime()
94 confdefs.append('#if !defined(_XOPEN_SOURCE)')
95 confdefs.append('#define _XOPEN_SOURCE 700')
96 @@ -975,7 +984,7 @@ if not cleaning and not helping:
97 confdefs.append('#if !defined(__BSD_VISIBLE)')
98 confdefs.append("#define __BSD_VISIBLE 1\n")
99 confdefs.append('#endif\n')
100 - elif sys.platform.startswith('openbsd'):
101 + elif config.env['target_platform'].startswith('openbsd'):
102 # required to define u_int in sys/time.h
103 confdefs.append('#if !defined(_BSD_SOURCE)')
104 confdefs.append("#define _BSD_SOURCE 1\n")
105 @@ -984,12 +993,12 @@ if not cleaning and not helping:
106 confdefs.append('#if !defined(__BSD_VISIBLE)')
107 confdefs.append("#define __BSD_VISIBLE 1\n")
108 confdefs.append('#endif\n')
109 - elif sys.platform.startswith('netbsd'):
110 + elif config.env['target_platform'].startswith('netbsd'):
111 # required to get strlcpy(), and more, from string.h
112 confdefs.append('#if !defined(_NETBSD_SOURCE)')
113 confdefs.append("#define _NETBSD_SOURCE 1\n")
114 confdefs.append('#endif\n')
115 - elif sys.platform.startswith('sunos5'):
116 + elif config.env['target_platform'].startswith('sunos5'):
117 # tested with gcc-5.5 on slowlaris 10
118 # required to get isascii(), and more, from ctype.h
119 confdefs.append('#if !defined(__XPG4_CHAR_CLASS__)')
120 @@ -1044,11 +1053,11 @@ if not cleaning and not helping:
121 ncurseslibs = ['!ncurses5-config --libs --cflags']
122 elif WhereIs('ncursesw5-config'):
123 ncurseslibs = ['!ncursesw5-config --libs --cflags']
124 - elif sys.platform.startswith('freebsd'):
125 + elif config.env['target_platform'].startswith('freebsd'):
126 ncurseslibs = ['-lncurses']
127 - elif (sys.platform.startswith('darwin') or
128 - sys.platform.startswith('openbsd') or
129 - sys.platform.startswith('sunos5')):
130 + elif (config.env['target_platform'].startswith('darwin') or
131 + config.env['target_platform'].startswith('openbsd') or
132 + config.env['target_platform'].startswith('sunos5')):
133 ncurseslibs = ['-lcurses']
134 else:
135 announce('Turning off ncurses support, library not found.')
136 @@ -1064,7 +1073,8 @@ if not cleaning and not helping:
137 announce("pkg_config is confused about the state "
138 "of libusb-1.0.")
139 usbflags = []
140 - elif sys.platform.startswith("freebsd"):
141 + elif config.env['target_platform'].startswith('freebsd'):
142 + # FIXME: shold directly test for libusb existence.
143 confdefs.append("#define HAVE_LIBUSB 1\n")
144 usbflags = ["-lusb"]
145 else:
146 @@ -2498,8 +2508,11 @@ if qt_env:
147 binaryinstall.append(GPSLibraryInstall(qt_env, installdir('libdir'),
148 compiled_qgpsmmlib, libgps_version))
149
150 -if ((not env['debug'] and not env['debug_opt'] and not env['profiling'] and
151 - not env['nostrip'] and not sys.platform.startswith('darwin'))):
152 +if ((not env['debug'] and
153 + not env['debug_opt'] and
154 + not env['profiling'] and
155 + not env['nostrip'] and
156 + not env['target_platform'].startswith('darwin'))):
157 env.AddPostAction(binaryinstall, '$STRIP $TARGET')
158
159 binaryinstall.append(env.Install(installdir('bindir'), bin_scripts))