/[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 Revision 1.22
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 2005/09/18 17:33:44 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.22 2011/12/10 20:03:17 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
11if [[ ${___ECLASS_ONCE_PORTABILITY} != "recur -_+^+_- spank" ]] ; then
12___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank"
10 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() {
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() {
31 local p 34 # First try `seq`
32 p=$(type -P seq) 35 local p=$(type -P seq)
36 if [[ -n ${p} ]] ; then
37 "${p}" "$@"
38 return $?
39 fi
33 40
34 case $# in 41 case $# in
35 1) 42 1) min=1 max=$1 step=1 ;;
36 min=1 43 2) min=$1 max=$2 step=1 ;;
37 max=$1 44 3) min=$1 max=$3 step=$2 ;;
38 step=1 45 *) die "seq called with wrong number of arguments" ;;
39 ;;
40 2)
41 min=$1
42 max=$2
43 step=1
44 ;;
45 3)
46 min=$1
47 max=$3
48 step=$2
49 ;;
50 *)
51 die "seq called with wrong parameters number"
52 esac 46 esac
53 47
48 # Then try `jot`
49 p=$(type -P jot)
54 if [[ -z "${p}" ]]; then 50 if [[ -n ${p} ]] ; then
55 local reps 51 local reps
56 # BSD userland 52 # BSD userland
57 if [[ ${step} != 0 ]]; then 53 if [[ ${step} != 0 ]] ; then
58 reps=$(( ($max-$min) / $step +1 )) 54 reps=$(( (max - min) / step + 1 ))
59 else 55 else
60 reps=0 56 reps=0
61 fi 57 fi
62 58
63 jot $reps $min $max $step 59 jot $reps $min $max $step
64 else 60 return $?
65 "${p}" $min $step $max
66 fi 61 fi
62
63 # Screw it, do the output ourselves
64 while :; do
65 [[ $max < $min && $step > 0 ]] && break
66 [[ $min < $max && $step < 0 ]] && break
67 echo $min
68 : $(( min += step ))
69 done
70 return 0
67} 71}
68 72
69# Gets the linker flag to link to dlopen() function 73# Gets the linker flag to link to dlopen() function
70dlopen_lib() { 74dlopen_lib() {
71 if [[ ${ELIBC} != *BSD ]]; then 75 # - Solaris needs nothing
76 # - Darwin needs nothing
77 # - *BSD needs nothing
78 # - Linux needs -ldl (glibc and uclibc)
79 # - Interix needs -ldl
80 case "${CHOST}" in
81 *-linux-gnu*|*-linux-uclibc|*-interix*)
72 echo "-ldl" 82 echo "-ldl"
83 ;;
84 esac
85}
86
87# Gets the name of the BSD-ish make command (pmake from NetBSD)
88#
89# This will return make (provided by system packages) for BSD userlands,
90# or bsdmake for Darwin userlands and pmake for the rest of userlands,
91# both of which are provided by sys-devel/pmake package.
92#
93# Note: the bsdmake for Darwin userland is with compatibility with MacOSX
94# default name.
95get_bmake() {
96 if [[ ${USERLAND} == *BSD ]]; then
97 echo make
98 elif [[ ${USERLAND} == "Darwin" ]]; then
99 echo bsdmake
100 else
101 echo pmake
73 fi 102 fi
74} 103}
75 104
105# Portable method of getting mount names and points.
106# Returns as "point node fs options"
107# Remember to convert 040 back to a space.
108get_mounts() {
109 local point= node= fs= opts= foo=
110
111 # Linux has /proc/mounts which should always exist
112 if [[ $(uname -s) == "Linux" ]] ; then
113 while read node point fs opts foo ; do
114 echo "${point} ${node} ${fs} ${opts}"
115 done < /proc/mounts
116 return
117 fi
118
119 # OK, pray we have a -p option that outputs mounts in fstab format
120 # using tabs as the seperator.
121 # Then pray that there are no tabs in the either.
122 # Currently only FreeBSD supports this and the other BSDs will
123 # have to be patched.
124 # Athough the BSD's may support /proc, they do NOT put \040 in place
125 # of the spaces and we should not force a /proc either.
126 local IFS=$'\t'
127 LC_ALL=C mount -p | while read node point fs foo ; do
128 opts=${fs#* }
129 fs=${fs%% *}
130 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
131 done
132}
133
134_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
135is-login-disabled() { _dead_portability_user_funcs; }
136
137fi

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.20