/[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.18
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 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.18 2011/10/27 07:16:08 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
11inherit user
10 12
11# treecopy orig1 orig2 orig3 .... dest 13# treecopy orig1 orig2 orig3 .... dest
12# 14#
13# mimic cp --parents copy, but working on BSD userland as well 15# mimic cp --parents copy, but working on BSD userland as well
14treecopy() { 16treecopy() {
26 28
27# seq min max 29# seq min max
28# 30#
29# compatibility function that mimes seq command if not available 31# compatibility function that mimes seq command if not available
30seq() { 32seq() {
33 # First try `seq`
31 local p=$(type -P seq) 34 local p=$(type -P seq)
35 if [[ -n ${p} ]] ; then
36 "${p}" "$@"
37 return $?
38 fi
32 39
33 case $# in 40 case $# in
34 1) min=1 max=$1 step=1 ;; 41 1) min=1 max=$1 step=1 ;;
35 2) min=$1 max=$2 step=1 ;; 42 2) min=$1 max=$2 step=1 ;;
36 3) min=$1 max=$3 step=$2 ;; 43 3) min=$1 max=$3 step=$2 ;;
37 *) die "seq called with wrong number of arguments" ;; 44 *) die "seq called with wrong number of arguments" ;;
38 esac 45 esac
39 46
47 # Then try `jot`
48 p=$(type -P jot)
40 if [[ -z ${p} ]] ; then 49 if [[ -n ${p} ]] ; then
41 local reps 50 local reps
42 # BSD userland 51 # BSD userland
43 if [[ ${step} != 0 ]]; then 52 if [[ ${step} != 0 ]] ; then
44 reps=$(( ($max-$min) / $step +1 )) 53 reps=$(( (max - min) / step + 1 ))
45 else 54 else
46 reps=0 55 reps=0
47 fi 56 fi
48 57
49 jot $reps $min $max $step 58 jot $reps $min $max $step
50 else 59 return $?
51 "${p}" $min $step $max
52 fi 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
53} 70}
54 71
55# Gets the linker flag to link to dlopen() function 72# Gets the linker flag to link to dlopen() function
56dlopen_lib() { 73dlopen_lib() {
57 if [[ ${ELIBC} != *BSD ]]; then 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*)
58 echo "-ldl" 81 echo "-ldl"
59 fi 82 ;;
60} 83 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} 84}
78 85
79# Gets the name of the BSD-ish make command (pmake from NetBSD) 86# Gets the name of the BSD-ish make command (pmake from NetBSD)
80# 87#
81# This will return make (provided by system packages) for BSD userlands, 88# This will return make (provided by system packages) for BSD userlands,
91 echo bsdmake 98 echo bsdmake
92 else 99 else
93 echo pmake 100 echo pmake
94 fi 101 fi
95} 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.
107get_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}

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

  ViewVC Help
Powered by ViewVC 1.1.20