Browse code

build: proper lzo detection and usage

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Adriaan de Jong <dejong@fox-it.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>

Alon Bar-Lev authored on 2012/03/01 05:12:09
Showing 12 changed files
... ...
@@ -41,9 +41,9 @@ AC_USE_SYSTEM_EXTENSIONS
41 41
 
42 42
 AC_ARG_ENABLE(
43 43
 	[lzo],
44
-	[AS_HELP_STRING([--disable-lzo], [disable LZO compression support])],
44
+	[AS_HELP_STRING([--enable-lzo], [enable LZO compression support])],
45 45
 	,
46
-	[enable_lzo="yes"]
46
+	[enable_lzo="no"]
47 47
 )
48 48
 
49 49
 AC_ARG_ENABLE(
... ...
@@ -241,19 +241,6 @@ AC_ARG_WITH(
241 241
 )
242 242
 
243 243
 AC_ARG_WITH(
244
-	[lzo-headers],
245
-	[AS_HELP_STRING([--with-lzo-headers=DIR], [LZO Include files location])],
246
-	[LZO_HDR_DIR="$withval"]
247
-	[CPPFLAGS="$CPPFLAGS -I$withval"] 
248
-)
249
-
250
-AC_ARG_WITH(
251
-	[lzo-lib],
252
-	[AS_HELP_STRING([--with-lzo-lib=DIR], [LZO Library location])],
253
-	[LDFLAGS="$LDFLAGS -L$withval"] 
254
-)
255
-
256
-AC_ARG_WITH(
257 244
 	[mem-check],
258 245
 	[AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=dmalloc|valgrind|ssl])],
