Add LZ4 compression support
[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 all lz4 compression support])
23   )
24
25   AC_ARG_ENABLE([lz4-builtin],
26     AS_HELP_STRING([--disable-lz4-builtin], [required to link an lz4 library])
27   )
28
29   AC_ARG_WITH(lz4,
30     AS_HELP_STRING([--with-lz4=DIR], [lz4 shared library prefix (eg: /usr/local)]),
31     [lz4="$withval" CPPFLAGS="$CPPFLAGS -I$withval/include" LDFLAGS="$LDFLAGS -L$withval/lib"]
32   )
33
34   AC_ARG_WITH(lz4-include,
35     AS_HELP_STRING([--with-lz4-include=DIR], [lz4 shared header directory]),
36     [lz4_include="$withval" CPPFLAGS="$CPPFLAGS -I$withval"]
37   )
38
39   AC_ARG_WITH(lz4-lib,
40     AS_HELP_STRING([--with-lz4-lib=DIR], [lz4 shared object directory]),
41     [lz4_lib="$withval" LDFLAGS="$LDFLAGS -L$withval"]
42   )
43
44   dnl Calling this early prevents autoconf lint.
45   AM_CONDITIONAL([CONFIGURE_LZ4_BUILTIN], [test "$enable_lz4_builtin" != 'no'])
46
47   AS_IF([test "$enable_lz4" != 'no' -a "$enable_lz4_builtin" != 'no' ], [
48     AC_DEFINE(HAVE_LZ4, 1, [Enable lz4 support.])
49     AC_DEFINE(HAVE_LZ4_BUILTIN, 1, [Enable lz4 builtin.])
50     AC_DEFINE(HAVE_LZ4_STATE, 1, [Enable lz4 external state features.])
51     AC_DEFINE(
52       [LZ4_compress_shim(a, b, c, d)],
53       [LZ4_compress_fast_extState(lz4_wrkmem, a, b, c, d, 0)],
54       [This is the best interface for the lz4 builtin.]
55     )
56   ],[
57     AS_IF([test "$enable_lz4" != 'no'], [
58       AC_CHECK_HEADERS(lz4.h, [
59         AC_DEFINE(LZ4_H, [<lz4.h>], [Location of lz4.h])
60
61         AC_CHECK_LIB(lz4, LZ4_compress_fast_extState, [
62           LIBS="$LIBS -llz4"
63           AC_DEFINE(HAVE_LZ4, 1, [Enable lz4 compression support.])
64           AC_DEFINE(HAVE_LZ4_STATE, 1, [Enable lz4 external state features.])
65           AC_DEFINE(
66             [LZ4_compress_shim(a, b, c, d)],
67             [LZ4_compress_fast_extState(lz4_wrkmem, a, b, c, d, 0)],
68             [The lz4-r129 library interface.]
69           )
70           break
71         ])
72
73         AC_CHECK_LIB(lz4, LZ4_compress_default, [
74           LIBS="$LIBS -llz4"
75           AC_DEFINE(HAVE_LZ4, 1, [Enable lz4 compression support.])
76           AC_DEFINE(
77             [LZ4_compress_shim(a, b, c, d)],
78             [LZ4_compress_default(a, b, c, d)],
79             [The lz4-r128 library interface.]
80           )
81           break
82         ])
83
84         AC_CHECK_LIB(lz4, LZ4_compress_limitedOutput, [
85           LIBS="$LIBS -llz4"
86           AC_DEFINE(HAVE_LZ4, 1, [Enable lz4 compression support.])
87           AC_DEFINE(
88             [LZ4_compress_shim(a, b, c, d)],
89             [LZ4_compress_limitedOutput(a, b, c, d)],
90             [The lz4-r59 library interface.]
91           )
92           AC_MSG_WARN("Using deprecated lz4-r59 interface.")
93           break
94         ])
95
96       ],[
97         AC_MSG_ERROR("lz4.h header file not found.")
98         break
99       ])
100
101     ])
102
103   ])
104
105 ])