Subject: Re: Cross-build problems
To: Gerald Heinig <Gerald.Heinig@planet-interkom.de>
From: Rafal Boni <rafal@mediaone.net>
List: current-users
Date: 10/13/2001 18:09:51
In message <3BC35C8D.8D0984AC@planet-interkom.de>, you write:
-> Has anyone cross-built world recently? If so, could you perhaps send me
-> your build scripts and mk.conf plus any environment variable settings,
-> because I'm sure I've left something out somewhere.
I haven't done so recently (because I've been working on getting the new
toolchain working natively), but I did cross-build the whole world multiple
times from x86->SGI without serious problems before the NEW_TOOLCHAIN and
it's associated build changes went into the tree. I assume if you don't
set USE_NEW_TOOLCHAIN, this should all still work, but YMMV.
Here's my build script, which is a hacked up version of the crosscomp tool
produced by Tim Rightnour & Bill Sommerfeld. This script uses the in-tree
toolchain rather than the pkgsrc cross toolchain, as I had lots of issues
building userland with the pkgsrc one.
You'll have to tweak ROOT, DESTDIR & BSDSRCDIR to your liking, as these
contain my local settings.
--rafal
#! /bin/sh
# $NetBSD: cross.sh,v 1.8 2000/11/14 05:59:10 thorpej Exp $
# Copyright (c) 2000 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Bill Sommerfeld and Tim Rightnour
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# cross-compilation fun
DOUPDATE=no
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/usr/pkg/bin
export PATH
ROOT=/extra
if [ -f ${ROOT}/cross-is-running ]; then
echo "A crosscompile is allready running in ${ROOT}. Aborting"
exit 1
else
touch ${ROOT}/cross-is-running
trap "rm -f ${ROOT}/cross-is-running" 0
fi
BSDSRCDIR=${ROOT}/src-current
args=`getopt utgsd: $*`
if test $? != 0
then
echo 'Usage: ...'
exit 2
fi
set -- $args
for i
do
case "$i"
in
-t)
SKIPTOOLS=yes; shift
;;
-d)
SUBDIR=$2; shift; shift
;;
-u)
DOUPDATE=yes; shift
;;
-g)
SKIPGAMES=yes; shift
;;
--)
shift; break;;
esac
done
HOST_ARCH=$(uname -m)
TA_ARCH=mipseb
TARGET_MACHINE=sgimips
# phase 0.. cross-build make.. dammit.
echo "BEGIN: Phase 0, build make"
BSDSRCDIR=${ROOT}/src-current
CROSS=cross-${HOST_ARCH}-to-${TA_ARCH}
DESTDIR=${ROOT}/${TARGET_MACHINE}/tools
BSDOBJDIR=${ROOT}/${TARGET_MACHINE}/tools/obj
export MAKECONF=${ROOT}/${TARGET_MACHINE}/Makeconf
MAKEDIR=${BSDSRCDIR}/share/mk
mkdir -p ${DESTDIR}
mkdir -p ${DESTDIR}/usr/bin
mkdir -p ${DESTDIR}/usr/sbin
mkdir -p ${DESTDIR}/usr/libexec
mkdir -p ${DESTDIR}/usr/share/doc/psd/12.make
mkdir -p ${DESTDIR}/usr/share/info
mkdir -p ${DESTDIR}/usr/share/misc
mkdir -p ${DESTDIR}/usr/share/ldscripts
mkdir -p ${DESTDIR}/usr/share/man/man1
mkdir -p ${DESTDIR}/usr/libdata/lint
mkdir -p ${DESTDIR}/usr/lib
mkdir -p ${BSDOBJDIR}
BLDUSER=$(id -u -n)
BLDGROUP=$(id -g -n)
MAKE="gmake -m ${MAKEDIR}"
cd ${BSDSRCDIR}
TOOLDIRS="usr.bin/make"
# static-link the cross-tools just to avoid lossage.
cat << EOF > ${MAKECONF}
TA_ARCH=${TA_ARCH}
MACHINE_ARCH=${TA_ARCH}
MACHINE=${TARGET_MACHINE}
BSDSRCDIR=${BSDSRCDIR}
BSDOBJDIR=${BSDOBJDIR}
OBJMACHINE=1
# USROBJMACHINE=1
MKLINKLIB=yes
MKPROFILE=no
MKLINT=no
MKPIC=no
MKMAN=no
MKINFO=no
LIBCRTBEGIN=${LIBCRTBEGIN}
LIBCRTEND=${LIBCRTEND}
BINOWN=${BLDUSER}
BINGRP=${BLDGROUP}
DOCOWN=${BLDUSER}
DOCGRP=${BLDGROUP}
INFOOWN=${BLDUSER}
INFOGRP=${BLDGROUP}
LIBOWN=${BLDUSER}
LIBGRP=${BLDGROUP}
MANOWN=${BLDUSER}
MANGRP=${BLDGROUP}
EOF
if [ -z "$BUILDAOUT" ]; then
cat << EOF >> ${MAKECONF}
BOOTSTRAP_ELF=1
EOF
fi
export MAKEOBJDIR=xobj.${TARGET_MACHINE}
if [ -z "$SKIPTOOLS" ]
then
for subdir in ${TOOLDIRS}
do
((cd ${subdir}
unset DESTDIR
for target in clean bmake
do
echo "BUILDING $target in $subdir"
pwd
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} -f Makefile.boot ${target} || exit 1
done) &&
(cd ${subdir}
for target in install
do
# MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} \
# DESTDIR=${DESTDIR} ${target} || exit 1
cp bmake ${DESTDIR}/usr/bin/make
done)) || exit 1
done
fi
echo "Rebuilding MAKE with make"
BSDSRCDIR=${ROOT}/src-current
CROSS=cross-${HOST_ARCH}-to-${TA_ARCH}
DESTDIR=${ROOT}/${TARGET_MACHINE}/tools
export MAKECONF=${ROOT}/${TARGET_MACHINE}/Makeconf
MAKEDIR=${BSDSRCDIR}/share/mk
mkdir -p ${DESTDIR}
mkdir -p ${DESTDIR}/usr/bin
mkdir -p ${DESTDIR}/usr/sbin
mkdir -p ${DESTDIR}/usr/libexec
mkdir -p ${DESTDIR}/usr/share/doc/psd/12.make
mkdir -p ${DESTDIR}/usr/share/info
mkdir -p ${DESTDIR}/usr/share/misc
mkdir -p ${DESTDIR}/usr/share/ldscripts
mkdir -p ${DESTDIR}/usr/share/man/man1
mkdir -p ${DESTDIR}/usr/libdata/lint
mkdir -p ${DESTDIR}/usr/lib
mkdir -p ${BSDOBJDIR}
BLDUSER=$(id -u -n)
BLDGROUP=$(id -g -n)
MAKE="${DESTDIR}/usr/bin/make -m ${MAKEDIR}"
export MAKE
cd ${BSDSRCDIR}
TOOLDIRS="usr.bin/make"
# static-link the cross-tools just to avoid lossage.
cat << EOF > ${MAKECONF}
TA_ARCH=${TA_ARCH}
MACHINE_ARCH=${TA_ARCH}
MACHINE=${TARGET_MACHINE}
BSDSRCDIR=${BSDSRCDIR}
BSDOBJDIR=${BSDOBJDIR}
OBJMACHINE=1
# USROBJMACHINE=1
MKLINKLIB=yes
MKPROFILE=no
MKLINT=no
MKPIC=no
MKMAN=no
MKINFO=no
LIBCRTBEGIN=${LIBCRTBEGIN}
LIBCRTEND=${LIBCRTEND}
BINOWN=${BLDUSER}
BINGRP=${BLDGROUP}
DOCOWN=${BLDUSER}
DOCGRP=${BLDGROUP}
INFOOWN=${BLDUSER}
INFOGRP=${BLDGROUP}
LIBOWN=${BLDUSER}
LIBGRP=${BLDGROUP}
MANOWN=${BLDUSER}
MANGRP=${BLDGROUP}
EOF
if [ -z "$BUILDAOUT" ]; then
cat << EOF >> ${MAKECONF}
BOOTSTRAP_ELF=1
EOF
fi
export MAKEOBJDIR=xobj.${TARGET_MACHINE}
if [ -z "$SKIPTOOLS" ]
then
for subdir in ${TOOLDIRS}
do
(cd ${subdir}
unset DESTDIR
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} obj )
done
for subdir in ${TOOLDIRS}
do
((cd ${subdir}
unset DESTDIR
for target in cleandir depend all
do
echo "BUILDING $target in $subdir"
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} ${target} || exit 1
done) &&
(cd ${subdir}
for target in install
do
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} \
DESTDIR=${DESTDIR} ${target} || exit 1
done)) || exit 1
done
fi
# phase 1: build cross-tools
echo "BUILDING BEGIN: Stage 1"
BLDUSER=$(id -u -n)
BLDGROUP=$(id -g -n)
MAKE="${DESTDIR}/usr/bin/make -m ${MAKEDIR}"
export MAKE
cd ${BSDSRCDIR}
AS=gas.new
LD=ld.new
#TOOLDIRS=gnu/lib/libbfd gnu/usr.bin/${AS} gnu/usr.bin/${LD} gnu/usr.bin/gcc
TOOLDIRS="usr.bin/make gnu/lib/libbfd gnu/usr.bin/${AS} gnu/usr.bin/${LD} gnu/usr.bin/egcs gnu/usr.bin/binutils usr.bin/xinstall usr.sbin/config usr.bin/rpcgen usr.bin/menuc usr.bin/msgc usr.bin/xlint lib/libvers usr.bin/compile_et usr.bin/crunch/crunchgen usr.bin/file"
# static-link the cross-tools just to avoid lossage.
cat << EOF > ${MAKECONF}
TA_ARCH=${TA_ARCH}
MACHINE_ARCH=${TA_ARCH}
MACHINE=${TARGET_MACHINE}
COMPILER_EXEC_PREFIX=${ROOT}/${TARGET_MACHINE}/tools
BSDSRCDIR=${BSDSRCDIR}
BSDOBJDIR=${BSDOBJDIR}
OBJMACHINE=1
# USROBJMACHINE=1
BOOTSTRAP_ELF=1
MKLINKLIB=yes
MKPROFILE=no
MKLINT=no
MKPIC=no
MKMAN=no
MKINFO=no
LIBCRTBEGIN=${LIBCRTBEGIN}
LIBCRTEND=${LIBCRTEND}
BINOWN=${BLDUSER}
BINGRP=${BLDGROUP}
DOCOWN=${BLDUSER}
DOCGRP=${BLDGROUP}
INFOOWN=${BLDUSER}
INFOGRP=${BLDGROUP}
LIBOWN=${BLDUSER}
LIBGRP=${BLDGROUP}
MANOWN=${BLDUSER}
MANGRP=${BLDGROUP}
EOF
export MAKEOBJDIR=xobj.${TARGET_MACHINE}
if [ -z "$SKIPTOOLS" ]
then
for subdir in ${TOOLDIRS}
do
(cd ${subdir}
unset DESTDIR
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} obj )
done
for subdir in ${TOOLDIRS}
do
((cd ${subdir}
unset DESTDIR
for target in cleandir depend all
do
echo BUILDING $target in $subdir
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} ${target} || exit 1
done) &&
(cd ${subdir}
for target in install
do
MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE} ${MAKE} \
DESTDIR=${DESTDIR} ${target} || exit 1
done)) || exit 1
done
fi
# phase 2: cross-build the world..
echo "BUILDING BEGIN: Stage 2"
unset MAKEOBJDIR
TOOLDIR=${ROOT}/${TARGET_MACHINE}/tools
DESTDIR=${ROOT}/${TARGET_MACHINE}/root
RELEASEDIR=${ROOT}/${TARGET_MACHINE}/release
BSDOBJDIR=${ROOT}/${TARGET_MACHINE}/obj
MAKE="${TOOLDIR}/usr/bin/make -m ${MAKEDIR}"
export MAKE
mkdir -p ${DESTDIR}
mkdir -p ${RELEASEDIR}
mkdir -p ${BSDOBJDIR}
cp ${TOOLDIR}/usr/bin/as ${TOOLDIR}/usr/libexec/
cp ${TOOLDIR}/usr/bin/ld ${TOOLDIR}/usr/libexec/
cat << EOF > ${MAKECONF}
AR=${TOOLDIR}/usr/bin/ar
AS=${TOOLDIR}/usr/bin/as
CC=${TOOLDIR}/usr/bin/cc -B${TOOLDIR}/usr/libexec/
CPP=${TOOLDIR}/usr/bin/cpp -B${TOOLDIR}/usr/libexec/
CXX=${TOOLDIR}/usr/bin/c++ -B${TOOLDIR}/usr/libexec/
FC=${TOOLDIR}/usr/bin/f77 -B${TOOLDIR}/usr/libexec/
LD=${TOOLDIR}/usr/bin/ld
LDFLAGS+=-nostdlib
NM=${TOOLDIR}/usr/bin/nm
OBJCOPY=${TOOLDIR}/usr/bin/objcopy
OBJDUMP=${TOOLDIR}/usr/bin/objdump
RANLIB=${TOOLDIR}/usr/bin/ranlib
MENUC=${TOOLDIR}/usr/bin/menuc
MSGC=${TOOLDIR}/usr/bin/msgc
SIZE=${TOOLDIR}/usr/bin/size
STRINGS=${TOOLDIR}/usr/bin/strings
STRIP=${TOOLDIR}/usr/bin/strip
CONFIG=${TOOLDIR}/usr/sbin/config
RPCGEN=${TOOLDIR}/usr/bin/rpcgen
FILE=${TOOLDIR}/usr/bin/file
LINT=${TOOLDIR}/usr/bin/lint
LINTFLAGS+= -B${TOOLDIR}/usr/libexec -L${DESTDIR}/usr/libdata/lint
COMPILE_ET=${TOOLDIR}/usr/bin/compile_et
CRUNCHGEN=${TOOLDIR}/usr/bin/crunchgen
TA_ARCH=${TA_ARCH}
MACHINE_ARCH=${TA_ARCH}
MACHINE=${TARGET_MACHINE}
BSDSRCDIR=${BSDSRCDIR}
BSDOBJDIR=${BSDOBJDIR}
OBJMACHINE=1
# USROBJMACHINE=1
DESTDIR=${DESTDIR}
OBJECT_FMT=ELF
MAKEDIR=${BSDSRCDIR}/share/mk
MAKE=${TOOLDIR}/usr/bin/make -m ${MAKEDIR}
MKCRYPTO=yes
KERBEROS=yes
KERBEROS5=yes
EOF
case ${BLDUSER} in
root)
;;
*)
cat <<EOF >>${MAKECONF}
INSTALL=${TOOLDIR}/usr/bin/install -U
USER_INSTALL=1
EOF
;;
esac
cd ${BSDSRCDIR}
export STRIP=${TOOLDIR}/usr/bin/strip
export CC=${TOOLDIR}/usr/bin/cc
export MACHINE_ARCH=${TA_ARCH} MACHINE=${TARGET_MACHINE}
#menuc msgc
export MENUDEF=${TOOLDIR}/usr/share/misc
export MSGDEF=${TOOLDIR}/usr/share/misc
export CRUNCHGEN=${TOOLDIR}/usr/bin/crunchgen
export DESTDIR
if [ "$SKIPGAMES" = "yes" ]; then
mv ${BSDSRCDIR}/games ${BSDSRCDIR}/nogames
fi
if [ ! -z "$SUBDIR" ]
then
cd $SUBDIR
case $DOUPDATE in
no)
${MAKE} cleandir &&
rmdir obj.${TARGET_MACHINE} &&
${MAKE} cleandir &&
${MAKE} obj &&
${MAKE} cleandir
${MAKE} includes &&
${MAKE} depend
;;
yes)
;;
esac
${MAKE} all
else
case $DOUPDATE in
no)
${MAKE} cleandir && ${MAKE} obj && ${MAKE} beforeinstall &&
${MAKE} includes &&
(cd ${BSDSRCDIR}/lib/csu && ${MAKE} && ${MAKE} install) &&
(cd ${BSDSRCDIR}/lib/libc && ${MAKE} && ${MAKE} install) &&
(cd ${BSDSRCDIR}/lib/libintl && ${MAKE} && ${MAKE} install) &&
${MAKE} build &&
cd etc && ${MAKE} KERNELS_DONE=1 release RELEASEDIR=${RELEASEDIR}
;;
yes)
# ${MAKE} obj &&
${MAKE} build UPDATE=1
;;
esac
fi
if [ "$SKIPGAMES" = "yes" ]; then
mv ${BSDSRCDIR}/nogames ${BSDSRCDIR}/games
fi
----
Rafal Boni rafal@mediaone.net