Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] autoconf-cache.eclass: helper functions for managing autoconf cache variables
Date: Wed, 30 Nov 2011 00:12:59
Message-Id: 201111291911.57865.vapier@gentoo.org
as i started to write more open coded autoconf cache variable tweaks, i got
annoyed to write a simple eclass.  here's a rough PoC.
-mike

# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/autotools.eclass,v 1.110 2011/11/14 17:08:49 vapier Exp $

# @ECLASS: autotools-cache.eclass
# @MAINTAINER:
# base-system@g.o
# @BLURB: Simplify management of autotool cache variables

# just for usex()
inherit eutils

_ac_varify() {
	echo ${1//[![:alnum:]_]/_}
}

ac_cv() {
	export ac_cv_$(_ac_varify "$1")="$2"
}

# @FUNCTION: ac_check_lib
# @USAGE: "<function> <library> [value]" ["<function> <library> [value]" ...]
ac_check_lib() {
	local line
	for line in "$@" ; do
		local args=( ${line} )
		local func=${args[0]} lib=${args[1]} val=${args[2]}
		ac_cv "lib_${lib}_${func}" "${val:-no}"
	done
}
# @FUNCTION: use_ac_check_lib
# @USAGE: <USE flag> "<function> <library>" ["<function> <library>" ...]
use_ac_check_lib() {
	local flag=$1 line packed=()
	for line in "${@:2}" ; do
		packed+=$( "${line} $(usex ${flag})" )
	done
	${FUNCNAME#use_} "${packed[@]}"
}

# @FUNCTION: ac_search_libs
# @USAGE: "<function> [value]" ["<function> [value]" ...]
ac_search_libs() {
	local line
	for line in "$@" ; do
		local args=( ${line} )
		local func=${args[0]} val=${args[1]}
		ac_cv "search_${func}" "${val:-no}"
	done
}
# @FUNCTION: use_ac_search_libs
# @USAGE: <USE flag> "<function> <library>" ["<function> <library>" ...]
use_ac_search_libs() {
	local flag=$1 line packed=()
	for line in "${@:2}" ; do
		local args=( ${line} )
		local lib=${args[1]}
		packed+=( "${line} $(usex ${flag} -l${lib})" )
	done
	${FUNCNAME#use_} "${packed[@]}"
}

# @FUNCTION: ac_check_headers
# @USAGE: "<header> [value]" ["<header> [value]" ...]
ac_check_headers() {
	local line
	for line in "$@" ; do
		local args=( ${line} )
		local h=${args[0]} val=${args[1]}
		ac_cv "header_${h}" "${val:-no}"
	done
}
# @FUNCTION: use_ac_check_headers
# @USAGE: <USE flag> <headers>
use_ac_check_headers() {
	local flag=$1 h packed=()
	for h in "${@:2}" ; do
		packed+=( "${h} $(usex ${flag})" )
	done
	ac_check_headers "${packed[@]}"
}

Attachments

File name MIME type
signature.asc application/pgp-signature