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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (hide annotations) (download)
Wed Jan 4 05:57:19 2012 UTC (3 years, 3 months ago) by vapier
Branch: MAIN
Changes since 1.23: +6 -5 lines
add missing "local" markings for variables

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

  ViewVC Help
Powered by ViewVC 1.1.20