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