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

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Thu Oct 27 07:16:08 2011 UTC (3 years ago) by vapier
Branch: MAIN
Changes since 1.17: +3 -55 lines
split out user management helpers into a dedicated eclass

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

  ViewVC Help
Powered by ViewVC 1.1.20