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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download)
Fri Feb 26 18:09:43 2010 UTC (4 years, 6 months ago) by grobian
Branch: MAIN
Changes since 1.14: +7 -5 lines
add support for Interix in dlopen_lib, bug #302575

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

  ViewVC Help
Powered by ViewVC 1.1.20