Import security/amavis-stats version 0.1.12_3
[dports.git] / Mk / bsd.openssl.mk
1 #
2 # $FreeBSD$
3 # bsd.openssl.mk - Support for OpenSSL based ports.
4 #
5 # Use of 'USE_OPENSSL=yes' includes this Makefile after bsd.ports.pre.mk
6 #
7 # the user/port can now set this options in the makefiles.
8 #
9 # WITH_OPENSSL_BASE=yes - Use the version in the base system.
10 # WITH_OPENSSL_PORT=yes - Use the port, even if base is up to date
11 #
12 # USE_OPENSSL_RPATH=yes - Pass RFLAGS options in CFLAGS,
13 #                         needed for ports who don't use LDFLAGS
14 #
15 # Overrideable defaults:
16 #
17 # OPENSSL_SHLIBVER=     3
18 # OPENSSL_PORT=         security/openssl
19 #
20 # The makefile sets this variables:
21 # OPENSSLBASE           - "/usr" or ${LOCALBASE}
22 # OPENSSLDIR            - path to openssl
23 # OPENSSLLIB            - path to the libs
24 # OPENSSLINC            - path to the matching includes
25 # OPENSSLRPATH          - rpath for dynamic linker
26 #
27 # MAKE_ENV              - extended with the variables above
28 # CONFIGURE_ENV         - extended with LDFLAGS
29 # BUILD_DEPENDS         - are added if needed
30 # RUN_DEPENDS           - are added if needed
31
32 OpenSSL_Include_MAINTAINER=     dinoex@FreeBSD.org
33
34 # honor obsolete options for a bit
35 .if defined(USE_OPENSSL_BASE) && !defined(WITH_OPENSSL_BASE)
36 WITH_OPENSSL_BASE=yes
37 .endif
38 .if defined(USE_OPENSSL_PORT) && !defined(WITH_OPENSSL_PORT)
39 WITH_OPENSSL_PORT=yes
40 .endif
41
42 #       if no preference was set, check for an installed base version
43 #       but give an installed port preference over it.
44 .if     !defined(WITH_OPENSSL_BASE) && \
45         !defined(WITH_OPENSSL_PORT) && \
46         !exists(${DESTDIR}/${LOCALBASE}/lib/libcrypto.so) && \
47         exists(${DESTDIR}/usr/include/openssl/opensslv.h)
48 WITH_OPENSSL_BASE=yes
49 .endif
50
51 .if defined(WITH_OPENSSL_BASE)
52 OPENSSLBASE=            /usr
53 OPENSSLDIR=             /etc/ssl
54
55 .if !exists(${DESTDIR}/usr/lib/libcrypto.so)
56 check-depends::
57         @${ECHO_CMD} "Dependency error: this port requires the OpenSSL library, which is part of"
58         @${ECHO_CMD} "the FreeBSD crypto distribution but not installed on your"
59         @${ECHO_CMD} "machine. Please see the \"OpenSSL\" section in the handbook"
60         @${ECHO_CMD} "(at \"http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/openssl.html\", for instance)"
61         @${ECHO_CMD} "for instructions on how to obtain and install the FreeBSD"
62         @${ECHO_CMD} "OpenSSL distribution."
63         @${FALSE}
64 .endif
65 .if exists(${LOCALBASE}/lib/libcrypto.so)
66 check-depends::
67         @${ECHO_CMD} "Dependency error: this port wants the OpenSSL library from the FreeBSD"
68         @${ECHO_CMD} "base system. You can't build against it, while a newer"
69         @${ECHO_CMD} "version is installed by a port."
70         @${ECHO_CMD} "Please deinstall the port or undefine WITH_OPENSSL_BASE."
71         @${FALSE}
72 .endif
73
74 # OpenSSL in the base system may not include IDEA for patent licensing reasons.
75 .if defined(MAKE_IDEA) && !defined(OPENSSL_IDEA)
76 OPENSSL_IDEA=           ${MAKE_IDEA}
77 .else
78 OPENSSL_IDEA?=          NO
79 .endif
80
81 .if ${OPENSSL_IDEA} == "NO"
82 # XXX This is a hack to work around the fact that /etc/make.conf clobbers
83 #     our CFLAGS. It might not be enough for all future ports.
84 .if defined(HAS_CONFIGURE)
85 CFLAGS+=                -DNO_IDEA
86 .else
87 OPENSSL_CFLAGS+=        -DNO_IDEA
88 .endif
89 MAKE_ARGS+=             OPENSSL_CFLAGS="${OPENSSL_CFLAGS}"
90 .endif
91 OPENSSLRPATH=           /usr/lib:${LOCALBASE}/lib
92
93 .else
94
95 OPENSSLBASE=            ${LOCALBASE}
96 .if     !defined(OPENSSL_PORT) && \
97         exists(${DESTDIR}/${LOCALBASE}/lib/libcrypto.so)
98 # find installed port and use it for dependency
99 PKG_DBDIR?=             ${DESTDIR}/var/db/pkg
100 .if !defined(OPENSSL_INSTALLED)
101 .if defined(WITH_PKGNG)
102 .if defined(DESTDIR)
103 PKGARGS=        -c ${DESTDIR}
104 .else
105 PKGARGS=
106 .endif
107 OPENSSL_INSTALLED!=     ${PKG_BIN} ${PKGARGS} which -qo ${LOCALBASE}/lib/libcrypto.so || :
108 .else
109 OPENSSL_INSTALLED!=     find "${PKG_DBDIR}/" -type f -name "+CONTENTS" -print0 | \
110                         xargs -0 grep -l "^lib/libssl.so." | \
111                         while read contents; do \
112                                 sslprefix=`grep "^@cwd " "$${contents}" | ${HEAD} -n 1`; \
113                                 if test "$${sslprefix}" = "@cwd ${LOCALBASE}" ; then \
114                                         echo "$${contents}"; break; fi; done
115 .endif
116 .endif
117 .if defined(OPENSSL_INSTALLED) && ${OPENSSL_INSTALLED} != ""
118 .if defined(WITH_PKGNG)
119 OPENSSL_PORT=           ${OPENSSL_INSTALLED}
120 OPENSSL_SHLIBFILE!=     ${PKG_INFO} -ql ${OPENSSL_INSTALLED} | grep "^`pkg query "%p" ${OPENSSL_INSTALLED}`/lib/libssl.so."
121 .else
122 OPENSSL_PORT!=          grep "^@comment ORIGIN:" "${OPENSSL_INSTALLED}" | ${CUT} -d : -f 2
123 OPENSSL_SHLIBFILE!=     grep "^lib/libssl.so." "${OPENSSL_INSTALLED}"
124 .endif
125 OPENSSL_SHLIBVER?=      ${OPENSSL_SHLIBFILE:E}
126 .else
127 # PKG_DBDIR was not found, default
128 OPENSSL_PORT?=          security/openssl
129 OPENSSL_SHLIBVER?=      8
130 .endif
131 .endif
132 OPENSSL_PORT?=          security/openssl
133 OPENSSL_SHLIBVER?=      8
134
135 OPENSSLDIR=             ${OPENSSLBASE}/openssl
136 BUILD_DEPENDS+=         ${LOCALBASE}/lib/libcrypto.so.${OPENSSL_SHLIBVER}:${PORTSDIR}/${OPENSSL_PORT}
137 RUN_DEPENDS+=           ${LOCALBASE}/lib/libcrypto.so.${OPENSSL_SHLIBVER}:${PORTSDIR}/${OPENSSL_PORT}
138 OPENSSLRPATH=           ${LOCALBASE}/lib
139
140 .endif
141
142 OPENSSLLIB=             ${OPENSSLBASE}/lib
143 OPENSSLINC=             ${OPENSSLBASE}/include
144
145 .if defined(USE_OPENSSL_RPATH)
146 CFLAGS+=                -Wl,-rpath,${OPENSSLRPATH}
147 .endif
148 OPENSSL_LDFLAGS+=       -Wl,-rpath,${OPENSSLRPATH}
149
150 LDFLAGS+=${OPENSSL_LDFLAGS}
151
152 MAKE_ENV+=              OPENSSLLIB=${OPENSSLLIB} OPENSSLINC=${OPENSSLINC} \
153                         OPENSSLBASE=${OPENSSLBASE} OPENSSLDIR=${OPENSSLDIR}
154
155 ### crypto
156 #RESTRICTED=            "Contains cryptography."
157