| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 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/eutils.eclass,v 1.363 2011/09/12 20:44:01 mgorny Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.367 2011/10/26 23:27:16 vapier Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: eutils.eclass |
5 | # @ECLASS: eutils.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org |
7 | # base-system@gentoo.org |
| 8 | # @BLURB: many extra (but common) functions that are used in ebuilds |
8 | # @BLURB: many extra (but common) functions that are used in ebuilds |
| … | |
… | |
| 917 | # A handy replacement for dos2unix, recode, fixdos, etc... This allows you |
917 | # A handy replacement for dos2unix, recode, fixdos, etc... This allows you |
| 918 | # to remove all of these text utilities from DEPEND variables because this |
918 | # to remove all of these text utilities from DEPEND variables because this |
| 919 | # is a script based solution. Just give it a list of files to convert and |
919 | # is a script based solution. Just give it a list of files to convert and |
| 920 | # they will all be changed from the DOS CRLF format to the UNIX LF format. |
920 | # they will all be changed from the DOS CRLF format to the UNIX LF format. |
| 921 | edos2unix() { |
921 | edos2unix() { |
| 922 | echo "$@" | xargs sed -i 's/\r$//' |
922 | [[ $# -eq 0 ]] && return 0 |
|
|
923 | sed -i 's/\r$//' -- "$@" || die |
| 923 | } |
924 | } |
| 924 | |
925 | |
| 925 | # Make a desktop file ! |
926 | # Make a desktop file ! |
| 926 | # Great for making those icons in kde/gnome startmenu ! |
927 | # Great for making those icons in kde/gnome startmenu ! |
| 927 | # Amaze your friends ! Get the women ! Join today ! |
928 | # Amaze your friends ! Get the women ! Join today ! |
| … | |
… | |
| 2026 | case ${opt} in |
2027 | case ${opt} in |
| 2027 | -a) return $(( r != 0 )) ;; |
2028 | -a) return $(( r != 0 )) ;; |
| 2028 | -o) return $(( r == $# )) ;; |
2029 | -o) return $(( r == $# )) ;; |
| 2029 | esac |
2030 | esac |
| 2030 | } |
2031 | } |
|
|
2032 | |
|
|
2033 | # @FUNCTION: in_iuse |
|
|
2034 | # @USAGE: <flag> |
|
|
2035 | # @DESCRIPTION: |
|
|
2036 | # Determines whether the given flag is in IUSE. Strips IUSE default prefixes |
|
|
2037 | # as necessary. |
|
|
2038 | # |
|
|
2039 | # Note that this function should not be used in the global scope. |
|
|
2040 | in_iuse() { |
|
|
2041 | debug-print-function ${FUNCNAME} "${@}" |
|
|
2042 | [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()" |
|
|
2043 | |
|
|
2044 | local flag=${1} |
|
|
2045 | local liuse=( ${IUSE} ) |
|
|
2046 | |
|
|
2047 | has "${flag}" "${liuse[@]#[+-]}" |
|
|
2048 | } |
|
|
2049 | |
|
|
2050 | # @FUNCTION: use_if_iuse |
|
|
2051 | # @USAGE: <flag> |
|
|
2052 | # @DESCRIPTION: |
|
|
2053 | # Return true if the given flag is in USE and IUSE. |
|
|
2054 | # |
|
|
2055 | # Note that this function should not be used in the global scope. |
|
|
2056 | use_if_iuse() { |
|
|
2057 | in_iuse $1 || return 1 |
|
|
2058 | use $1 |
|
|
2059 | } |
|
|
2060 | |
|
|
2061 | # @FUNCTION: usex |
|
|
2062 | # @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] |
|
|
2063 | # @DESCRIPTION: |
|
|
2064 | # If USE flag is set, echo [true output][true suffix] (defaults to "yes"), |
|
|
2065 | # otherwise echo [false output][false suffix] (defaults to "no"). |
|
|
2066 | usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 |