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