2
0

configure 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. #!/bin/sh
  2. ### Automatic build configuration script for Dinit.
  3. ### This script generates an "mconfig" file suitable for building on the current system.
  4. ## Initial preparation
  5. set -eu
  6. cd "$(dirname "$0")"
  7. ## Helper functions
  8. # POSIX "echo" behaviour has unspecified behavior in some cases, for example when the first
  9. # argument is "-n" or backslash ("\"). So, replace the shell built-in echo with a printf-based
  10. # function. For more information see: http://www.etalabs.net/sh_tricks.html
  11. echo()
  12. {
  13. IFS=" " printf %s\\n "$*"
  14. }
  15. # Output a line of information, may be followed by call to sub_info to provide additional information
  16. info()
  17. {
  18. echo "$*"
  19. }
  20. # Output additional information (intended to follow call to info)
  21. sub_info()
  22. {
  23. echo " ... $*"
  24. }
  25. # Output an error message, may be followed by a call to sub_error to provide additional information
  26. error()
  27. {
  28. >&2 echo "Error: $*"
  29. exit 1
  30. }
  31. # Output additional error information (intended to follow call to error)
  32. sub_error()
  33. {
  34. >&2 echo " ... Error: $*"
  35. exit 1
  36. }
  37. # Output a warning, with an optional "extra information" field
  38. # $1: Info, $2: Extra info (optional)
  39. warning()
  40. {
  41. >&2 echo
  42. >&2 echo "Warning: $1"
  43. [ -n "${2:-}" ] && >&2 echo " ... $2"
  44. >&2 echo
  45. }
  46. # Produce (as output) a random number from 0-65535
  47. randomnumber()
  48. {
  49. awk 'BEGIN {
  50. srand()
  51. printf("%d\n", 65536 * rand())
  52. }'
  53. }
  54. # Create a temporary directory and output its full path
  55. mktmpdir()
  56. {
  57. rn1=`randomnumber`
  58. rn2=`randomnumber`
  59. dirname="${TMPDIR:-/tmp}/dinit-cfg-${rn1}-${rn2}"
  60. mkdir "$dirname"
  61. echo "$dirname"
  62. }
  63. # Check whether the compiler ($CXX) seems to work
  64. cxx_works()
  65. {
  66. info Checking whether \""$1"\" is a working C++ compiler...
  67. if $CXX -o "$configtmpdir"/testfile "$configtmpdir"/testfile.cc; then
  68. rm -f "$configtmpdir"/testfile
  69. sub_info Yes.
  70. else
  71. rm -f "$configtmpdir"/testfile*
  72. sub_error It seems like \""$CXX"\" is not working a working C++ compiler. Please specify compiler.
  73. fi
  74. }
  75. # Test if the compiler accepts an argument (for compilation only); if so add it to named variable.
  76. # Note: this function will return failure if the flag is unsupported (use try_optional_cxx_argument
  77. # instead, to avoid errorring out).
  78. # $1 - the name of the variable to potentially add the argument to
  79. # $2 - the argument to test/add
  80. # CXX - the name of the compiler
  81. # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
  82. try_cxx_argument()
  83. {
  84. info Checking whether "$2" is accepted for compilation...
  85. if $CXX $CXXFLAGS $2 $CXXFLAGS_EXTRA $LDFLAGS $LDFLAGS_EXTRA "$configtmpdir"/testfile.cc \
  86. -c -o "$configtmpdir"/testfile.o > /dev/null 2>&1; then
  87. rm "$configtmpdir"/testfile.o
  88. sub_info Yes.
  89. eval "$1=\"\${$1} \$2\""
  90. eval "$1=\${$1# }"
  91. return 0
  92. else
  93. sub_info No.
  94. return 1
  95. fi
  96. }
  97. # Test if the compiler accepts an argument; same as try_cxx_argument, but doesn't return failure
  98. # if the flag is unsupported.
  99. # $1 - the name of the variable to potentially add the argument to
  100. # $2 - the argument to test/add
  101. # CXX - the name of the compiler
  102. # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
  103. try_optional_cxx_argument()
  104. {
  105. try_cxx_argument "$1" "$2" || :
  106. }
  107. # Test if an argument is supported during linking.
  108. # $1 - the name of the variable to potentially add the argument to
  109. # $2 - the argument to test/add
  110. # CXX - the name of the compiler
  111. # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
  112. try_ld_argument()
  113. {
  114. info Checking whether "$2" is accepted as a link-time option...
  115. if [ ! -e "$configtmpdir"/testfile.o ]; then
  116. # If the object file doesn't exist yet, need to compile
  117. if ! $CXX $CXXFLAGS $CXXFLAGS_EXTRA "$configtmpdir"/testfile.cc \
  118. -c -o "$configtmpdir"/testfile.o > /dev/null 2>&1; then
  119. sub_info "No (compilation failed)."
  120. return
  121. fi
  122. fi
  123. if $CXX $LDFLAGS $LDFLAGS_EXTRA $2 "$configtmpdir"/testfile.o \
  124. -o "$configtmpdir"/testfile > /dev/null 2>&1; then
  125. sub_info Yes.
  126. rm "$configtmpdir"/testfile
  127. eval "$1=\"\${$1} \$2\""
  128. eval "$1=\${$1# }"
  129. else
  130. sub_info No.
  131. fi
  132. }
  133. # Test if an argument is supported during both compiling and linking.
  134. # $1 - the name of the compiler-flags variable to potentially add the argument to
  135. # $2 - the name of the link-flags variable to potentially add the argument to
  136. # $3 - the argument to test/add
  137. # CXX - the name of the compiler
  138. # CXXFLAGS, CXXFLAGS_EXTRA, LDFLAGS, LDFLAGS_EXTRA - any predetermined flags
  139. try_both_argument()
  140. {
  141. info Checking whether "$3" is accepted for compiling and linking...
  142. if $CXX $CXXFLAGS $CXXFLAGS_EXTRA $LDFLAGS $LDFLAGS_EXTRA $3 "$configtmpdir"/testfile.cc \
  143. -o "$configtmpdir"/testfile > /dev/null 2>&1; then
  144. sub_info Yes.
  145. rm "$configtmpdir"/testfile
  146. eval "$1=\"\${$1} \$3\""
  147. eval "$1=\${$1# }"
  148. eval "$2=\"\${$2} \$3\""
  149. eval "$2=\${$2# }"
  150. else
  151. sub_info No.
  152. fi
  153. }
  154. usage()
  155. {
  156. cat << _EOF
  157. Usage: $0 [OPTION]...
  158. Generates build configuration for Dinit.
  159. Defaults for the options are specified in brackets.
  160. -h, --help This help message.
  161. -q, --quiet Don't print normal messages, just errors.
  162. -c, --clear Clear mconfig and configure's temporary files.
  163. Target options:
  164. --platform=PLATFORM Set the platform manually (for cross compilation)
  165. Note: for all cross-compiles please specify correct CXX and
  166. CXX_FOR_BUILD!
  167. Installation directories:
  168. --prefix=PREFIX Main installation prefix [/usr]
  169. --exec-prefix=EPREFIX Main executables prefix [/]
  170. --sbindir=SBINDIR Dinit executables [EPREFIX/sbin]
  171. --mandir=MANDIR Dinit man-pages location [PREFIX/share/man]
  172. --syscontrolsocket=SOCKETPATH Dinitctl socket location [/run/dinitctl] on Linux systems
  173. [/var/run/dinitctl] on other systems
  174. Optional options:
  175. --enable-strip Strip debug information in installation process [Enabled]
  176. --disable-strip Don't strip debug information in installation process
  177. --shutdown-prefix=PREFIX Name prefix for shutdown, poweroff, reboot, soft-reboot, halt
  178. programs []
  179. --enable-shutdown Build shutdown, poweroff, reboot, soft-reboot, halt programs
  180. [Enabled only on Linux]
  181. --disable-shutdown Don't build shutdown, poweroff, reboot, soft-reboot, halt
  182. programs
  183. --enable-cgroups Enable Cgroups support [Enabled only on Linux]
  184. --disable-cgroups Disable Cgroups support
  185. --enable-capabilities Enable capabilities support
  186. [Enabled on Linux if libcap available]
  187. --disable-capabilities Disable capabilities support
  188. --enable-utmpx Enable manipulating the utmp/utmpx database via the related
  189. POSIX functions [Depends on system]
  190. --disable-utmpx Disable manipulating the utmp/utmpx database via the related
  191. POSIX functions
  192. --enable-initgroups Enable initialization of supplementary groups for run-as
  193. [Enabled]
  194. --disable-initgroups Disable initialization of supplementary groups for run-as
  195. --enable-auto-restart Enable auto-restart for services by default (Deprecated;
  196. use --default-auto-restart=...)
  197. --disable-auto-restart Disable auto-restart for services by default (Deprecated;
  198. use --default-auto-restart=...)
  199. --default-start-timeout=sec Default start-timeout for services [60]
  200. --default-stop-timeout=sec Default stop-timeout for services [10]
  201. --default-auto-restart=(never|on-failure|always)
  202. When to automatically restart services. This controls the
  203. default value for the "restart" service setting; see the
  204. dinit-service(5) man page for details. [always]
  205. Build variables:
  206. Note: build variables can be passed in the environment, or as $0 argument (as "var=VALUE").
  207. Note: values for some options will be determined automatically, if not specified.
  208. Note: CXXFLAGS, TEST_CXXFLAGS, LDFLAGS and TEST_LDFLAGS by default will be set to options
  209. considered suitable for the platform, filtered to remove any options not supported by the
  210. compiler/linker. To disable this, specify the values explicitly (an empty string is accepted).
  211. To add options without removing the defaults, set the variable with _EXTRA appended to the
  212. name (eg CXXFLAGS_EXTRA).
  213. CXX C++ compiler
  214. CXX_FOR_BUILD C++ compiler generating code for the build system (for
  215. cross-compiles).
  216. CXXFLAGS_FOR_BUILD Flags to use when generating code for the build system.
  217. Defaults to the value of CXXFLAGS.
  218. CPPFLAGS_FOR_BUILD Preprocessor flags to use when generating code for the build
  219. system.
  220. Defaults to the value of CPPFLAGS.
  221. LDFLAGS_FOR_BUILD Link flags to use when generating code for the build system.
  222. Defaults to the value of LDFLAGS.
  223. CXXFLAGS Flags to use when compiling C++ code.
  224. CXXFLAGS_EXTRA Additional flags to use when compiling C++ code.
  225. TEST_CXXFLAGS Flags to use when compiling C++ code in tests.
  226. TEST_CXXFLAGS_EXTRA Additional flags to use when compiling C++ code in tests.
  227. CPPFLAGS Preprocessor flags to use when compiling C++ code.
  228. LDFLAGS Link flags.
  229. LDFLAGS_EXTRA Additional link flags.
  230. LDFLAGS_BASE Link flags to use in addition to any link-time optimisation
  231. (LTO)-related options. Set this to control link options without
  232. disabling LTO. Ignored if LDFLAGS is set.
  233. TEST_LDFLAGS Link flags when building test executables.
  234. TEST_LDFLAGS_EXTRA Additional link flags when building test executables.
  235. TEST_LDFLAGS_BASE Link flags to use when building test executables, in addition to
  236. LTO-releated options.
  237. LDFLAGS_LIBCAP Additional Link flags to link capabilities support (libcap).
  238. Note: paths specified via --prefix/--exec-prefix/--sbindir/--mandir, and build variable values,
  239. must be escaped for use in a makefile and in shell commands. If there are spaces in paths it is
  240. recommended to prepend a backslash (\) to them.
  241. For example: ./configure --prefix="/home/my\ home"
  242. See BUILD file for more information.
  243. _EOF
  244. exit 0
  245. }
  246. ## Don't take values from environment for these variables:
  247. for var in PREFIX \
  248. EPREFIX \
  249. SBINDIR \
  250. MANDIR \
  251. SHUTDOWN_PREFIX \
  252. BUILD_SHUTDOWN \
  253. SUPPORT_CGROUPS \
  254. SUPPORT_CAPABILITIES \
  255. SUPPORT_IOPRIO \
  256. SUPPORT_OOM_ADJ \
  257. USE_UTMPX \
  258. USE_INITGROUPS \
  259. SYSCONTROLSOCKET \
  260. STRIPOPTS
  261. do
  262. unset $var
  263. done
  264. ## Flag parser
  265. for arg in "$@"; do
  266. case "$arg" in
  267. -h|--help) usage ;;
  268. -q|--quiet)
  269. info() { true; }
  270. sub_info() { true; }
  271. warning() { true; }
  272. ;;
  273. -c|--clear) rm -f test* & rm -f mconfig && exit 0 ;;
  274. --platform=*) PLATFORM="${arg#*=}" && shift ;;
  275. --prefix=*) PREFIX="${arg#*=}" && shift ;;
  276. --exec-prefix=*) EPREFIX="${arg#*=}" && shift;;
  277. --sbindir=*) SBINDIR="${arg#*=}" && shift ;;
  278. --mandir=*) MANDIR="${arg#*=}" && shift ;;
  279. --default-start-timeout=*) DEFAULT_START_TIMEOUT="${arg#*=}" && shift ;;
  280. --default-stop-timeout=*) DEFAULT_STOP_TIMEOUT="${arg#*=}" && shift ;;
  281. --syscontrolsocket=*) SYSCONTROLSOCKET="${arg#*=}" && shift ;;
  282. --shutdown-prefix=*) SHUTDOWN_PREFIX="${arg#*=}" && shift ;;
  283. --enable-shutdown|--enable-shutdown=yes) BUILD_SHUTDOWN=yes ;;
  284. --disable-shutdown|--enable-shutdown=no) BUILD_SHUTDOWN=no ;;
  285. --enable-cgroups|--enable-cgroups=yes) SUPPORT_CGROUPS=1 ;;
  286. --disable-cgroups|--enable-cgroups=no) SUPPORT_CGROUPS=0 ;;
  287. --enable-capabilities|--enable-capabilities=yes) SUPPORT_CAPABILITIES=1 ;;
  288. --disable-capabilities|--enable-capabilities=no) SUPPORT_CAPABILITIES=0 ;;
  289. --enable-ioprio|--enable-ioprio=yes) SUPPORT_IOPRIO=1 ;;
  290. --disable-ioprio|--enable-ioprio=no) SUPPORT_IOPRIO=0 ;;
  291. --enable-oom-adj|--enable-oom-adj=yes) SUPPORT_OOM_ADJ=1 ;;
  292. --disable-oom-adj|--enable-oom-adj=no) SUPPORT_OOM_ADJ=0 ;;
  293. --enable-utmpx|--enable-utmpx=yes) USE_UTMPX=1 ;;
  294. --disable-utmpx|--enable-utmpx=no) USE_UTMPX=0 ;;
  295. --enable-initgroups|--enable-initgroups=yes) USE_INITGROUPS=1 ;;
  296. --disable-initgroups|--enable-initgroups=no) USE_INITGROUPS=0 ;;
  297. --enable-auto-restart|--enable-auto-restart=yes) DEFAULT_AUTO_RESTART=ALWAYS ;; # Deprecated
  298. --disable-auto-restart|--enable-auto-restart=no) DEFAULT_AUTO_RESTART=NEVER ;; # Deprecated
  299. --enable-strip|--enable-strip=yes) STRIPOPTS="-s" ;;
  300. --disable-strip|--enable-strip=no) STRIPOPTS="" ;;
  301. --default-auto-restart=never) DEFAULT_AUTO_RESTART=NEVER ;;
  302. --default-auto-restart=always) DEFAULT_AUTO_RESTART=ALWAYS ;;
  303. --default-auto-restart=on-failure) DEFAULT_AUTO_RESTART=ON_FAILURE ;;
  304. CXX=*|CXX_FOR_BUILD=*|CXXFLAGS_FOR_BUILD=*|CPPFLAGS_FOR_BUILD=*\
  305. |LDFLAGS_FOR_BUILD=*|CXXFLAGS=*|CXXFLAGS_EXTRA=*|TEST_CXXFLAGS=*\
  306. |TEST_CXXFLAGS_EXTRA=*|LDFLAGS=*|LDFLAGS_EXTRA=*|TEST_LDFLAGS=*\
  307. |TEST_LDFLAGS_EXTRA=*|CPPFLAGS=*|LDFLAGS_BASE=*|TEST_LDFLAGS_BASE=*\
  308. |LDFLAGS_LIBCAP) eval "${arg%%=*}=\${arg#*=}" ;;
  309. *=*) warning "Unknown variable: ${arg%%=*}" ;;
  310. *) warning "Unknown argument: $arg" ;;
  311. esac
  312. done
  313. ## Defaults for variables not specified by user
  314. : "${PLATFORM:=$(uname)}"
  315. : "${PREFIX:="/usr"}"
  316. : "${EPREFIX:="/"}"
  317. : "${SBINDIR:="${EPREFIX%%/}/sbin"}"
  318. : "${MANDIR:="${PREFIX%%/}/share/man"}"
  319. : "${SHUTDOWN_PREFIX:=""}"
  320. : "${CXXFLAGS_EXTRA:=""}"
  321. : "${TEST_CXXFLAGS_EXTRA:=""}"
  322. : "${CPPFLAGS:=""}"
  323. : "${LDFLAGS_EXTRA:=""}"
  324. : "${TEST_LDFLAGS_EXTRA:=""}"
  325. : "${DEFAULT_AUTO_RESTART:="ALWAYS"}"
  326. : "${DEFAULT_START_TIMEOUT:="60"}"
  327. : "${DEFAULT_STOP_TIMEOUT:="10"}"
  328. : "${USE_INITGROUPS:="1"}"
  329. if [ "$PLATFORM" = "Linux" ]; then
  330. : "${BUILD_SHUTDOWN:="yes"}"
  331. : "${SUPPORT_CGROUPS:="1"}"
  332. : "${SUPPORT_CAPABILITIES:="AUTO"}"
  333. : "${SUPPORT_IOPRIO:="1"}"
  334. : "${SUPPORT_OOM_ADJ:="1"}"
  335. : "${SYSCONTROLSOCKET:="/run/dinitctl"}"
  336. else
  337. : "${BUILD_SHUTDOWN:="no"}"
  338. : "${SUPPORT_CGROUPS:="0"}"
  339. : "${SUPPORT_CAPABILITIES:="0"}"
  340. : "${SUPPORT_IOPRIO:="0"}"
  341. : "${SUPPORT_OOM_ADJ:="0"}"
  342. : "${SYSCONTROLSOCKET:="/var/run/dinitctl"}"
  343. fi
  344. HAS_LTO=""
  345. ## Finalize $CXXFLAGS, $TEST_CXXFLAGS, $LDFLAGS, $TEST_LDFLAGS, $STRIPOPTS
  346. if [ -z "${CXXFLAGS+IS_SET}" ]; then
  347. CXXFLAGS=""
  348. AUTO_CXXFLAGS="true"
  349. else
  350. AUTO_CXXFLAGS="false"
  351. fi
  352. if [ -z "${TEST_CXXFLAGS+IS_SET}" ]; then
  353. TEST_CXXFLAGS=""
  354. AUTO_TEST_CXXFLAGS="true"
  355. else
  356. AUTO_TEST_CXXFLAGS="false"
  357. fi
  358. if [ -z "${LDFLAGS+IS_SET}" ]; then
  359. LDFLAGS=""
  360. AUTO_LDFLAGS="true"
  361. else
  362. AUTO_LDFLAGS="false"
  363. fi
  364. if [ -z "${TEST_LDFLAGS+IS_SET}" ]; then
  365. TEST_LDFLAGS=""
  366. AUTO_TEST_LDFLAGS="true"
  367. else
  368. AUTO_TEST_LDFLAGS="false"
  369. fi
  370. if [ -z "${LDFLAGS_BASE+IS_SET}" ]; then
  371. LDFLAGS_BASE=""
  372. AUTO_LDFLAGS_BASE="true"
  373. else
  374. AUTO_LDFLAGS_BASE="false"
  375. fi
  376. if [ -z "${TEST_LDFLAGS_BASE+IS_SET}" ]; then
  377. TEST_LDFLAGS_BASE=""
  378. AUTO_TEST_LDFLAGS_BASE="true"
  379. else
  380. AUTO_TEST_LDFLAGS=BASE="false"
  381. fi
  382. if [ -z "${LDFLAGS_LIBCAP+IS_SET}" ]; then
  383. LDFLAGS_LIBCAP=""
  384. AUTO_LDFLAGS_LIBCAP="true"
  385. else
  386. AUTO_LDFLAGS_LIBCAP="false"
  387. fi
  388. [ -z "${STRIPOPTS+IS_SET}" ] && STRIPOPTS="-s"
  389. ## Verify PLATFORM value
  390. if [ "$PLATFORM" != "Linux" ] && [ "$PLATFORM" != "FreeBSD" ] && \
  391. [ "$PLATFORM" != "OpenBSD" ] && [ "$PLATFORM" != "Darwin" ]; then
  392. warning "$PLATFORM platform is unknown!" "Known Platforms are: Linux, FreeBSD, OpenBSD, Darwin"
  393. fi
  394. ## Create testfile.cc to test c++ compiler
  395. configtmpdir=`mktmpdir`
  396. echo "int main(int argc, char **argv) { return 0; }" > "$configtmpdir"/testfile.cc || error "Can't create temporary file"
  397. ## Find and test C++ compiler
  398. if [ -z "${CXX:-}" ]; then
  399. info Checking C++ compiler...
  400. for guess in g++ clang++ c++; do
  401. if type "$guess" > /dev/null 2>&1; then
  402. CXX="$guess"
  403. sub_info "$CXX"
  404. break # Found
  405. fi
  406. done
  407. if [ -z "${CXX:-}" ]; then
  408. sub_error No C++ compiler found! # Not found
  409. fi
  410. fi
  411. cxx_works "$CXX"
  412. if [ -n "${CXX_FOR_BUILD:-}" ]; then
  413. cxx_works "$CXX_FOR_BUILD"
  414. fi
  415. ## Test compiler/linker supported arguments
  416. if [ "$AUTO_CXXFLAGS" = "true" ]; then
  417. if ! try_cxx_argument CXXFLAGS -std=c++11; then
  418. sub_error "The C++ compiler ($CXX) doesn't accept '-std=c++11' and may be too old."
  419. fi
  420. for argument in -Wall \
  421. -Os \
  422. -fno-plt
  423. do
  424. try_optional_cxx_argument CXXFLAGS $argument
  425. done
  426. if [ "$PLATFORM" != "Darwin" ]; then
  427. try_optional_cxx_argument CXXFLAGS -fno-rtti
  428. fi
  429. fi
  430. if [ "$AUTO_LDFLAGS" = true ] && [ "$AUTO_CXXFLAGS" = true ]; then
  431. DUMMY_LDFLAGS=""
  432. # -flto must work for both compiling and linking, but we don't want to add it to LDFLAGS as,
  433. # if LTO is used, CXXFLAGS will always be used alongside LDFLAGS.
  434. if try_both_argument CXXFLAGS DUMMY_LDFLAGS -flto; then
  435. HAS_LTO="true"
  436. else
  437. HAS_LTO="false"
  438. fi
  439. unset DUMMY_LDFLAGS
  440. fi
  441. if [ "$AUTO_LDFLAGS_BASE" = true ] && [ "$PLATFORM" = FreeBSD ]; then
  442. try_ld_argument LDFLAGS_BASE -lrt
  443. fi
  444. if [ "$SUPPORT_CAPABILITIES" != 0 ]; then
  445. if [ "$AUTO_LDFLAGS_LIBCAP" = true ]; then
  446. try_ld_argument LDFLAGS_LIBCAP -lcap
  447. if [ "$SUPPORT_CAPABILITIES" = AUTO ]; then
  448. if [ -z "$LDFLAGS_LIBCAP" ]; then
  449. SUPPORT_CAPABILITIES=0
  450. else
  451. SUPPORT_CAPABILITIES=1
  452. fi
  453. fi
  454. else
  455. # SUPPORT_CAPABILITIES may be set to AUTO, fix that:
  456. SUPPORT_CAPABILITES=1
  457. fi
  458. else
  459. LDFLAGS_LIBCAP=""
  460. fi
  461. if [ "$AUTO_TEST_LDFLAGS_BASE" = true ]; then
  462. TEST_LDFLAGS_BASE="\$(LDFLAGS_BASE)"
  463. established_TEST_LDFLAGS="$LDFLAGS_BASE"
  464. else
  465. established_TEST_LDFLAGS="$TEST_LDFLAGS_BASE"
  466. fi
  467. # Determine LDFLAGS/TEST_LDFLAGS. In the case of TEST_LDFLAGS we may still add sanitisation
  468. # options, shortly.
  469. if [ "$HAS_LTO" = true ]; then
  470. if [ "$AUTO_LDFLAGS" = true ]; then
  471. LDFLAGS="\$(LDFLAGS_BASE) \$(CXXFLAGS)"
  472. fi
  473. if [ "$AUTO_TEST_LDFLAGS" = true ]; then
  474. TEST_LDFLAGS="\$(TEST_LDFLAGS_BASE) \$(TEST_CXXFLAGS)"
  475. established_TEST_LDFLAGS="$established_TEST_LDFLAGS $TEST_CXXFLAGS"
  476. else
  477. established_TEST_LDFLAGS="$TEST_LDFLAGS"
  478. fi
  479. else
  480. # default LDFLAGS are just $(LDFLAGS_BASE)
  481. if [ "$AUTO_LDFLAGS" = true ]; then
  482. LDFLAGS="\$(LDFLAGS_BASE)"
  483. fi
  484. if [ "$AUTO_TEST_LDFLAGS" = true ]; then
  485. TEST_LDFLAGS="\$(TEST_LDFLAGS_BASE)"
  486. else
  487. established_TEST_LDFLAGS="$TEST_LDFLAGS"
  488. fi
  489. fi
  490. # Default for test flags (TEST_CXXFLAGS, TEST_LDFLAGS) is to use the build flags
  491. if [ "$AUTO_TEST_CXXFLAGS" = "true" ]; then
  492. TEST_CXXFLAGS="\$(CXXFLAGS)"
  493. established_TEST_CXXFLAGS="$CXXFLAGS"
  494. else
  495. established_TEST_CXXFLAGS="$TEST_CXXFLAGS"
  496. fi
  497. # Check whether sanitizers can be used for tests
  498. if [ "$AUTO_TEST_LDFLAGS" = "true" ] && [ "$AUTO_TEST_CXXFLAGS" = "true" ]; then
  499. DUMMY_LDFLAGS=""
  500. if [ "$HAS_LTO" = true ]; then
  501. # Avoid doubling-up sanitizer options
  502. LDFLAGS_VAR=DUMMY_LDFLAGS
  503. else
  504. LDFLAGS_VAR=TEST_LDFLAGS
  505. fi
  506. CXXFLAGS="$established_TEST_CXXFLAGS" CXXFLAGS_EXTRA="$TEST_CXXFLAGS_EXTRA" \
  507. LDFLAGS="$established_TEST_LDFLAGS" LDFLAGS_EXTRA="$TEST_LDFLAGS_EXTRA" \
  508. try_both_argument TEST_CXXFLAGS $LDFLAGS_VAR -fsanitize=address,undefined
  509. unset DUMMY_LDFLAGS
  510. fi
  511. ## Create mconfig
  512. rm -r "$configtmpdir"
  513. info Creating mconfig...
  514. cat << _EOF > mconfig
  515. ## Auto-generated by "$0" for "$PLATFORM"
  516. # All changes will be lost if "$0" is re-run.
  517. # See BUILD for help on all variables.
  518. # Installation path options.
  519. SBINDIR=$SBINDIR
  520. MANDIR=$MANDIR
  521. SYSCONTROLSOCKET=$SYSCONTROLSOCKET
  522. # General build options.
  523. CXX=$CXX
  524. CXXFLAGS=$CXXFLAGS
  525. CXXFLAGS_EXTRA=$CXXFLAGS_EXTRA
  526. TEST_CXXFLAGS=$TEST_CXXFLAGS
  527. TEST_CXXFLAGS_EXTRA=$TEST_CXXFLAGS_EXTRA
  528. CPPFLAGS=$CPPFLAGS
  529. LDFLAGS_BASE=$LDFLAGS_BASE
  530. LDFLAGS=$LDFLAGS
  531. LDFLAGS_EXTRA=$LDFLAGS_EXTRA
  532. TEST_LDFLAGS_BASE=$TEST_LDFLAGS_BASE
  533. TEST_LDFLAGS=$TEST_LDFLAGS
  534. TEST_LDFLAGS_EXTRA=$TEST_LDFLAGS_EXTRA
  535. BUILD_SHUTDOWN=$BUILD_SHUTDOWN
  536. STRIPOPTS=$STRIPOPTS
  537. # Dependencies
  538. LDFLAGS_LIBCAP=$LDFLAGS_LIBCAP
  539. # Feature settings
  540. SUPPORT_CGROUPS=$SUPPORT_CGROUPS
  541. USE_INITGROUPS=$USE_INITGROUPS
  542. SUPPORT_CAPABILITIES=$SUPPORT_CAPABILITIES
  543. SUPPORT_IOPRIO=$SUPPORT_IOPRIO
  544. SUPPORT_OOM_ADJ=$SUPPORT_OOM_ADJ
  545. # Optional settings
  546. SHUTDOWN_PREFIX=${SHUTDOWN_PREFIX:-}
  547. # Service defaults
  548. DEFAULT_AUTO_RESTART=$DEFAULT_AUTO_RESTART
  549. DEFAULT_START_TIMEOUT=$DEFAULT_START_TIMEOUT
  550. DEFAULT_STOP_TIMEOUT=$DEFAULT_STOP_TIMEOUT
  551. _EOF
  552. if [ -n "${USE_UTMPX:-}" ]; then
  553. echo "USE_UTMPX=$USE_UTMPX" >> mconfig
  554. fi
  555. if [ -n "${CXX_FOR_BUILD:-}" ]; then
  556. {
  557. echo ""
  558. echo "# For cross-compiling"
  559. echo "CXX_FOR_BUILD=$CXX_FOR_BUILD"
  560. } >> mconfig
  561. fi
  562. if [ -n "${CXXFLAGS_FOR_BUILD:-}" ]; then
  563. echo "CXXFLAGS_FOR_BUILD=$CXXFLAGS_FOR_BUILD" >> mconfig
  564. fi
  565. if [ -n "${CPPFLAGS_FOR_BUILD:-}" ]; then
  566. echo "CPPFLAGS_FOR_BUILD=$CPPFLAGS_FOR_BUILD" >> mconfig
  567. fi
  568. if [ -n "${LDFLAGS_FOR_BUILD:-}" ]; then
  569. echo "LDFLAGS_FOR_BUILD=$LDFLAGS_FOR_BUILD" >> mconfig
  570. fi
  571. sub_info done.
  572. info Done!
  573. exit 0