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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Fri Mar 27 08:00:56 2009 UTC (5 years, 4 months ago) by drizzt
Branch: MAIN
Changes since 1.12: +3 -3 lines
uclibc also wants -ldl

1 flameeyes 1.1 # Copyright 1999-2005 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 drizzt 1.13 # $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.12 2009/03/22 11:26:45 grobian 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.3 local p=$(type -P seq)
32 flameeyes 1.1
33     case $# in
34 vapier 1.3 1) min=1 max=$1 step=1 ;;
35     2) min=$1 max=$2 step=1 ;;
36     3) min=$1 max=$3 step=$2 ;;
37     *) die "seq called with wrong number of arguments" ;;
38 flameeyes 1.1 esac
39    
40 vapier 1.3 if [[ -z ${p} ]] ; then
41 flameeyes 1.1 local reps
42     # BSD userland
43     if [[ ${step} != 0 ]]; then
44     reps=$(( ($max-$min) / $step +1 ))
45     else
46     reps=0
47     fi
48    
49     jot $reps $min $max $step
50     else
51     "${p}" $min $step $max
52     fi
53     }
54    
55     # Gets the linker flag to link to dlopen() function
56     dlopen_lib() {
57 grobian 1.12 # this might need a proper case statement, so far this seems to work as is
58     # - Solaris needs nothing
59     # - Darwin needs nothing
60     # - *BSD needs nothing
61 drizzt 1.13 # - Linux needs -ldl (glibc and uclibc)
62     if [[ ${CHOST} == *-linux-gnu || ${CHOST} == *-linux-uclibc ]]; then
63 flameeyes 1.1 echo "-ldl"
64     fi
65     }
66    
67 flameeyes 1.2 # Gets the home directory for the specified user
68     # it's a wrap around egetent as the position of the home directory in the line
69     # varies depending on the os used.
70     #
71     # To use that, inherit eutils, not portability!
72     egethome() {
73     ent=$(egetent passwd $1)
74    
75 flameeyes 1.5 case ${CHOST} in
76     *-darwin*|*-freebsd*|*-dragonfly*)
77     # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
78 flameeyes 1.8 echo ${ent} | cut -d: -f9
79 flameeyes 1.6 ;;
80 flameeyes 1.5 *)
81     # Linux, NetBSD and OpenBSD use position 6 instead
82 flameeyes 1.8 echo ${ent} | cut -d: -f6
83 flameeyes 1.6 ;;
84 flameeyes 1.5 esac
85 flameeyes 1.2 }
86 flameeyes 1.4
87 flameeyes 1.7 # Gets the shell for the specified user
88     # it's a wrap around egetent as the position of the home directory in the line
89     # varies depending on the os used.
90     #
91     # To use that, inherit eutils, not portability!
92     egetshell() {
93     ent=$(egetent passwd "$1")
94    
95     case ${CHOST} in
96     *-darwin*|*-freebsd*|*-dragonfly*)
97     # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
98 flameeyes 1.8 echo ${ent} | cut -d: -f10
99 flameeyes 1.7 ;;
100     *)
101     # Linux, NetBSD and OpenBSD use position 6 instead
102 flameeyes 1.8 echo ${ent} cut -d: -f7
103 flameeyes 1.7 ;;
104     esac
105     }
106    
107     # Returns true if specified user has a shell that precludes logins
108     # on whichever operating system.
109     is-login-disabled() {
110     shell=$(egetshell "$1")
111    
112     case ${shell} in
113     /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin)
114     return 0 ;;
115     *)
116     return 1 ;;
117     esac
118     }
119    
120 flameeyes 1.4 # Gets the name of the BSD-ish make command (pmake from NetBSD)
121     #
122     # This will return make (provided by system packages) for BSD userlands,
123     # or bsdmake for Darwin userlands and pmake for the rest of userlands,
124     # both of which are provided by sys-devel/pmake package.
125     #
126     # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
127     # default name.
128     get_bmake() {
129     if [[ ${USERLAND} == *BSD ]]; then
130     echo make
131     elif [[ ${USERLAND} == "Darwin" ]]; then
132     echo bsdmake
133     else
134     echo pmake
135     fi
136     }
137 uberlord 1.9
138     # Portable method of getting mount names and points.
139 uberlord 1.10 # Returns as "point node fs options"
140 uberlord 1.9 # Remember to convert 040 back to a space.
141     get_mounts() {
142 uberlord 1.10 local point= node= fs= opts= foo=
143 uberlord 1.9
144     # Linux has /proc/mounts which should always exist
145     if [[ $(uname -s) == "Linux" ]] ; then
146 uberlord 1.10 while read node point fs opts foo ; do
147 swegener 1.11 echo "${point} ${node} ${fs} ${opts}"
148 uberlord 1.9 done < /proc/mounts
149 swegener 1.11 return
150 uberlord 1.9 fi
151    
152     # OK, pray we have a -p option that outputs mounts in fstab format
153     # using tabs as the seperator.
154     # Then pray that there are no tabs in the either.
155     # Currently only FreeBSD supports this and the other BSDs will
156     # have to be patched.
157     # Athough the BSD's may support /proc, they do NOT put \040 in place
158     # of the spaces and we should not force a /proc either.
159     local IFS=$'\t'
160     LC_ALL=C mount -p | while read node point fs foo ; do
161 uberlord 1.10 opts=${fs#* }
162     fs=${fs%% *}
163     echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
164 uberlord 1.9 done
165     }

  ViewVC Help
Powered by ViewVC 1.1.20