4829670f86fe70fad5a039f179ef3b8626cd052f
[openwrt/openwrt.git] / package / libs / openssl / Makefile
1 #
2 # Copyright (C) 2006-2016 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 PKG_NAME:=openssl
11 PKG_VERSION:=3.0.16
12 PKG_RELEASE:=1
13 PKG_BUILD_FLAGS:=no-mips16 gc-sections no-lto
14
15 PKG_BUILD_PARALLEL:=1
16
17 PKG_BASE:=$(subst $(space),.,$(wordlist 1,2,$(subst .,$(space),$(PKG_VERSION))))
18 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
19 PKG_SOURCE_URL:= \
20 https://www.openssl.org/source/ \
21 https://www.openssl.org/source/old/$(PKG_BASE)/ \
22 https://github.com/openssl/openssl/releases/download/$(PKG_NAME)-$(PKG_VERSION)/
23
24 PKG_HASH:=57e03c50feab5d31b152af2b764f10379aecd8ee92f16c985983ce4a99f7ef86
25
26 PKG_LICENSE:=Apache-2.0
27 PKG_LICENSE_FILES:=LICENSE
28 PKG_MAINTAINER:=Eneas U de Queiroz <cotequeiroz@gmail.com>
29 PKG_CPE_ID:=cpe:/a:openssl:openssl
30 PKG_CONFIG_DEPENDS:= \
31 CONFIG_OPENSSL_ENGINE \
32 CONFIG_OPENSSL_ENGINE_BUILTIN \
33 CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG \
34 CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO \
35 CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK \
36 CONFIG_OPENSSL_NO_DEPRECATED \
37 CONFIG_OPENSSL_OPTIMIZE_SPEED \
38 CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM \
39 CONFIG_OPENSSL_SMALL_FOOTPRINT \
40 CONFIG_OPENSSL_WITH_ARIA \
41 CONFIG_OPENSSL_WITH_ASM \
42 CONFIG_OPENSSL_WITH_ASYNC \
43 CONFIG_OPENSSL_WITH_BLAKE2 \
44 CONFIG_OPENSSL_WITH_CAMELLIA \
45 CONFIG_OPENSSL_WITH_CHACHA_POLY1305 \
46 CONFIG_OPENSSL_WITH_CMS \
47 CONFIG_OPENSSL_WITH_COMPRESSION \
48 CONFIG_OPENSSL_WITH_DTLS \
49 CONFIG_OPENSSL_WITH_EC2M \
50 CONFIG_OPENSSL_WITH_ERROR_MESSAGES \
51 CONFIG_OPENSSL_WITH_IDEA \
52 CONFIG_OPENSSL_WITH_MDC2 \
53 CONFIG_OPENSSL_WITH_NPN \
54 CONFIG_OPENSSL_WITH_PSK \
55 CONFIG_OPENSSL_WITH_RFC3779 \
56 CONFIG_OPENSSL_WITH_SEED \
57 CONFIG_OPENSSL_WITH_SM234 \
58 CONFIG_OPENSSL_WITH_SRP \
59 CONFIG_OPENSSL_WITH_SSE2 \
60 CONFIG_OPENSSL_WITH_TLS13 \
61 CONFIG_OPENSSL_WITH_WHIRLPOOL
62
63 include $(INCLUDE_DIR)/package.mk
64 include $(INCLUDE_DIR)/openssl-module.mk
65
66 ifneq ($(CONFIG_CCACHE),)
67 HOSTCC=$(HOSTCC_NOCACHE)
68 HOSTCXX=$(HOSTCXX_NOCACHE)
69 endif
70
71 define Package/openssl/Default
72 TITLE:=Open source SSL toolkit
73 URL:=https://www.openssl.org/
74 SECTION:=libs
75 CATEGORY:=Libraries
76 endef
77
78 define Package/libopenssl/config
79 source "$(SOURCE)/Config.in"
80 endef
81
82 define Package/openssl/Default/description
83 The OpenSSL Project is a collaborative effort to develop a robust,
84 commercial-grade, full-featured, and Open Source toolkit implementing the
85 Transport Layer Security (TLS) protocol as well as a full-strength
86 general-purpose cryptography library.
87 endef
88
89 define Package/libopenssl
90 $(call Package/openssl/Default)
91 SUBMENU:=SSL
92 DEPENDS:=+OPENSSL_WITH_COMPRESSION:zlib \
93 +OPENSSL_ENGINE_BUILTIN_AFALG:kmod-crypto-user \
94 +OPENSSL_ENGINE_BUILTIN_DEVCRYPTO:kmod-cryptodev \
95 +OPENSSL_ENGINE_BUILTIN_PADLOCK:kmod-crypto-hw-padlock \
96 +(arm||armeb||mips||mipsel||powerpc||arc):libatomic
97 TITLE+= (libraries)
98 ABI_VERSION:=$(firstword $(subst .,$(space),$(PKG_VERSION)))
99 MENU:=1
100 endef
101
102 define Package/libopenssl/description
103 $(call Package/openssl/Default/description)
104 This package contains the OpenSSL shared libraries, needed by other programs.
105 endef
106
107 define Package/openssl-util
108 $(call Package/openssl/Default)
109 SECTION:=utils
110 CATEGORY:=Utilities
111 DEPENDS:=+libopenssl +libopenssl-conf
112 TITLE+= (utility)
113 endef
114
115 define Package/openssl-util/description
116 $(call Package/openssl/Default/description)
117 This package contains the OpenSSL command-line utility.
118 endef
119
120 define Package/libopenssl-conf
121 $(call Package/openssl/Default)
122 SUBMENU:=SSL
123 TITLE:=/etc/ssl/openssl.cnf config file
124 DEPENDS:=libopenssl
125 endef
126
127 define Package/libopenssl-conf/conffiles
128 /etc/ssl/openssl.cnf
129 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),/etc/ssl/modules.cnf.d/devcrypto.cnf)
130 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK),/etc/ssl/modules.cnf.d/padlock.cnf)
131 endef
132
133 define Package/libopenssl-conf/description
134 $(call Package/openssl/Default/description)
135 This package installs the OpenSSL configuration file /etc/ssl/openssl.cnf.
136 endef
137
138 ifneq ($(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK)$(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),)
139 define Package/libopenssl-conf/postinst
140 #!/bin/sh
141
142 add_engine_config() {
143 if [ -z "$${IPKG_INSTROOT}" ] && uci -q get "openssl.$$1" >/dev/null; then
144 [ "$$(uci -q get "openssl.$$1.builtin")" = 1 ] && return
145 uci set "openssl.$$1.builtin=1" && uci commit openssl
146 return
147 fi
148 }
149
150 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),add_engine_config devcrypto)
151 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK),add_engine_config padlock)
152 endef
153 endif
154
155 $(eval $(call Package/openssl/add-provider,legacy))
156 define Package/libopenssl-legacy
157 $(call Package/openssl/Default)
158 $(call Package/openssl/module/Default)
159 TITLE:=OpenSSL legacy provider
160 endef
161
162 define Package/libopenssl-legacy/description
163 The OpenSSL legacy provider supplies OpenSSL implementations of algorithms that
164 have been deemed legacy. Such algorithms have commonly fallen out of use, have
165 been deemed insecure by the cryptography community, or something similar. See
166 https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html
167 endef
168
169 $(eval $(call Package/openssl/add-engine,afalg))
170 define Package/libopenssl-afalg
171 $(call Package/openssl/Default)
172 $(call Package/openssl/engine/Default)
173 TITLE:=AFALG hardware acceleration engine
174 DEPENDS += @KERNEL_AIO +PACKAGE_libopenssl-afalg:kmod-crypto-user \
175 @!OPENSSL_ENGINE_BUILTIN
176 endef
177
178 define Package/libopenssl-afalg/description
179 This package adds an engine that enables hardware acceleration
180 through the AF_ALG kernel interface.
181 See https://www.openssl.org/docs/man3.0/man5/config.html#Engine-Configuration
182 and https://openwrt.org/docs/techref/hardware/cryptographic.hardware.accelerators
183 The engine_id is "afalg"
184 endef
185
186 $(eval $(call Package/openssl/add-engine,devcrypto))
187 define Package/libopenssl-devcrypto
188 $(call Package/openssl/Default)
189 $(call Package/openssl/engine/Default)
190 TITLE:=/dev/crypto hardware acceleration engine
191 DEPENDS += +PACKAGE_libopenssl-devcrypto:kmod-cryptodev @!OPENSSL_ENGINE_BUILTIN
192 endef
193
194 define Package/libopenssl-devcrypto/description
195 This package adds an engine that enables hardware acceleration
196 through the /dev/crypto kernel interface.
197 See https://www.openssl.org/docs/man3.0/man5/config.html#Engine-Configuration
198 and https://openwrt.org/docs/techref/hardware/cryptographic.hardware.accelerators
199 The engine_id is "devcrypto"
200 endef
201
202 $(eval $(call Package/openssl/add-engine,padlock))
203 define Package/libopenssl-padlock
204 $(call Package/openssl/Default)
205 $(call Package/openssl/engine/Default)
206 TITLE:=VIA Padlock hardware acceleration engine
207 DEPENDS += @TARGET_x86 +PACKAGE_libopenssl-padlock:kmod-crypto-hw-padlock \
208 @!OPENSSL_ENGINE_BUILTIN
209 endef
210
211 define Package/libopenssl-padlock/description
212 This package adds an engine that enables VIA Padlock hardware acceleration.
213 See https://www.openssl.org/docs/man3.0/man5/config.html#Engine-Configuration
214 and https://openwrt.org/docs/techref/hardware/cryptographic.hardware.accelerators
215 The engine_id is "padlock"
216 endef
217
218 OPENSSL_OPTIONS:= shared no-tests
219
220 ifndef CONFIG_OPENSSL_WITH_BLAKE2
221 OPENSSL_OPTIONS += no-blake2
222 endif
223
224 ifndef CONFIG_OPENSSL_WITH_CHACHA_POLY1305
225 OPENSSL_OPTIONS += no-chacha no-poly1305
226 else
227 ifdef CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM
228 OPENSSL_OPTIONS += -DOPENSSL_PREFER_CHACHA_OVER_GCM
229 endif
230 endif
231
232 ifndef CONFIG_OPENSSL_WITH_ASYNC
233 OPENSSL_OPTIONS += no-async
234 endif
235
236 ifndef CONFIG_OPENSSL_WITH_EC2M
237 OPENSSL_OPTIONS += no-ec2m
238 endif
239
240 ifndef CONFIG_OPENSSL_WITH_ERROR_MESSAGES
241 OPENSSL_OPTIONS += no-err
242 endif
243
244 ifndef CONFIG_OPENSSL_WITH_TLS13
245 OPENSSL_OPTIONS += no-tls1_3
246 endif
247
248 ifndef CONFIG_OPENSSL_WITH_ARIA
249 OPENSSL_OPTIONS += no-aria
250 endif
251
252 ifndef CONFIG_OPENSSL_WITH_SM234
253 OPENSSL_OPTIONS += no-sm2 no-sm3 no-sm4
254 endif
255
256 ifndef CONFIG_OPENSSL_WITH_CAMELLIA
257 OPENSSL_OPTIONS += no-camellia
258 endif
259
260 ifndef CONFIG_OPENSSL_WITH_IDEA
261 OPENSSL_OPTIONS += no-idea
262 endif
263
264 ifndef CONFIG_OPENSSL_WITH_SEED
265 OPENSSL_OPTIONS += no-seed
266 endif
267
268 ifndef CONFIG_OPENSSL_WITH_MDC2
269 OPENSSL_OPTIONS += no-mdc2
270 endif
271
272 ifndef CONFIG_OPENSSL_WITH_WHIRLPOOL
273 OPENSSL_OPTIONS += no-whirlpool
274 endif
275
276 ifndef CONFIG_OPENSSL_WITH_CMS
277 OPENSSL_OPTIONS += no-cms
278 endif
279
280 ifndef CONFIG_OPENSSL_WITH_RFC3779
281 OPENSSL_OPTIONS += no-rfc3779
282 endif
283
284 ifdef CONFIG_OPENSSL_NO_DEPRECATED
285 OPENSSL_OPTIONS += no-deprecated
286 endif
287
288 ifeq ($(CONFIG_OPENSSL_OPTIMIZE_SPEED),y)
289 TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS)) -O3
290 endif
291
292 ifeq ($(CONFIG_OPENSSL_SMALL_FOOTPRINT),y)
293 OPENSSL_OPTIONS += -DOPENSSL_SMALL_FOOTPRINT
294 endif
295
296 ifdef CONFIG_OPENSSL_ENGINE
297 ifdef CONFIG_OPENSSL_ENGINE_BUILTIN
298 OPENSSL_OPTIONS += disable-dynamic-engine
299 ifndef CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG
300 OPENSSL_OPTIONS += no-afalgeng
301 endif
302 ifdef CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO
303 OPENSSL_OPTIONS += enable-devcryptoeng
304 endif
305 ifndef CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK
306 OPENSSL_OPTIONS += no-padlockeng
307 endif
308 else
309 ifdef CONFIG_PACKAGE_libopenssl-devcrypto
310 OPENSSL_OPTIONS += enable-devcryptoeng
311 endif
312 ifndef CONFIG_PACKAGE_libopenssl-afalg
313 OPENSSL_OPTIONS += no-afalgeng
314 endif
315 ifndef CONFIG_PACKAGE_libopenssl-padlock
316 OPENSSL_OPTIONS += no-padlockeng
317 endif
318 endif
319 else
320 OPENSSL_OPTIONS += no-engine
321 endif
322
323 ifndef CONFIG_OPENSSL_WITH_DTLS
324 OPENSSL_OPTIONS += no-dtls
325 endif
326
327 ifdef CONFIG_OPENSSL_WITH_COMPRESSION
328 OPENSSL_OPTIONS += zlib-dynamic
329 else
330 OPENSSL_OPTIONS += no-comp
331 endif
332
333 ifndef CONFIG_OPENSSL_WITH_NPN
334 OPENSSL_OPTIONS += no-nextprotoneg
335 endif
336
337 ifndef CONFIG_OPENSSL_WITH_PSK
338 OPENSSL_OPTIONS += no-psk
339 endif
340
341 ifndef CONFIG_OPENSSL_WITH_SRP
342 OPENSSL_OPTIONS += no-srp
343 endif
344
345 ifndef CONFIG_OPENSSL_WITH_ASM
346 OPENSSL_OPTIONS += no-asm
347 endif
348
349 ifdef CONFIG_i386
350 ifndef CONFIG_OPENSSL_WITH_SSE2
351 OPENSSL_OPTIONS += no-sse2
352 endif
353 endif
354
355 OPENSSL_TARGET:=linux-$(call qstrip,$(CONFIG_ARCH))-openwrt
356
357 STAMP_CONFIGURED := $(STAMP_CONFIGURED)_$(shell echo $(OPENSSL_OPTIONS) | $(MKHASH) md5)
358
359 define Build/Configure
360 (cd $(PKG_BUILD_DIR); \
361 ./Configure $(OPENSSL_TARGET) \
362 --prefix=/usr \
363 --libdir=lib \
364 --openssldir=/etc/ssl \
365 --cross-compile-prefix="$(TARGET_CROSS)" \
366 $(TARGET_CFLAGS) \
367 $(TARGET_CPPFLAGS) \
368 $(TARGET_LDFLAGS) \
369 $(OPENSSL_OPTIONS) && \
370 { [ -f $(STAMP_CONFIGURED) ] || make clean; } \
371 )
372 endef
373
374 TARGET_CFLAGS += $(FPIC)
375
376 define Build/Compile
377 +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
378 CC="$(TARGET_CC)" \
379 SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
380 OPENWRT_OPTIMIZATION_FLAGS="$(TARGET_CFLAGS)" \
381 $(OPENSSL_MAKEFLAGS) \
382 all
383 $(MAKE) -C $(PKG_BUILD_DIR) \
384 CC="$(TARGET_CC)" \
385 DESTDIR="$(PKG_INSTALL_DIR)" \
386 $(OPENSSL_MAKEFLAGS) \
387 install_sw install_ssldirs
388 endef
389
390 define Build/InstallDev
391 $(INSTALL_DIR) $(1)/usr/include
392 $(CP) $(PKG_INSTALL_DIR)/usr/include/openssl $(1)/usr/include/
393 $(INSTALL_DIR) $(1)/usr/lib/
394 $(CP) $(PKG_INSTALL_DIR)/usr/lib/lib{crypto,ssl}.{a,so*} $(1)/usr/lib/
395 $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
396 $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/{openssl,libcrypto,libssl}.pc $(1)/usr/lib/pkgconfig/
397 [ -n "$(TARGET_LDFLAGS)" ] && $(SED) 's#$(TARGET_LDFLAGS)##g' $(1)/usr/lib/pkgconfig/{openssl,libcrypto,libssl}.pc || true
398 endef
399
400 define Package/libopenssl/install
401 $(INSTALL_DIR) $(1)/etc/ssl/certs
402 $(INSTALL_DIR) $(1)/etc/ssl/private
403 chmod 0700 $(1)/etc/ssl/private
404 $(INSTALL_DIR) $(1)/usr/lib
405 $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libcrypto.so.* $(1)/usr/lib/
406 $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libssl.so.* $(1)/usr/lib/
407 $(if $(CONFIG_OPENSSL_ENGINE),$(INSTALL_DIR) $(1)/usr/lib/$(ENGINES_DIR))
408 endef
409
410 define Package/libopenssl-conf/install
411 $(INSTALL_DIR) $(1)/etc/ssl/modules.cnf.d $(1)/etc/config $(1)/etc/init.d
412 $(CP) $(PKG_INSTALL_DIR)/etc/ssl/openssl.cnf $(1)/etc/ssl/
413 $(INSTALL_BIN) ./files/openssl.init $(1)/etc/init.d/openssl
414 $(SED) 's!%ENGINES_DIR%!/usr/lib/$(ENGINES_DIR)!' $(1)/etc/init.d/openssl
415 touch $(1)/etc/config/openssl
416 $(if $(CONFIG_OPENSSL_ENGINE),,
417 $(SED) 's!engines = engines_sect!#&!' $(1)/etc/ssl/openssl.cnf)
418 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),
419 $(CP) ./files/devcrypto.cnf $(1)/etc/ssl/modules.cnf.d/
420 echo -e "config engine 'devcrypto'\n\toption enabled '1'\n\toption builtin '1'" >> $(1)/etc/config/openssl)
421 $(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK),
422 $(CP) ./files/padlock.cnf $(1)/etc/ssl/modules.cnf.d/
423 echo -e "\nconfig engine 'padlock'\n\toption enabled '1'\n\toption builtin '1'" >> $(1)/etc/config/openssl)
424 endef
425
426 define Package/openssl-util/install
427 $(INSTALL_DIR) $(1)/usr/bin
428 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/openssl $(1)/usr/bin/
429 endef
430
431 $(eval $(call BuildPackage,libopenssl))
432 $(eval $(call BuildPackage,libopenssl-conf))
433 $(eval $(call BuildPackage,libopenssl-afalg))
434 $(eval $(call BuildPackage,libopenssl-devcrypto))
435 $(eval $(call BuildPackage,libopenssl-legacy))
436 $(eval $(call BuildPackage,libopenssl-padlock))
437 $(eval $(call BuildPackage,openssl-util))