Bug#700290: pbuilder: clang support

Thorsten Glaser tg at mirbsd.de
Sun Mar 3 15:43:10 UTC 2013


Hideki Yamane dixit:

> Hookdir cannot satisfy its purpose - build with gcc, then check with clang,
> back to gcc, and use clang again... - if we choose using hookdir, we should
> add script to hookdir then remove it every time, it's not handy and doesn't
> encourage maintainers to check with clang.

It can…

I’m thinking of something like this (untested):

(cat >hookdir/D60clang; chmod +x hookdir/D60compiler) <<'EOF'
#!/bin/sh
set +e

# check whether we are asked to change the compiler
case $PBUILDER_COMPILER in
(clang|tcc)
	replace_gcc=1
	;;
(gcc-*)
	replace_gcc=0
	;;
(*)
	exit 0
	;;
esac

apt-get -y --force-yes --purge install "$PBUILDER_COMPILER" || {
	echo >&2 "E: Installing the compiler '$PBUILDER_COMPILER' failed"
	exit 1
}
test -x /usr/bin/"$PBUILDER_COMPILER" || {
	echo >&2 "E: Package '$PBUILDER_COMPILER' does not contain compiler driver?"
	exit 1
}

newcc=/usr/bin/$PBUILDER_COMPILER
case $PBUILDER_COMPILER in
(clang)
	newcxx=/usr/bin/clang++
	;;
(tcc)
	newcxx=/bin/false
	;;
(gcc-*)
	newcxx=/usr/bin/g++${PBUILDER_COMPILER#gcc}
	;;
(*)
	# cannot happen
	exit 255
esac

if test 1 = $replace_gcc; then
	e=0
	oldcc=$(readlink /usr/bin/gcc) || e=1
	oldcxx=$(readlink /usr/bin/g++) || e=1
	case $oldcc in
	(/usr/bin/gcc-*)
		oldcc=${oldcc#/usr/bin/}
		;;
	(gcc-*)
		;;
	(*)
		e=1
		;
	esac
	case $oldcxx in
	(/usr/bin/g++-*)
		oldcxx=${oldcxx#/usr/bin/}
		;;
	(gcc-*)
		;;
	(*)
		e=1
		;
	esac
	if test 1 = $e; then
		echo >&2 "E: Old compilers ('$oldcc', '$oldcxx') do not match gcc-defaults"
		exit 1
	fi
	rm -f /usr/bin/"$oldcc" /usr/bin/"$oldcxx"
	ln -s "$newcc" /usr/bin/"$oldcc"
	ln -s "$newcxx" /usr/bin/"$oldcxx"
fi

rm -f /usr/bin/gcc /usr/bin/g++
ln -s "$newcc" /usr/bin/gcc
ln -s "$newcxx" /usr/bin/g++
rm -f /usr/bin/cc /usr/bin/++
ln -s "$newcc" /usr/bin/cc
ln -s "$newcxx" /usr/bin/c++

exit 0
EOF

This would allow switching to any gcc version, tcc and clang;
adding pcc, TenDRA and other compilers is surely possible,
and this hook script is controlled by $PBUILDER_COMPILER which
you can just export before calling pbuilder/cowbuilder.

bye,
//mirabilos
-- 
<mirabilos>    │ untested
<Natureshadow> │ tut natürlich
<Natureshadow> │ was auch sonst ...
<mirabilos>    │ fijn ☺



More information about the Pkg-llvm-team mailing list