You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
7.4 KiB

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