1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
9 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
10 HOMEPAGE="https://www.openssl.org/"
11 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz"
14 SLOT="0/1.1" # .so version of libssl/libcrypto
15 [[ "${PV}" = *_pre* ]] || \
16 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x86-linux"
17 IUSE="+asm bindist elibc_musl rfc3779 sctp cpu_flags_x86_sse2 sslv3 static-libs test tls-heartbeat vanilla zlib"
18 RESTRICT="!bindist? ( bindist )"
20 RDEPEND=">=app-misc/c_rehash-1.7-r1
21 zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
24 sctp? ( >=net-misc/lksctp-tools-1.0.12 )
29 PDEPEND="app-misc/ca-certificates"
31 S="${WORKDIR}/${MY_P}"
33 MULTILIB_WRAPPED_HEADERS=(
34 usr/include/openssl/opensslconf.h
38 # keep this in sync with app-misc/c_rehash
39 SSL_CNF_DIR="/etc/ssl"
41 # Make sure we only ever touch Makefile.org and avoid patching a file
42 # that gets blown away anyways by the Configure script in src_configure
45 if ! use vanilla ; then
46 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
47 [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
53 # make sure the man pages are suffixed #302165
54 # don't bother building man pages if they're disabled
55 # Make DOCDIR Gentoo compliant
57 -e '/^MANSUFFIX/s:=.*:=ssl:' \
58 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
59 -e $(has noman FEATURES \
60 && echo '/^install:/s:install_docs::' \
61 || echo '/^MANDIR=/s:=.*:='${EPREFIX}'/usr/share/man:') \
62 -e "/^DOCDIR/s@\$(BASENAME)@&-${PF}@" \
63 Configurations/unix-Makefile.tmpl \
66 # quiet out unknown driver argument warnings since openssl
67 # doesn't have well-split CFLAGS and we're making it even worse
68 # and 'make depend' uses -Werror for added fun (#417795 again)
69 [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
71 # allow openssl to be cross-compiled
72 cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
73 chmod a+rx gentoo.config || die
75 append-flags -fno-strict-aliasing
76 append-flags $(test-flags-CC -Wa,--noexecstack)
77 append-cppflags -DOPENSSL_NO_BUF_FREELISTS
79 # Prefixify Configure shebang (#141906)
81 -e "1s,/usr/bin/env,${EPREFIX}&," \
83 # Remove test target when FEATURES=test isn't set
86 -e '/^$config{dirs}/s@ "test",@@' \
89 # The config script does stupid stuff to prompt the user. Kill it.
90 sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
91 ./config --test-sanity || die "I AM NOT SANE"
96 multilib_src_configure() {
99 unset CROSS_COMPILE #311473
101 tc-export CC AR RANLIB RC
103 # Clean out patent-or-otherwise-encumbered code
104 # Camellia: Royalty Free https://en.wikipedia.org/wiki/Camellia_(cipher)
105 # IDEA: Expired https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
106 # EC: ????????? ??/??/2015 https://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
107 # MDC2: Expired https://en.wikipedia.org/wiki/MDC-2
108 # RC5: Expired https://en.wikipedia.org/wiki/RC5
110 use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
111 echoit() { echo "$@" ; "$@" ; }
113 local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
115 # See if our toolchain supports __uint128_t. If so, it's 64bit
116 # friendly and can use the nicely optimized code paths. #460790
117 local ec_nistp_64_gcc_128
118 # Disable it for now though #469976
119 #if ! use bindist ; then
120 # echo "__uint128_t i;" > "${T}"/128.c
121 # if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
122 # ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
126 local sslout=$(./gentoo.config)
127 einfo "Use configuration ${sslout:-(openssl knows best)}"
128 local config="Configure"
129 [[ -z ${sslout} ]] && config="config"
131 # 'srp' was restricted until early 2017 as well.
132 # "disable-deprecated" option breaks too many consumers.
133 # Don't set it without thorough revdeps testing.
137 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
139 $(use_ssl !bindist ec) \
140 $(use_ssl !bindist srp) \
141 $(use elibc_musl && echo "no-async") \
142 ${ec_nistp_64_gcc_128} \
146 $(use_ssl sslv3 ssl3) \
147 $(use_ssl sslv3 ssl3-method) \
151 $(use_ssl tls-heartbeat heartbeats) \
153 --prefix="${EPREFIX}"/usr \
154 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
155 --libdir=$(get_libdir) \
159 # Clean out hardcoded flags that openssl uses
160 # Fix quoting for sed
161 local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
163 -e 's:-fomit-frame-pointer ::g' \
165 -e 's:-march=[-a-z0-9]* ::g' \
166 -e 's:-mcpu=[-a-z0-9]* ::g' \
167 -e 's:-m[a-z0-9]* ::g' \
171 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
172 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
176 multilib_src_compile() {
177 # depend is needed to use $confopts; it also doesn't matter
178 # that it's -j1 as the code itself serializes subdirs
183 multilib_src_test() {
187 multilib_src_install() {
188 emake DESTDIR="${D}" install
191 multilib_src_install_all() {
192 # openssl installs perl version of c_rehash by default, but
193 # we provide a shell version via app-misc/c_rehash
194 rm "${ED%/}"/usr/bin/c_rehash || die
196 dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
198 # This is crappy in that the static archives are still built even
199 # when USE=static-libs. But this is due to a failing in the openssl
200 # build system: the static archives are built as PIC all the time.
201 # Only way around this would be to manually configure+compile openssl
202 # twice; once with shared lib support enabled and once without.
203 use static-libs || rm -f "${ED%/}"/usr/lib*/lib*.a
205 # create the certs directory
206 keepdir ${SSL_CNF_DIR}/certs
208 # Namespace openssl programs to prevent conflicts with other man pages
209 cd "${ED%/}"/usr/share/man || die
211 for m in $(find . -type f | xargs grep -L '#include') ; do
212 d=${m%/*} ; d=${d#./} ; m=${m##*/}
213 [[ ${m} == openssl.1* ]] && continue
214 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
216 # fix up references to renamed man pages
217 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
218 ln -s ssl-${m} ${d}/openssl-${m}
219 # locate any symlinks that point to this man page ... we assume
220 # that any broken links are due to the above renaming
221 for s in $(find -L ${d} -type l) ; do
224 # We don't want to "|| die" here
225 ln -s ssl-${m} ${d}/ssl-${s}
226 ln -s ssl-${s} ${d}/openssl-${s}
229 [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
231 dodir /etc/sandbox.d #254521
232 echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED%/}"/etc/sandbox.d/10openssl
235 keepdir ${SSL_CNF_DIR}/private
239 ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
240 c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null