#!/bin/bash
# Without the shebang, not all Syntax highlighters would recognize it
# Bashrc for Paludis supporting multiple C/C++ compilers and per-package CFLAGS
# Version 0.2.1.1
# © 2008 Erik Hahn <erik_hahn@gmx.de>
# distributed under the GPLv2 or later.
# $path causes problems in some ebuilds. Wherever it comes from, fixing
# it doesn't harm
unset path
# Enable extended globbing
shopt -s extglob
# clear debug file
if [[ -e "/tmp/pbshrc-test" ]]; then
echo "" > /tmp/pbshrc-test
fi
function debug(){
if [[ -n $debug && $debug == 1 ]]; then
echo "$(date +%T) $1" >> /tmp/pbshrc-test
fi
}
function matchatom(){
debug "Test: $1"
if [[ "$1" =~ ^($CATEGORY|\*)/($PN|\*)(:$SLOT})?$ ]] ; then
debug "Match 1: $1"
return 0
else
debug "No Match"
return 1
fi
}
function parseconfig(){ #{{{
# set up some vars
local tmpfile="/tmp/paludisbashrc-$RANDOM"
local data
local atom
local ret
local fil
while read atom data; do
if matchatom "$atom"; then
if ((append)); then
ret="$ret ${data%%#*}"
else
ret="${data%%#*}"
fi
fi
done < $1
if [ $append -eq 1 ]; then #{{{
# Now filter out unwanted flags. They begin with '+' instead of '-'
fil="${ret// -*([0-9A-Za-z,=-])}"
fil=${fil//-([0-9A-Za-z,=-]*)}
fil=${fil//+/-} #replace the pluses by minuses
echo "${fil} " > $tmpfile # I don't like using a temporary file
ret=${ret//++([0-9A-Za-z,=-]*)} #remove filtering flags from $ret
# Finally, filter them out
while read -d' ' flag; do
if [ -n $flag ]; then
ret=${ret//${flag}/}
fi
done < $tmpfile
rm $tmpfile
fi #}}}
test -z "$ret" && return 1 # return 1 if nothing has been found
echo $ret
} #}}}
# Use configuration files in this directory
test -z $etc && etc="/etc/paludis"
# Source make.conf for static variables
source "$etc/make.conf"
# Set CC (TODO: see below)
if [[ -z $NCC ]]; then
CC="$(append=0 parseconfig $etc/cc.conf)" || die "error setting CC"
else
CC=$NCC
fi
# Set CXX
case $CC in
"gcc"|"tcc") CXX="g++" ;;
"icc") CXX="icpc"; LD="xild"; AR="xiar" ;;
*) die "error setting CXX" ;;
esac
if [ -n $NCXX ]; then
CXX=$NCXX
fi
if [ -n $NLD ]; then
LD=$NLD
fi
if [ -n $NAR ]; then
AR=$NAR
fi
# Set (C|CXX|LD)FLAGS #{{{
# TODO: maybe it's possible to put that in a function?
if [[ -z $NCFLAGS ]]; then
CFLAGS="$(append=1 parseconfig $etc/${CC}flags.conf)" || die "error setting CFLAGS"
else
CFLAGS=$NCFLAGS
fi
if [[ -z $NCXXFLAGS ]]; then
CXXFLAGS="${CFLAGS} $(append=1 parseconfig $etc/${CC}xxflags.conf)" || CXXFLAGS=${CFLAGS}
else
CXXFLAGS=$NCXXFLAGS
fi
if [[ -z "$NLDFLAGS" ]]; then
LDFLAGS="$(append=1 parseconfig $etc/ldflags.conf)" || die "error setting LDFLAGS"
else
LDFLAGS=$NLDFLAGS
fi #}}}
# vim: set ts=4 sw=4 tw=0 noet: