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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Tue Dec 27 17:55:12 2011 UTC (2 years, 10 months ago) by fauli
Branch: MAIN
Changes since 1.22: +2 -2 lines
Update copyright years in headers

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 fauli 1.23 # $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.22 2011/12/10 20:03:17 vapier 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     dest=${!#}
19     files_count=$#
20    
21     while(( $# > 1 )); do
22     dirstruct=$(dirname "$1")
23     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     case $# in
42 vapier 1.3 1) min=1 max=$1 step=1 ;;
43     2) min=$1 max=$2 step=1 ;;
44     3) min=$1 max=$3 step=$2 ;;
45     *) die "seq called with wrong number of arguments" ;;
46 flameeyes 1.1 esac
47    
48 vapier 1.16 # Then try `jot`
49     p=$(type -P jot)
50     if [[ -n ${p} ]] ; then
51 flameeyes 1.1 local reps
52     # BSD userland
53 vapier 1.16 if [[ ${step} != 0 ]] ; then
54     reps=$(( (max - min) / step + 1 ))
55 flameeyes 1.1 else
56     reps=0
57     fi
58    
59     jot $reps $min $max $step
60 vapier 1.16 return $?
61 flameeyes 1.1 fi
62 vapier 1.16
63     # Screw it, do the output ourselves
64     while :; do
65     [[ $max < $min && $step > 0 ]] && break
66     [[ $min < $max && $step < 0 ]] && break
67     echo $min
68     : $(( min += step ))
69     done
70     return 0
71 flameeyes 1.1 }
72    
73     # Gets the linker flag to link to dlopen() function
74     dlopen_lib() {
75 grobian 1.12 # - Solaris needs nothing
76     # - Darwin needs nothing
77     # - *BSD needs nothing
78 drizzt 1.13 # - Linux needs -ldl (glibc and uclibc)
79 grobian 1.15 # - Interix needs -ldl
80     case "${CHOST}" in
81     *-linux-gnu*|*-linux-uclibc|*-interix*)
82     echo "-ldl"
83     ;;
84     esac
85 flameeyes 1.1 }
86    
87 flameeyes 1.4 # Gets the name of the BSD-ish make command (pmake from NetBSD)
88     #
89     # This will return make (provided by system packages) for BSD userlands,
90     # or bsdmake for Darwin userlands and pmake for the rest of userlands,
91     # both of which are provided by sys-devel/pmake package.
92     #
93     # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
94     # default name.
95     get_bmake() {
96     if [[ ${USERLAND} == *BSD ]]; then
97     echo make
98     elif [[ ${USERLAND} == "Darwin" ]]; then
99     echo bsdmake
100     else
101     echo pmake
102     fi
103     }
104 uberlord 1.9
105     # Portable method of getting mount names and points.
106 uberlord 1.10 # Returns as "point node fs options"
107 uberlord 1.9 # Remember to convert 040 back to a space.
108     get_mounts() {
109 uberlord 1.10 local point= node= fs= opts= foo=
110 uberlord 1.9
111     # Linux has /proc/mounts which should always exist
112     if [[ $(uname -s) == "Linux" ]] ; then
113 uberlord 1.10 while read node point fs opts foo ; do
114 swegener 1.11 echo "${point} ${node} ${fs} ${opts}"
115 uberlord 1.9 done < /proc/mounts
116 swegener 1.11 return
117 uberlord 1.9 fi
118    
119     # OK, pray we have a -p option that outputs mounts in fstab format
120     # using tabs as the seperator.
121     # Then pray that there are no tabs in the either.
122     # Currently only FreeBSD supports this and the other BSDs will
123     # have to be patched.
124     # Athough the BSD's may support /proc, they do NOT put \040 in place
125     # of the spaces and we should not force a /proc either.
126     local IFS=$'\t'
127     LC_ALL=C mount -p | while read node point fs foo ; do
128 uberlord 1.10 opts=${fs#* }
129     fs=${fs%% *}
130     echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
131 uberlord 1.9 done
132     }
133 vapier 1.19
134     _dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
135     is-login-disabled() { _dead_portability_user_funcs; }
136 vapier 1.22
137     fi

  ViewVC Help
Powered by ViewVC 1.1.20