0001-Fix-errors-during-gpsd-3.20-cross-compilation.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From 727c37ef78f2229998ac51942f5d11c754d0c6b9 Mon Sep 17 00:00:00 2001
  2. From: Robert Hancock <hancock@sedsystems.ca>
  3. Date: Mon, 13 Jul 2020 17:33:48 -0600
  4. Subject: [PATCH] Fix errors during gpsd 3.20 cross-compilation
  5. Adapt some post-3.20 changes to the gpsd SConstruct file from the
  6. gpsd master branch to fix issues when cross-compiling. Original
  7. commits did not cherry-pick cleanly onto 3.20 due to other
  8. upstream changes.
  9. Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
  10. ---
  11. SConstruct | 81 ++++++++++++++++++++++--------------------------------
  12. 1 file changed, 33 insertions(+), 48 deletions(-)
  13. diff --git a/SConstruct b/SConstruct
  14. index 33e0ff326..93e8fcfea 100644
  15. --- a/SConstruct
  16. +++ b/SConstruct
  17. @@ -386,13 +386,16 @@ env['SC_PYTHON'] = sys.executable # Path to SCons Python
  18. # So we rely on MergeFlags/ParseFlags to do the right thing for us.
  19. env['STRIP'] = "strip"
  20. env['PKG_CONFIG'] = "pkg-config"
  21. -for i in ["AR", "CC", "CXX", "LD",
  22. - "PKG_CONFIG", "STRIP", "TAR"]:
  23. +for i in ["AR", # linker for static libs, usually "ar"
  24. + "CC",
  25. + "CXX",
  26. + # "LD", # scons does not use LD, usually "ld"
  27. + "PKG_CONFIG",
  28. + "SHLINK", # linker for shared libs, usually "gcc" or "g++", NOT "ld"
  29. + "STRIP",
  30. + "TAR"]:
  31. if i in os.environ:
  32. - j = i
  33. - if i == "LD":
  34. - i = "SHLINK"
  35. - env[i] = os.getenv(j)
  36. + env[i] = os.getenv(i)
  37. for i in ["ARFLAGS", "CFLAGS", "CXXFLAGS", "LDFLAGS", "SHLINKFLAGS",
  38. "CPPFLAGS", "CCFLAGS", "LINKFLAGS"]:
  39. if i in os.environ:
  40. @@ -483,7 +486,7 @@ devenv = (("ADDR2LINE", "addr2line"),
  41. ("GCCBUG", "gccbug"),
  42. ("GCOV", "gcov"),
  43. ("GPROF", "gprof"),
  44. - ("LD", "ld"),
  45. + # ("LD", "ld"), # scons does not use LD
  46. ("NM", "nm"),
  47. ("OBJCOPY", "objcopy"),
  48. ("OBJDUMP", "objdump"),
  49. @@ -565,6 +568,22 @@ def CheckXsltproc(context):
  50. return ret
  51. +def CheckTime_t(context):
  52. + context.Message('Checking if sizeof(time_t) is 64 bits... ')
  53. + ret = context.TryLink("""
  54. + #include <time.h>
  55. +
  56. + int main(int argc, char **argv) {
  57. + static int test_array[1 - 2 * ((long int) sizeof(time_t) < 8 )];
  58. + test_array[0] = 0;
  59. + (void) argc; (void) argv;
  60. + return 0;
  61. + }
  62. + """, '.c')
  63. + context.Result(ret)
  64. + return ret
  65. +
  66. +
  67. def CheckCompilerOption(context, option):
  68. context.Message('Checking if compiler accepts %s... ' % (option,))
  69. old_CFLAGS = context.env['CFLAGS'][:] # Get a *copy* of the old list
  70. @@ -597,42 +616,6 @@ def CheckHeaderDefines(context, file, define):
  71. return ret
  72. -def CheckSizeOf(context, type):
  73. - """Check sizeof 'type'"""
  74. - context.Message('Checking size of ' + type + '... ')
  75. -
  76. - program = """
  77. -#include <stdlib.h>
  78. -#include <stdio.h>
  79. -
  80. -/*
  81. - * The CheckSizeOf function does not have a way for the caller to
  82. - * specify header files to be included to provide the type being
  83. - * checked. As a workaround until that is remedied, include the
  84. - * header required for time_t, which is the sole current use of this
  85. - * function.
  86. - */
  87. -#include <time.h>
  88. -
  89. -int main() {
  90. - printf("%d", (int)sizeof(""" + type + """));
  91. - return 0;
  92. -}
  93. -"""
  94. -
  95. - # compile it
  96. - ret = context.TryCompile(program, '.c')
  97. - if 0 == ret:
  98. - announce('ERROR: TryCompile failed\n')
  99. - # fall back to sizeof(time_t) is 8
  100. - return '8'
  101. -
  102. - # run it
  103. - ret = context.TryRun(program, '.c')
  104. - context.Result(ret[0])
  105. - return ret[1]
  106. -
  107. -
  108. def CheckCompilerDefines(context, define):
  109. context.Message('Checking if compiler supplies %s... ' % (define,))
  110. ret = context.TryLink("""
  111. @@ -708,8 +691,8 @@ config = Configure(env, custom_tests={
  112. 'CheckCompilerOption': CheckCompilerOption,
  113. 'CheckHeaderDefines': CheckHeaderDefines,
  114. 'CheckPKG': CheckPKG,
  115. - 'CheckSizeOf': CheckSizeOf,
  116. 'CheckXsltproc': CheckXsltproc,
  117. + 'CheckTime_t': CheckTime_t,
  118. 'GetPythonValue': GetPythonValue,
  119. })
  120. @@ -1043,11 +1026,13 @@ else:
  121. confdefs.append("/* #undef HAVE_%s_H */\n"
  122. % hdr.replace("/", "_").upper())
  123. - sizeof_time_t = config.CheckSizeOf("time_t")
  124. - confdefs.append("#define SIZEOF_TIME_T %s\n" % sizeof_time_t)
  125. - announce("sizeof(time_t) is %s" % sizeof_time_t)
  126. - if 4 >= int(sizeof_time_t):
  127. + if 0 == config.CheckTime_t():
  128. announce("WARNING: time_t is too small. It will fail in 2038")
  129. + sizeof_time_t = 4
  130. + else:
  131. + sizeof_time_t = 8
  132. +
  133. + confdefs.append("#define SIZEOF_TIME_T %s\n" % sizeof_time_t)
  134. # check function after libraries, because some function require libraries
  135. # for example clock_gettime() require librt on Linux glibc < 2.17
  136. --
  137. 2.18.4