1#!/usr/bin/m4
2#
3# Copyright (c) 2017-2018 The strace developers.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14# 3. The name of the author may not be used to endorse or promote products
15#    derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28AC_DEFUN([st_DEMANGLE], [dnl
29
30AC_ARG_WITH([libiberty],
31	    [AS_HELP_STRING([--with-libiberty],
32			    [use libiberty to demangle symbols in stack trace])],
33	    [case "${withval}" in
34	     yes|no|check) ;;
35	     *) with_libiberty=yes
36		libiberty_CPPFLAGS="-I${withval}/include"
37		libiberty_LDFLAGS="-L${withval}/lib" ;;
38	     esac],
39	    [with_libiberty=check]
40)
41
42libiberty_CPPFLAGS=
43libiberty_LDFLAGS=
44libiberty_LIBS=
45use_libiberty=no
46
47AS_IF([test "x$with_libiberty" != xno],
48      [saved_CPPFLAGS="$CPPFLAGS"
49       CPPFLAGS="$CPPFLAGS $libiberty_CPPFLAGS"
50       AC_CHECK_HEADERS([demangle.h libiberty/demangle.h],
51	 [saved_LDFLAGS="$LDFLAGS"
52	  LDFLAGS="$LDFLAGS $libiberty_LDFLAGS"
53	  AC_CHECK_LIB([iberty],[cplus_demangle],
54	    [libiberty_LIBS="-liberty"
55	     use_libiberty=yes
56	    ],
57	    [if test "x$with_libiberty" != xcheck; then
58	       AC_MSG_FAILURE([failed to find cplus_demangle in libiberty])
59	     fi
60	    ]
61	  )
62	  LDFLAGS="$saved_LDFLAGS"
63	 ],
64	 [if test "x$with_libiberty" != xcheck; then
65	      AC_MSG_FAILURE([failed to find demangle.h])
66	  fi
67	 ]
68       )
69       CPPFLAGS="$saved_CPPFLAGS"
70      ]
71)
72
73AC_MSG_CHECKING([whether to enable symbols demangling in stack trace])
74if test "x$use_libiberty" = xyes; then
75	AC_DEFINE([USE_DEMANGLE], 1, [Do symbols demangling in stack trace])
76	AC_SUBST(libiberty_LIBS)
77	AC_SUBST(libiberty_LDFLAGS)
78	AC_SUBST(libiberty_CPPFLAGS)
79fi
80AC_MSG_RESULT([$use_libiberty])
81
82])
83