/[gentoo-x86]/eclass/portability.eclass
Gentoo

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Fri Jul 11 08:21:58 2014 UTC (2 months ago) by ulm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.25: +3 -3 lines
Avoid reserved names for functions and variables, bug 516092.

1 jlec 1.25 # Copyright 1999-2014 Gentoo Foundation
2 flameeyes 1.1 # Distributed under the terms of the GNU General Public License v2
3 ulm 1.26 # $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.25 2014/05/28 09:48:01 jlec Exp $
4 jlec 1.25
5     # @ECLASS: portability.eclass
6     # @MAINTAINER:
7     # base-system@gentoo.org
8     # @AUTHOR:
9     # Diego Pettenò <flameeyes@gentoo.org>
10     # @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
11 flameeyes 1.1
12 ulm 1.26 if [[ -z ${_PORTABILITY_ECLASS} ]]; then
13     _PORTABILITY_ECLASS=1
14 vapier 1.22
15 jlec 1.25 # @FUNCTION: treecopy
16     # @USAGE: <orig1> [orig2 orig3 ....] <dest>
17     # @RETURN:
18     # @DESCRIPTION:
19 flameeyes 1.1 # mimic cp --parents copy, but working on BSD userland as well
20     treecopy() {
21 vapier 1.24 local dest=${!#}
22     local files_count=$#
23 flameeyes 1.1
24 vapier 1.24 while (( $# > 1 )); do
25     local dirstruct=$(dirname "$1")
26 jlec 1.25 mkdir -p "${dest}/${dirstruct}" || die
27     cp -pPR "$1" "${dest}/${dirstruct}" || die
28 flameeyes 1.1
29     shift
30     done
31     }
32    
33 jlec 1.25 # @FUNCTION: seq
34     # @USAGE: [min] <max> [step]
35     # @RETURN: sequence from min to max regardless of seq command being present on system
36     # @DESCRIPTION:
37 flameeyes 1.1 # compatibility function that mimes seq command if not available
38     seq() {
39 vapier 1.16 # First try `seq`
40 vapier 1.17 local p=$(type -P seq)
41 vapier 1.16 if [[ -n ${p} ]] ; then
42 jlec 1.25 "${p}" "$@" || die
43 vapier 1.16 return $?
44     fi
45 flameeyes 1.1
46 vapier 1.24 local min max step
47 flameeyes 1.1 case $# in
48 vapier 1.3 1) min=1 max=$1 step=1 ;;
49     2) min=$1 max=$2 step=1 ;;
50     3) min=$1 max=$3 step=$2 ;;
51     *) die "seq called with wrong number of arguments" ;;
52 flameeyes 1.1 esac
53    
54 vapier 1.16 # Then try `jot`
55     p=$(type -P jot)
56     if [[ -n ${p} ]] ; then
57 flameeyes 1.1 local reps
58     # BSD userland
59 vapier 1.16 if [[ ${step} != 0 ]] ; then
60     reps=$(( (max - min) / step + 1 ))
61 flameeyes 1.1 else
62     reps=0
63     fi
64    
65 jlec 1.25 jot $reps $min $max $step || die
66 vapier 1.16 return $?
67 flameeyes 1.1 fi
68 vapier 1.16
69     # Screw it, do the output ourselves
70     while :; do
71     [[ $max < $min && $step > 0 ]] && break
72     [[ $min < $max && $step < 0 ]] && break
73     echo $min
74     : $(( min += step ))
75     done
76     return 0
77 flameeyes 1.1 }
78    
79 jlec 1.25 # @FUNCTION: dlopen_lib
80     # @USAGE:
81     # @RETURN: linker flag if needed
82     # @DESCRIPTION:
83 flameeyes 1.1 # Gets the linker flag to link to dlopen() function
84     dlopen_lib() {
85 grobian 1.12 # - Solaris needs nothing
86     # - Darwin needs nothing
87     # - *BSD needs nothing
88 drizzt 1.13 # - Linux needs -ldl (glibc and uclibc)
89 grobian 1.15 # - Interix needs -ldl
90     case "${CHOST}" in
91     *-linux-gnu*|*-linux-uclibc|*-interix*)
92     echo "-ldl"
93     ;;
94     esac
95 flameeyes 1.1 }
96    
97 jlec 1.25 # @FUNCTION: get_bmake
98     # @USAGE:
99     # @RETURN: system version of make
100     # @DESCRIPTION:
101 flameeyes 1.4 # Gets the name of the BSD-ish make command (pmake from NetBSD)
102     #
103     # This will return make (provided by system packages) for BSD userlands,
104     # or bsdmake for Darwin userlands and pmake for the rest of userlands,
105     # both of which are provided by sys-devel/pmake package.
106     #
107     # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
108     # default name.
109     get_bmake() {
110     if [[ ${USERLAND} == *BSD ]]; then
111     echo make
112     elif [[ ${USERLAND} == "Darwin" ]]; then
113     echo bsdmake
114     else
115     echo pmake
116     fi
117     }
118 uberlord 1.9
119 jlec 1.25 # @FUNCTION: get_mounts
120     # @USAGE:
121     # @RETURN: table of mounts in form "point node fs opts"
122     # @MAINTAINER:
123     # @DESCRIPTION:
124 uberlord 1.9 # Portable method of getting mount names and points.
125 uberlord 1.10 # Returns as "point node fs options"
126 uberlord 1.9 # Remember to convert 040 back to a space.
127     get_mounts() {
128 uberlord 1.10 local point= node= fs= opts= foo=
129 uberlord 1.9
130     # Linux has /proc/mounts which should always exist
131     if [[ $(uname -s) == "Linux" ]] ; then
132 uberlord 1.10 while read node point fs opts foo ; do
133 swegener 1.11 echo "${point} ${node} ${fs} ${opts}"
134 uberlord 1.9 done < /proc/mounts
135 swegener 1.11 return
136 uberlord 1.9 fi
137    
138     # OK, pray we have a -p option that outputs mounts in fstab format
139     # using tabs as the seperator.
140     # Then pray that there are no tabs in the either.
141     # Currently only FreeBSD supports this and the other BSDs will
142     # have to be patched.
143     # Athough the BSD's may support /proc, they do NOT put \040 in place
144     # of the spaces and we should not force a /proc either.
145     local IFS=$'\t'
146     LC_ALL=C mount -p | while read node point fs foo ; do
147 uberlord 1.10 opts=${fs#* }
148     fs=${fs%% *}
149     echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
150 uberlord 1.9 done
151     }
152 vapier 1.19
153     _dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
154     is-login-disabled() { _dead_portability_user_funcs; }
155 vapier 1.22
156     fi

  ViewVC Help
Powered by ViewVC 1.1.20