1 # $NetBSD: builtin.mk,v 1.27 2009/06/07 11:06:26 wiz Exp $
5 BUILTIN_FIND_LIBS:= des
6 BUILTIN_FIND_FILES_VAR:= H_OPENSSLCONF H_OPENSSLV
7 BUILTIN_FIND_FILES.H_OPENSSLCONF= /usr/include/openssl/opensslconf.h
8 BUILTIN_FIND_FILES.H_OPENSSLV= /usr/include/openssl/opensslv.h
10 .include "../../mk/buildlink3/bsd.builtin.mk"
13 ### Determine if there is a built-in implementation of the package and
14 ### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
16 .if !defined(IS_BUILTIN.openssl)
17 IS_BUILTIN.openssl= no
18 . if empty(H_OPENSSLV:M__nonexistent__) && empty(H_OPENSSLV:M${LOCALBASE}/*)
19 IS_BUILTIN.openssl= yes
22 MAKEVARS+= IS_BUILTIN.openssl
25 ### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
26 ### a package name to represent the built-in package.
28 .if !defined(BUILTIN_PKG.openssl) && \
29 !empty(IS_BUILTIN.openssl:M[yY][eE][sS]) && \
30 empty(H_OPENSSLV:M__nonexistent__)
31 BUILTIN_VERSION.openssl!= \
32 ${AWK} 'BEGIN { hex="0123456789abcdef"; \
33 split("abcdefghijklmnopqrstuvwxyz", alpha, ""); \
35 /\#define[ ]*OPENSSL_VERSION_NUMBER/ { \
36 major = index(hex, substr($$3, 3, 1)) - 1; \
37 i = 16 * (index(hex, substr($$3, 4, 1)) - 1); \
38 i += index(hex, substr($$3, 5, 1)) - 1; \
40 i = 16 * (index(hex, substr($$3, 6, 1)) - 1); \
41 i += index(hex, substr($$3, 7, 1)) - 1; \
43 i = 16 * (index(hex, substr($$3, 8, 1)) - 1); \
44 i += index(hex, substr($$3, 9, 1)) - 1; \
47 } else if (i > 26) { \
50 patchlevel = alpha[i]; \
52 printf "%s%s%s%s\n", \
53 major, minor, teeny, patchlevel; \
58 . if !empty(BUILTIN_VERSION.openssl:M0\.9\.6g) && \
59 empty(H_OPENSSLV:M__nonexistent__)
61 # If the native OpenSSL contains the security fixes pulled up to the
62 # netbsd-1-6 branch on 2003-11-07, then pretend it's openssl-0.9.6l.
64 BUILTIN_OPENSSL_HAS_20031107_FIX!= \
65 ${AWK} 'BEGIN { ans = "no" } \
66 /OPENSSL_HAS_20031107_FIX/ { ans = "yes" } \
67 END { print ans; exit 0 } \
69 . if !empty(BUILTIN_OPENSSL_HAS_20031107_FIX:M[yY][eE][sS])
70 BUILTIN_VERSION.openssl= 0.9.6l
73 # If the native OpenSSL contains the security fixes pulled up to the
74 # netbsd-1-6 branch on 2004-04-01, then pretend it's openssl-0.9.6m.
76 BUILTIN_OPENSSL_HAS_20040401_FIX!= \
77 ${AWK} 'BEGIN { ans = "no" } \
78 /OPENSSL_HAS_20040401_FIX/ { ans = "yes" } \
79 END { print ans; exit 0 } \
81 . if !empty(BUILTIN_OPENSSL_HAS_20040401_FIX:M[yY][eE][sS])
82 BUILTIN_VERSION.openssl= 0.9.6m
84 . elif !empty(BUILTIN_VERSION.openssl:M0\.9\.7d) && \
85 empty(H_OPENSSLV:M__nonexistent__)
87 # If the native OpenSSL contains the security fixes pulled up to the
88 # netbsd-2-0, netbsd-2, and netbsd-3-0 branches on 2005-10-11, then
89 # pretend it's openssl-0.9.7h.
91 BUILTIN_OPENSSL_HAS_20051011_FIX!= \
92 ${AWK} 'BEGIN { ans = "no" } \
93 /OPENSSL_HAS_20051011_FIX/ { ans = "yes" } \
94 END { print ans; exit 0 } \
96 . if !empty(BUILTIN_OPENSSL_HAS_20051011_FIX:M[yY][eE][sS])
97 BUILTIN_VERSION.openssl= 0.9.7h
100 BUILTIN_PKG.openssl= openssl-${BUILTIN_VERSION.openssl}
102 MAKEVARS+= BUILTIN_PKG.openssl
104 .if !defined(BUILTIN_OPENSSL_HAS_THREADS) && \
105 !empty(IS_BUILTIN.openssl:M[yY][eE][sS]) && \
106 empty(H_OPENSSLCONF:M__nonexistent__)
107 BUILTIN_OPENSSL_HAS_THREADS!= \
108 ${AWK} 'BEGIN { ans = "no" } \
109 /\#[ ]*define[ ]*OPENSSL_THREADS/ { ans= "yes" } \
110 /\#[ ]*define[ ]*THREADS/ { ans = "yes" } \
111 END { print ans; exit 0 } \
114 MAKEVARS+= BUILTIN_OPENSSL_HAS_THREADS
117 ### Determine whether we should use the built-in implementation if it
118 ### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
120 .if !defined(USE_BUILTIN.openssl)
121 . if ${PREFER.openssl} == "pkgsrc"
122 USE_BUILTIN.openssl= no
124 USE_BUILTIN.openssl= ${IS_BUILTIN.openssl}
125 . if defined(BUILTIN_PKG.openssl) && \
126 !empty(IS_BUILTIN.openssl:M[yY][eE][sS])
127 USE_BUILTIN.openssl= yes
128 . for dep_ in ${BUILDLINK_API_DEPENDS.openssl}
129 . if !empty(USE_BUILTIN.openssl:M[yY][eE][sS])
130 USE_BUILTIN.openssl!= \
131 if ${PKG_ADMIN} pmatch ${dep_:Q} ${BUILTIN_PKG.openssl:Q}; then \
139 . if !empty(IS_BUILTIN.openssl:M[yY][eE][sS]) && \
140 defined(USE_FEATURES.openssl)
141 . if !empty(USE_FEATURES.openssl:Mthreads) && \
142 !empty(BUILTIN_OPENSSL_HAS_THREADS:M[nN][oO])
143 USE_BUILTIN.openssl= no
146 . endif # PREFER.openssl
148 MAKEVARS+= USE_BUILTIN.openssl
151 ### The section below only applies if we are not including this file
152 ### solely to determine whether a built-in implementation exists.
154 CHECK_BUILTIN.openssl?= no
155 .if !empty(CHECK_BUILTIN.openssl:M[nN][oO])
157 . if !empty(USE_BUILTIN.openssl:M[yY][eE][sS])
158 BUILDLINK_PREFIX.openssl= /usr
161 # By default, we don't bother with the old DES API.
163 . if !empty(USE_OLD_DES_API:M[yY][eE][sS])
165 # If we're using the old DES API, then check to see if the old DES
166 # code was factored out into a separate library and header files and
167 # no longer a part of libcrypto.
169 . if !empty(USE_BUILTIN.openssl:M[yY][eE][sS])
170 . if exists(${BUILDLINK_PREFIX.openssl}/include/des.h) && \
171 !empty(BUILTIN_LIB_FOUND.des:M[yY][eE][sS])
172 BUILDLINK_TRANSFORM+= l:crypto:des:crypto
173 WRAPPER_REORDER_CMDS+= reorder:l:des:crypto
177 # The idea is to avoid the need to patch source files for packages that
178 # use OpenSSL for DES support by ensuring that including <openssl/des.h>
179 # will always present the old DES API.
181 # (1) If des_old.h exists, then we're using OpenSSL>=0.9.7, and
182 # <openssl/des.h> already does the right thing.
184 # (2) If des_old.h doesn't exist, then one of two things is happening:
185 # (a) If <openssl/des.h> is old and (only) supports the old DES API,
186 # then <openssl/des.h> does the right thing.
187 # (b) If it's NetBSD's Special(TM) one that stripped out the old DES
188 # support into a separate library and header (-ldes, <des.h>),
189 # then we create a new header <openssl/des.h> that includes the
190 # system one and <des.h>, and we create an <openssl/des_old.h>
191 # that just includes <des.h>.
193 BUILDLINK_TARGETS+= buildlink-openssl-des-h
194 . if !target(buildlink-openssl-des-h)
195 .PHONY: buildlink-openssl-des-h
196 buildlink-openssl-des-h:
198 bl_odes_h="${BUILDLINK_DIR}/include/openssl/des.h"; \
199 bl_odes_old_h="${BUILDLINK_DIR}/include/openssl/des_old.h"; \
200 odes_h="${BUILDLINK_PREFIX.openssl}/include/openssl/des.h"; \
201 odes_old_h="${BUILDLINK_PREFIX.openssl}/include/openssl/des_old.h"; \
202 des_h="${BUILDLINK_PREFIX.openssl}/include/des.h"; \
203 if ${TEST} -f "$$odes_old_h"; then \
204 ${ECHO_BUILDLINK_MSG} "<openssl/des.h> supports old DES API."; \
206 elif ${GREP} -q "des_cblock" "$$odes_h" 2>/dev/null; then \
207 ${ECHO_BUILDLINK_MSG} "<openssl/des.h> supports old DES API."; \
209 elif ${TEST} -f "$$des_h" -a -f "$$odes_h"; then \
210 ${ECHO_BUILDLINK_MSG} "Creating $$bl_odes_h"; \
211 ${RM} -f $$bl_odes_h; \
212 ${MKDIR} `${DIRNAME} $$bl_odes_h`; \
213 ( ${ECHO} "/* Created by openssl/builtin.mk:${.TARGET} */"; \
214 ${ECHO} "#include \"$$odes_h\""; \
215 ${ECHO} "#include \"$$des_h\""; \
217 ${ECHO_BUILDLINK_MSG} "Creating $$bl_odes_old_h"; \
218 ${RM} -f $$bl_odes_old_h; \
219 ${MKDIR} `${DIRNAME} $$bl_odes_old_h`; \
220 ( ${ECHO} "/* Created by openssl/builtin.mk:${.TARGET} */"; \
221 ${ECHO} "#include \"$$des_h\""; \
222 ) > $$bl_odes_old_h; \
225 ${ECHO} "Unable to find headers for old DES API."; \
229 . endif # USE_OLD_DES_API == yes
231 . if defined(PKG_SYSCONFDIR.openssl)
232 SSLDIR= ${PKG_SYSCONFDIR.openssl}
233 . elif !empty(USE_BUILTIN.openssl:M[yY][eE][sS])
234 . if ${OPSYS} == "NetBSD"
237 SSLDIR= /etc/ssl # most likely place
240 SSLDIR= ${PKG_SYSCONFBASEDIR}/openssl
243 SSLCERTS= ${SSLDIR}/certs
244 SSLKEYS= ${SSLDIR}/private
246 BUILD_DEFS+= SSLDIR SSLCERTS SSLKEYS
248 # create pc files for builtin version; other versions assumed to contain them
249 # If we are using the builtin version, check whether it has a *.pc
250 # files or not. If the latter, generate fake ones.
251 . if !empty(USE_BUILTIN.openssl:M[Yy][Ee][Ss])
252 BUILDLINK_TARGETS+= openssl-fake-pc
254 . if !defined(HAS_OPENSSL_FAKE_PC)
259 src=${BUILDLINK_PREFIX.openssl}/lib/pkgconfig/libcrypto.pc; \
260 dst=${BUILDLINK_DIR}/lib/pkgconfig/libcrypto.pc; \
261 ${MKDIR} ${BUILDLINK_DIR}/lib/pkgconfig; \
262 if ${TEST} -f $${src}; then \
263 ${LN} -sf $${src} $${dst}; \
265 { ${ECHO} "Name: OpenSSL-libcrypto"; \
266 ${ECHO} "Description: OpenSSL cryptography library"; \
267 ${ECHO} "Version: ${BUILTIN_VERSION.openssl}"; \
268 ${ECHO} "Libs: -L${BUILDLINK_PREFIX.openssl}/lib -lcrypto"; \
269 ${ECHO} "Cflags: -I${BUILDLINK_PREFIX.openssl}/include"; \
273 src=${BUILDLINK_PREFIX.openssl}/lib/pkgconfig/libssl.pc; \
274 dst=${BUILDLINK_DIR}/lib/pkgconfig/libssl.pc; \
275 ${MKDIR} ${BUILDLINK_DIR}/lib/pkgconfig; \
276 if ${TEST} -f $${src}; then \
277 ${LN} -sf $${src} $${dst}; \
279 { ${ECHO} "Name: OpenSSL"; \
280 ${ECHO} "Description: Secure Sockets Layer and cryptography libraries"; \
281 ${ECHO} "Version: ${BUILTIN_VERSION.openssl}"; \
282 ${ECHO} "Libs: -L${BUILDLINK_PREFIX.openssl}/lib -lssl -lcrypto"; \
283 ${ECHO} "Cflags: -I${BUILDLINK_PREFIX.openssl}/include"; \
287 src=${BUILDLINK_PREFIX.openssl}/lib/pkgconfig/openssl.pc; \
288 dst=${BUILDLINK_DIR}/lib/pkgconfig/openssl.pc; \
289 ${MKDIR} ${BUILDLINK_DIR}/lib/pkgconfig; \
290 if ${TEST} -f $${src}; then \
291 ${LN} -sf $${src} $${dst}; \
293 { ${ECHO} "Name: OpenSSL"; \
294 ${ECHO} "Description: Secure Sockets Layer and cryptography libraries and tools"; \
295 ${ECHO} "Version: ${BUILTIN_VERSION.openssl}"; \
296 ${ECHO} "Libs: -L${BUILDLINK_PREFIX.openssl}/lib -lssl -lcrypto"; \
297 ${ECHO} "Cflags: -I${BUILDLINK_PREFIX.openssl}/include"; \
303 .endif # CHECK_BUILTIN.openssl