summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2015-08-08 13:49:04 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2015-08-08 17:38:18 -0700
commit56bd759df1d0c750a065b8c845e93d5dfa6b549d (patch)
tree3f91093cdb475e565ae857f1c5a7fd339e2d781e /eclass/portability.eclass
downloadgentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.tar.gz
gentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.tar.bz2
gentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.zip
proj/gentoo: Initial commit
This commit represents a new era for Gentoo: Storing the gentoo-x86 tree in Git, as converted from CVS. This commit is the start of the NEW history. Any historical data is intended to be grafted onto this point. Creation process: 1. Take final CVS checkout snapshot 2. Remove ALL ChangeLog* files 3. Transform all Manifests to thin 4. Remove empty Manifests 5. Convert all stale $Header$/$Id$ CVS keywords to non-expanded Git $Id$ 5.1. Do not touch files with -kb/-ko keyword flags. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org> X-Thanks: Alec Warner <antarus@gentoo.org> - did the GSoC 2006 migration tests X-Thanks: Robin H. Johnson <robbat2@gentoo.org> - infra guy, herding this project X-Thanks: Nguyen Thai Ngoc Duy <pclouds@gentoo.org> - Former Gentoo developer, wrote Git features for the migration X-Thanks: Brian Harring <ferringb@gentoo.org> - wrote much python to improve cvs2svn X-Thanks: Rich Freeman <rich0@gentoo.org> - validation scripts X-Thanks: Patrick Lauer <patrick@gentoo.org> - Gentoo dev, running new 2014 work in migration X-Thanks: Michał Górny <mgorny@gentoo.org> - scripts, QA, nagging X-Thanks: All of other Gentoo developers - many ideas and lots of paint on the bikeshed
Diffstat (limited to 'eclass/portability.eclass')
-rw-r--r--eclass/portability.eclass156
1 files changed, 156 insertions, 0 deletions
diff --git a/eclass/portability.eclass b/eclass/portability.eclass
new file mode 100644
index 000000000000..2e4e01d51432
--- /dev/null
+++ b/eclass/portability.eclass
@@ -0,0 +1,156 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+# @ECLASS: portability.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @AUTHOR:
+# Diego Pettenò <flameeyes@gentoo.org>
+# @BLURB: This eclass is created to avoid using non-portable GNUisms inside ebuilds
+
+if [[ -z ${_PORTABILITY_ECLASS} ]]; then
+_PORTABILITY_ECLASS=1
+
+# @FUNCTION: treecopy
+# @USAGE: <orig1> [orig2 orig3 ....] <dest>
+# @RETURN:
+# @DESCRIPTION:
+# mimic cp --parents copy, but working on BSD userland as well
+treecopy() {
+ local dest=${!#}
+ local files_count=$#
+
+ while (( $# > 1 )); do
+ local dirstruct=$(dirname "$1")
+ mkdir -p "${dest}/${dirstruct}" || die
+ cp -pPR "$1" "${dest}/${dirstruct}" || die
+
+ shift
+ done
+}
+
+# @FUNCTION: seq
+# @USAGE: [min] <max> [step]
+# @RETURN: sequence from min to max regardless of seq command being present on system
+# @DESCRIPTION:
+# compatibility function that mimes seq command if not available
+seq() {
+ # First try `seq`
+ local p=$(type -P seq)
+ if [[ -n ${p} ]] ; then
+ "${p}" "$@" || die
+ return $?
+ fi
+
+ local min max step
+ 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 number of arguments" ;;
+ esac
+
+ # Then try `jot`
+ p=$(type -P jot)
+ if [[ -n ${p} ]] ; then
+ local reps
+ # BSD userland
+ if [[ ${step} != 0 ]] ; then
+ reps=$(( (max - min) / step + 1 ))
+ else
+ reps=0
+ fi
+
+ jot $reps $min $max $step || die
+ return $?
+ fi
+
+ # Screw it, do the output ourselves
+ while :; do
+ [[ $max < $min && $step > 0 ]] && break
+ [[ $min < $max && $step < 0 ]] && break
+ echo $min
+ : $(( min += step ))
+ done
+ return 0
+}
+
+# @FUNCTION: dlopen_lib
+# @USAGE:
+# @RETURN: linker flag if needed
+# @DESCRIPTION:
+# Gets the linker flag to link to dlopen() function
+dlopen_lib() {
+ # - Solaris needs nothing
+ # - Darwin needs nothing
+ # - *BSD needs nothing
+ # - Linux needs -ldl (glibc and uclibc)
+ # - Interix needs -ldl
+ case "${CHOST}" in
+ *-linux-gnu*|*-linux-uclibc|*-interix*)
+ echo "-ldl"
+ ;;
+ esac
+}
+
+# @FUNCTION: get_bmake
+# @USAGE:
+# @RETURN: system version of make
+# @DESCRIPTION:
+# Gets the name of the BSD-ish make command (pmake from NetBSD)
+#
+# This will return make (provided by system packages) for BSD userlands,
+# or bsdmake for Darwin userlands and pmake for the rest of userlands,
+# both of which are provided by sys-devel/pmake package.
+#
+# Note: the bsdmake for Darwin userland is with compatibility with MacOSX
+# default name.
+get_bmake() {
+ if [[ ${USERLAND} == *BSD ]]; then
+ echo make
+ elif [[ ${USERLAND} == "Darwin" ]]; then
+ echo bsdmake
+ else
+ echo pmake
+ fi
+}
+
+# @FUNCTION: get_mounts
+# @USAGE:
+# @RETURN: table of mounts in form "point node fs opts"
+# @MAINTAINER:
+# @DESCRIPTION:
+# Portable method of getting mount names and points.
+# Returns as "point node fs options"
+# Remember to convert 040 back to a space.
+get_mounts() {
+ local point= node= fs= opts= foo=
+
+ # Linux has /proc/mounts which should always exist
+ if [[ $(uname -s) == "Linux" ]] ; then
+ while read node point fs opts foo ; do
+ echo "${point} ${node} ${fs} ${opts}"
+ done < /proc/mounts
+ return
+ fi
+
+ # OK, pray we have a -p option that outputs mounts in fstab format
+ # using tabs as the seperator.
+ # Then pray that there are no tabs in the either.
+ # Currently only FreeBSD supports this and the other BSDs will
+ # have to be patched.
+ # Athough the BSD's may support /proc, they do NOT put \040 in place
+ # of the spaces and we should not force a /proc either.
+ local IFS=$'\t'
+ LC_ALL=C mount -p | while read node point fs foo ; do
+ opts=${fs#* }
+ fs=${fs%% *}
+ echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}"
+ done
+}
+
+_dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; }
+is-login-disabled() { _dead_portability_user_funcs; }
+
+fi