Added portability eclass with seq() function to replace seq command. Make eutils...
authorDiego Elio Pettenò <flameeyes@gentoo.org>
Sun, 18 Sep 2005 17:33:44 +0000 (17:33 +0000)
committerDiego Elio Pettenò <flameeyes@gentoo.org>
Sun, 18 Sep 2005 17:33:44 +0000 (17:33 +0000)
eclass/eutils.eclass
eclass/portability.eclass [new file with mode: 0644]

index 347a3c9bcc4660daaafba28fce701bd50629eced..3f63db4c420b04e4c05565b4b6e987a90b47c53c 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2005 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.196 2005/09/06 01:59:22 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.197 2005/09/18 17:33:44 flameeyes Exp $
 #
 # Author: Martin Schlemmer <azarah@gentoo.org>
 #
@@ -9,7 +9,7 @@
 #
 # NB:  If you add anything, please comment it!
 
-inherit multilib
+inherit multilib portability
 
 DEPEND="!bootstrap? ( sys-devel/patch )"
 # sys-apps/shadow is needed for useradd, etc, bug #94745.
@@ -479,13 +479,7 @@ enewuser() {
                euid="next"
        fi
        if [[ ${euid} == "next" ]] ; then
-               local pwrange
-               if [[ ${USERLAND} == "BSD" ]] ; then
-                       pwrange=$(jot 898 101)
-               else
-                       pwrange=$(seq 101 999)
-               fi
-               for euid in ${pwrange} ; do
+               for euid in $(seq 101 999) ; do
                        [[ -z $(egetent passwd ${euid}) ]] && break
                done
        fi
@@ -679,7 +673,7 @@ enewgroup() {
                # If we need the next available
                case ${egid} in
                  *[!0-9]*) # Non numeric
-                       for egid in `jot 898 101`; do
+                       for egid in $(seq 101 999); do
                                [ -z "`egetent group ${egid}`" ] && break
                        done
                esac
@@ -688,7 +682,7 @@ enewgroup() {
        elif [[ "${USERLAND}" == "BSD" ]] ; then
                case ${egid} in
                        *[!0-9]*) # Non numeric
-                               for egid in `jot 898 101`; do
+                               for egid in $(seq 101 999); do
                                        [ -z "`egetent group ${egid}`" ] && break
                                done
                esac
diff --git a/eclass/portability.eclass b/eclass/portability.eclass
new file mode 100644 (file)
index 0000000..a83e354
--- /dev/null
@@ -0,0 +1,75 @@
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.1 2005/09/18 17:33:44 flameeyes Exp $
+#
+# Author: Diego Pettenò <flameeyes@gentoo.org>
+#
+# This eclass is created to avoid using non-portable GNUisms inside ebuilds
+#
+# NB:  If you add anything, please comment it!
+
+# treecopy orig1 orig2 orig3 .... dest
+#
+# mimic cp --parents copy, but working on BSD userland as well
+treecopy() {
+       dest=${!#}
+       files_count=$#
+
+       while(( $# > 1 )); do
+               dirstruct=$(dirname "$1")
+               mkdir -p "${dest}/${dirstruct}"
+               cp -pPR "$1" "${dest}/${dirstruct}"
+
+               shift
+       done
+}
+
+# seq min max
+#
+# compatibility function that mimes seq command if not available
+seq() {
+       local p
+       p=$(type -P seq)
+
+       case $# in
+               1)
+                       min=1
+                       max=$1
+                       step=1
+                       ;;
+               2)
+                       min=$1
+                       max=$2
+                       step=1
+                       ;;
+               3)
+                       min=$1
+                       max=$3
+                       step=$2
+                       ;;
+               *)
+                       die "seq called with wrong parameters number"
+       esac
+
+       if [[ -z "${p}" ]]; then
+               local reps
+               # BSD userland
+               if [[ ${step} != 0 ]]; then
+                       reps=$(( ($max-$min) / $step +1 ))
+               else
+                       reps=0
+               fi
+
+               jot $reps $min $max $step
+       else
+               "${p}" $min $step $max
+       fi
+}
+
+# Gets the linker flag to link to dlopen() function
+dlopen_lib() {
+       if [[ ${ELIBC} != *BSD ]]; then
+               echo "-ldl"
+       fi
+}
+