-
Notifications
You must be signed in to change notification settings - Fork 0
/
distccache.subr
170 lines (130 loc) · 3.55 KB
/
distccache.subr
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
if [ ! "$_CBSD_DISTCCACHE_SUBR" ]; then
_CBSD_DISTCCACHE_SUBR=1
###
# distcc and ccache related function
#return 0 when all fine
#return 1 when no distcc
#return 2 when no hosts
#return 3 when distcc not ready
distcc_check() {
local _res
_res=$( which distcc )
if [ $? -ne 0 ]; then
echo "no distcc in system"
return 1
fi
if [ -z "${CBSD_DISTCCHOST}" ]; then
echo "no CBSD_DISTCCHOST environment"
return 2
fi
#ping distcc here
return 0
}
#return 0 when all fine
#return 1 when no ccache
ccache_check() {
local _res
_res=$( which ccache )
if [ $? -ne 0 ]; then
${ECHO} "${MAGENTA}No ccache in system, ccache disabled${NORMAL}"
return 1
fi
return 0
}
# export in maxjobs summary num of cores
distcc_detect_cpu() {
local i
maxjobs=$( /sbin/sysctl -n hw.ncpu )
for i in $CBSD_DISTCCHOST; do
if [ $( echo $i |grep "/" ) ]; then
NUM=$( echo $i|tr "/," " "| /usr/bin/awk '{printf $2}' )
[ -z "${NUM}" ] && NUM=$( /sbin/sysctl -n hw.ncpu )
fi
maxjobs=$((maxjobs + NUM))
done
export maxjobs
}
#put into copy ($2) of original make.conf ($1) specific distcc or ccache records
#when get only one arg, generate file from empty
prepare_make_conf()
{
local src=$1
shift
local dst=$1
[ -z "${src}" ] && return 0
[ -z "${dst}" ] && dst=${src}
/usr/bin/truncate -s0 ${dst}
[ -r "${src}" ] && /bin/cp -a ${src} ${dst}
[ "${ccache}" = "0" -a "${distcc}" = "0" ] && return 0
local PATH
#set +o errexit
: ${CC="cc"}
COMPILER_VERSION=$( ${CC} --version )
echo $COMPILER_VERSION |grep gcc > /dev/null 2>&1
[ $? -eq 0 ] && COMPILER_TYPE="gcc"
echo $COMPILER_VERSION |grep clang > /dev/null 2>&1
[ $? -eq 0 ] && COMPILER_TYPE="clang"
set -o errexit
if [ $distcc -eq 1 ]; then
PKGSRC_COMPILER="distcc"
distcc_detect_cpu
cat >> $dst <<EOF
.if !defined(NO_DISTCC)
DISTCC_HOSTS="${CBSD_DISTCCHOST}"
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin"
CCACHE_PREFIX="/usr/local/bin/distcc"
EOF
[ $ccache -eq 0 ] && /bin/cat >> $dst << EOF
CC:=/usr/local/bin/distcc
CXX:=/usr/local/bin/distcc
EOF
cat >> $dst <<EOF
MAKE_JOBS_NUMBER=${maxjobs}
MAKE_ARGS+=-j${maxjobs}
#.MAKEFLAGS+= -j${maxjobs}
MFLAGS+= -j${maxjobs}
.endif
EOF
fi
if [ $ccache -eq 1 ]; then
PKGSRC_COMPILER="ccache"
cat >> $dst <<EOF
WITH_CCACHE_BUILD=yes
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*))
.if !defined(NOCCACHE) && exists(/usr/local/libexec/ccache/world/cc)
CC:=\${CC:C,^cc,/usr/local/libexec/ccache/world/cc,1}
CXX:=\${CXX:C,^c\+\+,/usr/local/libexec/ccache/world/c++,1}
.endif
.endif
# /usr/local/share/doc/ccache/ccache-howto-freebsd.txt
#Clang will return a lot of 'unused argument' warnings: they are harmless.
#Just add this to /etc/make.conf if you want to hide them:
.if \${CC:T} == "clang"
CFLAGS+= -Qunused-arguments
.endif
EOF
fi
[ -n "${PKGSRC_COMPILER}" ] && /bin/cat >> $dst <<EOF
PKGSRC_COMPILER="${PKGSRC_COMPILER}"
EOF
cat >> $dst << EOF
COMPILER_TYPE=$COMPILER_TYPE
EOF
if [ $distcc -eq 1 -a $ccache -eq 1 ]; then
export CCACHE_PREFIX="distcc"
export DISTCC_HOSTS="${CBSD_DISTCCHOST}"
fi
## append for override from template conf if src is set
[ "$dst" != "$src" ] && /bin/cat $src >> $dst
return 0
}
init_ccache_dir()
{
[ -z "${ccache_dir_prefix}" ] && ccache_dir_prefix="ccache"
ccache_dir_source="${dbdir}/ccache/${ccache_dir_prefix}-${arch}-${ver}-${stable}"
${ECHO} "${MAGENTA}Init ccache directory: ${GREEN}${ccache_dir_source}${MAGENTA}...${NORMAL}"
[ ! -d "${ccache_dir_source}" ] && /bin/mkdir -p ${ccache_dir_source}
export ccache_dir_source="${ccache_dir_source}"
}
###
fi