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

Diff of /eclass/portability.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 Revision 1.18
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.15 2010/02/26 18:09:43 grobian Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.18 2011/10/27 07:16:08 vapier Exp $
4# 4#
5# Author: Diego Pettenò <flameeyes@gentoo.org> 5# Author: Diego Pettenò <flameeyes@gentoo.org>
6# 6#
7# This eclass is created to avoid using non-portable GNUisms inside ebuilds 7# This eclass is created to avoid using non-portable GNUisms inside ebuilds
8# 8#
9# NB: If you add anything, please comment it! 9# NB: If you add anything, please comment it!
10
11inherit user
10 12
11# treecopy orig1 orig2 orig3 .... dest 13# treecopy orig1 orig2 orig3 .... dest
12# 14#
13# mimic cp --parents copy, but working on BSD userland as well 15# mimic cp --parents copy, but working on BSD userland as well
14treecopy() { 16treecopy() {
26 28
27# seq min max 29# seq min max
28# 30#
29# compatibility function that mimes seq command if not available 31# compatibility function that mimes seq command if not available
30seq() { 32seq() {
33 # First try `seq`
31 local p=$(type -P seq) 34 local p=$(type -P seq)
35 if [[ -n ${p} ]] ; then
36 "${p}" "$@"
37 return $?
38 fi
32 39
33 case $# in 40 case $# in
34 1) min=1 max=$1 step=1 ;; 41 1) min=1 max=$1 step=1 ;;
35 2) min=$1 max=$2 step=1 ;; 42 2) min=$1 max=$2 step=1 ;;
36 3) min=$1 max=$3 step=$2 ;; 43 3) min=$1 max=$3 step=$2 ;;
37 *) die "seq called with wrong number of arguments" ;; 44 *) die "seq called with wrong number of arguments" ;;
38 esac 45 esac
39 46
47 # Then try `jot`
48 p=$(type -P jot)
40 if [[ -z ${p} ]] ; then 49 if [[ -n ${p} ]] ; then
41 local reps 50 local reps
42 # BSD userland 51 # BSD userland
43 if [[ ${step} != 0 ]]; then 52 if [[ ${step} != 0 ]] ; then
44 reps=$(( ($max-$min) / $step +1 )) 53 reps=$(( (max - min) / step + 1 ))
45 else 54 else
46 reps=0 55 reps=0
47 fi 56 fi
48 57
49 jot $reps $min $max $step 58 jot $reps $min $max $step
50 else 59 return $?
51 "${p}" $min $step $max
52 fi 60 fi
61
62 # Screw it, do the output ourselves
63 while :; do
64 [[ $max < $min && $step > 0 ]] && break
65 [[ $min < $max && $step < 0 ]] && break
66 echo $min
67 : $(( min += step ))
68 done
69 return 0
53} 70}
54 71
55# Gets the linker flag to link to dlopen() function 72# Gets the linker flag to link to dlopen() function
56dlopen_lib() { 73dlopen_lib() {
57 # - Solaris needs nothing 74 # - Solaris needs nothing
61 # - Interix needs -ldl 78 # - Interix needs -ldl
62 case "${CHOST}" in 79 case "${CHOST}" in
63 *-linux-gnu*|*-linux-uclibc|*-interix*) 80 *-linux-gnu*|*-linux-uclibc|*-interix*)
64 echo "-ldl" 81 echo "-ldl"
65 ;; 82 ;;
66 esac
67}
68
69# Gets the home directory for the specified user
70# it's a wrap around egetent as the position of the home directory in the line
71# varies depending on the os used.
72#
73# To use that, inherit eutils, not portability!
74egethome() {
75 ent=$(egetent passwd $1)
76
77 case ${CHOST} in
78 *-darwin*|*-freebsd*|*-dragonfly*)
79 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
80 echo ${ent} | cut -d: -f9
81 ;;
82 *)
83 # Linux, NetBSD and OpenBSD use position 6 instead
84 echo ${ent} | cut -d: -f6
85 ;;
86 esac
87}
88
89# Gets the shell for the specified user
90# it's a wrap around egetent as the position of the home directory in the line
91# varies depending on the os used.
92#
93# To use that, inherit eutils, not portability!
94egetshell() {
95 ent=$(egetent passwd "$1")
96
97 case ${CHOST} in
98 *-darwin*|*-freebsd*|*-dragonfly*)
99 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir
100 echo ${ent} | cut -d: -f10
101 ;;
102 *)
103 # Linux, NetBSD and OpenBSD use position 6 instead
104 echo ${ent} cut -d: -f7
105 ;;
106 esac
107}
108
109# Returns true if specified user has a shell that precludes logins
110# on whichever operating system.
111is-login-disabled() {
112 shell=$(egetshell "$1")
113
114 case ${shell} in
115 /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin)
116 return 0 ;;
117 *)
118 return 1 ;;
119 esac 83 esac
120} 84}
121 85
122# Gets the name of the BSD-ish make command (pmake from NetBSD) 86# Gets the name of the BSD-ish make command (pmake from NetBSD)
123# 87#
163 opts=${fs#* } 127 opts=${fs#* }
164 fs=${fs%% *} 128 fs=${fs%% *}
165 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}" 129 echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
166 done 130 done
167} 131}
168

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20