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

Diff of /eclass/portability.eclass

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

Revision 1.24 Revision 1.25
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2014 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.24 2012/01/04 05:57:19 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v 1.25 2014/05/28 09:48:01 jlec Exp $
4# 4
5# @ECLASS: portability.eclass
6# @MAINTAINER:
7# base-system@gentoo.org
8# @AUTHOR:
5# Author: Diego Pettenò <flameeyes@gentoo.org> 9# Diego Pettenò <flameeyes@gentoo.org>
6#
7# This eclass is created to avoid using non-portable GNUisms inside ebuilds 10# @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
8#
9# NB: If you add anything, please comment it!
10 11
11if [[ ${___ECLASS_ONCE_PORTABILITY} != "recur -_+^+_- spank" ]] ; then 12if [[ ${___ECLASS_ONCE_PORTABILITY} != "recur -_+^+_- spank" ]] ; then
12___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank" 13___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank"
13 14
14# treecopy orig1 orig2 orig3 .... dest 15# @FUNCTION: treecopy
15# 16# @USAGE: <orig1> [orig2 orig3 ....] <dest>
17# @RETURN:
18# @DESCRIPTION:
16# mimic cp --parents copy, but working on BSD userland as well 19# mimic cp --parents copy, but working on BSD userland as well
17treecopy() { 20treecopy() {
18 local dest=${!#} 21 local dest=${!#}
19 local files_count=$# 22 local files_count=$#
20 23
21 while (( $# > 1 )); do 24 while (( $# > 1 )); do
22 local dirstruct=$(dirname "$1") 25 local dirstruct=$(dirname "$1")
23 mkdir -p "${dest}/${dirstruct}" 26 mkdir -p "${dest}/${dirstruct}" || die
24 cp -pPR "$1" "${dest}/${dirstruct}" 27 cp -pPR "$1" "${dest}/${dirstruct}" || die
25 28
26 shift 29 shift
27 done 30 done
28} 31}
29 32
30# seq min max 33# @FUNCTION: seq
31# 34# @USAGE: [min] <max> [step]
35# @RETURN: sequence from min to max regardless of seq command being present on system
36# @DESCRIPTION:
32# compatibility function that mimes seq command if not available 37# compatibility function that mimes seq command if not available
33seq() { 38seq() {
34 # First try `seq` 39 # First try `seq`
35 local p=$(type -P seq) 40 local p=$(type -P seq)
36 if [[ -n ${p} ]] ; then 41 if [[ -n ${p} ]] ; then
37 "${p}" "$@" 42 "${p}" "$@" || die
38 return $? 43 return $?
39 fi 44 fi
40 45
41 local min max step 46 local min max step
42 case $# in 47 case $# in
55 reps=$(( (max - min) / step + 1 )) 60 reps=$(( (max - min) / step + 1 ))
56 else 61 else
57 reps=0 62 reps=0
58 fi 63 fi
59 64
60 jot $reps $min $max $step 65 jot $reps $min $max $step || die
61 return $? 66 return $?
62 fi 67 fi
63 68
64 # Screw it, do the output ourselves 69 # Screw it, do the output ourselves
65 while :; do 70 while :; do
69 : $(( min += step )) 74 : $(( min += step ))
70 done 75 done
71 return 0 76 return 0
72} 77}
73 78
79# @FUNCTION: dlopen_lib
80# @USAGE:
81# @RETURN: linker flag if needed
82# @DESCRIPTION:
74# Gets the linker flag to link to dlopen() function 83# Gets the linker flag to link to dlopen() function
75dlopen_lib() { 84dlopen_lib() {
76 # - Solaris needs nothing 85 # - Solaris needs nothing
77 # - Darwin needs nothing 86 # - Darwin needs nothing
78 # - *BSD needs nothing 87 # - *BSD needs nothing
83 echo "-ldl" 92 echo "-ldl"
84 ;; 93 ;;
85 esac 94 esac
86} 95}
87 96
97# @FUNCTION: get_bmake
98# @USAGE:
99# @RETURN: system version of make
100# @DESCRIPTION:
88# Gets the name of the BSD-ish make command (pmake from NetBSD) 101# Gets the name of the BSD-ish make command (pmake from NetBSD)
89# 102#
90# This will return make (provided by system packages) for BSD userlands, 103# This will return make (provided by system packages) for BSD userlands,
91# or bsdmake for Darwin userlands and pmake for the rest of userlands, 104# or bsdmake for Darwin userlands and pmake for the rest of userlands,
92# both of which are provided by sys-devel/pmake package. 105# both of which are provided by sys-devel/pmake package.
101 else 114 else
102 echo pmake 115 echo pmake
103 fi 116 fi
104} 117}
105 118
119# @FUNCTION: get_mounts
120# @USAGE:
121# @RETURN: table of mounts in form "point node fs opts"
122# @MAINTAINER:
123# @DESCRIPTION:
106# Portable method of getting mount names and points. 124# Portable method of getting mount names and points.
107# Returns as "point node fs options" 125# Returns as "point node fs options"
108# Remember to convert 040 back to a space. 126# Remember to convert 040 back to a space.
109get_mounts() { 127get_mounts() {
110 local point= node= fs= opts= foo= 128 local point= node= fs= opts= foo=

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20