The "isysroot" method for building world with clang. First of all, Makefile.inc1 is modified to build the clang libraries and binaries during the cross-tools stage, iff CC=clang. We basically adjust WMAKEENV, which applies to the world stage, and LIB32FLAGS, which optionally applies to 32-bit world stage, to add -isysroot, -B and -L options, so the compiler looks under ${WORLDTMP} for its headers, startup objects and libraries. We also need to create symlinks from ${WORLDTMP}/usr/bin/as and ld to ${WORLDTMP}/usr/lib, since the -B option in clang is not additive, and is used both for finding CRT startup objects and for finding the assembler and linker. diff --git a/Makefile.inc1 b/Makefile.inc1 index d2581c5..c31eba9 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -257,6 +257,10 @@ WMAKEENV= ${CROSSENV} \ VERSION="${VERSION}" \ INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${TMPPATH} +.if ${CC:T:Mclang} == "clang" +WMAKEENV+= CC="${CC} -isysroot ${WORLDTMP} -B${WORLDTMP}/usr/lib/ -L${WORLDTMP}/usr/lib/" \ + CXX="${CXX} -isysroot ${WORLDTMP} -B${WORLDTMP}/usr/lib/ -L${WORLDTMP}/usr/lib/" +.endif .if ${MK_CDDL} == "no" WMAKEENV+= NO_CTF=1 .endif @@ -289,8 +293,11 @@ LIB32WMAKEENV= MACHINE=powerpc MACHINE_ARCH=powerpc \ .endif -LIB32FLAGS= -m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \ - -isystem ${LIB32TMP}/usr/include/ \ +LIB32FLAGS= -m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT +.if ${CC:T:Mclang} == "clang" +LIB32FLAGS+= -isysroot ${LIB32TMP}/ +.endif +LIB32FLAGS+= -isystem ${LIB32TMP}/usr/include/ \ -L${LIB32TMP}/usr/lib32 \ -B${LIB32TMP}/usr/lib32 @@ -440,6 +447,11 @@ everything: @echo "--------------------------------------------------------------" @echo ">>> stage 4.4: building everything" @echo "--------------------------------------------------------------" +.if ${CC:T:Mclang} == "clang" + # mergemaster goes through this but those files do not exist + [ ! -e ${WORLDTMP}/usr/bin/as ] || ln -sf ${WORLDTMP}/usr/bin/as ${WORLDTMP}/usr/lib/as + [ ! -e ${WORLDTMP}/usr/bin/ld ] || ln -sf ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/lib/ld +.endif ${_+_}cd ${.CURDIR}; ${WMAKE} par-all .if defined(LIB32TMP) build32: @@ -453,6 +465,12 @@ build32: mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${LIB32TMP}/usr/include >/dev/null mkdir -p ${WORLDTMP} +.if ${CC:T:Mclang} == "clang" + # relink /usr/bin/{as,ld} to the lib32 tmp so the -B can pick up + # the /usr/bin/ld and /usr/bin/as + ln -sf ${WORLDTMP}/usr/bin/as ${LIB32TMP}/usr/lib32/as + ln -sf ${WORLDTMP}/usr/bin/ld ${LIB32TMP}/usr/lib32/ld +.endif ln -sf ${.CURDIR}/sys ${WORLDTMP} .if ${MK_KERBEROS} != "no" .for _t in obj depend all @@ -1078,8 +1096,15 @@ _kgzip= usr.sbin/kgzip .endif .endif +.if ${CC:T:Mclang} == "clang" +_clang= usr.bin/clang +_clang_libs= lib/clang +.endif + cross-tools: .for _tool in \ + ${_clang_libs} \ + ${_clang} \ gnu/usr.bin/binutils \ gnu/usr.bin/cc \ usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \