/[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.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 2005/09/18 17:33:44 flameeyes 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() {
31 local p 39 # First try `seq`
32 p=$(type -P seq) 40 local p=$(type -P seq)
41 if [[ -n ${p} ]] ; then
42 "${p}" "$@" || die
43 return $?
44 fi
33 45
46 local min max step
34 case $# in 47 case $# in
35 1) 48 1) min=1 max=$1 step=1 ;;
36 min=1 49 2) min=$1 max=$2 step=1 ;;
37 max=$1 50 3) min=$1 max=$3 step=$2 ;;
38 step=1 51 *) 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 52 esac
53 53
54 # Then try `jot`
55 p=$(type -P jot)
54 if [[ -z "${p}" ]]; then 56 if [[ -n ${p} ]] ; then
55 local reps 57 local reps
56 # BSD userland 58 # BSD userland
57 if [[ ${step} != 0 ]]; then 59 if [[ ${step} != 0 ]] ; then
58 reps=$(( ($max-$min) / $step +1 )) 60 reps=$(( (max - min) / step + 1 ))
59 else 61 else
60 reps=0 62 reps=0
61 fi 63 fi
62 64
63 jot $reps $min $max $step 65 jot $reps $min $max $step || die
66 return $?
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
77}
78
79# @FUNCTION: dlopen_lib
80# @USAGE:
81# @RETURN: linker flag if needed
82# @DESCRIPTION:
83# Gets the linker flag to link to dlopen() function
84dlopen_lib() {
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*)
92 echo "-ldl"
93 ;;
94 esac
95}
96
97# @FUNCTION: get_bmake
98# @USAGE:
99# @RETURN: system version of make
100# @DESCRIPTION:
101# Gets the name of the BSD-ish make command (pmake from NetBSD)
102#
103# This will return make (provided by system packages) for BSD userlands,
104# or bsdmake for Darwin userlands and pmake for the rest of userlands,
105# both of which are provided by sys-devel/pmake package.
106#
107# Note: the bsdmake for Darwin userland is with compatibility with MacOSX
108# default name.
109get_bmake() {
110 if [[ ${USERLAND} == *BSD ]]; then
111 echo make
112 elif [[ ${USERLAND} == "Darwin" ]]; then
113 echo bsdmake
64 else 114 else
65 "${p}" $min $step $max 115 echo pmake
66 fi 116 fi
67} 117}
68 118
69# Gets the linker flag to link to dlopen() function 119# @FUNCTION: get_mounts
70dlopen_lib() { 120# @USAGE:
71 if [[ ${ELIBC} != *BSD ]]; then 121# @RETURN: table of mounts in form "point node fs opts"
72 echo "-ldl" 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
73 fi 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
74} 151}
75 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  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.20