a660939753ad168e08f6d2ea84f89921dfcc2162
[gentoo.git] / app-shells / bash / bash-4.4_p23-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
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 prefix
7
8 # Official patchlevel
9 # See ftp://ftp.cwru.edu/pub/bash/bash-4.4-patches/
10 PLEVEL=${PV##*_p}
11 MY_PV=${PV/_p*}
12 MY_PV=${MY_PV/_/-}
13 MY_P=${PN}-${MY_PV}
14 is_release() {
15         case ${PV} in
16         *_alpha*|*_beta*|*_rc*) return 1 ;;
17         *) return 0 ;;
18         esac
19 }
20 [[ ${PV} != *_p* ]] && PLEVEL=0
21 patches() {
22         local opt=$1 plevel=${2:-${PLEVEL}} pn=${3:-${PN}} pv=${4:-${MY_PV}}
23         [[ ${plevel} -eq 0 ]] && return 1
24         eval set -- {1..${plevel}}
25         set -- $(printf "${pn}${pv/\.}-%03d " "$@")
26         if [[ ${opt} == -s ]] ; then
27                 echo "${@/#/${DISTDIR}/}"
28         else
29                 local u
30                 for u in ftp://ftp.cwru.edu/pub/bash mirror://gnu/${pn} ; do
31                         printf "${u}/${pn}-${pv}-patches/%s " "$@"
32                 done
33         fi
34 }
35
36 # The version of readline this bash normally ships with.
37 READLINE_VER="7.0"
38
39 DESCRIPTION="The standard GNU Bourne again shell"
40 HOMEPAGE="http://tiswww.case.edu/php/chet/bash/bashtop.html"
41 if is_release ; then
42         SRC_URI="mirror://gnu/bash/${MY_P}.tar.gz $(patches)"
43 else
44         SRC_URI="ftp://ftp.cwru.edu/pub/bash/${MY_P}.tar.gz"
45 fi
46
47 LICENSE="GPL-3"
48 SLOT="0"
49 KEYWORDS="~alpha amd64 ~arm arm64 ~hppa ia64 ~m68k ~mips ppc ppc64 ~s390 ~sh sparc x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
50 IUSE="afs bashlogger examples mem-scramble +net nls plugins +readline"
51
52 DEPEND="
53         >=sys-libs/ncurses-5.2-r2:0=
54         readline? ( >=sys-libs/readline-${READLINE_VER}:0= )
55         nls? ( virtual/libintl )
56 "
57 RDEPEND="
58         ${DEPEND}
59         !<sys-apps/portage-2.1.6.7_p1
60 "
61 # we only need yacc when the .y files get patched (bash42-005)
62 #DEPEND+=" virtual/yacc"
63
64 S="${WORKDIR}/${MY_P}"
65
66 pkg_setup() {
67         if is-flag -malign-double ; then #7332
68                 eerror "Detected bad CFLAGS '-malign-double'.  Do not use this"
69                 eerror "as it breaks LFS (struct stat64) on x86."
70                 die "remove -malign-double from your CFLAGS mr ricer"
71         fi
72         if use bashlogger ; then
73                 ewarn "The logging patch should ONLY be used in restricted (i.e. honeypot) envs."
74                 ewarn "This will log ALL output you enter into the shell, you have been warned."
75         fi
76 }
77
78 src_unpack() {
79         unpack ${MY_P}.tar.gz
80 }
81
82 src_prepare() {
83         # Include official patches
84         [[ ${PLEVEL} -gt 0 ]] && eapply -p0 $(patches -s)
85
86         eapply "${FILESDIR}/${PN}-4.4-jobs_overflow.patch" #644720
87         eapply "${FILESDIR}/${PN}-4.4-set-SHOBJ_STATUS.patch" #644720
88
89         # Clean out local libs so we know we use system ones w/releases.
90         if is_release ; then
91                 rm -rf lib/{readline,termcap}/*
92                 touch lib/{readline,termcap}/Makefile.in # for config.status
93                 sed -ri -e 's:\$[(](RL|HIST)_LIBSRC[)]/[[:alpha:]]*.h::g' Makefile.in || die
94         fi
95
96         # Prefixify hardcoded path names. No-op for non-prefix.
97         hprefixify pathnames.h.in
98
99         # Avoid regenerating docs after patches #407985
100         sed -i -r '/^(HS|RL)USER/s:=.*:=:' doc/Makefile.in || die
101         touch -r . doc/*
102
103         eapply_user
104 }
105
106 src_configure() {
107         local myconf=(
108                 --disable-profiling
109                 --docdir='$(datarootdir)'/doc/${PF}
110                 --htmldir='$(docdir)/html'
111                 --with-curses
112                 $(use_enable mem-scramble)
113                 $(use_enable net net-redirections)
114                 $(use_enable readline)
115                 $(use_enable readline bang-history)
116                 $(use_enable readline history)
117                 $(use_with afs)
118                 $(use_with mem-scramble bash-malloc)
119         )
120
121         # For descriptions of these, see config-top.h
122         # bashrc/#26952 bash_logout/#90488 ssh/#24762 mktemp/#574426
123         append-cppflags \
124                 -DDEFAULT_PATH_VALUE=\'\"${EPREFIX}/usr/local/sbin:${EPREFIX}/usr/local/bin:${EPREFIX}/usr/sbin:${EPREFIX}/usr/bin:${EPREFIX}/sbin:${EPREFIX}/bin\"\' \
125                 -DSTANDARD_UTILS_PATH=\'\"${EPREFIX}/bin:${EPREFIX}/usr/bin:${EPREFIX}/sbin:${EPREFIX}/usr/sbin\"\' \
126                 -DSYS_BASHRC=\'\"${EPREFIX}/etc/bash/bashrc\"\' \
127                 -DSYS_BASH_LOGOUT=\'\"${EPREFIX}/etc/bash/bash_logout\"\' \
128                 -DNON_INTERACTIVE_LOGIN_SHELLS \
129                 -DSSH_SOURCE_BASHRC \
130                 $(use bashlogger && echo -DSYSLOG_HISTORY)
131
132         # Don't even think about building this statically without
133         # reading Bug 7714 first.  If you still build it statically,
134         # don't come crying to us with bugs ;).
135         #use static && export LDFLAGS="${LDFLAGS} -static"
136         use nls || myconf+=( --disable-nls )
137
138         # Historically, we always used the builtin readline, but since
139         # our handling of SONAME upgrades has gotten much more stable
140         # in the PM (and the readline ebuild itself preserves the old
141         # libs during upgrades), linking against the system copy should
142         # be safe.
143         # Exact cached version here doesn't really matter as long as it
144         # is at least what's in the DEPEND up above.
145         export ac_cv_rl_version=${READLINE_VER%%_*}
146
147         # Force linking with system curses ... the bundled termcap lib
148         # sucks bad compared to ncurses.  For the most part, ncurses
149         # is here because readline needs it.  But bash itself calls
150         # ncurses in one or two small places :(.
151
152         if is_release ; then
153                 # Use system readline only with released versions.
154                 myconf+=( --with-installed-readline=. )
155         fi
156
157         if use plugins; then
158                 append-ldflags -Wl,-rpath,/usr/$(get_libdir)/bash
159         else
160                 # Disable the plugins logic by hand since bash doesn't
161                 # provide a way of doing it.
162                 export ac_cv_func_dl{close,open,sym}=no \
163                         ac_cv_lib_dl_dlopen=no ac_cv_header_dlfcn_h=no
164                 sed -i \
165                         -e '/LOCAL_LDFLAGS=/s:-rdynamic::' \
166                         configure || die
167         fi
168         tc-export AR #444070
169         econf "${myconf[@]}"
170 }
171
172 src_compile() {
173         emake
174
175         if use plugins ; then
176                 emake -C examples/loadables all others
177         fi
178 }
179
180 src_install() {
181         local d f
182
183         default
184
185         dodir /bin
186         mv "${ED%/}"/usr/bin/bash "${ED%/}"/bin/ || die
187         dosym bash /bin/rbash
188
189         insinto /etc/bash
190         doins "${FILESDIR}"/bash_logout
191         doins "$(prefixify_ro "${FILESDIR}"/bashrc)"
192         keepdir /etc/bash/bashrc.d
193         insinto /etc/skel
194         for f in bash{_logout,_profile,rc} ; do
195                 newins "${FILESDIR}"/dot-${f} .${f}
196         done
197
198         local sed_args=(
199                 -e "s:#${USERLAND}#@::"
200                 -e '/#@/d'
201         )
202         if ! use readline ; then
203                 sed_args+=( #432338
204                         -e '/^shopt -s histappend/s:^:#:'
205                         -e 's:use_color=true:use_color=false:'
206                 )
207         fi
208         sed -i \
209                 "${sed_args[@]}" \
210                 "${ED%/}"/etc/skel/.bashrc \
211                 "${ED%/}"/etc/bash/bashrc || die
212
213         if use plugins ; then
214                 exeinto /usr/$(get_libdir)/bash
215                 doexe $(echo examples/loadables/*.o | sed 's:\.o::g')
216                 insinto /usr/include/bash-plugins
217                 doins *.h builtins/*.h include/*.h lib/{glob/glob.h,tilde/tilde.h}
218         fi
219
220         if use examples ; then
221                 for d in examples/{functions,misc,scripts,startup-files} ; do
222                         exeinto /usr/share/doc/${PF}/${d}
223                         insinto /usr/share/doc/${PF}/${d}
224                         for f in ${d}/* ; do
225                                 if [[ ${f##*/} != PERMISSION ]] && [[ ${f##*/} != *README ]] ; then
226                                         doexe ${f}
227                                 else
228                                         doins ${f}
229                                 fi
230                         done
231                 done
232         fi
233
234         doman doc/*.1
235         newdoc CWRU/changelog ChangeLog
236         dosym bash.info /usr/share/info/bashref.info
237 }
238
239 pkg_preinst() {
240         if [[ -e ${EROOT}/etc/bashrc ]] && [[ ! -d ${EROOT}/etc/bash ]] ; then
241                 mkdir -p "${EROOT}"/etc/bash
242                 mv -f "${EROOT}"/etc/bashrc "${EROOT}"/etc/bash/
243         fi
244
245         if [[ -L ${EROOT}/bin/sh ]] ; then
246                 # rewrite the symlink to ensure that its mtime changes. having /bin/sh
247                 # missing even temporarily causes a fatal error with paludis.
248                 local target=$(readlink "${EROOT}"/bin/sh)
249                 local tmp=$(emktemp "${EROOT}"/bin)
250                 ln -sf "${target}" "${tmp}"
251                 mv -f "${tmp}" "${EROOT}"/bin/sh
252         fi
253 }
254
255 pkg_postinst() {
256         # If /bin/sh does not exist, provide it
257         if [[ ! -e ${EROOT}/bin/sh ]] ; then
258                 ln -sf bash "${EROOT}"/bin/sh
259         fi
260 }