/[gentoo-x86]/eclass/portability.eclass
Gentoo

Contents of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Dec 14 18:43:34 2005 UTC (8 years, 7 months ago) by flameeyes
Branch: MAIN
Changes since 1.4: +7 -6 lines
Refactor egethome() function to use ${CHOST} instead of (deprecated) ${USERLAND}. Also add DragonFly support (same as FreeBSD).

1 flameeyes 1.1 # Copyright 1999-2005 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 flameeyes 1.5 # $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.4 2005/09/26 23:33:55 flameeyes Exp $
4 flameeyes 1.1 #
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 vapier 1.3 local p=$(type -P seq)
32 flameeyes 1.1
33     case $# in
34 vapier 1.3 1) min=1 max=$1 step=1 ;;
35     2) min=$1 max=$2 step=1 ;;
36     3) min=$1 max=$3 step=$2 ;;
37     *) die "seq called with wrong number of arguments" ;;
38 flameeyes 1.1 esac
39    
40 vapier 1.3 if [[ -z ${p} ]] ; then
41 flameeyes 1.1 local reps
42     # BSD userland
43     if [[ ${step} != 0 ]]; then
44     reps=$(( ($max-$min) / $step +1 ))
45     else
46     reps=0
47     fi
48    
49     jot $reps $min $max $step
50     else
51     "${p}" $min $step $max
52     fi
53     }
54    
55     # Gets the linker flag to link to dlopen() function
56     dlopen_lib() {
57     if [[ ${ELIBC} != *BSD ]]; then
58     echo "-ldl"
59     fi
60     }
61    
62 flameeyes 1.2 # Gets the home directory for the specified user
63     # it's a wrap around egetent as the position of the home directory in the line
64     # varies depending on the os used.
65     #
66     # To use that, inherit eutils, not portability!
67     egethome() {
68     ent=$(egetent passwd $1)
69    
70 flameeyes 1.5 case ${CHOST} in
71     *-darwin*|*-freebsd*|*-dragonfly*)
72     # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
73 flameeyes 1.2 cut -d: -f9 <<<${ent}
74 flameeyes 1.5 *)
75     # Linux, NetBSD and OpenBSD use position 6 instead
76 flameeyes 1.2 cut -d: -f6 <<<${ent}
77 flameeyes 1.5 esac
78 flameeyes 1.2 }
79 flameeyes 1.4
80     # Gets the name of the BSD-ish make command (pmake from NetBSD)
81     #
82     # This will return make (provided by system packages) for BSD userlands,
83     # or bsdmake for Darwin userlands and pmake for the rest of userlands,
84     # both of which are provided by sys-devel/pmake package.
85     #
86     # Note: the bsdmake for Darwin userland is with compatibility with MacOSX
87     # default name.
88     get_bmake() {
89     if [[ ${USERLAND} == *BSD ]]; then
90     echo make
91     elif [[ ${USERLAND} == "Darwin" ]]; then
92     echo bsdmake
93     else
94     echo pmake
95     fi
96     }

  ViewVC Help
Powered by ViewVC 1.1.20