File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_tools.sh
Revision 1.10: 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 tools
#
# (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
#    by Michael Pounov <misho@elwix.org>
#
# $Id: build_tools.sh,v 1.10 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
V=${VERSION}
#[ -r ${CENV} ] && . ${CENV}
unset INSTALL
unset VERSION
VERSION="$V"

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

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

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

clean_tools()
{
	echo "+++ Clean ELWIX FreeBSD tools ... ${WORLD}/usr/local"

	rm -rf ${WORLD}/usr/local
	install -d ${WORLD}/usr/local
	install -d ${WORLD}/usr/local/bin
	install -d ${WORLD}/usr/local/include
	install -d ${WORLD}/usr/local/lib
	install -d ${WORLD}/usr/local/libdata
	install -d ${WORLD}/usr/local/sbin

}

clean_bootstrap()
{
	echo "+++ Clean ELWIX pkgsrc bootstrap tools ..."

	rm -Rf ${WORLD}/usr/pkgsrc/bootstrap/work
	rm -f /elwix ${WORLD}/usr/pkgsrc
	rm -Rf ${WORLD}/elwix
	install -d ${WORLD}/elwix
	ln -sf ${WORLD}/elwix /elwix
	ln -sf ${PKGSRC} ${WORLD}/usr/pkgsrc

	install -d ${PKGDIR}
	install -d ${PKGDIR}/db
	install -d ${PKGDIR}/etc
}

compile_deps()
{
	echo "+++ Compile ELWIX programs bootstrap tools ..."
	if [ -d tools -a -f tools/Makefile ]; then
		cd tools
		make cleandepend
		make clean
		make obj
		make
		make install
		cd -
	fi
}

compile_bootstrap()
{
	echo "+++ Compile ELWIX pkgsrc bootstrap tools ..."
	if [ ! -d ${WORLD}/usr/pkgsrc/bootstrap/work ]; then
		cd ${WORLD}/usr/pkgsrc/bootstrap
		./cleanup --prefix /elwix/pkg --pkgdbdir /elwix/pkg/db 
		./bootstrap --prefix /elwix/pkg --pkgdbdir /elwix/pkg/db
		cd -
	else
		echo " Skip bootstrap pkgsrc - already inited pkgsrc"
	fi

	cat >>/elwix/pkg/etc/mk.conf << _EOF

.if defined(USE_CROSS_COMPILE) && !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
USE_DESTDIR=		yes
DEPENDS_TARGET=		package-install

TOOLDIR=                ${CROSSTOOLDIR}
CROSS_DESTDIR=		${WORLD}

TARGET=			${TARGET}
TARGET_ARCH=		${TARGET_ARCH}
MACHINE_PLATFORM=	FreeBSD-${PLATFORM}-${TARGET_ARCH}
MACHINE_GNU_PLATFORM=	${TARGET_ARCH}-elwix-freebsd

PKGSRC_COMPILER=	gcc
USE_PKGSRC_GCC=		no
USE_NATIVE_GCC=		yes

.endif			# end cross-compilation settings
_EOF
}

compile_fbsdtools()
{
	echo "+++ Compile ELWIX FreeBSD tools ..."

	if [ "$(uname -m)" != ${TARGET} ]; then
		BSDSTATDIR="${BSDOBJ}/${TARGET}.${TARGET_ARCH}${BSDSRC}/lib/libbsdstat"
	else
		BSDSTATDIR="${BSDOBJ}${BSDSRC}/lib/libbsdstat"
	fi

	cd $CROSS_FT_ATH
	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	cp ${CROSSTOOLDIR}/usr/include/private/bsdstat/bsdstat.h ${BSDTOOLS}/ath/common || exit 1
	${CBUILD} DESTDIR=${WORLD} LIBBSDSTATDIR="${BSDSTATDIR}" || exit 1
	${CBUILD} DESTDIR=${WORLD} install || exit 1
	cd -

#	cd $CROSS_FT_CXGB
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_IFINFO
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_MCTEST
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} MK_MAN="no" || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin MK_MAN="no" BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_NETMAP
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_NETBLAST
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_NETRCV
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -

