/[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.26
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2014 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.26 2014/07/11 08:21:58 ulm 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 4
11# treecopy orig1 orig2 orig3 .... dest 5# @ECLASS: portability.eclass
12# 6# @MAINTAINER:
7# base-system@gentoo.org
8# @AUTHOR:
9# Diego Pettenò <flameeyes@gentoo.org>
10# @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
11
12if [[ -z ${_PORTABILITY_ECLASS} ]]; then
13_PORTABILITY_ECLASS=1
14
15# @FUNCTION: treecopy
16# @USAGE: <orig1> [orig2 orig3 ....] <dest>
17# @RETURN:
18# @DESCRIPTION:
13# mimic cp --parents copy, but working on BSD userland as well 19# mimic cp --parents copy, but working on BSD userland as well
14treecopy() { 20treecopy() {
15 dest=${!#} 21 local dest=${!#}
16 files_count=$# 22 local files_count=$#
17 23
18 while(( $# > 1 )); do 24 while (( $# > 1 )); do
19 dirstruct=$(dirname "$1") 25 local dirstruct=$(dirname "$1")
20 mkdir -p "${dest}/${dirstruct}" 26 mkdir -p "${dest}/${dirstruct}" || die
21 cp -pPR "$1" "${dest}/${dirstruct}" 27 cp -pPR "$1" "${dest}/${dirstruct}" || die
22 28
23 shift 29 shift
24 done 30 done
25} 31}
26 32
27# seq min max 33# @FUNCTION: seq
28# 34# @USAGE: [min] <max> [step]
35# @RETURN: sequence from min to max regardless of seq command being present on system
36# @DESCRIPTION:
29# compatibility function that mimes seq command if not available 37# compatibility function that mimes seq command if not available
30seq() { 38seq() {
39 # First try `seq`
31 local p=$(type -P seq) 40 local p=$(type -P seq)
41 if [[ -n ${p} ]] ; then
42 "${p}" "$@" || die
43 return $?
44 fi
32 45
46 local min max step
33 case $# in 47 case $# in
34 1) min=1 max=$1 step=1 ;; 48 1) min=1 max=$1 step=1 ;;
35 2) min=$1 max=$2 step=1 ;; 49 2) min=$1 max=$2 step=1 ;;
36 3) min=$1 max=$3 step=$2 ;; 50 3) min=$1 max=$3 step=$2 ;;
37 *) die "seq called with wrong number of arguments" ;; 51 *) die "seq called with wrong number of arguments" ;;
38 esac 52 esac
39 53
54 # Then try `jot`
55 p=$(type -P jot)
40 if [[ -z ${p} ]] ; then 56 if [[ -n ${p} ]] ; then
41 local reps 57 local reps
42 # BSD userland 58 # BSD userland
43 if [[ ${step} != 0 ]]; then 59 if [[ ${step} != 0 ]] ; then
44 reps=$(( ($max-$min) / $step +1 )) 60 reps=$(( (max - min) / step + 1 ))
45 else 61 else
46 reps=0 62 reps=0
47 fi 63 fi
48 64
49 jot $reps $min $max $step 65 jot $reps $min $max $step || die
50 else 66 return $?
51 "${p}" $min $step $max
52 fi 67 fi
68
69 # Screw it, do the output ourselves
70 while :; do
71 [[ $max < $min && $step > 0 ]] && break
72 [[ $min < $max && $step < 0 ]] && break
73 echo $min
74 : $(( min += step ))
75 done
76 return 0
53} 77}
54 78
79# @FUNCTION: dlopen_lib
80# @USAGE:
81# @RETURN: linker flag if needed
82# @DESCRIPTION:
55# Gets the linker flag to link to dlopen() function 83# Gets the linker flag to link to dlopen() function
56dlopen_lib() { 84dlopen_lib() {
57 if [[ ${ELIBC} != *BSD ]]; then 85 # - Solaris needs nothing
86 # - Darwin needs nothing
87 # - *BSD needs nothing
88 # - Linux needs -ldl (glibc and uclibc)
89 # - Interix needs -ldl
90 case "${CHOST}" in
91 *-linux-gnu*|*-linux-uclibc|*-interix*)
58 echo "-ldl" 92 echo "-ldl"
59 fi 93 ;;
94 esac
60} 95}
61 96
62# Gets the home directory for the specified user 97# @FUNCTION: get_bmake
63# it's a wrap around egetent as the position of the home directory in the line 98# @USAGE:
64# varies depending on the os used. 99# @RETURN: system version of make
65# 100# @DESCRIPTION:
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}
78
79# Gets the name of the BSD-ish make command (pmake from NetBSD) 101# Gets the name of the BSD-ish make command (pmake from NetBSD)
80# 102#
81# This will return make (provided by system packages) for BSD userlands, 103# This will return make (provided by system packages) for BSD userlands,
82# or bsdmake for Darwin userlands and pmake for the rest of userlands, 104# or bsdmake for Darwin userlands and pmake for the rest of userlands,
83# both of which are provided by sys-devel/pmake package. 105# both of which are provided by sys-devel/pmake package.
91 echo bsdmake 113 echo bsdmake
92 else 114 else
93 echo pmake 115 echo pmake
94 fi 116 fi
95} 117}
118
119# @FUNCTION: get_mounts
120# @USAGE:
121# @RETURN: table of mounts in form "point node fs opts"
122# @MAINTAINER:
123# @DESCRIPTION:
124# Portable method of getting mount names and points.
125# Returns as "point node fs options"
126# Remember to convert 040 back to a space.
127get_mounts() {
128 local point= node= fs= opts= foo=
129
130 # Linux has /proc/mounts which should always exist
131 if [[ $(uname -s) == "Linux" ]] ; then
132 while read node point fs opts foo ; do
133 echo "${point} ${node} ${fs} ${opts}"
134 done < /proc/mounts
135 return
136 fi
137
138 # OK, pray we have a -p option that outputs mounts in fstab format
139 # using tabs as the seperator.
140 # Then pray that there are no tabs in the either.
141 # Currently only FreeBSD supports this and the other BSDs will
142 # have to be patched.
143 # Athough the BSD's may support /proc, they do NOT put \040 in place
144 # of the spaces and we should not force a /proc either.
145 local IFS=$'\t'
146 LC_ALL=C mount -p | while read node point fs foo ; do
147 opts=${fs#* }
148 fs=${fs%% *}
149 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
150 done
151}
152
153_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
154is-login-disabled() { _dead_portability_user_funcs; }
155
156fi

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

  ViewVC Help
Powered by ViewVC 1.1.20