f9ba8f533c703d12c27023e3980886571815505b
[gentoo.git] / sys-libs / readline / readline-7.0_p5-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit flag-o-matic multilib-minimal toolchain-funcs usr-ldscript
7
8 # Official patches
9 # See ftp://ftp.cwru.edu/pub/bash/readline-7.0-patches/
10 PLEVEL="${PV##*_p}"
11 MY_PV="${PV/_p*}"
12 MY_PV="${MY_PV/_/-}"
13 MY_P="${PN}-${MY_PV}"
14 [[ ${PV} != *_p* ]] && PLEVEL=0
15 patches() {
16         [[ ${PLEVEL} -eq 0 ]] && return 1
17         local opt=$1
18         eval set -- {1..${PLEVEL}}
19         set -- $(printf "${PN}${MY_PV/\.}-%03d " "$@")
20         if [[ ${opt} == -s ]] ; then
21                 echo "${@/#/${DISTDIR}/}"
22         else
23                 local u
24                 for u in ftp://ftp.cwru.edu/pub/bash mirror://gnu/${PN} ; do
25                         printf "${u}/${PN}-${MY_PV}-patches/%s " "$@"
26                 done
27         fi
28 }
29
30 DESCRIPTION="Another cute console display library"
31 HOMEPAGE="https://tiswww.case.edu/php/chet/readline/rltop.html"
32
33 case ${PV} in
34         *_alpha*|*_beta*|*_rc*)
35                 SRC_URI+=" ftp://ftp.cwru.edu/pub/bash/${MY_P}.tar.gz"
36         ;;
37         *)
38                 SRC_URI="mirror://gnu/${PN}/${MY_P}.tar.gz $(patches)"
39         ;;
40 esac
41
42 LICENSE="GPL-3"
43 SLOT="0/7"  # subslot matches SONAME major
44 KEYWORDS="~alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 ~riscv s390 sh sparc x86 ~amd64-linux ~x86-linux"
45 IUSE="static-libs +unicode utils"
46
47 RDEPEND=">=sys-libs/ncurses-5.9-r3:0=[static-libs?,unicode?,${MULTILIB_USEDEP}]"
48 DEPEND="${RDEPEND}
49         virtual/pkgconfig"
50
51 S=${WORKDIR}/${MY_P}
52
53 PATCHES=(
54         "${FILESDIR}"/${PN}-5.0-no_rpath.patch
55         "${FILESDIR}"/${PN}-6.2-rlfe-tgoto.patch #385091
56         "${FILESDIR}"/${PN}-7.0-headers.patch
57         "${FILESDIR}"/${PN}-7.0-missing-echo-proto.patch
58         "${FILESDIR}"/${PN}-7.0-mingw.patch
59 )
60
61 # Needed because we don't want the patches being unpacked
62 # (which emits annoying and useless error messages)
63 src_unpack() {
64         unpack ${MY_P}.tar.gz
65 }
66
67 src_prepare() {
68         [[ ${PLEVEL} -gt 0 ]] && eapply -p0 $(patches -s)
69         default
70
71         # Force ncurses linking. #71420
72         # Use pkg-config to get the right values. #457558
73         local ncurses_libs=$($(tc-getPKG_CONFIG) ncurses$(usex unicode w '') --libs)
74         sed -i \
75                 -e "/^SHLIB_LIBS=/s:=.*:='${ncurses_libs}':" \
76                 support/shobj-conf || die
77         sed -i \
78                 -e "/^[[:space:]]*LIBS=.-lncurses/s:-lncurses:${ncurses_libs}:" \
79                 examples/rlfe/configure || die
80
81         # fix building under Gentoo/FreeBSD; upstream FreeBSD deprecated
82         # objformat for years, so we don't want to rely on that.
83         sed -i -e '/objformat/s:if .*; then:if true; then:' support/shobj-conf || die
84
85         ln -s ../.. examples/rlfe/readline || die # for local readline headers
86 }
87
88 src_configure() {
89         # fix implicit decls with widechar funcs
90         append-cppflags -D_GNU_SOURCE
91         # https://lists.gnu.org/archive/html/bug-readline/2010-07/msg00013.html
92         append-cppflags -Dxrealloc=_rl_realloc -Dxmalloc=_rl_malloc -Dxfree=_rl_free
93
94         # Make sure configure picks a better ar than `ar`. #484866
95         export ac_cv_prog_AR=$(tc-getAR)
96
97         # Force the test since we used sed above to force it.
98         export bash_cv_termcap_lib=ncurses
99
100         # Control cross-compiling cases when we know the right answer.
101         # In cases where the C library doesn't support wide characters, readline
102         # itself won't work correctly, so forcing the answer below should be OK.
103         if tc-is-cross-compiler ; then
104                 use kernel_Winnt || export bash_cv_func_sigsetjmp='present'
105                 export bash_cv_func_ctype_nonascii='yes'
106                 export bash_cv_wcwidth_broken='no' #503312
107         fi
108
109         # This is for rlfe, but we need to make sure LDFLAGS doesn't change
110         # so we can re-use the config cache file between the two.
111         append-ldflags -L.
112
113         multilib-minimal_src_configure
114 }
115
116 multilib_src_configure() {
117         local myeconfargs=(
118                 --cache-file="${BUILD_DIR}"/config.cache
119                 --with-curses
120                 $(use_enable static-libs static)
121         )
122         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
123
124         if use utils && multilib_is_native_abi && ! tc-is-cross-compiler ; then
125                 # code is full of AC_TRY_RUN()
126                 mkdir -p examples/rlfe || die
127                 cd examples/rlfe || die
128                 ECONF_SOURCE="${S}"/examples/rlfe \
129                 econf --cache-file="${BUILD_DIR}"/config.cache
130         fi
131 }
132
133 multilib_src_compile() {
134         emake
135
136         if use utils && multilib_is_native_abi && ! tc-is-cross-compiler ; then
137                 # code is full of AC_TRY_RUN()
138                 cd examples/rlfe || die
139                 local l
140                 for l in readline history ; do
141                         ln -s ../../shlib/lib${l}$(get_libname)* lib${l}$(get_libname) || die
142                         ln -s ../../lib${l}.a lib${l}.a || die
143                 done
144                 emake
145         fi
146 }
147
148 multilib_src_install() {
149         default
150
151         if multilib_is_native_abi ; then
152                 gen_usr_ldscript -a readline history #4411
153
154                 if use utils && ! tc-is-cross-compiler; then
155                         dobin examples/rlfe/rlfe
156                 fi
157         fi
158 }
159
160 multilib_src_install_all() {
161         HTML_DOCS="doc/history.html doc/readline.html doc/rluserman.html" einstalldocs
162         dodoc USAGE
163         docinto ps
164         dodoc doc/*.ps
165 }
166 pkg_preinst() {
167         # bug #29865
168         # Reappeared in #595324 with paludis so keeping this for now...
169         preserve_old_lib /$(get_libdir)/lib{history,readline}.so.{4,5,6}
170 }
171
172 pkg_postinst() {
173         preserve_old_lib_notify /$(get_libdir)/lib{history,readline}.so.{4,5,6}
174 }