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.

126 lines
5.4 KiB

  1. From 5f9513eb341d520d10c48f8ba2bd145063405fdd Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Sat, 10 Dec 2016 18:08:05 +0100
  4. Subject: [PATCH 23/23] build: take compiler options from environment
  5. This makes it possible to compile IoTivity with custom compiler
  6. options. This way someone can use optimized compiler settings for the
  7. target CPU. I want to use this in OpenWrt / LEDE to build specific
  8. IoTivity binaries for each CPU architecture, there the build system
  9. provides the matching compiler options.
  10. Change-Id: I86772f73b81c41d7e96e51b434fd9e3b4992753a
  11. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  12. ---
  13. build_common/SConscript | 25 +++++++++++++++++++++
  14. build_common/linux/SConscript | 27 ++++++++++++-----------
  15. resource/csdk/connectivity/build/linux/SConscript | 27 ++++++++++++-----------
  16. 3 files changed, 53 insertions(+), 26 deletions(-)
  17. --- a/build_common/SConscript
  18. +++ b/build_common/SConscript
  19. @@ -120,6 +120,7 @@ help_vars.Add(PathVariable('ANDROID_NDK'
  20. help_vars.Add(PathVariable('ANDROID_HOME', 'Android SDK path', None, PathVariable.PathAccept))
  21. help_vars.Add(PathVariable('ANDROID_GRADLE', 'Gradle binary file', None, PathVariable.PathIsFile))
  22. help_vars.Add(EnumVariable('WITH_UPSTREAM_LIBCOAP', 'Use latest stable version of LibCoAP downloaded from github', default_with_upstream_libcoap, allowed_values=('0','1')))
  23. +help_vars.Add(BoolVariable('WITH_ENV', 'Use compiler options from environment', False))
  24. AddOption('--prefix',
  25. dest='prefix',
  26. @@ -153,6 +154,30 @@ else:
  27. )
  28. Help(help_vars.GenerateHelpText(env))
  29. +if env.get('WITH_ENV'):
  30. + env['ENV'] = os.environ
  31. + if 'CC' in os.environ:
  32. + env['CC'] = Split(os.environ['CC'])
  33. + print "using CC from environment: %s" % env['CC']
  34. + if 'CXX' in os.environ:
  35. + env['CXX'] = Split(os.environ['CXX'])
  36. + print "using CXX from environment: %s" % env['CXX']
  37. + if 'CFLAGS' in os.environ:
  38. + env['CFLAGS'] = Split(os.environ['CFLAGS'])
  39. + print "using CFLAGS from environment: %s" % env['CFLAGS']
  40. + if 'CXXFLAGS' in os.environ:
  41. + env['CXXFLAGS'] = Split(os.environ['CXXFLAGS'])
  42. + print "using CXXFLAGS from environment: %s" % env['CXXFLAGS']
  43. + if 'CCFLAGS' in os.environ:
  44. + env['CCFLAGS'] = Split(os.environ['CCFLAGS'])
  45. + print "using CCFLAGS from environment: %s" % env['CCFLAGS']
  46. + if 'CPPFLAGS' in os.environ:
  47. + env['CPPFLAGS'] = Split(os.environ['CPPFLAGS'])
  48. + print "using CPPFLAGS from environment: %s" % env['CPPFLAGS']
  49. + if 'LDFLAGS' in os.environ:
  50. + env['LINKFLAGS'] = Split(os.environ['LDFLAGS'])
  51. + print "using LDFLAGS/LINKFLAGS from environment: %s" % env['LINKFLAGS']
  52. +
  53. tc_set_msg = '''
  54. ************************************ Warning **********************************
  55. * Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
  56. --- a/build_common/linux/SConscript
  57. +++ b/build_common/linux/SConscript
  58. @@ -23,16 +23,17 @@ env.AppendUnique(CCFLAGS = ['-Wall', '-W
  59. env.AppendUnique(LIBS = ['dl', 'pthread', 'uuid'])
  60. # Set arch flags that match best TARGET_ARCH variable
  61. -target_arch = env.get('TARGET_ARCH')
  62. -if target_arch in ['x86']:
  63. - env.AppendUnique(CCFLAGS = ['-m32'])
  64. - env.AppendUnique(LINKFLAGS = ['-m32'])
  65. -elif target_arch in ['x86_64']:
  66. - env.AppendUnique(CCFLAGS = ['-m64'])
  67. - env.AppendUnique(LINKFLAGS = ['-m64'])
  68. -elif target_arch in ['arm']:
  69. - env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
  70. -elif target_arch in ['arm-v7a', 'armeabi-v7a']:
  71. - env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
  72. -elif target_arch.find('arm64') > 0:
  73. - env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
  74. +if not env.get('WITH_ENV'):
  75. + target_arch = env.get('TARGET_ARCH')
  76. + if target_arch in ['x86']:
  77. + env.AppendUnique(CCFLAGS = ['-m32'])
  78. + env.AppendUnique(LINKFLAGS = ['-m32'])
  79. + elif target_arch in ['x86_64']:
  80. + env.AppendUnique(CCFLAGS = ['-m64'])
  81. + env.AppendUnique(LINKFLAGS = ['-m64'])
  82. + elif target_arch in ['arm']:
  83. + env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
  84. + elif target_arch in ['arm-v7a', 'armeabi-v7a']:
  85. + env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
  86. + elif target_arch.find('arm64') > 0:
  87. + env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
  88. --- a/resource/csdk/connectivity/build/linux/SConscript
  89. +++ b/resource/csdk/connectivity/build/linux/SConscript
  90. @@ -22,16 +22,17 @@ env.AppendUnique(CCFLAGS = ['-Wall', '-f
  91. env.AppendUnique(LIBS = ['dl', 'pthread'])
  92. # Set arch flags
  93. -target_arch = env.get('TARGET_ARCH')
  94. -if target_arch in ['x86']:
  95. - env.AppendUnique(CCFLAGS = ['-m32'])
  96. - env.AppendUnique(LINKFLAGS = ['-m32'])
  97. -elif target_arch in ['x86_64']:
  98. - env.AppendUnique(CCFLAGS = ['-m64'])
  99. - env.AppendUnique(LINKFLAGS = ['-m64'])
  100. -elif target_arch in ['arm']:
  101. - env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
  102. -elif target_arch in ['arm-v7a', 'armeabi-v7a']:
  103. - env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
  104. -elif target_arch.find('arm64') > 0:
  105. - env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
  106. +if not env.get('WITH_ENV'):
  107. + target_arch = env.get('TARGET_ARCH')
  108. + if target_arch in ['x86']:
  109. + env.AppendUnique(CCFLAGS = ['-m32'])
  110. + env.AppendUnique(LINKFLAGS = ['-m32'])
  111. + elif target_arch in ['x86_64']:
  112. + env.AppendUnique(CCFLAGS = ['-m64'])
  113. + env.AppendUnique(LINKFLAGS = ['-m64'])
  114. + elif target_arch in ['arm']:
  115. + env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
  116. + elif target_arch in ['arm-v7a', 'armeabi-v7a']:
  117. + env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
  118. + elif target_arch.find('arm64') > 0:
  119. + env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])