2
0

mconfig.Linux.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. echo "LDFLAGS_BASE="
  71. if [ "$NOT_HAS_LTO" = 0 ]; then
  72. echo "LDFLAGS=\$(LDFLAGS_BASE) \$(CXXFLAGS)"
  73. else
  74. echo "LDFLAGS=\$(LDFLAGS_BASE)"
  75. fi
  76. echo "TEST_CXXFLAGS=\$(CXXFLAGS) $SANITIZE_OPTS"
  77. echo "TEST_LDFLAGS_BASE=\$(LDFLAGS_BASE)"
  78. if [ "$NOT_HAS_LTO" = 0 ]; then
  79. echo "TEST_LDFLAGS=\$(TEST_LDFLAGS_BASE) \$(TEST_CXXFLAGS)"
  80. else
  81. echo "TEST_LDFLAGS=\$(TEST_LDFLAGS_BASE)"
  82. fi
  83. echo "BUILD_SHUTDOWN=yes"
  84. echo ""
  85. echo "# Notes:"
  86. echo "# -D_GLIBCXX_USE_CXX11_ABI=1 : force use of new ABI, see above / BUILD"
  87. echo "# -fno-rtti (optional) : Dinit does not require C++ Run-time Type Information"
  88. echo "# -fno-plt (optional) : Recommended optimisation"
  89. echo "# -flto (optional) : Perform link-time optimisation"
  90. echo "# -fsanitize=address,undefined : Apply sanitizers (during unit tests)"
  91. echo "# LDFLAGS should also contain C++ optimisation flags for LTO (-flto)."
  92. )
  93. FEATURE_SETTINGS=$(
  94. echo ""
  95. echo ""
  96. echo "# Feature settings"
  97. echo ""
  98. echo "SUPPORT_CGROUPS=1"
  99. )
  100. SERVICE_DEFAULTS=$(
  101. echo ""
  102. echo ""
  103. echo "# Service defaults"
  104. echo ""
  105. echo "DEFAULT_AUTO_RESTART=true"
  106. echo "DEFAULT_START_TIMEOUT=60"
  107. echo "DEFAULT_STOP_TIMEOUT=10"
  108. )
  109. (
  110. echo "$INST_PATH_OPTS"
  111. echo "$GENERAL_BUILD_SETTINGS"
  112. echo "$FEATURE_SETTINGS"
  113. echo "$SERVICE_DEFAULTS"
  114. ) >> ../mconfig