Extract common logic in OpenSSL-specific code
[tinc] / m4 / lz4.m4
1 dnl  lz4.m4: Tinc autoconf integration for the LZ4 codec.
2 dnl  Copyright 2015 Darik Horn <dajhorn@vanadac.com>.
3 dnl
4 dnl  This program is free software; you can redistribute it and/or modify
5 dnl  it under the terms of the GNU General Public License as published by
6 dnl  the Free Software Foundation; either version 2 of the License, or
7 dnl  (at your option) any later version.
8 dnl
9 dnl  This program is distributed in the hope that it will be useful,
10 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl  GNU General Public License for more details.
13 dnl
14 dnl  You should have received a copy of the GNU General Public License along
15 dnl  with this program; if not, write to the Free Software Foundation, Inc.,
16 dnl  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
19 AC_DEFUN([tinc_LZ4], [
20
21   AC_ARG_ENABLE([lz4],
22     AS_HELP_STRING([--disable-lz4], [disable lz4 compression support]))
23
24   AC_ARG_ENABLE([lz4-builtin],
25     AS_HELP_STRING([--disable-lz4-builtin], [do not use lz4 builtin]))
26
27   AS_IF([test "x$enable_lz4" != "xno"], [
28     AC_DEFINE(HAVE_LZ4, 1, [enable lz4 compression support])
29
30     AC_ARG_WITH(lz4,
31       AS_HELP_STRING([--with-lz4=DIR], [lz4 shared library prefix (eg: /usr/local)]),
32       [lz4="$withval"
33        CPPFLAGS="$CPPFLAGS-I$withval/include"
34        LDFLAGS="$LDFLAGS -L$withval/lib"]
35     )
36
37     AC_ARG_WITH(lz4-include,
38       AS_HELP_STRING([--with-lz4-include=DIR], [lz4 shared header directory]),
39       [lz4_include="$withval"
40        CPPFLAGS="$CPPFLAGS -I$withval"]
41     )
42
43     AC_ARG_WITH(lz4-lib,
44       AS_HELP_STRING([--with-lz4-lib=DIR], [lz4 shared object directory]),
45       [lz4_lib="$withval"
46        LDFLAGS="$LDFLAGS -L$withval"]
47     )
48
49     dnl First we check the system copy of the library
50     AS_IF([test "x$enable_lz4_builtin" != 'xyes'], [
51       AC_CHECK_HEADERS(lz4.h, [
52         AC_CHECK_LIB(lz4, LZ4_compress_fast_extState,
53           [lz4_header='<lz4.h>'
54            LIBS="$LIBS -llz4"])
55       ])
56     ])
57
58     dnl If it was not found or is too old, fallback to the built-in copy
59     AS_IF([test "x$enable_lz4_builtin" != 'xno' -a "x$lz4_header" = 'x'], [
60       lz4_header='"lib/lz4/lz4.h"'
61       lz4_builtin=1
62       AC_DEFINE(HAVE_LZ4_BUILTIN, 1, [Enable lz4 builtin.])
63     ])
64
65     dnl If the first one failed and the second one is disabled, there's nothing more we can do
66     AS_IF([test "x$lz4_header" = 'x'], [
67       AC_MSG_ERROR("lz4 library was not found and fallback to builtin is disabled.");
68     ])
69
70   ])
71
72   AC_DEFINE_UNQUOTED(LZ4_H, [$lz4_header], [Location of lz4.h])
73
74   AM_CONDITIONAL([CONFIGURE_LZ4_BUILTIN], [test "x$lz4_builtin" = 'x1'])
75
76 ])