dev-libs/openssl: arm/x86 stable, bug #575548
[gentoo.git] / dev-libs / openssl / openssl-1.0.2g-r2.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils flag-o-matic toolchain-funcs multilib multilib-minimal
8
9 MY_P=${P/_/-}
10 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
11 HOMEPAGE="http://www.openssl.org/"
12 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz"
13
14 LICENSE="openssl"
15 # subslot set to 1.0.2g version as this is the first release without SSLv2
16 # support and thus breaks nearly every openssl consumer (see bug #575548)
17 SLOT="0"
18 KEYWORDS="~alpha amd64 arm ~arm64 hppa ~ia64 ~m68k ~mips ~ppc ppc64 ~s390 ~sh ~sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
19 IUSE="+asm bindist gmp kerberos rfc3779 sctp cpu_flags_x86_sse2 static-libs test +tls-heartbeat vanilla zlib"
20 RESTRICT="!bindist? ( bindist )"
21
22 # The blocks are temporary just to make sure people upgrade to a
23 # version that lack runtime version checking.  We'll drop them in
24 # the future.
25 RDEPEND=">=app-misc/c_rehash-1.7-r1
26         gmp? ( >=dev-libs/gmp-5.1.3-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
27         zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )
28         kerberos? ( >=app-crypt/mit-krb5-1.11.4[${MULTILIB_USEDEP}] )
29         abi_x86_32? (
30                 !<=app-emulation/emul-linux-x86-baselibs-20140508
31                 !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)]
32         )
33         !<net-misc/openssh-5.9_p1-r4
34         !<net-libs/neon-0.29.6-r1"
35 DEPEND="${RDEPEND}
36         >=dev-lang/perl-5
37         sctp? ( >=net-misc/lksctp-tools-1.0.12 )
38         test? (
39                 sys-apps/diffutils
40                 sys-devel/bc
41         )"
42 PDEPEND="app-misc/ca-certificates"
43
44 S="${WORKDIR}/${MY_P}"
45
46 MULTILIB_WRAPPED_HEADERS=(
47         usr/include/openssl/opensslconf.h
48 )
49
50 src_prepare() {
51         # keep this in sync with app-misc/c_rehash
52         SSL_CNF_DIR="/etc/ssl"
53
54         # Make sure we only ever touch Makefile.org and avoid patching a file
55         # that gets blown away anyways by the Configure script in src_configure
56         rm -f Makefile
57
58         if ! use vanilla ; then
59                 epatch "${FILESDIR}"/${PN}-1.0.0a-ldflags.patch #327421
60                 epatch "${FILESDIR}"/${PN}-1.0.0d-windres.patch #373743
61                 epatch "${FILESDIR}"/${PN}-1.0.2g-parallel-build.patch
62                 epatch "${FILESDIR}"/${PN}-1.0.2a-parallel-obj-headers.patch
63                 epatch "${FILESDIR}"/${PN}-1.0.2a-parallel-install-dirs.patch
64                 epatch "${FILESDIR}"/${PN}-1.0.2a-parallel-symlinking.patch #545028
65                 epatch "${FILESDIR}"/${PN}-1.0.2-ipv6.patch
66                 epatch "${FILESDIR}"/${PN}-1.0.2a-x32-asm.patch #542618
67                 epatch "${FILESDIR}"/${PN}-1.0.1p-default-source.patch #554338
68
69                 epatch_user #332661
70         fi
71
72         # disable fips in the build
73         # make sure the man pages are suffixed #302165
74         # don't bother building man pages if they're disabled
75         sed -i \
76                 -e '/DIRS/s: fips : :g' \
77                 -e '/^MANSUFFIX/s:=.*:=ssl:' \
78                 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
79                 -e $(has noman FEATURES \
80                         && echo '/^install:/s:install_docs::' \
81                         || echo '/^MANDIR=/s:=.*:='${EPREFIX}'/usr/share/man:') \
82                 Makefile.org \
83                 || die
84         # show the actual commands in the log
85         sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
86
87         # since we're forcing $(CC) as makedep anyway, just fix
88         # the conditional as always-on
89         # helps clang (#417795), and versioned gcc (#499818)
90         sed -i 's/expr.*MAKEDEPEND.*;/true;/' util/domd || die
91
92         # quiet out unknown driver argument warnings since openssl
93         # doesn't have well-split CFLAGS and we're making it even worse
94         # and 'make depend' uses -Werror for added fun (#417795 again)
95         [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
96
97         # allow openssl to be cross-compiled
98         cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
99         chmod a+rx gentoo.config
100
101         append-flags -fno-strict-aliasing
102         append-flags $(test-flags-CC -Wa,--noexecstack)
103         append-cppflags -DOPENSSL_NO_BUF_FREELISTS
104
105         sed -i '1s,^:$,#!'${EPREFIX}'/usr/bin/perl,' Configure #141906
106         # The config script does stupid stuff to prompt the user.  Kill it.
107         sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
108         ./config --test-sanity || die "I AM NOT SANE"
109
110         multilib_copy_sources
111 }
112
113 multilib_src_configure() {
114         unset APPS #197996
115         unset SCRIPTS #312551
116         unset CROSS_COMPILE #311473
117
118         tc-export CC AR RANLIB RC
119
120         # Clean out patent-or-otherwise-encumbered code
121         # Camellia: Royalty Free            http://en.wikipedia.org/wiki/Camellia_(cipher)
122         # IDEA:     Expired                 http://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
123         # EC:       ????????? ??/??/2015    http://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
124         # MDC2:     Expired                 http://en.wikipedia.org/wiki/MDC-2
125         # RC5:      Expired                 http://en.wikipedia.org/wiki/RC5
126
127         use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
128         echoit() { echo "$@" ; "$@" ; }
129
130         local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
131
132         # See if our toolchain supports __uint128_t.  If so, it's 64bit
133         # friendly and can use the nicely optimized code paths. #460790
134         local ec_nistp_64_gcc_128
135         # Disable it for now though #469976
136         #if ! use bindist ; then
137         #       echo "__uint128_t i;" > "${T}"/128.c
138         #       if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
139         #               ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
140         #       fi
141         #fi
142
143         local sslout=$(./gentoo.config)
144         einfo "Use configuration ${sslout:-(openssl knows best)}"
145         local config="Configure"
146         [[ -z ${sslout} ]] && config="config"
147
148         echoit \
149         ./${config} \
150                 ${sslout} \
151                 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
152                 enable-camellia \
153                 $(use_ssl !bindist ec) \
154                 ${ec_nistp_64_gcc_128} \
155                 enable-idea \
156                 enable-mdc2 \
157                 enable-rc5 \
158                 enable-tlsext \
159                 enable-ssl2 \
160                 $(use_ssl asm) \
161                 $(use_ssl gmp gmp -lgmp) \
162                 $(use_ssl kerberos krb5 --with-krb5-flavor=${krb5}) \
163                 $(use_ssl rfc3779) \
164                 $(use_ssl sctp) \
165                 $(use_ssl tls-heartbeat heartbeats) \
166                 $(use_ssl zlib) \
167                 --prefix="${EPREFIX}"/usr \
168                 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
169                 --libdir=$(get_libdir) \
170                 shared threads \
171                 || die
172
173         # Clean out hardcoded flags that openssl uses
174         local CFLAG=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
175                 -e 's:^CFLAG=::' \
176                 -e 's:-fomit-frame-pointer ::g' \
177                 -e 's:-O[0-9] ::g' \
178                 -e 's:-march=[-a-z0-9]* ::g' \
179                 -e 's:-mcpu=[-a-z0-9]* ::g' \
180                 -e 's:-m[a-z0-9]* ::g' \
181         )
182         sed -i \
183                 -e "/^CFLAG/s|=.*|=${CFLAG} ${CFLAGS}|" \
184                 -e "/^SHARED_LDFLAGS=/s|$| ${LDFLAGS}|" \
185                 Makefile || die
186 }
187
188 multilib_src_compile() {
189         # depend is needed to use $confopts; it also doesn't matter
190         # that it's -j1 as the code itself serializes subdirs
191         emake -j1 depend
192         emake all
193         # rehash is needed to prep the certs/ dir; do this
194         # separately to avoid parallel build issues.
195         emake rehash
196 }
197
198 multilib_src_test() {
199         emake -j1 test
200 }
201
202 multilib_src_install() {
203         emake INSTALL_PREFIX="${D}" install
204 }
205
206 multilib_src_install_all() {
207         # openssl installs perl version of c_rehash by default, but
208         # we provide a shell version via app-misc/c_rehash
209         rm "${ED}"/usr/bin/c_rehash || die
210
211         dodoc CHANGES* FAQ NEWS README doc/*.txt doc/c-indentation.el
212         dohtml -r doc/*
213         use rfc3779 && dodoc engines/ccgost/README.gost
214
215         # This is crappy in that the static archives are still built even
216         # when USE=static-libs.  But this is due to a failing in the openssl
217         # build system: the static archives are built as PIC all the time.
218         # Only way around this would be to manually configure+compile openssl
219         # twice; once with shared lib support enabled and once without.
220         use static-libs || rm -f "${ED}"/usr/lib*/lib*.a
221
222         # create the certs directory
223         dodir ${SSL_CNF_DIR}/certs
224         cp -RP certs/* "${ED}"${SSL_CNF_DIR}/certs/ || die
225         rm -r "${ED}"${SSL_CNF_DIR}/certs/{demo,expired}
226
227         # Namespace openssl programs to prevent conflicts with other man pages
228         cd "${ED}"/usr/share/man
229         local m d s
230         for m in $(find . -type f | xargs grep -L '#include') ; do
231                 d=${m%/*} ; d=${d#./} ; m=${m##*/}
232                 [[ ${m} == openssl.1* ]] && continue
233                 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
234                 mv ${d}/{,ssl-}${m}
235                 # fix up references to renamed man pages
236                 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
237                 ln -s ssl-${m} ${d}/openssl-${m}
238                 # locate any symlinks that point to this man page ... we assume
239                 # that any broken links are due to the above renaming
240                 for s in $(find -L ${d} -type l) ; do
241                         s=${s##*/}
242                         rm -f ${d}/${s}
243                         ln -s ssl-${m} ${d}/ssl-${s}
244                         ln -s ssl-${s} ${d}/openssl-${s}
245                 done
246         done
247         [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
248
249         dodir /etc/sandbox.d #254521
250         echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
251
252         diropts -m0700
253         keepdir ${SSL_CNF_DIR}/private
254 }
255
256 pkg_preinst() {
257         has_version ${CATEGORY}/${PN}:0.9.8 && return 0
258         preserve_old_lib /usr/$(get_libdir)/lib{crypto,ssl}.so.0.9.8
259 }
260
261 pkg_postinst() {
262         ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
263         c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
264         eend $?
265
266         has_version ${CATEGORY}/${PN}:0.9.8 && return 0
267         preserve_old_lib_notify /usr/$(get_libdir)/lib{crypto,ssl}.so.0.9.8
268 }