Drop arm-linux keyword from tree.
[gentoo.git] / dev-libs / openssl / openssl-1.1.1_pre9.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 inherit flag-o-matic toolchain-funcs multilib multilib-minimal
7
8 MY_P=${P/_/-}
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"
12
13 LICENSE="openssl"
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 )"
19
20 RDEPEND=">=app-misc/c_rehash-1.7-r1
21         zlib? ( >=sys-libs/zlib-1.2.8-r1[static-libs(+)?,${MULTILIB_USEDEP}] )"
22 DEPEND="${RDEPEND}
23         >=dev-lang/perl-5
24         sctp? ( >=net-misc/lksctp-tools-1.0.12 )
25         test? (
26                 sys-apps/diffutils
27                 sys-devel/bc
28         )"
29 PDEPEND="app-misc/ca-certificates"
30
31 S="${WORKDIR}/${MY_P}"
32
33 MULTILIB_WRAPPED_HEADERS=(
34         usr/include/openssl/opensslconf.h
35 )
36
37 src_prepare() {
38         # keep this in sync with app-misc/c_rehash
39         SSL_CNF_DIR="/etc/ssl"
40
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
43         rm -f Makefile
44
45         if ! use vanilla ; then
46                 if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]] ; then
47                         [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
48                 fi
49         fi
50
51         eapply_user #332661
52
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
56         sed -i \
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 \
64                 || die
65
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
70
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
74
75         append-flags -fno-strict-aliasing
76         append-flags $(test-flags-CC -Wa,--noexecstack)
77         append-cppflags -DOPENSSL_NO_BUF_FREELISTS
78
79         # Prefixify Configure shebang (#141906)
80         sed \
81                 -e "1s,/usr/bin/env,${EPREFIX}&," \
82                 -i Configure || die
83         # Remove test target when FEATURES=test isn't set
84         if ! use test ; then
85                 sed \
86                         -e '/^$config{dirs}/s@ "test",@@' \
87                         -i Configure || die
88         fi
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"
92
93         multilib_copy_sources
94 }
95
96 multilib_src_configure() {
97         unset APPS #197996
98         unset SCRIPTS #312551
99         unset CROSS_COMPILE #311473
100
101         tc-export CC AR RANLIB RC
102
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
109
110         use_ssl() { usex $1 "enable-${2:-$1}" "no-${2:-$1}" " ${*:3}" ; }
111         echoit() { echo "$@" ; "$@" ; }
112
113         local krb5=$(has_version app-crypt/mit-krb5 && echo "MIT" || echo "Heimdal")
114
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"
123         #       fi
124         #fi
125
126         local sslout=$(./gentoo.config)
127         einfo "Use configuration ${sslout:-(openssl knows best)}"
128         local config="Configure"
129         [[ -z ${sslout} ]] && config="config"
130
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.
134         echoit \
135         ./${config} \
136                 ${sslout} \
137                 $(use cpu_flags_x86_sse2 || echo "no-sse2") \
138                 enable-camellia \
139                 $(use_ssl !bindist ec) \
140                 $(use_ssl !bindist srp) \
141                 $(use elibc_musl && echo "no-async") \
142                 ${ec_nistp_64_gcc_128} \
143                 enable-idea \
144                 enable-mdc2 \
145                 enable-rc5 \
146                 $(use_ssl sslv3 ssl3) \
147                 $(use_ssl sslv3 ssl3-method) \
148                 $(use_ssl asm) \
149                 $(use_ssl rfc3779) \
150                 $(use_ssl sctp) \
151                 $(use_ssl tls-heartbeat heartbeats) \
152                 $(use_ssl zlib) \
153                 --prefix="${EPREFIX}"/usr \
154                 --openssldir="${EPREFIX}"${SSL_CNF_DIR} \
155                 --libdir=$(get_libdir) \
156                 shared threads \
157                 || die
158
159         # Clean out hardcoded flags that openssl uses
160         # Fix quoting for sed
161         local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \
162                 -e 's:^CFLAGS=::' \
163                 -e 's:-fomit-frame-pointer ::g' \
164                 -e 's:-O[0-9] ::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' \
168                 -e 's:\\:\\\\:g' \
169         )
170         sed -i \
171                 -e "/^CFLAGS=/s|=.*|=${DEFAULT_CFLAGS} ${CFLAGS}|" \
172                 -e "/^LDFLAGS=/s|=[[:space:]]*$|=${LDFLAGS}|" \
173                 Makefile || die
174 }
175
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
179         emake -j1 depend
180         emake all
181 }
182
183 multilib_src_test() {
184         emake -j1 test
185 }
186
187 multilib_src_install() {
188         emake DESTDIR="${D}" install
189 }
190
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
195
196         dodoc CHANGES* FAQ NEWS README doc/*.txt doc/${PN}-c-indent.el
197
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
204
205         # create the certs directory
206         keepdir ${SSL_CNF_DIR}/certs
207
208         # Namespace openssl programs to prevent conflicts with other man pages
209         cd "${ED%/}"/usr/share/man || die
210         local m d s
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!"
215                 mv ${d}/{,ssl-}${m}
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
222                         s=${s##*/}
223                         rm -f ${d}/${s}
224                         # We don't want to "|| die" here
225                         ln -s ssl-${m} ${d}/ssl-${s}
226                         ln -s ssl-${s} ${d}/openssl-${s}
227                 done
228         done
229         [[ -n $(find -L ${d} -type l) ]] && die "broken manpage links found :("
230
231         dodir /etc/sandbox.d #254521
232         echo 'SANDBOX_PREDICT="/dev/crypto"' > "${ED%/}"/etc/sandbox.d/10openssl
233
234         diropts -m0700
235         keepdir ${SSL_CNF_DIR}/private
236 }
237
238 pkg_postinst() {
239         ebegin "Running 'c_rehash ${EROOT%/}${SSL_CNF_DIR}/certs/' to rebuild hashes #333069"
240         c_rehash "${EROOT%/}${SSL_CNF_DIR}/certs" >/dev/null
241         eend $?
242 }