Collection of DPF-based plugins for packaging
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.

112 lines
4.1KB

  1. # ==============================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
  3. # ==============================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_COMPILER_FLAGS_LDFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Add warning flags for the linker to VARIABLE, which defaults to
  12. # WARN_LDFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be
  13. # manually added to the LDFLAGS variable for each target in the code base.
  14. #
  15. # This macro depends on the environment set up by AX_COMPILER_FLAGS.
  16. # Specifically, it uses the value of $ax_enable_compile_warnings to decide
  17. # which flags to enable.
  18. #
  19. # LICENSE
  20. #
  21. # Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
  22. # Copyright (c) 2017, 2018 Reini Urban <rurban@cpan.org>
  23. #
  24. # Copying and distribution of this file, with or without modification, are
  25. # permitted in any medium without royalty provided the copyright notice
  26. # and this notice are preserved. This file is offered as-is, without any
  27. # warranty.
  28. #serial 9
  29. AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
  30. AX_REQUIRE_DEFINED([AX_APPEND_LINK_FLAGS])
  31. AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
  32. AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
  33. AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
  34. # Variable names
  35. m4_define([ax_warn_ldflags_variable],
  36. [m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))])
  37. # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
  38. # flags, otherwise they are always appended to the warn_ldflags variable,
  39. # and Clang warns on them for every compilation unit.
  40. # If this is passed to GCC, it will explode, so the flag must be enabled
  41. # conditionally.
  42. AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
  43. ax_compiler_flags_test="-Werror=unknown-warning-option"
  44. ],[
  45. ax_compiler_flags_test=""
  46. ])
  47. AX_CHECK_LINK_FLAG([-Wl,--as-needed], [
  48. AX_APPEND_LINK_FLAGS([-Wl,--as-needed],
  49. [AM_LDFLAGS],[$ax_compiler_flags_test])
  50. ])
  51. AX_CHECK_LINK_FLAG([-Wl,-z,relro], [
  52. AX_APPEND_LINK_FLAGS([-Wl,-z,relro],
  53. [AM_LDFLAGS],[$ax_compiler_flags_test])
  54. ])
  55. AX_CHECK_LINK_FLAG([-Wl,-z,now], [
  56. AX_APPEND_LINK_FLAGS([-Wl,-z,now],
  57. [AM_LDFLAGS],[$ax_compiler_flags_test])
  58. ])
  59. AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [
  60. AX_APPEND_LINK_FLAGS([-Wl,-z,noexecstack],
  61. [AM_LDFLAGS],[$ax_compiler_flags_test])
  62. ])
  63. # textonly, retpolineplt not yet
  64. # macOS and cygwin linker do not have --as-needed
  65. AX_CHECK_LINK_FLAG([-Wl,--no-as-needed], [
  66. ax_compiler_flags_as_needed_option="-Wl,--no-as-needed"
  67. ], [
  68. ax_compiler_flags_as_needed_option=""
  69. ])
  70. # macOS linker speaks with a different accent
  71. ax_compiler_flags_fatal_warnings_option=""
  72. AX_CHECK_LINK_FLAG([-Wl,--fatal-warnings], [
  73. ax_compiler_flags_fatal_warnings_option="-Wl,--fatal-warnings"
  74. ])
  75. AX_CHECK_LINK_FLAG([-Wl,-fatal_warnings], [
  76. ax_compiler_flags_fatal_warnings_option="-Wl,-fatal_warnings"
  77. ])
  78. # Base flags
  79. AX_APPEND_LINK_FLAGS([ dnl
  80. $ax_compiler_flags_as_needed_option dnl
  81. $3 dnl
  82. ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
  83. AS_IF([test "$ax_enable_compile_warnings" != "no"],[
  84. # "yes" flags
  85. AX_APPEND_LINK_FLAGS([$4 $5 $6 $7],
  86. ax_warn_ldflags_variable,
  87. [$ax_compiler_flags_test])
  88. ])
  89. AS_IF([test "$ax_enable_compile_warnings" = "error"],[
  90. # "error" flags; -Werror has to be appended unconditionally because
  91. # it's not possible to test for
  92. #
  93. # suggest-attribute=format is disabled because it gives too many false
  94. # positives
  95. AX_APPEND_LINK_FLAGS([ dnl
  96. $ax_compiler_flags_fatal_warnings_option dnl
  97. ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
  98. ])
  99. # Substitute the variables
  100. AC_SUBST(ax_warn_ldflags_variable)
  101. ])dnl AX_COMPILER_FLAGS