File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_world.sh
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Fri Jul 16 18:35:50 2021 UTC (3 years, 4 months ago) by misho
Branches: MAIN
CVS tags: elwix2_8, HEAD, ELWIX2_7
ver 2.7

#!/bin/sh
#
# ELWIX build script for world
#
# (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
#    by Michael Pounov <misho@elwix.org>
#
# $Id: build_world.sh,v 1.7 2021/07/16 18:35:50 misho Exp $
#

[ -r ./config/rc.elwix ] && . ./config/rc.elwix
if [ X"${ELWIX_IS_CONFIGURED}" != X"YES" ]; then
	echo
	echo "ELWIX project is not configured !?!"
	echo
	exit 1
fi

if [ ! -d $BSDSRC ]; then
	echo
	echo "ELWIX project is not configured - missing BSD sources !?!"
	echo
	exit 1
fi

if [ ! -d $ADIR ]; then
	echo
	echo "ELWIX project is not configured - missing TargetArch directory !?!"
	echo
	exit 1
fi

if [ "${USER}" != "root" ]; then
	echo
	echo "ELWIX project is not configured - BSD kernel must compile under root !?!"
	echo
	exit 1
fi

# Set TARGET_CPUTYPE only for world compiling. Don't use this in kernel build!
X_TARGET_CPUTYPE="TARGET_CPUTYPE=${TARGET_CPUTYPE}"

clean_world()
{
	echo "+++ Clean ELWIX World ... $WORLD"
	rm -rf $WORLD
	mkdir -p $WORLD

	rm -f ${CBUILD} ${CGBUILD} ${CENV}
}

build_toolchain()
{
	echo "+++ Build ELWIX Toolchain ..."
	cd $BSDSRC
	env MAKEOBJDIRPREFIX=${BSDOBJ} make ${PARALLEL_BUILD} \
		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} ${X_TARGET_CPUTYPE} \
		SRCCONF=${SRCCONF} __MAKE_CONF=${MAKECONF} DESTDIR=${WORLD} toolchain
	if [ $? -eq 0 ]; then
		cd -
	else
		exit 1
	fi
}

build_world()
{
	echo "+++ Build ELWIX World ..."
	cd $BSDSRC
	if [ -z "$1" ]; then
		env MAKEOBJDIRPREFIX=${BSDOBJ} make ${PARALLEL_BUILD} \
			TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} ${X_TARGET_CPUTYPE} \
			SRCCONF=${SRCCONF} __MAKE_CONF=${MAKECONF} buildworld
	else
		env MAKEOBJDIRPREFIX=${BSDOBJ} NO_CLEAN="YES" make ${PARALLEL_BUILD} \
			TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} ${X_TARGET_CPUTYPE} \
			SRCCONF=${SRCCONF} __MAKE_CONF=${MAKECONF} buildworld
	fi
	if [ $? -eq 0 ]; then
		cd -
	else
		exit 1
	fi
}

install_world()
{
	echo "+++ Install ELWIX World ... $WORLD"
	cd $BSDSRC
	env MAKEOBJDIRPREFIX=${BSDOBJ} make \
		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} ${X_TARGET_CPUTYPE} \
		SRCCONF=${SRCCONF} __MAKE_CONF=${MAKECONF} DESTDIR=${WORLD} installworld
	cd -

	if [ $? -eq 0 ]; then
		echo "ELWIX Platform:${PLATFORM} Version:${VERSION} TargetArch:${TARGET_ARCH}" >${WORLD}/elwix.ver
	fi

	echo "+++ Completed ELWIX World ... $WORLD"
}

build_cross()
{
	echo "+++ Build ELWIX Cross script ..."
	cd $BSDSRC
	cat >${CENV} <<_EOF
#!/bin/sh
#
# Create auto cross build env script
#
export \\
_EOF
	env MAKEOBJDIRPREFIX=${BSDOBJ} make TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} ${X_TARGET_CPUTYPE} \
		WORLDTMP=${WORLD} buildenvvars >> ${CENV}
	cat >>${CENV} <<_EOF
PATH=$WORLD/elwix/pkg/bin:$WORLD/elwix/pkg/sbin:/elwix/pkg/bin:/elwix/pkg/sbin:$PKG/bin:$PKG/sbin:\$PATH:$PATH

if [ -n "\${REPLACE_MAKEOBJDIRPREFIX}" ]; then
	MAKEOBJDIRPREFIX="\${REPLACE_MAKEOBJDIRPREFIX}"
fi

export CROSS_WORLD=$WORLD
export CFLAGS="\$CFLAGS -I\${CROSS_WORLD}/usr/include"
export LDFLAGS="\$LDFLAGS -L\${CROSS_WORLD}/lib -L\${CROSS_WORLD}/usr/lib"

_EOF
	cd -
	cp ${CENV} ${CBUILD}
	cp ${CENV} ${CGBUILD}
	cp ${CENV} ${CEXEC}
	cat >>${CBUILD} <<_EOF
make \$*
_EOF
	echo "+++ Ready cross script ${CBUILD}"
	cat >>${CGBUILD} <<_EOF
gmake \$*
_EOF
	echo "+++ Ready cross script ${CGBUILD}"
	cat >>${CEXEC} <<_EOF
eval \$*
_EOF
	echo "+++ Ready cross script ${CEXEC}"
	chmod +x ${CBUILD} ${CGBUILD} ${CEXEC} ${CENV}
	echo "Done."
}

### main()
if [ -n "${1}" ]; then
	rm ${WORLD}/elwix.ver
fi

if ! SnitVer ${WORLD}/elwix.ver; then
	if [ -z "$1" ]; then
		clean_world
	fi
#	build_toolchain $1
	build_world $1
	install_world

	build_cross
else
	echo "Skipped ELWIX World build ..."
fi

echo "+++ Complete build ELWIX World"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>