Add files from parent branch HEAD:
[pkgsrcv2.git] / security / openssl / builtin.mk
1 # $NetBSD: builtin.mk,v 1.27 2009/06/07 11:06:26 wiz Exp $
2
3 BUILTIN_PKG:=   openssl
4
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
9
10 .include "../../mk/buildlink3/bsd.builtin.mk"
11
12 ###
13 ### Determine if there is a built-in implementation of the package and
14 ### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
15 ###
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
20 .  endif
21 .endif
22 MAKEVARS+=      IS_BUILTIN.openssl
23
24 ###
25 ### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
26 ### a package name to represent the built-in package.
27 ###
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, ""); \
34                 }                                                       \
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;         \
39                         minor = "."i;                                   \
40                         i = 16 * (index(hex, substr($$3, 6, 1)) - 1);   \
41                         i += index(hex, substr($$3, 7, 1)) - 1;         \
42                         teeny = "."i;                                   \
43                         i = 16 * (index(hex, substr($$3, 8, 1)) - 1);   \
44                         i += index(hex, substr($$3, 9, 1)) - 1;         \
45                         if (i == 0) {                                   \
46                                 patchlevel = "";                        \
47                         } else if (i > 26) {                            \
48                                 patchlevel = "a";                       \
49                         } else {                                        \
50                                 patchlevel = alpha[i];                  \
51                         }                                               \
52                         printf "%s%s%s%s\n",                            \
53                                 major, minor, teeny, patchlevel;        \
54                         exit 0;                                         \
55                 }                                                       \
56         ' ${H_OPENSSLV}
57
58 .  if !empty(BUILTIN_VERSION.openssl:M0\.9\.6g) && \
59       empty(H_OPENSSLV:M__nonexistent__)
60 #
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.
63 #
64 BUILTIN_OPENSSL_HAS_20031107_FIX!=                                      \
65         ${AWK} 'BEGIN { ans = "no" }                                    \
66                 /OPENSSL_HAS_20031107_FIX/ { ans = "yes" }              \
67                 END { print ans; exit 0 }                               \
68         ' ${H_OPENSSLV}
69 .    if !empty(BUILTIN_OPENSSL_HAS_20031107_FIX:M[yY][eE][sS])
70 BUILTIN_VERSION.openssl=        0.9.6l
71 .    endif
72 #
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.
75 #
76 BUILTIN_OPENSSL_HAS_20040401_FIX!=                                      \
77         ${AWK} 'BEGIN { ans = "no" }                                    \
78                 /OPENSSL_HAS_20040401_FIX/ { ans = "yes" }              \
79                 END { print ans; exit 0 }                               \
80         ' ${H_OPENSSLV}
81 .    if !empty(BUILTIN_OPENSSL_HAS_20040401_FIX:M[yY][eE][sS])
82 BUILTIN_VERSION.openssl=        0.9.6m
83 .    endif
84 .  elif !empty(BUILTIN_VERSION.openssl:M0\.9\.7d) && \
85         empty(H_OPENSSLV:M__nonexistent__)
86 #
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.
90 #
91 BUILTIN_OPENSSL_HAS_20051011_FIX!=                                      \
92         ${AWK} 'BEGIN { ans = "no" }                                    \
93                 /OPENSSL_HAS_20051011_FIX/ { ans = "yes" }              \
94                 END { print ans; exit 0 }                               \
95         ' ${H_OPENSSLV}
96 .    if !empty(BUILTIN_OPENSSL_HAS_20051011_FIX:M[yY][eE][sS])
97 BUILTIN_VERSION.openssl=        0.9.7h
98 .    endif
99 .  endif
100 BUILTIN_PKG.openssl=    openssl-${BUILTIN_VERSION.openssl}
101 .endif
102 MAKEVARS+=      BUILTIN_PKG.openssl
103
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 }                               \
112         ' ${H_OPENSSLCONF:Q}
113 .endif
114 MAKEVARS+=      BUILTIN_OPENSSL_HAS_THREADS
115
116 ###
117 ### Determine whether we should use the built-in implementation if it
118 ### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
119 ###
120 .if !defined(USE_BUILTIN.openssl)
121 .  if ${PREFER.openssl} == "pkgsrc"
122 USE_BUILTIN.openssl=    no
123 .  else
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 \
132                 ${ECHO} yes;                                            \
133         else                                                            \
134                 ${ECHO} no;                                             \
135         fi
136 .        endif
137 .      endfor
138 .    endif
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
144 .      endif
145 .    endif
146 .  endif  # PREFER.openssl
147 .endif
148 MAKEVARS+=      USE_BUILTIN.openssl
149
150 ###
151 ### The section below only applies if we are not including this file
152 ### solely to determine whether a built-in implementation exists.
153 ###
154 CHECK_BUILTIN.openssl?= no
155 .if !empty(CHECK_BUILTIN.openssl:M[nN][oO])
156
157 .  if !empty(USE_BUILTIN.openssl:M[yY][eE][sS])
158 BUILDLINK_PREFIX.openssl=       /usr
159 .  endif
160
161 # By default, we don't bother with the old DES API.
162 USE_OLD_DES_API?=       no
163 .  if !empty(USE_OLD_DES_API:M[yY][eE][sS])
164 #
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.
168 #
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
174 .      endif
175 .    endif
176
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.
180 #
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.
183 #
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>.
192 #
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:
197         ${RUN}                                                          \
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."; \
205                 exit 0;                                                 \
206         elif ${GREP} -q "des_cblock" "$$odes_h" 2>/dev/null; then       \
207                 ${ECHO_BUILDLINK_MSG} "<openssl/des.h> supports old DES API."; \
208                 exit 0;                                                 \
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\"";                       \
216                 ) > $$bl_odes_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;                                    \
223                 exit 0;                                                 \
224         else                                                            \
225                 ${ECHO} "Unable to find headers for old DES API.";      \
226                 exit 1;                                                 \
227         fi
228 .    endif
229 .  endif  # USE_OLD_DES_API == yes
230
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"
235 SSLDIR= /etc/openssl
236 .    else
237 SSLDIR= /etc/ssl                # most likely place
238 .    endif
239 .  else
240 SSLDIR= ${PKG_SYSCONFBASEDIR}/openssl
241 .  endif
242
243 SSLCERTS=       ${SSLDIR}/certs
244 SSLKEYS=        ${SSLDIR}/private
245
246 BUILD_DEFS+=    SSLDIR SSLCERTS SSLKEYS
247
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
253
254 .    if !defined(HAS_OPENSSL_FAKE_PC)
255 HAS_OPENSSL_FAKE_PC=
256
257 openssl-fake-pc:
258         ${RUN} \
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}; \
264         else \
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"; \
270                 } >$${dst}; \
271         fi
272         ${RUN} \
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}; \
278         else \
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"; \
284                 } >$${dst}; \
285         fi
286         ${RUN} \
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}; \
292         else \
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"; \
298                 } >$${dst}; \
299         fi
300 .    endif
301 .  endif
302
303 .endif  # CHECK_BUILTIN.openssl