1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: portability.eclass
6 # base-system@gentoo.org
8 # Diego Pettenò <flameeyes@gentoo.org>
9 # @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
11 if [[ -z ${_PORTABILITY_ECLASS} ]]; then
15 # @USAGE: <orig1> [orig2 orig3 ....] <dest>
18 # mimic cp --parents copy, but working on BSD userland as well
23 while (( $# > 1 )); do
24 local dirstruct=$(dirname "$1")
25 mkdir -p "${dest}/${dirstruct}" || die
26 cp -pPR "$1" "${dest}/${dirstruct}" || die
33 # @USAGE: [min] <max> [step]
34 # @RETURN: sequence from min to max regardless of seq command being present on system
36 # compatibility function that mimes seq command if not available
39 local p=$(type -P seq)
40 if [[ -n ${p} ]] ; then
47 1) min=1 max=$1 step=1 ;;
48 2) min=$1 max=$2 step=1 ;;
49 3) min=$1 max=$3 step=$2 ;;
50 *) die "seq called with wrong number of arguments" ;;
55 if [[ -n ${p} ]] ; then
58 if [[ ${step} != 0 ]] ; then
59 reps=$(( (max - min) / step + 1 ))
64 jot $reps $min $max $step || die
68 # Screw it, do the output ourselves
70 [[ $max -lt $min && $step -gt 0 ]] && break
71 [[ $min -lt $max && $step -gt 0 ]] && break
78 # @FUNCTION: dlopen_lib
80 # @RETURN: linker flag if needed
82 # Gets the linker flag to link to dlopen() function
84 # - Solaris needs nothing
85 # - Darwin needs nothing
86 # - *BSD needs nothing
87 # - Linux needs -ldl (glibc and uclibc)
88 # - Interix needs -ldl
90 *-linux-gnu*|*-linux-uclibc|*-interix*)
96 # @FUNCTION: get_bmake
98 # @RETURN: system version of make
100 # Gets the name of the BSD-ish make command (bmake from NetBSD)
102 # This will return make (provided by system packages) for BSD userlands,
103 # or bsdmake for Darwin userlands and pmake for the rest of userlands,
104 # both of which are provided by sys-devel/pmake package.
106 # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
109 if [[ ${CBUILD:-${CHOST}} == *bsd* ]]; then
111 elif [[ ${CBUILD:-${CHOST}} == *darwin* ]]; then
118 # @FUNCTION: get_mounts
120 # @RETURN: table of mounts in form "point node fs opts"
123 # Portable method of getting mount names and points.
124 # Returns as "point node fs options"
125 # Remember to convert 040 back to a space.
127 local point= node= fs= opts= foo=
129 # Linux has /proc/mounts which should always exist
130 if [[ $(uname -s) == "Linux" ]] ; then
131 while read node point fs opts foo ; do
132 echo "${point} ${node} ${fs} ${opts}"
137 # OK, pray we have a -p option that outputs mounts in fstab format
138 # using tabs as the seperator.
139 # Then pray that there are no tabs in the either.
140 # Currently only FreeBSD supports this and the other BSDs will
141 # have to be patched.
142 # Athough the BSD's may support /proc, they do NOT put \040 in place
143 # of the spaces and we should not force a /proc either.
145 LC_ALL=C mount -p | while read node point fs foo ; do
148 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
152 _dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
153 is-login-disabled() { _dead_portability_user_funcs; }