Support FEATURES=force-prefix.
[portage.git] / bin / ebuild-helpers / doman
1 #!/bin/bash
2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
6
7 if [[ $# -lt 1 ]] ; then
8         helpers_die "${0##*/}: at least one argument needed"
9         exit 1
10 fi
11
12 [[ " ${FEATURES} " == *" force-prefix "* ]] || \
13         case "$EAPI" in 0|1|2) ED=${D} ;; esac
14
15 i18n=""
16
17 ret=0
18
19 for x in "$@" ; do
20         if [[ ${x:0:6} == "-i18n=" ]] ; then
21                 i18n=${x:6}/
22                 continue
23         fi
24         if [[ ${x:0:6} == ".keep_" ]] ; then
25                 continue
26         fi
27
28         suffix=${x##*.}
29
30         # These will be automatically decompressed by ecompressdir.
31         if has ${suffix} Z gz bz2 ; then
32                 realname=${x%.*}
33                 suffix=${realname##*.}
34         fi
35
36         if has "${EAPI:-0}" 2 3 || [[ -z ${i18n} ]] \
37                 && ! has "${EAPI:-0}" 0 1 \
38                 && [[ $x =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]
39         then
40                 name=${BASH_REMATCH[1]##*/}.${BASH_REMATCH[4]}
41                 mandir=${BASH_REMATCH[2]}/man${suffix:0:1}
42         else
43                 name=${x##*/}
44                 mandir=${i18n#/}man${suffix:0:1}
45         fi
46
47
48         if [[ ${mandir} == *man[0-9n] ]] ; then
49                 if [[ -s ${x} ]] ; then
50                         if [[ ! -d ${ED}/usr/share/man/${mandir} ]] ; then
51                                 install -d "${ED}/usr/share/man/${mandir}"
52                         fi
53
54                         install -m0644 "${x}" "${ED}/usr/share/man/${mandir}/${name}"
55                         ((ret|=$?))
56                 elif [[ ! -e ${x} ]] ; then
57                         echo "!!! ${0##*/}: $x does not exist" 1>&2
58                         ((ret|=1))
59                 fi
60         else
61                 vecho "doman: '${x}' is probably not a man page; skipping" 1>&2
62                 ((ret|=1))
63         fi
64 done
65
66 [[ $ret -ne 0 ]] && helpers_die "${0##*/} failed"
67 exit ${ret}