#	cd $CROSS_FT_NETSND
#	${CBUILD} DESTDIR=${WORLD} clean || exit 1
#	${CBUILD} DESTDIR=${WORLD} || exit 1
#	${CBUILD} DESTDIR=${WORLD}/usr/local/bin BINDIR="" install || exit 1
#	cd -
}

compile_files()
{
	cd files
	${CBUILD} DESTDIR=${WORLD} clean || exit 1
	${CBUILD} DESTDIR=${WORLD} obj || exit 1
	${CBUILD} DESTDIR=${WORLD} depend || exit 1
	${CBUILD} DESTDIR=${WORLD} || exit 1
	${CBUILD} DESTDIR=${WORLD} install || exit 1
	cd -
}

compile_sw()
{
	CROSS_OPTS=$(eval echo "\$$2_OPTS")

	cd $1$2
	${CEXEC} INSTALL="/usr/bin/install" ./configure $CROSS_OPTS ${CROSS_PFX}
	${CBUILD} clean
	${CBUILD}
	${CBUILD} install
	cd -
}

compile_tools()
{
	echo "+++ Compile ELWIX Cross ..."

	for i in ${CROSS_TOOLS}; do
		if [ -d "${CROSS_PATH}$i" ]; then
			compile_sw ${CROSS_PATH} $i
		else
			Die "Error:: ${CROSS_PATH}$i not found!"
		fi
	done
}

install_tools()
{
	LIBS="${ROMFS_USR2}/lib"
	LIBEXEC="${ROMFS_USR2}/libexec"
	BIN="${ROMFS_USR2}/bin"
	SBIN="${ROMFS_USR2}/sbin"
	ETC="${ROMFS_USR2}/etc"

	echo "+++ Install ELWIX RomFS secondary firmware ... ${ROMFS_USR2}"

	StripFiles \*.so\* ${PKG}/lib
	InstallFiles \*.so\* ${PKG}/lib $LIBS
	StripFiles \* ${PKG}/libexec
	InstallFiles \* ${PKG}/libexec $LIBEXEC
	StripFiles \* ${PKG}/bin
	InstallFiles \* ${PKG}/bin $BIN
	StripFiles \* ${PKG}/sbin
	InstallFiles \* ${PKG}/sbin $SBIN

	InstallFiles \* ${PKG}/etc $ETC

	chown -R root:wheel $SBIN $BIN $LIBDATA $LIBEXEC $LIBS
}

build_tools()
{
	echo "+++ Build ELWIX core firmware image ... ${WORLD}/usr/local --> ${REL}/${LOCALFS_IMG}"

	cd ${WORLD}/usr/local
	find . -name ".debug" -exec rm -rf {} \;
	pax -w -z -v -f${REL}/${LOCALFS_IMG} .
	cd -

	echo "+++ Completed ELWIX core firmware image ... ${REL}/${LOCALFS_IMG}"
}

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

if [ "${COMPILE_DEPTOOLS}" = "YES" ]; then
	compile_deps || exit 1
fi

#if ! SnitVer ${WORLD}/elwix/elwix.ver; then
#	clean_bootstrap
#	compile_bootstrap || exit 1
#
#	echo "ELWIX Platform:${PLATFORM} Version:${VERSION} TargetArch:${TARGET_ARCH}" >${WORLD}/elwix/elwix.ver
#else
#	echo "Skipped ELWIX bootstrap pkgsrc tools build ..."
#fi

if ! SnitVer ${WORLD}/usr/local/elwix.ver; then
	clean_tools || exit 1

	compile_fbsdtools || exit 1
	compile_files || exit 1
	compile_tools || exit 1

	build_tools || exit 1

	echo "ELWIX Platform:${PLATFORM} Version:${VERSION} TargetArch:${TARGET_ARCH}" >${WORLD}/usr/local/elwix.ver
else
	echo "Skipped ELWIX tools build ..."
fi

echo "+++ Complete build ELWIX tools"

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