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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Mon Oct 31 17:39:52 2011 UTC (2 years, 11 months ago) by vapier
Branch: MAIN
Changes since 1.18: +6 -3 lines
drop unused funcs

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

  ViewVC Help
Powered by ViewVC 1.1.20