| 1 |
# Copyright 1999-2005 Gentoo Foundation
|
| 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 $
|
| 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 |
|
| 11 |
# treecopy orig1 orig2 orig3 .... dest
|
| 12 |
#
|
| 13 |
# mimic cp --parents copy, but working on BSD userland as well
|
| 14 |
treecopy() {
|
| 15 |
dest=${!#}
|
| 16 |
files_count=$#
|
| 17 |
|
| 18 |
while(( $# > 1 )); do
|
| 19 |
dirstruct=$(dirname "$1")
|
| 20 |
mkdir -p "${dest}/${dirstruct}"
|
| 21 |
cp -pPR "$1" "${dest}/${dirstruct}"
|
| 22 |
|
| 23 |
shift
|
| 24 |
done
|
| 25 |
}
|
| 26 |
|
| 27 |
# seq min max
|
| 28 |
#
|
| 29 |
# compatibility function that mimes seq command if not available
|
| 30 |
seq() {
|
| 31 |
local p
|
| 32 |
p=$(type -P seq)
|
| 33 |
|
| 34 |
case $# in
|
| 35 |
1)
|
| 36 |
min=1
|
| 37 |
max=$1
|
| 38 |
step=1
|
| 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
|
| 53 |
|
| 54 |
if [[ -z "${p}" ]]; then
|
| 55 |
local reps
|
| 56 |
# BSD userland
|
| 57 |
if [[ ${step} != 0 ]]; then
|
| 58 |
reps=$(( ($max-$min) / $step +1 ))
|
| 59 |
else
|
| 60 |
reps=0
|
| 61 |
fi
|
| 62 |
|
| 63 |
jot $reps $min $max $step
|
| 64 |
else
|
| 65 |
"${p}" $min $step $max
|
| 66 |
fi
|
| 67 |
}
|
| 68 |
|
| 69 |
# Gets the linker flag to link to dlopen() function
|
| 70 |
dlopen_lib() {
|
| 71 |
if [[ ${ELIBC} != *BSD ]]; then
|
| 72 |
echo "-ldl"
|
| 73 |
fi
|
| 74 |
}
|
| 75 |
|
| 76 |
# Gets the home directory for the specified user
|
| 77 |
# it's a wrap around egetent as the position of the home directory in the line
|
| 78 |
# varies depending on the os used.
|
| 79 |
#
|
| 80 |
# To use that, inherit eutils, not portability!
|
| 81 |
egethome() {
|
| 82 |
ent=$(egetent passwd $1)
|
| 83 |
|
| 84 |
if [[ "${USERLAND}" == "Darwin" || "${ELIBC}" == "FreeBSD" ]]; then
|
| 85 |
# Darwin/OSX and FreeBSD uses position 9 to store the home dir
|
| 86 |
cut -d: -f9 <<<${ent}
|
| 87 |
else
|
| 88 |
# Linux and NetBSD uses position 6 instead
|
| 89 |
cut -d: -f6 <<<${ent}
|
| 90 |
fi
|
| 91 |
}
|