mconfig.Linux.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. HAS_LTO=$?
  51. test_compiler_arg "$compiler" -fno-rtti
  52. test_compiler_arg "$compiler" -fno-plt
  53. BUILD_OPTS="-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++11 -Os -Wall $supported_opts"
  54. if test $HAS_LTO = 0; then
  55. LD_OPTS="-flto -Os"
  56. else
  57. LD_OPTS=""
  58. fi
  59. echo "Using build options : $supported_opts"
  60. supported_opts=""
  61. test_compile_link_arg "$compiler" -fsanitize=address,undefined
  62. SANITIZE_OPTS="$supported_opts"
  63. echo "Sanitize options : $SANITIZE_OPTS"
  64. rm testfile.cc
  65. GENERAL_BUILD_SETTINGS=$(
  66. echo ""
  67. echo ""
  68. echo "# General build options."
  69. echo ""
  70. echo "# Linux (GCC). Note with GCC 5.x/6.x you must use the old ABI, with GCC 7.x you must use"
  71. echo "# the new ABI. See BUILD.txt file for more information."
  72. echo "CXX=$compiler"
  73. echo "CXXOPTS=$BUILD_OPTS"
  74. echo "LDFLAGS=$LD_OPTS"
  75. echo "BUILD_SHUTDOWN=yes"
  76. echo "SANITIZEOPTS=$SANITIZE_OPTS"
  77. echo ""
  78. echo "# Notes:"
  79. echo "# -D_GLIBCXX_USE_CXX11_ABI=1 : force use of new ABI, see above / BUILD.txt"
  80. echo "# -fno-rtti (optional) : Dinit does not require C++ Run-time Type Information"
  81. echo "# -fno-plt (optional) : Recommended optimisation"
  82. echo "# -flto (optional) : Perform link-time optimisation"
  83. echo "# -fsanitize=address,undefined : Apply sanitizers (during unit tests)"
  84. )
  85. #echo "$INST_PATH_OPTS"
  86. #echo "$GENERAL_BUILD_SETTINGS"
  87. (
  88. echo "$INST_PATH_OPTS"
  89. echo "$GENERAL_BUILD_SETTINGS"
  90. ) >> ../mconfig