259 246
 	[
... ...
@@ -664,41 +651,44 @@ case "${with_mem_check}" in
664 664
 		;;
665 665
 esac
666 666
 
667
-dnl
668
-dnl check for LZO library
669
-dnl
670
-if test "${enable_lzo}" = "yes" && test "${enable_lzo_stub}" = "no"; then
671
-   LZO_H=""
672
-   AC_CHECKING([for LZO Library and Header files])
673
-   AC_CHECK_HEADER(lzo/lzo1x.h,
674
-	[ LZO_H="2"
675
-	  lzolibs="lzo2 lzo"
676
-	  AC_DEFINE(LZO_HEADER_DIR, 1, [Use lzo/ directory prefix for LZO header files (for LZO 2.0)])
677
-	],
678
-	[ AC_CHECK_HEADER(lzo1x.h, [ LZO_H="1" ; lzolibs=lzo ]) ]
679
-   )
680
-
681
-   if test -n "$LZO_H"; then
682
-     havelzolib=0
683
-     for i in $lzolibs ; do
684
-	if test $havelzolib = 1 ; then break ; fi
685
-	AC_CHECK_LIB($i, lzo1x_1_15_compress,
686
-          [
687
-	    LIBS="${LIBS} -l$i"
688
-	    AC_DEFINE(USE_LZO, 1, [Use LZO compression library])
689
-	    AC_DEFINE_UNQUOTED(LZO_VERSION_NUM, "$LZO_H", [LZO version number])
690
-	    havelzolib=1
691
-	  ]
692
-        )
693
-     done
694
-     if test $havelzolib = 0 ; then
695
-       AC_MSG_ERROR([LZO headers were found but LZO library was not found])
696
-     fi
697
-   else
698
-     AC_MSG_RESULT([LZO headers were not found])
699
-     AC_MSG_RESULT([LZO library available from http://www.oberhumer.com/opensource/lzo/])
700
-     AC_MSG_ERROR([Or try ./configure --disable-lzo OR ./configure --enable-lzo-stub])
701
-   fi
667
+AC_ARG_VAR([LZO_CFLAGS], [C compiler flags for lzo])
668
+AC_ARG_VAR([LZO_LIBS], [linker flags for lzo])
669
+have_lzo="yes"
670
+if test -z "${LZO_LIBS}"; then
671
+	AC_CHECK_LIB(
672
+		[lzo2],
673
+		[lzo1x_1_15_compress],
674
+		[LZO_LIBS="-llzo2"],
675
+		[AC_CHECK_LIB(
676
+			[lzo],
677
+			[lzo1x_1_15_compress],
678
+			[LZO_LIBS="-llzo"],
679
+			[have_lzo="no"]
680
+		)]
681
+	)
682
+fi
683
+if test "${have_lzo}" = "yes"; then
684
+	saved_CFLAGS="${CFLAGS}"
685
+	CFLAGS="${CFLAGS} ${LZO_CFLAGS}"
686
+	AC_CHECK_HEADERS(
687
+		[lzo/lzoutil.h],
688
+		,
689
+		[AC_CHECK_HEADERS(
690
+			[lzoutil.h],
691
+			,
692
+			[AC_MSG_ERROR([lzoutil.h is missing])]
693
+		)]
694
+	)
695
+	AC_CHECK_HEADERS(
696
+		[lzo/lzo1x.h],
697
+		,
698
+		[AC_CHECK_HEADERS(
699
+			[lzo1x.h],
700
+			,
701
+			[AC_MSG_ERROR([lzo1x.h is missing])]
702
+		)]
703
+	)
704
+	CFLAGS="${saved_CFLAGS}"
702 705
 fi
703 706
 
704 707
 PKG_CHECK_MODULES(
... ...
@@ -862,11 +852,16 @@ if test "${enable_selinux}" = "yes"; then
862 862
 	AC_DEFINE([ENABLE_SELINUX], [1], [SELinux support])
863 863
 fi
864 864
 
865
+if test "${enable_lzo}" = "yes"; then
866
+	test "${have_lzo}" != "yes" && AC_MSG_ERROR([lzo enabled but missing])
867
+	OPTIONAL_LZO_CFLAGS="${LZO_CFLAGS}"
868
+	OPTIONAL_LZO_LIBS="${LZO_LIBS}"
869
+	AC_DEFINE([ENABLE_LZO], [1], [Enable LZO compression library])
870
+fi
865 871
 if test "${enable_lzo_stub}" = "yes"; then
866 872
 	test "${enable_lzo}" = "yes" && AC_MSG_ERROR([Cannot have both lzo stub and lzo enabled])
867 873
 	AC_DEFINE([ENABLE_LZO_STUB], [1], [Enable LZO stub capability])
868
-	AC_DEFINE([USE_LZO], [1], [Enable LZO compression library])
869
-	AC_DEFINE([LZO_VERSION_NUM], ["STUB"], [LZO version number])
874
+	AC_DEFINE([ENABLE_LZO], [1], [Enable LZO compression library])
870 875
 fi
871 876
 
872 877
 if test "${enable_pkcs11}" = "yes"; then
... ...
@@ -904,6 +899,8 @@ AC_SUBST([TAP_WIN_MIN_MINOR])
904 904
 
905 905
 AC_SUBST([OPTIONAL_DL_LIBS])
906 906
 AC_SUBST([OPTIONAL_SELINUX_LIBS])
907
+AC_SUBST([OPTIONAL_LZO_CFLAGS])
908
+AC_SUBST([OPTIONAL_LZO_LIBS])
907 909
 AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
908 910
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
909 911
 
... ...
@@ -110,7 +110,7 @@ Development support for OpenVPN.
110 110
 	--disable-dependency-tracking \
111 111
 	--docdir="%{_docdir}/%{name}-%{version}" \
112 112
 	%{?with_password_save:--enable-password-save} \
113
-	%{?without_lzo:--disable-lzo} \
113
+	%{!?without_lzo:--enable-lzo} \
114 114
 	%{?with_pkcs11:--enable-pkcs11} \
115 115
 	%{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
116 116
 %__make
... ...
@@ -68,7 +68,7 @@
68 68
  *
69 69
  * @par Settings that control this module's activity
70 70
  * Whether or not the Data Channel Compression module is active depends on
71
- * the compile-time \c USE_LZO preprocessor macro and the runtime flags
71
+ * the compile-time \c ENABLE_LZO preprocessor macro and the runtime flags
72 72
  * stored in \c lzo_compress_workspace.flags of the associated VPN tunnel.
73 73
  * The latter are initialized from \c options.lzo, which gets its value
74 74
  * from the process's configuration sources, such as its configuration
... ...
@@ -17,6 +17,7 @@ MAINTAINERCLEANFILES = \
17 17
 INCLUDES = -I$(top_srcdir)/include
18 18
 
19 19
 AM_CFLAGS = \
20
+	$(OPTIONAL_LZO_CFLAGS) \
20 21
 	$(OPTIONAL_PKCS11_HELPER_CFLAGS)
21 22
 
22 23
 sbin_PROGRAMS = openvpn
... ...
@@ -100,6 +101,7 @@ openvpn_SOURCES = \
100 100
 	cryptoapi.h cryptoapi.c
101 101
 openvpn_LDADD = \
102 102
 	$(SOCKETS_LIBS) \
103
+	$(OPTIONAL_LZO_LIBS) \
103 104
 	$(OPTIONAL_PKCS11_HELPER_LIBS) \
104 105
 	$(OPTIONAL_SELINUX_LIBS) \
105 106
 	$(OPTIONAL_DL_LIBS)
... ...
@@ -438,7 +438,7 @@ encrypt_sign (struct context *c, bool comp_frag)
438 438
 
439 439
   if (comp_frag)
440 440
     {
441
-#ifdef USE_LZO
441
+#ifdef ENABLE_LZO
442 442
       /* Compress the packet. */
443 443
       if (lzo_defined (&c->c2.lzo_compwork))
444 444
 	lzo_compress (&c->c2.buf, b->lzo_compress_buf, &c->c2.lzo_compwork, &c->c2.frame);
... ...
@@ -840,7 +840,7 @@ process_incoming_link (struct context *c)
840 840
 	fragment_incoming (c->c2.fragment, &c->c2.buf, &c->c2.frame_fragment);
841 841
 #endif
842 842
 
843
-#ifdef USE_LZO
843
+#ifdef ENABLE_LZO
844 844
       /* decompress the incoming packet */
845 845
       if (lzo_defined (&c->c2.lzo_compwork))
846 846
 	lzo_decompress (&c->c2.buf, c->c2.buffers->lzo_decompress_buf, &c->c2.lzo_compwork, &c->c2.frame);
... ...
@@ -1789,7 +1789,7 @@ do_deferred_options (struct context *c, const unsigned int found)
1789 1789
     }
1790 1790
 #endif
1791 1791
 
1792
-#ifdef USE_LZO
1792
+#ifdef ENABLE_LZO
1793 1793
   if (found & OPT_P_COMP)
1794 1794
     {
1795 1795
       if (lzo_defined (&c->c2.lzo_compwork))
... ...
@@ -2370,7 +2370,7 @@ do_init_crypto (struct context *c, const unsigned int flags)
2370 2370
 static void
2371 2371
 do_init_frame (struct context *c)
2372 2372
 {
2373
-#ifdef USE_LZO
2373
+#ifdef ENABLE_LZO
2374 2374
   /*
2375 2375
    * Initialize LZO compression library.
2376 2376
    */
... ...
@@ -2393,7 +2393,7 @@ do_init_frame (struct context *c)
2393 2393
       lzo_adjust_frame_parameters (&c->c2.frame_fragment_omit);	/* omit LZO frame delta from final frame_fragment */
2394 2394
 #endif
2395 2395
     }
2396
-#endif /* USE_LZO */
2396
+#endif /* ENABLE_LZO */
2397 2397
 
2398 2398
 #ifdef ENABLE_SOCKS
2399 2399
   /*
... ...
@@ -2564,7 +2564,7 @@ init_context_buffers (const struct frame *frame)
2564 2564
   b->decrypt_buf = alloc_buf (BUF_SIZE (frame));
2565 2565
 #endif
2566 2566
 
2567
-#ifdef USE_LZO
2567
+#ifdef ENABLE_LZO
2568 2568
   b->lzo_compress_buf = alloc_buf (BUF_SIZE (frame));
2569 2569
   b->lzo_decompress_buf = alloc_buf (BUF_SIZE (frame));
2570 2570
 #endif
... ...
@@ -2581,7 +2581,7 @@ free_context_buffers (struct context_buffers *b)
2581 2581
       free_buf (&b->read_tun_buf);
2582 2582
       free_buf (&b->aux_buf);
2583 2583
 
2584
-#ifdef USE_LZO
2584
+#ifdef ENABLE_LZO
2585 2585
       free_buf (&b->lzo_compress_buf);
2586 2586
       free_buf (&b->lzo_decompress_buf);
2587 2587
 #endif
... ...
@@ -3419,7 +3419,7 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int
3419 3419
       goto sig;
3420 3420
   }
3421 3421
 
3422
-#ifdef USE_LZO
3422
+#ifdef ENABLE_LZO
3423 3423
   /* initialize LZO compression library. */
3424 3424
   if ((options->lzo & LZO_SELECTED) && (c->mode == CM_P2P || child))
3425 3425
     lzo_compress_init (&c->c2.lzo_compwork, options->lzo);
... ...
@@ -3536,7 +3536,7 @@ close_instance (struct context *c)
3536 3536
 	/* if xinetd/inetd mode, don't allow restart */
3537 3537
 	do_close_check_if_restart_permitted (c);
3538 3538
 
3539
-#ifdef USE_LZO
3539
+#ifdef ENABLE_LZO
3540 3540
 	if (lzo_defined (&c->c2.lzo_compwork))
3541 3541
 	  lzo_compress_uninit (&c->c2.lzo_compwork);
3542 3542
 #endif
... ...
@@ -28,7 +28,7 @@
28 28
 
29 29
 #include "syshead.h"
30 30
 
31
-#ifdef USE_LZO
31
+#ifdef ENABLE_LZO
32 32
 
33 33
 #include "lzo.h"
34 34
 #include "error.h"
... ...
@@ -301,4 +301,4 @@ void lzo_print_stats (const struct lzo_compress_workspace *lzo_compwork, struct
301 301
 
302 302
 #else
303 303
 static void dummy(void) {}
304
-#endif /* USE_LZO */
304
+#endif /* ENABLE_LZO */
... ...
@@ -32,7 +32,7 @@
32 32
  */
33 33
 
34 34
 
35
-#ifdef USE_LZO
35
+#ifdef ENABLE_LZO
36 36
 
37 37
 /**
38 38
  * @addtogroup compression
... ...
@@ -40,11 +40,14 @@
40 40
  */
41 41
 
42 42
 #ifndef ENABLE_LZO_STUB
43
-#ifdef LZO_HEADER_DIR
43
+#if defined(HAVE_LZO_LZOUTIL_H)
44 44
 #include "lzo/lzoutil.h"
45
-#include "lzo/lzo1x.h"
46
-#else
45
+#elif defined(HAVE_LZOUTIL_H)
47 46
 #include "lzoutil.h"
47
+#endif
48
+#if defined(HAVE_LZO_LZO1X_H)
49
+#include "lzo/lzo1x.h"
50
+#elif defined(HAVE_LZO1X_H)
48 51
 #include "lzo1x.h"
49 52
 #endif
50 53
 #endif
... ...
@@ -340,5 +343,5 @@ lzo_defined (const struct lzo_compress_workspace *lzowork)
340 340
 /** @} addtogroup compression */
341 341
 
342 342
 
343
-#endif /* USE_LZO */
343
+#endif /* ENABLE_LZO */
344 344
 #endif
... ...
@@ -105,7 +105,7 @@ struct context_buffers
105 105
 #endif
106 106
 
107 107
   /* workspace buffers for LZO compression */
108
-#ifdef USE_LZO
108
+#ifdef ENABLE_LZO
109 109
   struct buffer lzo_compress_buf;
110 110
   struct buffer lzo_decompress_buf;
111 111
 #endif
... ...
@@ -372,7 +372,7 @@ struct context_2
372 372
 
373 373
 #endif /* USE_CRYPTO */
374 374
 
375
-#ifdef USE_LZO
375
+#ifdef ENABLE_LZO
376 376
   struct lzo_compress_workspace lzo_compwork;
377 377
                                 /**< Compression workspace used by the
378 378
                                  *   \link compression Data Channel
... ...
@@ -75,8 +75,12 @@ const char title_string[] =
75 75
 #endif /* defined(USE_POLARSSL) */
76 76
 #endif /* USE_SSL */
77 77
 #endif /* USE_CRYPTO */
78
-#ifdef USE_LZO
79
-  " [LZO" LZO_VERSION_NUM "]"
78
+#ifdef ENABLE_LZO
79
+#ifdef ENABLE_LZO_STUB
80
+  " [LZO (STUB)]"
81
+#else
82
+  " [LZO]"
83
+#endif
80 84
 #endif
81 85
 #if EPOLL
82 86
   " [EPOLL]"
... ...
@@ -354,7 +358,7 @@ static const char usage_message[] =
354 354
 #ifdef ENABLE_DEBUG
355 355
   "--gremlin mask  : Special stress testing mode (for debugging only).\n"
356 356
 #endif
357
-#ifdef USE_LZO
357
+#ifdef ENABLE_LZO
358 358
   "--comp-lzo      : Use fast LZO compression -- may add up to 1 byte per\n"
359 359
   "                  packet for uncompressible data.\n"
360 360
   "--comp-noadapt  : Don't use adaptive compression when --comp-lzo\n"
... ...
@@ -1512,7 +1516,7 @@ show_settings (const struct options *o)
1512 1512
 
1513 1513
   SHOW_BOOL (fast_io);
1514 1514
 
1515
-#ifdef USE_LZO
1515
+#ifdef ENABLE_LZO
1516 1516
   SHOW_INT (lzo);
1517 1517
 #endif
1518 1518
 
... ...
@@ -2954,7 +2958,7 @@ options_string (const struct options *o,
2954 2954
       tt = NULL;
2955 2955
     }
2956 2956
 
2957
-#ifdef USE_LZO
2957
+#ifdef ENABLE_LZO
2958 2958
   if (o->lzo & LZO_SELECTED)
2959 2959
     buf_printf (&out, ",comp-lzo");
2960 2960
 #endif
... ...
@@ -6180,7 +6184,7 @@ add_option (struct options *options,
6180 6180
       options->passtos = true;
6181 6181
     }
6182 6182
 #endif
6183
-#ifdef USE_LZO
6183
+#ifdef ENABLE_LZO
6184 6184
   else if (streq (p[0], "comp-lzo"))
6185 6185
     {
6186 6186
       VERIFY_PERMISSION (OPT_P_COMP);
... ...
@@ -6206,7 +6210,7 @@ add_option (struct options *options,
6206 6206
       VERIFY_PERMISSION (OPT_P_COMP);
6207 6207
       options->lzo &= ~LZO_ADAPTIVE;
6208 6208
     }
6209
-#endif /* USE_LZO */
6209
+#endif /* ENABLE_LZO */
6210 6210
 #ifdef USE_CRYPTO
6211 6211
   else if (streq (p[0], "show-ciphers"))
6212 6212
     {
... ...
@@ -343,7 +343,7 @@ struct options
343 343
   /* optimize TUN/TAP/UDP writes */
344 344
   bool fast_io;
345 345
 
346
-#ifdef USE_LZO
346
+#ifdef ENABLE_LZO
347 347
   /* LZO_x flags from lzo.h */
348 348
   unsigned int lzo;
349 349
 #endif
... ...
@@ -259,7 +259,7 @@ print_status (const struct context *c, struct status_output *so)
259 259
   status_printf (so, "TCP/UDP read bytes," counter_format, c->c2.link_read_bytes);
260 260
   status_printf (so, "TCP/UDP write bytes," counter_format, c->c2.link_write_bytes);
261 261
   status_printf (so, "Auth read bytes," counter_format, c->c2.link_read_bytes_auth);
262
-#ifdef USE_LZO
262
+#ifdef ENABLE_LZO
263 263
   if (lzo_defined (&c->c2.lzo_compwork))
264 264
     lzo_print_stats (&c->c2.lzo_compwork, so);
265 265
 #endif