ax_linuxkm.m4 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # ax_linuxkm.m4 -- macros for getting attributes of default configured kernel
  2. #
  3. # Copyright (C) 2006-2024 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. AC_DEFUN([AC_PATH_DEFAULT_KERNEL_SOURCE],
  21. [
  22. AC_MSG_CHECKING([for default kernel build root])
  23. if test -d /lib/modules/`uname -r`/build/.config; then
  24. DEFAULT_KERNEL_ROOT=/lib/modules/`uname -r`/build
  25. AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT])
  26. elif test -r /usr/src/linux/.config; then
  27. DEFAULT_KERNEL_ROOT=/usr/src/linux
  28. AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT])
  29. else
  30. AC_MSG_RESULT([no default configured kernel found])
  31. fi
  32. ])
  33. AC_DEFUN([AC_DEFAULT_KERNEL_ARCH],
  34. [
  35. AC_REQUIRE([AC_PROG_AWK])
  36. AC_MSG_CHECKING([for default kernel arch])
  37. if test -f ${KERNEL_ROOT}/.config; then
  38. # "# Linux/x86 5.8.1-gentoo Kernel Configuration"
  39. DEFAULT_KERNEL_ARCH=`$AWK '/^# Linux/\
  40. {split($[]2,arch_fields,"/"); print arch_fields[[2]]; exit(0);}' ${KERNEL_ROOT}/.config`
  41. fi
  42. if test -n "$DEFAULT_KERNEL_ARCH"; then
  43. AC_MSG_RESULT([$DEFAULT_KERNEL_ARCH])
  44. else
  45. AC_MSG_RESULT([no default configured kernel arch found])
  46. fi
  47. ])
  48. AC_DEFUN([AX_SIMD_CC_COMPILER_FLAGS], [
  49. AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
  50. AC_REQUIRE([AX_VCS_CHECKOUT])
  51. AC_REQUIRE([AX_DEBUG])
  52. AC_LANG_PUSH([C])
  53. if test "$CFLAGS_FPU_DISABLE" = ""; then
  54. AX_APPEND_COMPILE_FLAGS([-mno-80387],[CFLAGS_FPU_DISABLE])
  55. AX_APPEND_COMPILE_FLAGS([-mno-fp-ret-in-387],[CFLAGS_FPU_DISABLE])
  56. AX_APPEND_COMPILE_FLAGS([-mno-fpu],[CFLAGS_FPU_DISABLE])
  57. fi
  58. if test "$CFLAGS_FPU_ENABLE" = ""; then
  59. AX_APPEND_COMPILE_FLAGS([-m80387],[CFLAGS_FPU_ENABLE])
  60. AX_APPEND_COMPILE_FLAGS([-mfpu],[CFLAGS_FPU_ENABLE])
  61. fi
  62. if test "$CFLAGS_SIMD_DISABLE" = ""; then
  63. AX_APPEND_COMPILE_FLAGS([-mno-sse],[CFLAGS_SIMD_DISABLE])
  64. AX_APPEND_COMPILE_FLAGS([-mgeneral-regs-only],[CFLAGS_SIMD_DISABLE])
  65. fi
  66. if test "$CFLAGS_SIMD_ENABLE" = ""; then
  67. AX_APPEND_COMPILE_FLAGS([-msse],[CFLAGS_SIMD_ENABLE])
  68. AX_APPEND_COMPILE_FLAGS([-mmmx],[CFLAGS_SIMD_ENABLE])
  69. AX_APPEND_COMPILE_FLAGS([-msse2],[CFLAGS_SIMD_ENABLE])
  70. AX_APPEND_COMPILE_FLAGS([-msse4],[CFLAGS_SIMD_ENABLE])
  71. AX_APPEND_COMPILE_FLAGS([-mavx],[CFLAGS_SIMD_ENABLE])
  72. AX_APPEND_COMPILE_FLAGS([-mavx2],[CFLAGS_SIMD_ENABLE])
  73. AX_APPEND_COMPILE_FLAGS([-mno-general-regs-only],[CFLAGS_SIMD_ENABLE])
  74. fi
  75. if test "$CFLAGS_AUTO_VECTORIZE_DISABLE" = ""; then
  76. AX_APPEND_COMPILE_FLAGS([-fno-builtin],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  77. AX_APPEND_COMPILE_FLAGS([-fno-tree-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  78. AX_APPEND_COMPILE_FLAGS([-fno-tree-loop-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  79. AX_APPEND_COMPILE_FLAGS([-fno-tree-slp-vectorize],[CFLAGS_AUTO_VECTORIZE_DISABLE])
  80. fi
  81. if test "$CFLAGS_AUTO_VECTORIZE_ENABLE" = ""; then
  82. AX_APPEND_COMPILE_FLAGS([-fbuiltin],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  83. AX_APPEND_COMPILE_FLAGS([-ftree-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  84. AX_APPEND_COMPILE_FLAGS([-ftree-loop-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  85. AX_APPEND_COMPILE_FLAGS([-ftree-slp-vectorize],[CFLAGS_AUTO_VECTORIZE_ENABLE])
  86. fi
  87. case "$host_cpu" in
  88. x86_64)
  89. # note that gnu as accepts archs of the form -march=+no387, signifying the
  90. # default target arch modified with no387. by default, we use that here.
  91. if test "$ASFLAGS_FPU_DISABLE_SIMD_ENABLE" = ""; then
  92. 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])
  93. fi
  94. if test "$ASFLAGS_FPU_ENABLE_SIMD_DISABLE" = ""; then
  95. 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])
  96. fi
  97. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  98. 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])
  99. fi
  100. if test "$ASFLAGS_FPUSIMD_ENABLE" = ""; then
  101. 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])
  102. fi
  103. ;;
  104. aarch64)
  105. if test "$BASE_TARGET_ARCH" = ""; then
  106. BASE_TARGET_ARCH=all
  107. fi
  108. if test "$ASFLAGS_FPU_DISABLE_SIMD_ENABLE" = ""; then
  109. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+simd"],[ASFLAGS_FPU_DISABLE_SIMD_ENABLE])
  110. fi
  111. if test "$ASFLAGS_FPU_ENABLE_SIMD_DISABLE" = ""; then
  112. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+fpu+nosimd"],[ASFLAGS_FPU_ENABLE_SIMD_DISABLE])
  113. fi
  114. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  115. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+nosimd"],[ASFLAGS_FPUSIMD_DISABLE])
  116. fi
  117. if test "$ASFLAGS_FPUSIMD_ENABLE" = ""; then
  118. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+fpu+simd"],[ASFLAGS_FPUSIMD_ENABLE])
  119. fi
  120. ;;
  121. *)
  122. # fall back to defining only $ASFLAGS_FPUSIMD_DISABLE
  123. if test "$BASE_TARGET_ARCH" = ""; then
  124. BASE_TARGET_ARCH=all
  125. fi
  126. if test "$ASFLAGS_FPUSIMD_DISABLE" = ""; then
  127. AX_APPEND_COMPILE_FLAGS([-Wa,-march="${BASE_TARGET_ARCH}+nofpu+nosimd"],[ASFLAGS_FPUSIMD_DISABLE])
  128. fi
  129. ;;
  130. esac
  131. AC_LANG_POP
  132. ])