3 # Trap these signals and kill ourselves if recieved
4 # Force ourselves to die if any of these signals are recieved
5 # most likely our controlling terminal is gone
6 trap "echo SIGTERM signal recieved killing $0 with pid $$;kill -9 $$" SIGTERM
7 trap "echo SIGHUP signal recieved killing $0 with pid $$;kill -9 $$" SIGHUP
8 trap "echo SIGKILL signal recieved killing $0 with pid $$;kill -9 $$" SIGKILL
10 #SIGINT interrupt character (usually Ctrl-C)
11 # * example: high-level sequence of events
12 # * my process (call it "P") is running
14 # * kernel recognizes this and generates SIGINT signal
15 trap "echo SIGINT signal recieved killing $0 with pid $$;kill -9 $$" SIGINT
17 check_genkernel_version(){
18 if [ -x /usr/bin/genkernel ]
20 genkernel_version=$(genkernel --version)
21 genkernel_version_major=${genkernel_version%%.*}
22 genkernel_version_minor_sub=${genkernel_version#${genkernel_version_major}.}
23 genkernel_version_minor=${genkernel_version_minor_sub%%.*}
24 genkernel_version_sub=${genkernel_version##*.}
25 if [ -n "${genkernel_version}" -a "${genkernel_version_major}" -eq '3' -a "${genkernel_version_minor}" -ge '3' ]
27 echo "Genkernel version ${genkernel_version} found ... continuing"
29 echo "ERROR: Your genkernel version is too low in your seed stage. genkernel version 3.3.0"
30 echo "or greater is required."
39 ABI=$(portageq envvar ABI)
40 DEFAULT_ABI=$(portageq envvar DEFAULT_ABI)
41 LIBDIR_default=$(portageq envvar LIBDIR_default)
50 elif [ -n "${DEFAULT_ABI}" ]
57 local var="LIBDIR_${abi}"
58 var=$(portageq envvar ${var})
64 if [ -n "${clst_CCACHE}" ]
66 export clst_myfeatures="${clst_myfeatures} ccache"
67 clst_root_path=/ run_merge --oneshot --nodeps dev-util/ccache || exit 1
70 if [ -n "${clst_DISTCC}" ]
72 export clst_myfeatures="${clst_myfeatures} distcc"
73 export DISTCC_HOSTS="${clst_distcc_hosts}"
74 [ -e /etc/make.conf ] && \
75 echo 'USE="${USE} -avahi -gtk -gnome"' >> /etc/make.conf
76 clst_root_path=/ run_merge --oneshot --nodeps sys-devel/distcc || exit 1
77 sed -i '/USE="${USE} -avahi -gtk -gnome"/d' /etc/make.conf
79 echo "${clst_distcc_hosts}" > /etc/distcc/hosts
81 # This sets up automatic cross-distcc-fu according to
82 # http://www.gentoo.org/doc/en/cross-compiling-distcc.xml
83 CHOST=$(portageq envvar CHOST)
84 # TODO: change to use get_libdir
85 cd /usr/lib/distcc/bin
86 rm cc gcc g++ c++ 2>/dev/null
87 echo -e '#!/bin/bash\nexec /usr/lib/distcc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
88 chmod a+x /usr/lib/distcc/bin/${CHOST}-wrapper
89 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
92 if [ -n "${clst_ICECREAM}" ]
94 clst_root_path=/ run_merge --oneshot --nodeps sys-devel/icecream || exit 1
96 # This sets up automatic cross-icecc-fu according to
97 # http://gentoo-wiki.com/HOWTO_Setup_An_ICECREAM_Compile_Cluster#Icecream_and_cross-compiling
98 CHOST=$(portageq envvar CHOST)
100 cd /usr/${LIBDIR}/icecc/bin
101 rm cc gcc g++ c++ 2>/dev/null
102 echo -e '#!/bin/bash\nexec /usr/'${LIBDIR}'/icecc/bin/'${CHOST}'-g${0:$[-2]} "$@"' > ${CHOST}-wrapper
103 chmod a+x ${CHOST}-wrapper
104 for i in cc gcc g++ c++; do ln -s ${CHOST}-wrapper ${i}; done
105 export PATH="/usr/lib/icecc/bin:${PATH}"
106 export PREROOTPATH="/usr/lib/icecc/bin"
108 export FEATURES="${clst_myfeatures}"
111 setup_myemergeopts(){
112 if [ -n "${clst_VERBOSE}" ]
114 clst_myemergeopts="--verbose"
116 clst_myemergeopts="--quiet"
118 if [ -n "${clst_FETCH}" ]
120 export bootstrap_opts="-f"
121 export clst_myemergeopts="${clst_myemergeopts} -f"
122 elif [ -n "${clst_PKGCACHE}" ]
124 export clst_myemergeopts="${clst_myemergeopts} --usepkg --buildpkg --newuse"
125 export bootstrap_opts="-r"
130 if [ -x /usr/bin/binutils-config ]
132 mythang=$( cd /etc/env.d/binutils; ls ${clst_CHOST}-* | head -n 1 )
133 if [ -z "${mythang}" ]
137 binutils-config ${mythang}; update_env_settings
142 if [ -x /usr/bin/gcc-config ]
144 mythang=$( cd /etc/env.d/gcc; ls ${clst_CHOST}-* | head -n 1 )
145 if [ -z "${mythang}" ]
149 gcc-config ${mythang}; update_env_settings
154 # We need to merge our package manager with USE="build" set in case it is
155 # portage to avoid frying our /etc/make.conf file. Otherwise, we could
156 # just let emerge system could merge it.
157 [ -e /etc/make.conf ] && echo 'USE="${USE} build"' >> /etc/make.conf
158 run_merge --oneshot --nodeps virtual/portage
159 sed -i '/USE="${USE} build"/d' /etc/make.conf
163 rm -rf /etc/distcc/hosts
164 for i in cc gcc c++ g++; do
165 # TODO: change to use get_libdir
166 rm -f /usr/lib/distcc/bin/${i}
167 ln -s /usr/bin/distcc /usr/lib/distcc/bin/${i}
169 rm -f /usr/lib/distcc/bin/*-wrapper
174 for i in cc gcc c++ g++; do
175 rm -f /usr/${LIBDIR}/icecc/bin/${i}
176 ln -s /usr/bin/icecc /usr/${LIBDIR}/icecc/bin/${i}
178 rm -f /usr/${LIBDIR}/icecc/bin/*-wrapper
183 if [ -n "${clst_DISTCC}" ]
187 if [ -n "${clst_ICECREAM}" ]
191 case ${clst_target} in
192 stage1|stage2|stage3)
193 rm -f /var/lib/portage/world
194 touch /var/lib/portage/world
197 echo "Skipping removal of world file for ${clst_target}"
201 rm -f /var/log/emerge.log /var/log/portage/elog/*
205 update_env_settings(){
206 [ -x /usr/sbin/env-update ] && /usr/sbin/env-update
208 [ -f /tmp/envscript ] && source /tmp/envscript
217 # ROOT is / by default, so remove any ROOT= settings from make.conf
218 sed -i '/ROOT=/d' /etc/make.conf
220 if [ "${1}" != "/" -a -n "${1}" ]
222 echo "ROOT=\"${1}\"" >> /etc/make.conf
232 # Sets up the ROOT= parameter
233 # with no options ROOT=/
234 make_destpath ${clst_root_path}
236 export EMERGE_WARNING_DELAY=0
238 export EBEEP_IGNORE=0
239 export EPAUSE_IGNORE=0
240 export CONFIG_PROTECT="-*"
242 if [ -n "${clst_VERBOSE}" ]
244 echo "ROOT=${ROOT} emerge ${clst_myemergeopts} -pt $@" || exit 1
245 emerge ${clst_myemergeopts} -pt $@ || exit 3
246 echo "Press any key within 15 seconds to pause the build..."
250 echo "Press any key to continue..."
255 echo "emerge ${clst_myemergeopts} $@" || exit 1
257 emerge ${clst_myemergeopts} $@ || exit 1
261 if [ "${clst_DEBUG}" = "1" ]
265 echo "Profile/target info:"
266 echo "Profile inheritance:"
267 python -c 'import portage; print portage.settings.profiles'
268 # TODO: grab our entire env
269 # <zmedico> to get see the ebuild env you can do something like:
270 # `set > /tmp/env_dump.${EBUILD_PHASE}` inside /etc/portage/bashrc
271 # XXX: Also, portageq does *not* source profile.bashrc at any time.
273 echo "STAGE1_USE: $(portageq envvar STAGE1_USE)"
275 echo "USE (profile): $(portageq envvar USE)"
276 echo "USE (stage1): ${USE}"
277 echo "FEATURES (profile): $(portageq envvar FEATURES)"
278 echo "FEATURES (stage1): ${FEATURES}"
280 echo "ARCH: $(portageq envvar ARCH)"
281 echo "CHOST: $(portageq envvar CHOST)"
282 echo "CFLAGS: $(portageq envvar CFLAGS)"
284 echo "PROFILE_ARCH: $(portageq envvar PROFILE_ARCH)"
286 echo "ABI: $(portageq envvar ABI)"
287 echo "DEFAULT_ABI: $(portageq envvar DEFAULT_ABI)"
288 echo "KERNEL_ABI: $(portageq envvar KERNEL_ABI)"
289 echo "MULTILIB_ABIS: $(portageq envvar MULTILIB_ABIS)"
294 run_default_funcs() {
295 if [ "${RUN_DEFAULT_FUNCS}" != "no" ]
304 # Copy libs of a executable in the chroot
305 function copy_libs() {
306 # Check if it's a dynamix exec
307 ldd ${1} > /dev/null 2>&1 || return
309 for lib in `ldd ${1} | awk '{ print $3 }'`
314 if [ ! -e ${clst_root_path}/${lib} ]
317 [ -e "${clst_root_path}/${lib}" ] && \
318 strip -R .comment -R .note ${clst_root_path}/${lib} \
319 || echo "WARNING : Cannot strip lib ${clst_root_path}/${lib} !"
322 echo "WARNING : Some library was not found for ${lib} !"
327 function copy_symlink() {
329 [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 ))
331 if [ ${STACK} -le 0 ]
333 echo "WARNING : ${TARGET} : too many levels of symbolic links !"
337 [ ! -e ${clst_root_path}/`dirname ${1}` ] && \
338 mkdir -p ${clst_root_path}/`dirname ${1}`
339 [ ! -e ${clst_root_path}/${1} ] && \
340 cp -vfdp ${1} ${clst_root_path}/${1}
342 if [[ -n $(type -p realpath) ]]; then
343 TARGET=`realpath ${1}`
345 TARGET=`readlink -f ${1}`
349 copy_symlink ${TARGET} ${STACK}
355 function copy_file() {
360 echo "WARNING : File not found : ${f}"
364 [ ! -e ${clst_root_path}/`dirname ${f}` ] && \
365 mkdir -p ${clst_root_path}/`dirname ${f}`
366 [ ! -e ${clst_root_path}/${f} ] && \
367 cp -vfdp ${f} ${clst_root_path}/${f}
368 if [ -x ${f} -a ! -h ${f} ]
371 strip -R .comment -R .note ${clst_root_path}/${f} > /dev/null 2>&1
378 create_handbook_icon() {
379 # This function creates a local icon to the Gentoo Handbook
380 echo "[Desktop Entry]
384 URL=file:///mnt/cdrom/docs/handbook/html/index.html
386 Name=Gentoo Linux Handbook
387 GenericName=Gentoo Linux Handbook
388 Comment=This is a link to the local copy of the Gentoo Linux Handbook.
389 Icon=text-editor" > /usr/share/applications/gentoo-handbook.desktop
392 # We do this everywhere, so why not put it in this script