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

Diff of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1.1.1 Revision 1.24
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.1.1.1 2005/11/30 09:59:30 chriswhite Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.24 2012/01/04 05:57:19 vapier Exp $
4# 4#
5# Author: Diego Pettenò <flameeyes@gentoo.org> 5# Author: Diego Pettenò <flameeyes@gentoo.org>
6# 6#
7# This eclass is created to avoid using non-portable GNUisms inside ebuilds 7# This eclass is created to avoid using non-portable GNUisms inside ebuilds
8# 8#
9# NB: If you add anything, please comment it! 9# NB: If you add anything, please comment it!
10 10
11if [[ ${___ECLASS_ONCE_PORTABILITY} != "recur -_+^+_- spank" ]] ; then
12___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank"
13
11# treecopy orig1 orig2 orig3 .... dest 14# treecopy orig1 orig2 orig3 .... dest
12# 15#
13# mimic cp --parents copy, but working on BSD userland as well 16# mimic cp --parents copy, but working on BSD userland as well
14treecopy() { 17treecopy() {
15 dest=${!#} 18 local dest=${!#}
16 files_count=$# 19 local files_count=$#
17 20
18 while(( $# > 1 )); do 21 while (( $# > 1 )); do
19 dirstruct=$(dirname "$1") 22 local dirstruct=$(dirname "$1")
20 mkdir -p "${dest}/${dirstruct}" 23 mkdir -p "${dest}/${dirstruct}"
21 cp -pPR "$1" "${dest}/${dirstruct}" 24 cp -pPR "$1" "${dest}/${dirstruct}"
22 25
23 shift 26 shift
24 done 27 done
26 29
27# seq min max 30# seq min max
28# 31#
29# compatibility function that mimes seq command if not available 32# compatibility function that mimes seq command if not available
30seq() { 33seq() {
34 # First try `seq`
31 local p=$(type -P seq) 35 local p=$(type -P seq)
36 if [[ -n ${p} ]] ; then
37 "${p}" "$@"
38 return $?
39 fi
32 40
41 local min max step
33 case $# in 42 case $# in
34 1) min=1 max=$1 step=1 ;; 43 1) min=1 max=$1 step=1 ;;
35 2) min=$1 max=$2 step=1 ;; 44 2) min=$1 max=$2 step=1 ;;
36 3) min=$1 max=$3 step=$2 ;; 45 3) min=$1 max=$3 step=$2 ;;
37 *) die "seq called with wrong number of arguments" ;; 46 *) die "seq called with wrong number of arguments" ;;
38 esac 47 esac
39 48
49 # Then try `jot`
50 p=$(type -P jot)
40 if [[ -z ${p} ]] ; then 51 if [[ -n ${p} ]] ; then
41 local reps 52 local reps
42 # BSD userland 53 # BSD userland
43 if [[ ${step} != 0 ]]; then 54 if [[ ${step} != 0 ]] ; then
44 reps=$(( ($max-$min) / $step +1 )) 55 reps=$(( (max - min) / step + 1 ))
45 else 56 else
46 reps=0 57 reps=0
47 fi 58 fi
48 59
49 jot $reps $min $max $step 60 jot $reps $min $max $step
50 else 61 return $?
51 "${p}" $min $step $max
52 fi 62 fi
63
64 # Screw it, do the output ourselves
65 while :; do
66 [[ $max < $min && $step > 0 ]] && break
67 [[ $min < $max && $step < 0 ]] && break
68 echo $min
69 : $(( min += step ))
70 done
71 return 0
53} 72}
54 73
55# Gets the linker flag to link to dlopen() function 74# Gets the linker flag to link to dlopen() function
56dlopen_lib() { 75dlopen_lib() {
57 if [[ ${ELIBC} != *BSD ]]; then 76 # - Solaris needs nothing
77 # - Darwin needs nothing
78 # - *BSD needs nothing
79 # - Linux needs -ldl (glibc and uclibc)
80 # - Interix needs -ldl
81 case "${CHOST}" in
82 *-linux-gnu*|*-linux-uclibc|*-interix*)
58 echo "-ldl" 83 echo "-ldl"
59 fi 84 ;;
60} 85 esac
61
62# Gets the home directory for the specified user
63# it's a wrap around egetent as the position of the home directory in the line
64# varies depending on the os used.
65#
66# To use that, inherit eutils, not portability!
67egethome() {
68 ent=$(egetent passwd $1)
69
70 if [[ "${USERLAND}" == "Darwin" || "${ELIBC}" == "FreeBSD" ]]; then
71 # Darwin/OSX and FreeBSD uses position 9 to store the home dir
72 cut -d: -f9 <<<${ent}
73 else
74 # Linux and NetBSD uses position 6 instead
75 cut -d: -f6 <<<${ent}
76 fi
77} 86}
78 87
79# Gets the name of the BSD-ish make command (pmake from NetBSD) 88# Gets the name of the BSD-ish make command (pmake from NetBSD)
80# 89#
81# This will return make (provided by system packages) for BSD userlands, 90# This will return make (provided by system packages) for BSD userlands,
91 echo bsdmake 100 echo bsdmake
92 else 101 else
93 echo pmake 102 echo pmake
94 fi 103 fi
95} 104}
105
106# Portable method of getting mount names and points.
107# Returns as "point node fs options"
108# Remember to convert 040 back to a space.
109get_mounts() {
110 local point= node= fs= opts= foo=
111
112 # Linux has /proc/mounts which should always exist
113 if [[ $(uname -s) == "Linux" ]] ; then
114 while read node point fs opts foo ; do
115 echo "${point} ${node} ${fs} ${opts}"
116 done < /proc/mounts
117 return
118 fi
119
120 # OK, pray we have a -p option that outputs mounts in fstab format
121 # using tabs as the seperator.
122 # Then pray that there are no tabs in the either.
123 # Currently only FreeBSD supports this and the other BSDs will
124 # have to be patched.
125 # Athough the BSD's may support /proc, they do NOT put \040 in place
126 # of the spaces and we should not force a /proc either.
127 local IFS=$'\t'
128 LC_ALL=C mount -p | while read node point fs foo ; do
129 opts=${fs#* }
130 fs=${fs%% *}
131 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
132 done
133}
134
135_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
136is-login-disabled() { _dead_portability_user_funcs; }
137
138fi

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.20