]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUILD] fix platform-dependant build issues related to crypt()
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Mar 2010 18:10:14 +0000 (19:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 4 Mar 2010 18:10:14 +0000 (19:10 +0100)
Holger Just and Ross West reported build issues on FreeBSD and
Solaris that were initially caused by the definition of
_XOPEN_SOURCE at the top of auth.c, which was required on Linux
to avoid a build warning.

Krzysztof Oledzki found that using _GNU_SOURCE instead also worked
on Linux and did not cause any issue on several versions of FreeBSD.
Solaris still reported a warning this time, which was fixed by
including <crypt.h>, which itself is not present on FreeBSD nor on
all Linux toolchains.

So by adding a new build option (NEED_CRYPT_H), we can get Solaris
to get crypt() working and stop complaining at the same time, without
impacting other platforms.

This fix was tested at least on several linux toolchains (at least
uclibc, glibc 2.2.5, 2.3.6 and 2.7), on FreeBSD 4 to 8, Solaris 8
(which needs crypt.h), and AIX 5.3 (without crypt.h).

Every time it builds without a warning.

Makefile
src/auth.c

index 022731d8beb2851fdb5ddd8666e29d70c3e183c5..4c133558210d60e0553476eff9195385dafa03b2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,8 @@
 #   USE_TPROXY           : enable transparent proxy. Automatic.
 #   USE_LINUX_TPROXY     : enable full transparent proxy (need kernel patch).
 #   USE_LINUX_SPLICE     : enable kernel 2.6 splicing (broken on old kernels)
+#   USE_LIBCRYPT         : enable crypted passwords using -lcrypt
+#   USE_CRYPT_H          : set it if your system requires including crypt.h
 #
 # Options can be forced by specifying "USE_xxx=1" or can be disabled by using
 # "USE_xxx=" (empty string).
@@ -208,6 +210,8 @@ ifeq ($(TARGET),solaris)
   TARGET_CFLAGS  = -fomit-frame-pointer -DFD_SETSIZE=65536 -D_REENTRANT
   TARGET_LDFLAGS = -lnsl -lsocket
   USE_TPROXY     = implicit
+  USE_LIBCRYPT    = implicit
+  USE_CRYPT_H     = implicit
 else
 ifeq ($(TARGET),freebsd)
   # This is for FreeBSD
@@ -336,6 +340,11 @@ BUILD_OPTIONS   += $(call ignore_implicit,USE_LIBCRYPT)
 OPTIONS_LDFLAGS += -lcrypt
 endif
 
+ifneq ($(USE_CRYPT_H),)
+OPTIONS_CFLAGS  += -DNEED_CRYPT_H
+BUILD_OPTIONS   += $(call ignore_implicit,USE_CRYPT_H)
+endif
+
 ifneq ($(USE_POLL),)
 OPTIONS_CFLAGS += -DENABLE_POLL
 OPTIONS_OBJS   += src/ev_poll.o
index 93af8d68cce922d64400d1a5fe6d5bdd72a6d887..8ae4858640bb9069cc18160049df5f94cac1eb40 100644 (file)
  *
  */
 
-#define _XOPEN_SOURCE 500
+#ifdef CONFIG_HAP_CRYPT
+/* This is to have crypt() defined on Linux */
+#define _GNU_SOURCE
+
+#ifdef NEED_CRYPT_H
+/* some platforms such as Solaris need this */
+#include <crypt.h>
+#endif
+#endif /* CONFIG_HAP_CRYPT */
 
 #include <stdio.h>
 #include <stdlib.h>