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.

125 lines
5.0KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_c_compile_value.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_C_COMPILE_VALUE (COMPILE-VALUE, ALIAS, INCLUDES)
  8. #
  9. # DESCRIPTION
  10. #
  11. # The AX_C_COMPILE_VALUE macro determines a compile time value by
  12. # generating the object code and reading the value from the code. Static
  13. # data initializers like sizeof(int) are unavailable to preprocessor. The
  14. # macro calculates the values known to compiler's static initializer.
  15. #
  16. # Assumptions: The sought value should not exceed 65535. The shell
  17. # interpreter and the sed utility are expected to exist and work similarly
  18. # across possible build platforms.
  19. #
  20. # Result: The resulting configure script will generate the preprocessor
  21. # symbol definition:
  22. #
  23. # #define COMPILE_VALUE_<ALIAS> <NUMBER>
  24. #
  25. # It was important that the value was embedded into the object file in a
  26. # predefined byte order during the test. This ensured that the result was
  27. # independent from the target platform's byte order.
  28. #
  29. # The existing AC_CHECK_SIZEOF macro also computes the size of the given
  30. # type without running the test program. However, the existing macro will
  31. # produce a piece of configure script that will take the time proportional
  32. # to the logarithm of the sought value.
  33. #
  34. # Example of use in configure.in:
  35. #
  36. # AX_C_COMPILE_VALUE(sizeof(int), sizeof_int)
  37. # AX_C_COMPILE_VALUE([sizeof(int[[543]])], sizeof_int543)
  38. #
  39. # As a result of running the generated configure script, the following
  40. # definition will appear in config.h:
  41. #
  42. # #define COMPILE_VALUE_SIZEOF_INT 4
  43. # #define COMPILE_VALUE_SIZEOF_INT543 2172
  44. #
  45. # LICENSE
  46. #
  47. # Copyright (c) 2008 Ilguiz Latypov
  48. #
  49. # This program is free software; you can redistribute it and/or modify it
  50. # under the terms of the GNU General Public License as published by the
  51. # Free Software Foundation; either version 2 of the License, or (at your
  52. # option) any later version.
  53. #
  54. # This program is distributed in the hope that it will be useful, but
  55. # WITHOUT ANY WARRANTY; without even the implied warranty of
  56. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  57. # Public License for more details.
  58. #
  59. # You should have received a copy of the GNU General Public License along
  60. # with this program. If not, see <https://www.gnu.org/licenses/>.
  61. #
  62. # As a special exception, the respective Autoconf Macro's copyright owner
  63. # gives unlimited permission to copy, distribute and modify the configure
  64. # scripts that are the output of Autoconf when processing the Macro. You
  65. # need not follow the terms of the GNU General Public License when using
  66. # or distributing such scripts, even though portions of the text of the
  67. # Macro appear in them. The GNU General Public License (GPL) does govern
  68. # all other use of the material that constitutes the Autoconf Macro.
  69. #
  70. # This special exception to the GPL applies to versions of the Autoconf
  71. # Macro released by the Autoconf Archive. When you make and distribute a
  72. # modified version of the Autoconf Macro, you may extend this special
  73. # exception to the GPL to apply to your modified version as well.
  74. #serial 7
  75. ## Portability defines that help interoperate with classic and modern autoconfs
  76. ifdef([AC_TR_SH],[
  77. define([AC_TR_SH_REUSE],[AC_TR_SH([$1])])
  78. define([AC_TR_CPP_REUSE],[AC_TR_CPP([$1])])
  79. ], [
  80. define([AC_TR_SH_REUSE],
  81. [patsubst(translit([[$1]], [*+], [pp]), [[^a-zA-Z0-9_]], [_])])
  82. define([AC_TR_CPP_REUSE],
  83. [patsubst(translit([[$1]],
  84. [*abcdefghijklmnopqrstuvwxyz],
  85. [PABCDEFGHIJKLMNOPQRSTUVWXYZ]),
  86. [[^A-Z0-9_]], [_])])
  87. ])
  88. AC_DEFUN([AX_C_COMPILE_VALUE], [
  89. pushdef([ac_c_compile_value],
  90. AC_TR_SH_REUSE([ac_cv_c_compile_value_$2]))dnl
  91. ac_c_compile_value_expand="$1"
  92. AC_CACHE_CHECK([value of $1 by analyzing object code],
  93. ac_c_compile_value, [
  94. save_CFLAGS="$CFLAGS"
  95. CFLAGS="$CFLAGS -c -o conftest.o"
  96. AC_TRY_COMPILE([$3
  97. #include <stddef.h>
  98. #include <stdint.h>
  99. #include <stdlib.h>
  100. #define COMPILE_VALUE $ac_c_compile_value_expand
  101. #define HEX_DIGIT(n) ((n) >= 10 ? 'a' + (n) - 10 : '0' + (n))
  102. char object_code_block[] = {
  103. '\n', 'e', '4', 'V', 'A',
  104. '0', 'x',
  105. (char) HEX_DIGIT((((COMPILE_VALUE / 16) / 16) / 16) % 16),
  106. (char) HEX_DIGIT(((COMPILE_VALUE / 16) / 16) % 16),
  107. (char) HEX_DIGIT((COMPILE_VALUE / 16) % 16),
  108. (char) HEX_DIGIT(COMPILE_VALUE % 16),
  109. 'Y', '3', 'p', 'M', '\n'
  110. };],
  111. [],
  112. [ac_c_compile_value=`
  113. typeset -i n=\`sed -ne 's/^e4VA0x\(.*\)Y3pM$/0x\1/p' < conftest.o\`;
  114. echo $n`],
  115. [ac_c_compile_value=0])
  116. CFLAGS="$save_CFLAGS"])
  117. AC_DEFINE_UNQUOTED(AC_TR_CPP_REUSE(compile_value_$2),
  118. [$[]ac_c_compile_value],
  119. [$1])
  120. popdef([ac_c_compile_value])dnl
  121. ])