1# SPDX-License-Identifier: FSFAP
2#
3# ===========================================================================
4#      https://gitlab.isc.org/isc-projects/autoconf-archive/ax_jemalloc.html
5# ===========================================================================
6#
7# SYNOPSIS
8#
9#   AX_CHECK_JEMALLOC([, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
10#
11# DESCRIPTION
12#
13#   Test for the jemalloc library in a path
14#
15# LICENSE
16#
17#   Copyright (c) 2021 Internet Systems Consortium
18#
19#   Copying and distribution of this file, with or without modification, are
20#   permitted in any medium without royalty provided the copyright notice
21#   and this notice are preserved. This file is offered as-is, without any
22#   warranty.
23
24#serial 1
25
26#
27AC_DEFUN([AX_CHECK_JEMALLOC], [
28     found=false
29     PKG_CHECK_MODULES(
30	[JEMALLOC], [jemalloc],
31	[
32	    found=true
33	], [
34	    AC_CHECK_HEADERS([malloc_np.h jemalloc/jemalloc.h],
35		[
36		    save_LIBS="$LIBS"
37		    save_LDFLAGS="$LDFLAGS"
38		    save_CPPFLAGS="$CPPFLAGS"
39		    AC_SEARCH_LIBS([mallocx], [jemalloc],
40			[
41			    found=true
42			    AS_IF([test "$ac_cv_search_mallocx" != "none required"],
43				[JEMALLOC_LIBS="$ac_cv_search_mallocx"])
44			])
45		    CPPFLAGS="$save_CPPFLAGS"
46		    LDFLAGS="$save_LDFLAGS"
47		    LIBS="$save_LIBS"
48		])
49	])
50
51    AS_IF([$found], [$1], [$2])
52
53    AC_SUBST([JEMALLOC_CFLAGS])
54    AC_SUBST([JEMALLOC_LIBS])
55])
56