1 dnl Copyright © 2014 Nick Bowler
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
7 dnl DX_COMMAND_OUTPUT(variable, command, [action-if-ok], [action-if-failed])
9 dnl Helper to capture standard output of a shell command. If the command
10 dnl is successful then variable is assigned with its output (with newlines
11 dnl converted to spaces), and action-if-ok is performed. Otherwise, if
12 dnl the command is unsuccessful, then variable is not changed, and
13 dnl action-if-failed is performed.
14 AC_DEFUN([DX_COMMAND_OUTPUT], [AC_REQUIRE([_DX_COMMAND_OUTPUT_SETUP])dnl
15 AS_IF([$2 >conftest.out 2>&AS_MESSAGE_LOG_FD],
16 [m4_do([dx_fn_cmdout_collect_output $1],
17 [m4_ifnblank([$3], [m4_newline([$3])])])],
22 AC_DEFUN_ONCE([_DX_COMMAND_OUTPUT_SETUP], [m4_divert_push([INIT_PREPARE])dnl
23 # Helper function to store the contents of conftest.out into a shell variable.
24 dx_fn_cmdout_collect_output () {
29 while read _dx_tmp <&3
32 [AS_VAR_APPEND([$][1], [" $_dx_tmp"])],
33 [AS_VAR_SET([$][1], [$_dx_tmp])])