1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils flag-o-matic toolchain-funcs multilib multilib-minimal
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"
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)
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 )"
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
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}] )
30 !<=app-emulation/emul-linux-x86-baselibs-20140508
31 !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)]
33 !<net-misc/openssh-5.9_p1-r4
34 !<net-libs/neon-0.29.6-r1"
37 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
42 PDEPEND="app-misc/ca-certificates"
44 S="${WORKDIR}/${MY_P}"
46 MULTILIB_WRAPPED_HEADERS=(
47 usr/include/openssl/opensslconf.h
51 # keep this in sync with app-misc/c_rehash
52 SSL_CNF_DIR="/etc/ssl"
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
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
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
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:') \
84 # show the actual commands in the log
85 sed -i '/^SET_X/s:=.*:=set -x:' Makefile.shared
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
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
97 # allow openssl to be cross-compiled
98 cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
99 chmod a+rx gentoo.config
101 append-flags -fno-strict-aliasing
102 append-flags $(test-flags-CC -Wa,--noexecstack)
103 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
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"
110 multilib_copy_sources
113 multilib_src_configure() {
115 unset SCRIPTS #312551
116 unset CROSS_COMPILE #311473
118 tc-export CC AR RANLIB RC
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
127 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
128 echoit() { echo "$@" ; "$@" ; }
130 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
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"
143 local sslout=$(./gentoo.config)
144 einfo "Use configuration ${sslout:-(openssl knows best)}"
145 local config="Configure"
146 [[ -z ${sslout} ]] && config="config"
151 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
153 $(use_ssl !bindist ec) \
154 ${ec_nistp_64_gcc_128} \
161 $(use_ssl gmp gmp -lgmp) \
162 $(use_ssl kerberos krb5 --with-krb5-flavor=${krb5}) \
165 $(use_ssl tls-heartbeat heartbeats) \
167 --prefix="${EPREFIX}"/usr \
168 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
169 --libdir=$(get_libdir) \
173 # Clean out hardcoded flags that openssl uses
174 local CFLAG=$(grep ^CFLAG= Makefile | LC_ALL=C sed \
176 -e 's:-fomit-frame-pointer ::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' \
183 -e "/^CFLAG/s|=.*|=${CFLAG} ${CFLAGS}|" \
184 -e "/^SHARED_LDFLAGS=/s|$| ${LDFLAGS}|" \
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
193 # rehash is needed to prep the certs/ dir; do this
194 # separately to avoid parallel build issues.
198 multilib_src_test() {
202 multilib_src_install() {
203 emake INSTALL_PREFIX="${D}" install
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
211 dodoc CHANGES* FAQ NEWS README doc/*.txt doc/c-indentation.el
213 use rfc3779 && dodoc engines/ccgost/README.gost
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
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}
227 # Namespace openssl programs to prevent conflicts with other man pages
228 cd "${ED}"/usr/share/man
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!"
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
243 ln -s ssl-${m} ${d}/ssl-${s}
244 ln -s ssl-${s} ${d}/openssl-${s}
247 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
249 dodir /etc/sandbox.d #254521
250 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
253 keepdir ${SSL_CNF_DIR}/private
257 has_version ${CATEGORY}/${PN}:0.9.8 && return 0
258 preserve_old_lib /usr/$(get_libdir)/lib{crypto,ssl}.so.0.9.8
262 ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
263 c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
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