mconfig.Linux.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/sh
  2. rm -f ../mconfig
  3. INST_PATH_OPTS=$(
  4. echo "# Installation path options.";
  5. echo "";
  6. echo "SBINDIR=/sbin";
  7. echo "MANDIR=/usr/share/man";
  8. echo "SYSCONTROLSOCKET=/run/dinitctl"
  9. )
  10. test_compiler_arg() {
  11. "$1" -c "$2" testfile.cc -o testfile.o > /dev/null 2>&1
  12. if test $? = 0; then
  13. rm testfile.o
  14. supported_opts="$supported_opts $2"
  15. supported_opts=${supported_opts# }
  16. return 0
  17. else
  18. return 1
  19. fi
  20. }
  21. # test argument is supported by compiler at both compile and link
  22. test_compile_link_arg() {
  23. "$1" "$2" testfile.cc -o testfile > /dev/null 2>&1
  24. if test $? = 0; then
  25. rm testfile
  26. supported_opts="$supported_opts $2"
  27. supported_opts=${supported_opts# }
  28. return 0
  29. else
  30. return 1
  31. fi
  32. }
  33. for compiler in g++ clang++ c++ ""; do
  34. if test -z "$compiler"; then
  35. break # none found
  36. fi
  37. type $compiler > /dev/null
  38. if test $? = 0; then
  39. break # found
  40. fi
  41. done
  42. if test -z "$compiler"; then
  43. echo "*** No compiler found ***"
  44. exit 1
  45. fi
  46. echo "Compiler found : $compiler"
  47. echo "int main(int argc, char **argv) { return 0; }" > testfile.cc
  48. supported_opts=""
  49. test_compiler_arg "$compiler" -flto
  50. NOT_HAS_LTO=$?
  51. test_compiler_arg "$compiler" -fno-rtti
  52. test_compiler_arg "$compiler" -fno-plt
  53. BUILD_OPTS="-std=c++11 -Os -Wall $supported_opts"
  54. echo "Using build options : $supported_opts"
  55. supported_opts=""
  56. test_compile_link_arg "$compiler" -fsanitize=address,undefined
  57. SANITIZE_OPTS="$supported_opts"
  58. echo "Sanitize options : $SANITIZE_OPTS"
  59. rm testfile.cc
  60. GENERAL_BUILD_SETTINGS=$(
  61. echo ""
  62. echo ""
  63. echo "# General build options."
  64. echo ""
  65. echo "# Linux (GCC). Note with GCC 5.x/6.x you must use the old ABI, with GCC 7.x you must use"
  66. echo "# the new ABI. See BUILD file for more information."
  67. echo "CXX=$compiler"
  68. echo "CXXFLAGS=$BUILD_OPTS"
  69. echo "CPPFLAGS=-D_GLIBCXX_USE_CXX11_ABI=1"
  70. if [ "$NOT_HAS_LTO" = 0 ]; then
  71. echo "LDFLAGS=\$(CXXFLAGS)"
  72. else
  73. echo "LDFLAGS="
  74. fi
  75. echo "TEST_CXXFLAGS=\$(CXXFLAGS) $SANITIZE_OPTS"
  76. echo "TEST_LDFLAGS=\$(LDFLAGS) \$(TEST_CXXFLAGS)"
  77. echo "BUILD_SHUTDOWN=yes"
  78. echo ""
  79. echo "# Notes:"
  80. echo "# -D_GLIBCXX_USE_CXX11_ABI=1 : force use of new ABI, see above / BUILD"
  81. echo "# -fno-rtti (optional) : Dinit does not require C++ Run-time Type Information"
  82. echo "# -fno-plt (optional) : Recommended optimisation"
  83. echo "# -flto (optional) : Perform link-time optimisation"
  84. echo "# -fsanitize=address,undefined : Apply sanitizers (during unit tests)"
  85. echo "# LDFLAGS should also contain C++ optimisation flags for LTO (-flto)."
  86. )
  87. FEATURE_SETTINGS=$(
  88. echo ""
  89. echo ""
  90. echo "# Feature settings"
  91. echo ""
  92. echo "SUPPORT_CGROUPS=1"
  93. )
  94. (
  95. echo "$INST_PATH_OPTS"
  96. echo "$GENERAL_BUILD_SETTINGS"
  97. echo "$FEATURE_SETTINGS"
  98. ) >> ../mconfig