make_buildopts_h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. GREP=${GREP:-grep}
  3. MD5=${MD5:-md5sum}
  4. cat << END
  5. /*
  6. * buildopts.h
  7. * Automatically generated
  8. */
  9. END
  10. if ${GREP} "AST_DEVMODE" makeopts | ${GREP} -q "yes"
  11. then
  12. echo "#define AST_DEVMODE 1"
  13. # AST_DEVMODE is no longer an API/ABI affecting option so it no longer
  14. # gets added to BUILDOPTS.
  15. fi
  16. ADD_CFLAGS_TO_BUILDOPTS=false
  17. MENUSELECT_CFLAGS=$(${GREP} -e "^MENUSELECT_CFLAGS" menuselect.makeopts)
  18. echo "$MENUSELECT_CFLAGS" | grep -q -e "ADD_CFLAGS_TO_BUILDOPTS_H" && ADD_CFLAGS_TO_BUILDOPTS=true
  19. # Clean up MENUSELECT_CFLAGS by removing the "MENUSELECT_CFLAGS="
  20. # at the front, the "ADD_CFLAGS_TO_BUILDOPTS_H" flag, and any "-D"
  21. # entries.
  22. MENUSELECT_CFLAGS=$( echo "$MENUSELECT_CFLAGS" | \
  23. sed -r -e "s/(MENUSELECT_CFLAGS=|ADD_CFLAGS_TO_BUILDOPTS_H|-D)//g")
  24. # This is a list of flags that don't affect the ABI.
  25. # "ADD_CFLAGS_TO_BUILDOPTS_H" is NOT set, we'll filter these
  26. # out of the buildopts.h file.
  27. #
  28. # These used to always be filtered out but if they're not in
  29. # buildopts.h, many IDEs will show them as undefined and mark
  30. # any code blocks enabled by them as disabled.
  31. #
  32. # The original reasoning for removing them was that trivial
  33. # changes to the buildopts.h file will cause ccache to
  34. # invalidate any source files that use it and increase the
  35. # compile time. It's not such a huge deal these days but
  36. # to preserve backwards behavior the default is still to
  37. # remove them.
  38. #
  39. # The ABI-breaking flags are always included in buildopts.h.
  40. # This variable is used by sed so it needs to be a valid
  41. # regex which will be surrounded by parens.]
  42. FILTER_OUT="\
  43. AO2_DEBUG|BETTER_BACKTRACES|BUILD_NATIVE|\
  44. COMPILE_DOUBLE|DEBUG_CHAOS|DEBUG_SCHEDULER|\
  45. DONT_OPTIMIZE|DUMP_SCHEDULER|\
  46. LOTS_OF_SPANS|MALLOC_DEBUG|RADIO_RELAX|\
  47. REBUILD_PARSERS|REF_DEBUG|USE_HOARD_ALLOCATOR"
  48. # Create buildopts.h
  49. INCLUDE_CFLAGS="$MENUSELECT_CFLAGS"
  50. # Do the filter-out if needed.
  51. if ! $ADD_CFLAGS_TO_BUILDOPTS ; then
  52. INCLUDE_CFLAGS=$( echo "$MENUSELECT_CFLAGS" | \
  53. sed -r -e "s/(${FILTER_OUT})//g")
  54. fi
  55. # Output the defines.
  56. for x in ${INCLUDE_CFLAGS}; do
  57. echo "#define ${x} 1"
  58. done
  59. # We NEVER include the non-ABI-breaking flags in the
  60. # BUILDOPTS or use them to calculate the checksum so
  61. # we always filter out any that may exist.
  62. # After the filter-out, we also need to convert the
  63. # possibly-multi-spaced MENUSELECT_CFLAGS to a nice
  64. # comma-separated list.
  65. # I.E.
  66. # Remove leading spaces.
  67. # Convert consecutive interior spaces to a single space.
  68. # Remove trailing spaces.
  69. # Convert the now-single-spaces in the interior to ", ".
  70. BUILDOPTS=$( echo "$MENUSELECT_CFLAGS" | \
  71. sed -r -e "s/(${FILTER_OUT}|LOW_MEMORY)//g" -e "s/^\s+//g;s/\s+/ /g;s/\s+$//g;s/\s/, /g" )
  72. # Calculate the checksum on only the ABI-breaking flags.
  73. BUILDSUM=$(echo "${BUILDOPTS}" | ${MD5} | cut -c1-32)
  74. echo "#define AST_BUILDOPT_SUM \"${BUILDSUM}\""
  75. echo "#define AST_BUILDOPTS \"${BUILDOPTS}\""
  76. # However, it'd be nice to see the non-ABI-breaking flags
  77. # when you do a "core show settings" so we create a separate
  78. # define for them.
  79. BUILDOPTS_ALL=$( echo "$MENUSELECT_CFLAGS" | \
  80. sed -r -e "s/^\s+//g;s/\s+/ /g;s/\s+$//g;s/\s/, /g" )
  81. echo "#define AST_BUILDOPTS_ALL \"${BUILDOPTS_ALL}\""