1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: portability.eclass
7 # base-system@gentoo.org
9 # Diego Pettenò <flameeyes@gentoo.org>
10 # @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
12 if [[ -z ${_PORTABILITY_ECLASS} ]]; then
16 # @USAGE: <orig1> [orig2 orig3 ....] <dest>
19 # mimic cp --parents copy, but working on BSD userland as well
24 while (( $# > 1 )); do
25 local dirstruct=$(dirname "$1")
26 mkdir -p "${dest}/${dirstruct}" || die
27 cp -pPR "$1" "${dest}/${dirstruct}" || die
34 # @USAGE: [min] <max> [step]
35 # @RETURN: sequence from min to max regardless of seq command being present on system
37 # compatibility function that mimes seq command if not available
40 local p=$(type -P seq)
41 if [[ -n ${p} ]] ; then
48 1) min=1 max=$1 step=1 ;;
49 2) min=$1 max=$2 step=1 ;;
50 3) min=$1 max=$3 step=$2 ;;
51 *) die "seq called with wrong number of arguments" ;;
56 if [[ -n ${p} ]] ; then
59 if [[ ${step} != 0 ]] ; then
60 reps=$(( (max - min) / step + 1 ))
65 jot $reps $min $max $step || die
69 # Screw it, do the output ourselves
71 [[ $max < $min && $step > 0 ]] && break
72 [[ $min < $max && $step < 0 ]] && break
79 # @FUNCTION: dlopen_lib
81 # @RETURN: linker flag if needed
83 # Gets the linker flag to link to dlopen() function
85 # - Solaris needs nothing
86 # - Darwin needs nothing
87 # - *BSD needs nothing
88 # - Linux needs -ldl (glibc and uclibc)
89 # - Interix needs -ldl
91 *-linux-gnu*|*-linux-uclibc|*-interix*)
97 # @FUNCTION: get_bmake
99 # @RETURN: system version of make
101 # Gets the name of the BSD-ish make command (bmake from NetBSD)
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.
107 # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
110 if [[ ${CBUILD:-${CHOST}} == *bsd* ]]; then
112 elif [[ ${CBUILD:-${CHOST}} == *darwin* ]]; then
119 # @FUNCTION: get_mounts
121 # @RETURN: table of mounts in form "point node fs opts"
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.
128 local point= node= fs= opts= foo=
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}"
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.
146 LC_ALL=C mount -p | while read node point fs foo ; do
149 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
153 _dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
154 is-login-disabled() { _dead_portability_user_funcs; }