sys-process/glances: 3.1.4.1-r1 amd64 stable, bug #720368
[gentoo.git] / dev-libs / openssl / openssl-1.1.1g.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
7
8 MY_P=${P/_/-}
9
10 # This patch set is based on the following files from Fedora 31,
11 # see https://src.fedoraproject.org/rpms/openssl/blob/f31/f/openssl.spec
12 # for more details:
13 # - hobble-openssl (SOURCE1)
14 # - ec_curve.c (SOURCE12) -- MODIFIED
15 # - ectest.c (SOURCE13)
16 # - openssl-1.1.1-ec-curves.patch (PATCH37) -- MODIFIED
17 BINDIST_PATCH_SET="openssl-1.1.1e-bindist-1.0.tar.xz"
18
19 DESCRIPTION="full-strength general purpose cryptography library (including SSL and TLS)"
20 HOMEPAGE="https://www.openssl.org/"
21 SRC_URI="mirror://openssl/source/${MY_P}.tar.gz
22         bindist? (
23                 mirror://gentoo/${BINDIST_PATCH_SET}
24                 https://dev.gentoo.org/~whissi/dist/openssl/${BINDIST_PATCH_SET}
25         )"
26
27 LICENSE="openssl"
28 SLOT="0/1.1" # .so version of libssl/libcrypto
29 [[ "${PV}" = *_pre* ]] || \
30 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~x86-linux"
31 IUSE="+asm bindist elibc_musl rfc3779 sctp cpu_flags_x86_sse2 sslv3 static-libs test tls-heartbeat vanilla zlib"
32 RESTRICT="!bindist? ( bindist )
33         !test? ( test )"
34
35 RDEPEND=">=app-misc/c_rehash-1.7-r1
36         zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
37 DEPEND="${RDEPEND}"
38 BDEPEND="
39         >=dev-lang/perl-5
40         sctp? ( >=net-misc/lksctp-tools-1.0.12 )
41         test? (
42                 sys-apps/diffutils
43                 sys-devel/bc
44                 sys-process/procps
45         )"
46 PDEPEND="app-misc/ca-certificates"
47
48 PATCHES=(
49         "${FILESDIR}"/${PN}-1.1.0j-parallel_install_fix.patch #671602
50 )
51
52 S="${WORKDIR}/${MY_P}"
53
54 # force upgrade to prevent broken login, bug 696950
55 RDEPEND+=" !<net-misc/openssh-8.0_p1-r3"
56
57 MULTILIB_WRAPPED_HEADERS=(
58         usr/include/openssl/opensslconf.h
59 )
60
61 pkg_setup() {
62         [[ ${MERGE_TYPE} == binary ]] && return
63
64         # must check in pkg_setup; sysctl don't work with userpriv!
65         if has test ${FEATURES} && use sctp; then
66                 # test_ssl_new will fail with "Ensure SCTP AUTH chunks are enabled in kernel"
67                 # if sctp.auth_enable is not enabled.
68                 local sctp_auth_status=$(sysctl -n net.sctp.auth_enable 2>/dev/null)
69                 if [[ -z "${sctp_auth_status}" ]] || [[ ${sctp_auth_status} != 1 ]]; then
70                         die "FEATURES=test with USE=sctp requires net.sctp.auth_enable=1!"
71                 fi
72         fi
73 }
74
75 src_prepare() {
76         # allow openssl to be cross-compiled
77         cp "${FILESDIR}"/gentoo.config-1.0.2 gentoo.config || die
78         chmod a+rx gentoo.config || die
79
80         if use bindist; then
81                 mv "${WORKDIR}"/bindist-patches/hobble-openssl "${WORKDIR}" || die
82                 bash "${WORKDIR}"/hobble-openssl || die
83
84                 cp -f "${WORKDIR}"/bindist-patches/ec_curve.c "${S}"/crypto/ec/ || die
85                 cp -f "${WORKDIR}"/bindist-patches/ectest.c "${S}"/test/ || die
86
87                 eapply "${WORKDIR}"/bindist-patches/ec-curves.patch
88
89                 local known_failing_test
90                 for known_failing_test in \
91                         30-test_evp_extra.t \
92                         80-test_ssl_new.t \
93                 ; do
94                         ebegin "Disabling test '${known_failing_test}' which is known to fail with USE=bindist"
95                         rm test/recipes/${known_failing_test} || die
96                         eend $?
97                 done
98
99                 # Also see the configure parts below:
100                 # enable-ec \
101                 # $(use_ssl !bindist ec2m) \
102         fi
103
104         # keep this in sync with app-misc/c_rehash
105         SSL_CNF_DIR="/etc/ssl"
106
107         # Make sure we only ever touch Makefile.org and avoid patching a file
108         # that gets blown away anyways by the Configure script in src_configure
109         rm -f Makefile
110
111         if ! use vanilla ; then
112                 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
113                         [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
114                 fi
115         fi
116
117         eapply_user #332661
118
119         if has test ${FEATURES} && use sctp && has network-sandbox ${FEATURES}; then
120                 ebegin "Disabling test '80-test_ssl_new.t' which is known to fail with FEATURES=network-sandbox"
121                 rm test/recipes/80-test_ssl_new.t || die
122                 eend $?
123         fi
124
125         # make sure the man pages are suffixed #302165
126         # don't bother building man pages if they're disabled
127         # Make DOCDIR Gentoo compliant
128         sed -i \
129                 -e '/^MANSUFFIX/s:=.*:=ssl:' \
130                 -e '/^MAKEDEPPROG/s:=.*:=$(CC):' \
131                 -e $(has noman FEATURES \
132                         && echo '/^install:/s:install_docs::' \
133                         || echo '/^MANDIR=/s:=.*:='${EPREFIX}'/usr/share/man:') \
134                 -e "/^DOCDIR/s@\$(BASENAME)@&-${PVR}@" \
135                 Configurations/unix-Makefile.tmpl \
136                 || die
137
138         # quiet out unknown driver argument warnings since openssl
139         # doesn't have well-split CFLAGS and we're making it even worse
140         # and 'make depend' uses -Werror for added fun (#417795 again)
141         [[ ${CC} == *clang* ]] && append-flags -Qunused-arguments
142
143         append-flags -fno-strict-aliasing
144         append-flags $(test-flags-CC -Wa,--noexecstack)
145         append-cppflags -DOPENSSL_NO_BUF_FREELISTS
146
147         # Prefixify Configure shebang (#141906)
148         sed \
149                 -e "1s,/usr/bin/env,${EPREFIX}&," \
150                 -i Configure || die
151         # Remove test target when FEATURES=test isn't set
152         if ! use test ; then
153                 sed \
154                         -e '/^$config{dirs}/s@ "test",@@' \
155                         -i Configure || die
156         fi
157         # The config script does stupid stuff to prompt the user.  Kill it.
158         sed -i '/stty -icanon min 0 time 50; read waste/d' config || die
159         ./config --test-sanity || die "I AM NOT SANE"
160
161         multilib_copy_sources
162 }
163
164 multilib_src_configure() {
165         unset APPS #197996
166         unset SCRIPTS #312551
167         unset CROSS_COMPILE #311473
168
169         tc-export CC AR RANLIB RC
170
171         # Clean out patent-or-otherwise-encumbered code
172         # Camellia: Royalty Free            https://en.wikipedia.org/wiki/Camellia_(cipher)
173         # IDEA:     Expired                 https://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm
174         # EC:       ????????? ??/??/2015    https://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography
175         # MDC2:     Expired                 https://en.wikipedia.org/wiki/MDC-2
176         # RC5:      Expired                 https://en.wikipedia.org/wiki/RC5
177
178         use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
179         echoit() { echo "$@" ; "$@" ; }
180
181         local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
182
183         # See if our toolchain supports __uint128_t.  If so, it's 64bit
184         # friendly and can use the nicely optimized code paths. #460790
185         local ec_nistp_64_gcc_128
186         # Disable it for now though #469976
187         #if ! use bindist ; then
188         #       echo "__uint128_t i;" > "${T}"/128.c
189         #       if ${CC} ${CFLAGS} -c "${T}"/128.c -o /dev/null >&/dev/null ; then
190         #               ec_nistp_64_gcc_128="enable-ec_nistp_64_gcc_128"
191         #       fi
192         #fi
193
194         local sslout=$(./gentoo.config)
195         einfo "Use configuration ${sslout:-(openssl knows best)}"
196         local config="Configure"
197         [[ -z ${sslout} ]] && config="config"
198
199         # Fedora hobbled-EC needs 'no-ec2m'
200         # 'srp' was restricted until early 2017 as well.
201         # "disable-deprecated" option breaks too many consumers.
202         # Don't set it without thorough revdeps testing.
203         # Make sure user flags don't get added *yet* to avoid duplicated
204         # flags.
205         CFLAGS= LDFLAGS= echoit \
206         ./${config} \
207                 ${sslout} \
208                 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
209                 enable-camellia \
210                 enable-ec \
211                 $(use_ssl !bindist ec2m) \
212                 enable-srp \
213                 $(use elibc_musl && echo "no-async") \
214                 ${ec_nistp_64_gcc_128} \
215                 enable-idea \
216                 enable-mdc2 \
217                 enable-rc5 \
218                 $(use_ssl sslv3 ssl3) \
219                 $(use_ssl sslv3 ssl3-method) \
220                 $(use_ssl asm) \
221                 $(use_ssl rfc3779) \
222                 $(use_ssl sctp) \
223                 $(use_ssl tls-heartbeat heartbeats) \
224                 $(use_ssl zlib) \
225                 --prefix="${EPREFIX}"/usr \
226                 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
227                 --libdir=$(get_libdir) \
228                 shared threads \
229                 || die
230
231         # Clean out hardcoded flags that openssl uses
232         local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
233                 -e 's:^CFLAGS=::' \
234                 -e 's:\(^\| \)-fomit-frame-pointer::g' \
235                 -e 's:\(^\| \)-O[^ ]*::g' \
236                 -e 's:\(^\| \)-march=[^ ]*::g' \
237                 -e 's:\(^\| \)-mcpu=[^ ]*::g' \
238                 -e 's:\(^\| \)-m[^ ]*::g' \
239                 -e 's:^ *::' \
240                 -e 's: *$::' \
241                 -e 's: \+: :g' \
242                 -e 's:\\:\\\\:g'
243         )
244
245         # Now insert clean default flags with user flags
246         sed -i \
247                 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
248                 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
249                 Makefile || die
250 }
251
252 multilib_src_compile() {
253         # depend is needed to use $confopts; it also doesn't matter
254         # that it's -j1 as the code itself serializes subdirs
255         emake -j1 depend
256         emake all
257 }
258
259 multilib_src_test() {
260         emake -j1 test
261 }
262
263 multilib_src_install() {
264         # We need to create $ED/usr on our own to avoid a race condition #665130
265         if [[ ! -d "${ED}/usr" ]]; then
266                 # We can only create this directory once
267                 mkdir "${ED}"/usr || die
268         fi
269
270         emake DESTDIR="${D}" install
271 }
272
273 multilib_src_install_all() {
274         # openssl installs perl version of c_rehash by default, but
275         # we provide a shell version via app-misc/c_rehash
276         rm "${ED}"/usr/bin/c_rehash || die
277
278         dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
279
280         # This is crappy in that the static archives are still built even
281         # when USE=static-libs.  But this is due to a failing in the openssl
282         # build system: the static archives are built as PIC all the time.
283         # Only way around this would be to manually configure+compile openssl
284         # twice; once with shared lib support enabled and once without.
285         use static-libs || rm -f "${ED}"/usr/lib*/lib*.a
286
287         # create the certs directory
288         keepdir ${SSL_CNF_DIR}/certs
289
290         # Namespace openssl programs to prevent conflicts with other man pages
291         cd "${ED}"/usr/share/man || die
292         local m d s
293         for m in $(find . -type f | xargs grep -L '#include') ; do
294                 d=${m%/*} ; d=${d#./} ; m=${m##*/}
295                 [[ ${m} == openssl.1* ]] && continue
296                 [[ -n $(find -L ${d} -type l) ]] && die "erp, broken links already!"
297                 mv ${d}/{,ssl-}${m}
298                 # fix up references to renamed man pages
299                 sed -i '/^[.]SH "SEE ALSO"/,/^[.]/s:\([^(, ]*(1)\):ssl-\1:g' ${d}/ssl-${m}
300                 ln -s ssl-${m} ${d}/openssl-${m}
301                 # locate any symlinks that point to this man page ... we assume
302                 # that any broken links are due to the above renaming
303                 for s in $(find -L ${d} -type l) ; do
304                         s=${s##*/}
305                         rm -f ${d}/${s}
306                         # We don't want to "|| die" here
307                         ln -s ssl-${m} ${d}/ssl-${s}
308                         ln -s ssl-${s} ${d}/openssl-${s}
309                 done
310         done
311         [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
312
313         dodir /etc/sandbox.d #254521
314         echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED}"/etc/sandbox.d/10openssl
315
316         diropts -m0700
317         keepdir ${SSL_CNF_DIR}/private
318 }
319
320 pkg_postinst() {
321         ebegin "Running 'c_rehash ${EROOT}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
322         c_rehash "${EROOT}${SSL_CNF_DIR}/certs" >/dev/null
323         eend $?
324 }