mconfig.Linux.sh 3.2 KB

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