ax_linuxkm.m4 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # ax_linuxkm.m4 -- macros for getting attributes of default configured kernel
  2. #
  3. # Copyright (C) 2006-2021 wolfSSL Inc.
  4. #
  5. # This file is part of wolfSSL.
  6. #
  7. # wolfSSL is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # wolfSSL is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. #/
  21. AC_DEFUN([AC_PATH_DEFAULT_KERNEL_SOURCE],
  22. [
  23. AC_MSG_CHECKING([for default kernel build root])
  24. if test -d /lib/modules/`uname -r`/build/.config; then
  25. DEFAULT_KERNEL_ROOT=/lib/modules/`uname -r`/build
  26. AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT])
  27. elif test -r /usr/src/linux/.config; then
  28. DEFAULT_KERNEL_ROOT=/usr/src/linux
  29. AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT])
  30. else
  31. AC_MSG_RESULT([no default configured kernel found])
  32. fi
  33. ])
  34. AC_DEFUN([AC_DEFAULT_KERNEL_ARCH],
  35. [
  36. AC_REQUIRE([AC_PROG_AWK])
  37. AC_MSG_CHECKING([for default kernel arch])
  38. if test -f ${KERNEL_ROOT}/.config; then
  39. # "# Linux/x86 5.8.1-gentoo Kernel Configuration"
  40. DEFAULT_KERNEL_ARCH=`$AWK '/^# Linux/\
  41. {split($[]2,arch_fields,"/"); print arch_fields[[2]]; exit(0);}' ${KERNEL_ROOT}/.config`
  42. fi
  43. if test -n "$DEFAULT_KERNEL_ARCH"; then
  44. AC_MSG_RESULT([$DEFAULT_KERNEL_ARCH])
  45. else
  46. AC_MSG_RESULT([no default configured kernel arch found])
  47. fi
  48. ])
  49. AC_DEFUN([AX_SIMD_CC_COMPILER_FLAGS], [
  50. AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
  51. AC_REQUIRE([AX_VCS_CHECKOUT])
  52. AC_REQUIRE([AX_DEBUG])
  53. AC_LANG_PUSH([C])
  54. if test "$CFLAGS_FPU_DISABLE" = ""; then
  55. AX_APPEND_COMPILE_FLAGS([-mno-80387],[CFLAGS_FPU_DISABLE])
  56. AX_APPEND_COMPILE_FLAGS([-mno-fp-ret-in-387],[CFLAGS_FPU_DISABLE])
  57. AX_APPEND_COMPILE_FLAGS([-mno-fpu],[CFLAGS_FPU_DISABLE])
  58. fi
  59. if test "$CFLAGS_FPU_ENABLE" = ""; then
  60. AX_APPEND_COMPILE_FLAGS([-m80387],[CFLAGS_FPU_ENABLE])
  61. AX_APPEND_COMPILE_FLAGS([-mfpu],[CFLAGS_FPU_ENABLE])
  62. fi
  63. if test "$CFLAGS_SIMD_DISABLE" = ""; then
  64. AX_APPEND_COMPILE_FLAGS([-mno-sse],[CFLAGS_SIMD_DISABLE])
  65. AX_APPEND_COMPILE_FLAGS([-mgeneral-regs-only],[CFLAGS_SIMD_DISABLE])
  66. fi
  67. if test "$CFLAGS_SIMD_ENABLE" = ""; then
  68. AX_APPEND_COMPILE_FLAGS([-msse],[CFLAGS_SIMD_ENABLE])
  69. AX_APPEND_COMPILE_FLAGS([-mmmx],[CFLAGS_SIMD_ENABLE])
  70. AX_APPEND_COMPILE_FLAGS([-msse2],[CFLAGS_SIMD_ENABLE])
  71. AX_APPEND_COMPILE_FLAGS([-msse4],[CFLAGS_SIMD_ENABLE])
  72. AX_APPEND_COMPILE_FLAGS([-mavx],[CFLAGS_SIMD_ENABLE])
  73. AX_APPEND_COMPILE_FLAGS([-mavx2],[CFLAGS_SIMD_ENABLE])
  74. AX_APPEND_COMPILE_FLAGS([-mno-general-regs-only],[CFLAGS_SIMD_ENABLE])
  75. fi
  76. if test "$CFLAGS_AUTO_VECTORIZE_DISABLE" = ""; then
  77. AX_APPEND_COMPILE_FLAGS([-fno-builtin],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  78. AX_APPEND_COMPILE_FLAGS([-fno-tree-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  79. AX_APPEND_COMPILE_FLAGS([-fno-tree-loop-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  80. AX_APPEND_COMPILE_FLAGS([-fno-tree-slp-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  81. fi
  82. if test "$CFLAGS_AUTO_VECTORIZE_ENABLE" = ""; then
  83. AX_APPEND_COMPILE_FLAGS([-fbuiltin],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  84. AX_APPEND_COMPILE_FLAGS([-ftree-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  85. AX_APPEND_COMPILE_FLAGS([-ftree-loop-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  86. AX_APPEND_COMPILE_FLAGS([-ftree-slp-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  87. fi
  88. case "$host_cpu" in
  89. x86_64)
  90. # note that gnu as accepts archs of the form -march=+no387, signifying the
  91. # default target arch modified with no387. by default, we use that here.
  92. if test "$ASFLAGS_FPU_DISABLE_SIMD_ENABLE" = ""; then
  93. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+no87+no287+no387+no687+sse+sse2+sse3+ssse3+sse4.1+sse4.2+sse4+avx+avx2+avx512f"],[ASFLAGS_FPU_DISABLE_SIMD_ENABLE])
  94. fi
  95. if test "$ASFLAGS_FPU_ENABLE_SIMD_DISABLE" = ""; then
  96. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+387+687+nosse+nosse2+nosse3+nossse3+nosse4.1+nosse4.2+nosse4+noavx+noavx2+noavx512f"],[ASFLAGS_FPU_ENABLE_SIMD_DISABLE])
  97. fi
  98. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  99. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+no387+no687+nosse+nosse2+nosse3+nossse3+nosse4.1+nosse4.2+nosse4+noavx+noavx2+noavx512f"],[ASFLAGS_FPUSIMD_DISABLE])
  100. fi
  101. if test "$ASFLAGS_FPUSIMD_ENABLE" = ""; then
  102. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+387+687+sse+sse2+sse3+ssse3+sse4.1+sse4.2+sse4+avx+avx2+avx512f"],[ASFLAGS_FPUSIMD_ENABLE])
  103. fi
  104. ;;
  105. aarch64)
  106. if test "$BASE_TARGET_ARCH" = ""; then
  107. BASE_TARGET_ARCH=all
  108. fi
  109. if test "$ASFLAGS_FPU_DISABLE_SIMD_ENABLE" = ""; then
  110. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+simd"],[ASFLAGS_FPU_DISABLE_SIMD_ENABLE])
  111. fi
  112. if test "$ASFLAGS_FPU_ENABLE_SIMD_DISABLE" = ""; then
  113. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+fpu+nosimd"],[ASFLAGS_FPU_ENABLE_SIMD_DISABLE])
  114. fi
  115. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  116. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+nosimd"],[ASFLAGS_FPUSIMD_DISABLE])
  117. fi
  118. if test "$ASFLAGS_FPUSIMD_ENABLE" = ""; then
  119. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+fpu+simd"],[ASFLAGS_FPUSIMD_ENABLE])
  120. fi
  121. ;;
  122. *)
  123. # fall back to defining only $ASFLAGS_FPUSIMD_DISABLE
  124. if test "$BASE_TARGET_ARCH" = ""; then
  125. BASE_TARGET_ARCH=all
  126. fi
  127. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  128. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+nosimd"],[ASFLAGS_FPUSIMD_DISABLE])
  129. fi
  130. ;;
  131. esac
  132. AC_LANG_POP
  133. ])