public
Description: A bashrc for paludis supporting the Intel C++ compiler and per-package CFLAGS
Homepage: http://ihatenicks.bplaced.net/paludis-bashrc/
Clone URL: git://github.com/ehahn/paludis-bashrc.git
paludis-bashrc / bashrc
100644 134 lines (107 sloc) 2.773 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/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: