openssl: add option to disable PSK support
[oweals/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_BASE:=1.0.2
12 PKG_BUGFIX:=h
13 PKG_VERSION:=$(PKG_BASE)$(PKG_BUGFIX)
14 PKG_RELEASE:=1
15 PKG_USE_MIPS16:=0
16
17 PKG_BUILD_PARALLEL:=0
18
19 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
20 PKG_SOURCE_URL:=http://www.openssl.org/source/ \
21         ftp://ftp.openssl.org/source/ \
22         http://www.openssl.org/source/old/$(PKG_BASE)/ \
23         ftp://ftp.funet.fi/pub/crypt/mirrors/ftp.openssl.org/source \
24         ftp://ftp.sunet.se/pub/security/tools/net/openssl/source/
25 PKG_MD5SUM:=9392e65072ce4b614c1392eefc1f23d0
26
27 PKG_LICENSE:=OpenSSL
28 PKG_LICENSE_FILES:=LICENSE
29 PKG_CONFIG_DEPENDS:= \
30         CONFIG_OPENSSL_ENGINE_CRYPTO \
31         CONFIG_OPENSSL_ENGINE_DIGEST \
32         CONFIG_OPENSSL_WITH_EC \
33         CONFIG_OPENSSL_WITH_EC2M \
34         CONFIG_OPENSSL_WITH_SSL3 \
35         CONFIG_OPENSSL_HARDWARE_SUPPORT \
36         CONFIG_OPENSSL_WITH_DEPRECATED \
37         CONFIG_OPENSSL_WITH_COMPRESSION \
38         CONFIG_OPENSSL_WITH_NPN \
39         CONFIG_OPENSSL_WITH_PSK
40
41 include $(INCLUDE_DIR)/package.mk
42
43 ifneq ($(CONFIG_CCACHE),)
44 HOSTCC=$(HOSTCC_NOCACHE)
45 HOSTCXX=$(HOSTCXX_NOCACHE)
46 endif
47
48 define Package/openssl/Default
49   TITLE:=Open source SSL toolkit
50   URL:=http://www.openssl.org/
51 endef
52
53 define Package/libopenssl/config
54 source "$(SOURCE)/Config.in"
55 endef
56
57 define Package/openssl/Default/description
58 The OpenSSL Project is a collaborative effort to develop a robust,
59 commercial-grade, full-featured, and Open Source toolkit implementing the Secure
60 Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well
61 as a full-strength general purpose cryptography library.
62 endef
63
64 define Package/libopenssl
65 $(call Package/openssl/Default)
66   SECTION:=libs
67   SUBMENU:=SSL
68   CATEGORY:=Libraries
69   DEPENDS:=+OPENSSL_WITH_COMPRESSION:zlib
70   TITLE+= (libraries)
71   ABI_VERSION:=$(PKG_VERSION)
72   MENU:=1
73 endef
74
75 define Package/libopenssl/description
76 $(call Package/openssl/Default/description)
77 This package contains the OpenSSL shared libraries, needed by other programs.
78 endef
79
80 define Package/openssl-util
81   $(call Package/openssl/Default)
82   SECTION:=utils
83   CATEGORY:=Utilities
84   DEPENDS:=+libopenssl
85   TITLE+= (utility)
86 endef
87
88 define Package/openssl-util/conffiles
89 /etc/ssl/openssl.cnf
90 endef
91
92 define Package/openssl-util/description
93 $(call Package/openssl/Default/description)
94 This package contains the OpenSSL command-line utility.
95 endef
96
97
98 OPENSSL_NO_CIPHERS:= no-idea no-md2 no-mdc2 no-rc5 no-sha0 no-camellia no-krb5
99 OPENSSL_OPTIONS:= shared no-err no-sse2 no-ssl2
100
101 ifdef CONFIG_OPENSSL_ENGINE_CRYPTO
102   OPENSSL_OPTIONS += -DHAVE_CRYPTODEV
103   ifdef CONFIG_OPENSSL_ENGINE_DIGEST
104     OPENSSL_OPTIONS += -DUSE_CRYPTODEV_DIGESTS
105   endif
106 else
107   OPENSSL_OPTIONS += no-engines
108 endif
109
110 ifndef CONFIG_OPENSSL_WITH_EC
111   OPENSSL_OPTIONS += no-ec
112 endif
113
114 ifndef CONFIG_OPENSSL_WITH_EC2M
115   OPENSSL_OPTIONS += no-ec2m
116 endif
117
118 ifndef CONFIG_OPENSSL_WITH_SSL3
119   OPENSSL_OPTIONS += no-ssl3
120 endif
121
122 ifndef CONFIG_OPENSSL_HARDWARE_SUPPORT
123   OPENSSL_OPTIONS += no-hw
124 endif
125
126 ifndef CONFIG_OPENSSL_WITH_DEPRECATED
127   OPENSSL_OPTIONS += no-deprecated
128 endif
129
130 ifdef CONFIG_OPENSSL_WITH_COMPRESSION
131   OPENSSL_OPTIONS += zlib-dynamic
132 else
133   OPENSSL_OPTIONS += no-comp
134 endif
135
136 ifndef CONFIG_OPENSSL_WITH_NPN
137   OPENSSL_OPTIONS += no-nextprotoneg
138 endif
139
140 ifndef CONFIG_OPENSSL_WITH_PSK
141   OPENSSL_OPTIONS += no-psk
142 endif
143
144 ifeq ($(CONFIG_x86_64),y)
145   OPENSSL_TARGET:=linux-x86_64-openwrt
146   OPENSSL_MAKEFLAGS += LIBDIR=lib
147 else
148   OPENSSL_OPTIONS+=no-sse2
149   ifeq ($(CONFIG_mips)$(CONFIG_mipsel),y)
150     OPENSSL_TARGET:=linux-mips-openwrt
151 #  else ifeq ($(CONFIG_arm)$(CONFIG_armeb),y)
152 #    OPENSSL_TARGET:=linux-armv4-openwrt
153   else
154     OPENSSL_TARGET:=linux-generic-openwrt
155     OPENSSL_OPTIONS+=no-perlasm
156   endif
157 endif
158
159 STAMP_CONFIGURED := $(STAMP_CONFIGURED)_$(subst $(space),_,$(OPENSSL_OPTIONS))
160
161 define Build/Configure
162         [ -f $(STAMP_CONFIGURED) ] || { \
163                 rm -f $(PKG_BUILD_DIR)/*.so.* $(PKG_BUILD_DIR)/*.a; \
164                 find $(PKG_BUILD_DIR) -name \*.o | xargs rm -f; \
165         }
166         (cd $(PKG_BUILD_DIR); \
167                 ./Configure $(OPENSSL_TARGET) \
168                         --prefix=/usr \
169                         --openssldir=/etc/ssl \
170                         $(TARGET_CPPFLAGS) \
171                         $(TARGET_LDFLAGS) -ldl \
172                         -DOPENSSL_SMALL_FOOTPRINT \
173                         $(OPENSSL_NO_CIPHERS) \
174                         $(OPENSSL_OPTIONS) \
175         )
176         # XXX: OpenSSL "make depend" will look for installed headers before its own,
177         # so remove installed stuff first
178         -$(SUBMAKE) -j1 clean-staging
179         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
180                 MAKEDEPPROG="$(TARGET_CROSS)gcc" \
181                 OPENWRT_OPTIMIZATION_FLAGS="$(TARGET_CFLAGS)" \
182                 $(OPENSSL_MAKEFLAGS) \
183                 depend
184 endef
185
186 TARGET_CFLAGS += $(FPIC) -I$(CURDIR)/include
187
188 define Build/Compile
189         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
190                 CC="$(TARGET_CC)" \
191                 ASFLAGS="$(TARGET_ASFLAGS) -I$(PKG_BUILD_DIR)/crypto -c" \
192                 AR="$(TARGET_CROSS)ar r" \
193                 RANLIB="$(TARGET_CROSS)ranlib" \
194                 OPENWRT_OPTIMIZATION_FLAGS="$(TARGET_CFLAGS)" \
195                 $(OPENSSL_MAKEFLAGS) \
196                 all
197         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
198                 CC="$(TARGET_CC)" \
199                 ASFLAGS="$(TARGET_ASFLAGS) -I$(PKG_BUILD_DIR)/crypto -c" \
200                 AR="$(TARGET_CROSS)ar r" \
201                 RANLIB="$(TARGET_CROSS)ranlib" \
202                 OPENWRT_OPTIMIZATION_FLAGS="$(TARGET_CFLAGS)" \
203                 $(OPENSSL_MAKEFLAGS) \
204                 build-shared
205         # Work around openssl build bug to link libssl.so with libcrypto.so.
206         -rm $(PKG_BUILD_DIR)/libssl.so.*.*.*
207         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
208                 CC="$(TARGET_CC)" \
209                 OPENWRT_OPTIMIZATION_FLAGS="$(TARGET_CFLAGS)" \
210                 $(OPENSSL_MAKEFLAGS) \
211                 do_linux-shared
212         $(MAKE) -C $(PKG_BUILD_DIR) \
213                 CC="$(TARGET_CC)" \
214                 INSTALL_PREFIX="$(PKG_INSTALL_DIR)" \
215                 $(OPENSSL_MAKEFLAGS) \
216                 install
217 endef
218
219 define Build/InstallDev
220         $(INSTALL_DIR) $(1)/usr/include
221         $(CP) $(PKG_INSTALL_DIR)/usr/include/openssl $(1)/usr/include/
222         $(INSTALL_DIR) $(1)/usr/lib/
223         $(CP) $(PKG_INSTALL_DIR)/usr/lib/lib{crypto,ssl}.{a,so*} $(1)/usr/lib/
224         $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
225         $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/{openssl,libcrypto,libssl}.pc $(1)/usr/lib/pkgconfig/
226         [ -n "$(TARGET_LDFLAGS)" ] && $(SED) 's#$(TARGET_LDFLAGS)##g' $(1)/usr/lib/pkgconfig/{openssl,libcrypto,libssl}.pc || true
227 endef
228
229 define Package/libopenssl/install
230         $(INSTALL_DIR) $(1)/usr/lib
231         $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libcrypto.so.* $(1)/usr/lib/
232         $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libssl.so.* $(1)/usr/lib/
233 endef
234
235 define Package/openssl-util/install
236         $(INSTALL_DIR) $(1)/etc/ssl
237         $(CP) $(PKG_INSTALL_DIR)/etc/ssl/openssl.cnf $(1)/etc/ssl/
238         $(INSTALL_DIR) $(1)/etc/ssl/certs
239         $(INSTALL_DIR) $(1)/etc/ssl/private
240         chmod 0700 $(1)/etc/ssl/private
241         $(INSTALL_DIR) $(1)/usr/bin
242         $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/openssl $(1)/usr/bin/
243 endef
244
245 $(eval $(call BuildPackage,libopenssl))
246 $(eval $(call BuildPackage,openssl-util))