1 dnl Copyright © 2011 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 m4_define([_DX_COMPUTE_C_STRING_PROG], [AC_LANG_PROGRAM([dnl
11 char thestr@<:@@:>@ = $1;
12 char padstr@<:@@:>@ = "\n!&?~" $1 "~?&!\n";
15 FILE *f = fopen("conftest.out", "w");
18 for (i = 0; i < sizeof thestr; i++) {
19 if (*(thestr+i) == '\n')
22 fprintf(f, "%s\n", thestr);
26 AC_DEFUN([_DX_COMPUTE_C_STRING_NORUN], [dnl
27 AC_REQUIRE([DX_PROG_STRINGS])
28 if test x"$STRINGS" = x""; then
29 AC_MSG_WARN([strings is recommended for cross compilation])
32 dx_c_strings="$STRINGS -n 1"
35 AC_COMPILE_IFELSE([_DX_COMPUTE_C_STRING_PROG([$2], [$3])], [dnl
36 $dx_c_strings conftest.$OBJEXT | sed -n '/^!&?~/ {
39 s/^!&?~\(.*\)~?&!$/\1/p
45 if read $1 < conftest.out; then :; else
46 AC_MSG_ERROR([failed to extract string due to cross compilation.])
49 ifelse([$4], [], [:], [$4])])
53 dnl DX_COMPUTE_C_STRING(variable, string, [prologue], [action-if-failed])
55 dnl Assigns the value of a C string literal specified by string to the shell
56 dnl variable specified by variable. Any newlines in the string are converted
57 dnl to spaces. In a cross compilation environment, it works by scanning a
58 dnl compiled object file.
59 AC_DEFUN([DX_COMPUTE_C_STRING], [dnl
61 AC_RUN_IFELSE([_DX_COMPUTE_C_STRING_PROG([$2], [$3])],
62 [read $1 < conftest.out],
63 [ifelse([$4], [], [:], [$4])],
64 [_DX_COMPUTE_C_STRING_NORUN([$1], [$2], [$3], [$4])])