Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Last active May 11, 2023 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Simon-L/19fc2876dc40a368f034172bde366c7b to your computer and use it in GitHub Desktop.
Save Simon-L/19fc2876dc40a368f034172bde366c7b to your computer and use it in GitHub Desktop.
PKG_NAME="export-toolchain"
PKG_VERSION="0.1.0"
PKG_LICENSE=""
PKG_SITE=""
PKG_DEPENDS_TARGET=""
PKG_DEPENDS_HOST=""
PKG_LONGDESC=""
PKG_TOOLCHAIN="manual"
make_target() {
destfile=${PKG_BUILD}/build-vars.sh
echo "#! /bin/bash" >> ${destfile}
echo "# Here are the interesting variables" >> ${destfile}
echo "# Build related:" >> ${destfile}
echo "export BUILD=\"${BUILD}\"" >> ${destfile}
echo "export BUILD_ROOT=\"${BUILD_ROOT}\"" >> ${destfile}
echo "# Distro related:" >> ${destfile}
echo "export DISTRO_BOOTLABEL=\"${DISTRO_BOOTLABEL}\"" >> ${destfile}
echo "export DISTRO_DIR=\"${DISTRO_DIR}\"" >> ${destfile}
echo "export DISTRO_DISKLABEL=\"${DISTRO_DISKLABEL}\"" >> ${destfile}
echo "export DISTRO=\"${DISTRO}\"" >> ${destfile}
echo "export DISTRO_MIRROR=\"${DISTRO_MIRROR}\"" >> ${destfile}
echo "export DISTRONAME=\"${DISTRONAME}\"" >> ${destfile}
echo "export DISTRO_PKG_SETTINGS=\"${DISTRO_PKG_SETTINGS}\"" >> ${destfile}
echo "export DISTRO_SRC=\"${DISTRO_SRC}\"" >> ${destfile}
echo "export HOME_URL=\"${HOME_URL}\"" >> ${destfile}
echo "# Project related:" >> ${destfile}
echo "export PROJECT_CFLAGS=\"${PROJECT_CFLAGS}\"" >> ${destfile}
echo "export PROJECT_DIR=\"${PROJECT_DIR}\"" >> ${destfile}
echo "export PROJECT=\"${PROJECT}\"" >> ${destfile}
echo "# Toolchain variables:" >> ${destfile}
echo "export TARGET_CFLAGS=\"${TARGET_CFLAGS}\"" >> ${destfile}
echo "export TARGET_CXXFLAGS=\"${TARGET_CXXFLAGS}\"" >> ${destfile}
echo "export TARGET_LDFLAGS=\"${TARGET_LDFLAGS}\"" >> ${destfile}
echo "export NINJA_OPTS=\"${NINJA_OPTS}\"" >> ${destfile}
echo "export MAKEFLAGS=\"${MAKEFLAGS}\"" >> ${destfile}
echo "export DESTIMAGE=\"${DESTIMAGE}\"" >> ${destfile}
echo "export CC=\"${CC}\"" >> ${destfile}
echo "export CXX=\"${CXX}\"" >> ${destfile}
echo "export CPP=\"${CPP}\"" >> ${destfile}
echo "export LD=\"${LD}\"" >> ${destfile}
echo "export AS=\"${AS}\"" >> ${destfile}
echo "export AR=\"${AR}\"" >> ${destfile}
echo "export NM=\"${NM}\"" >> ${destfile}
echo "export RANLIB=\"${RANLIB}\"" >> ${destfile}
echo "export OBJCOPY=\"${OBJCOPY}\"" >> ${destfile}
echo "export OBJDUMP=\"${OBJDUMP}\"" >> ${destfile}
echo "export STRIP=\"${STRIP}\"" >> ${destfile}
echo "export CPPFLAGS=\"${CPPFLAGS}\"" >> ${destfile}
echo "export CFLAGS=\"${CFLAGS}\"" >> ${destfile}
echo "export CXXFLAGS=\"${CXXFLAGS}\"" >> ${destfile}
echo "export LDFLAGS=\"${LDFLAGS}\"" >> ${destfile}
echo "export PKG_CONFIG=\"${PKG_CONFIG}\"" >> ${destfile}
echo "export PKG_CONFIG_PATH=\"${PKG_CONFIG_PATH}\"" >> ${destfile}
echo "export PKG_CONFIG_LIBDIR=\"${PKG_CONFIG_LIBDIR}\"" >> ${destfile}
echo "export PKG_CONFIG_SYSROOT_DIR=\"${PKG_CONFIG_SYSROOT_DIR}\"" >> ${destfile}
echo "export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=\"${PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}\"" >> ${destfile}
echo "export PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"${PKG_CONFIG_ALLOW_SYSTEM_LIBS}\"" >> ${destfile}
echo "export CMAKE_CONF=\"${CMAKE_CONF}\"" >> ${destfile}
echo "export CMAKE=\"${CMAKE}\"" >> ${destfile}
echo "export HOST_CC=\"${HOST_CC}\"" >> ${destfile}
echo "export HOST_CXX=\"${HOST_CXX}\"" >> ${destfile}
echo "export HOSTCC=\"${HOSTCC}\"" >> ${destfile}
echo "export HOSTCXX=\"${HOSTCXX}\"" >> ${destfile}
echo "export CC_FOR_BUILD=\"${CC_FOR_BUILD}\"" >> ${destfile}
echo "export CXX_FOR_BUILD=\"${CXX_FOR_BUILD}\"" >> ${destfile}
echo "export BUILD_CC=\"${BUILD_CC}\"" >> ${destfile}
echo "export BUILD_CXX=\"${BUILD_CXX}\"" >> ${destfile}
echo "export _python_sysroot=\"${_python_sysroot}\"" >> ${destfile}
echo "export _python_prefix=\"${_python_prefix}\"" >> ${destfile}
echo "export _python_exec_prefix=\"${_python_exec_prefix}\"" >> ${destfile}
echo "export SYSROOT_PREFIX=\"${SYSROOT_PREFIX}\"" >> ${destfile}
echo "# Build system related:" >> ${destfile}
echo "export CMAKE_CONF=\"${CMAKE_CONF}\"" >> ${destfile}
echo "export CMAKE_GENERATOR_NINJA=\"${CMAKE_GENERATOR_NINJA}\"" >> ${destfile}
echo "export TARGET_CONFIGURE_OPTS=\"${TARGET_CONFIGURE_OPTS}\"" >> ${destfile}
echo "export TARGET_CMAKE_OPTS=\"${TARGET_CMAKE_OPTS}\"" >> ${destfile}
echo "export TARGET_MESON_OPTS=\"${TARGET_MESON_OPTS}\"" >> ${destfile}
echo "export HOST_CONFIGURE_OPTS=\"${HOST_CONFIGURE_OPTS}\"" >> ${destfile}
echo "export HOST_CMAKE_OPTS=\"${HOST_CMAKE_OPTS}\"" >> ${destfile}
echo "export HOST_MESON_OPTS=\"${HOST_MESON_OPTS}\"" >> ${destfile}
echo "export INIT_CONFIGURE_OPTS=\"${INIT_CONFIGURE_OPTS}\"" >> ${destfile}
echo "export INIT_CMAKE_OPTS=\"${INIT_CMAKE_OPTS}\"" >> ${destfile}
echo "export INIT_MESON_OPTS=\"${INIT_MESON_OPTS}\"" >> ${destfile}
echo "export BOOTSTRAP_CONFIGURE_OPTS=\"${BOOTSTRAP_CONFIGURE_OPTS}\"" >> ${destfile}
echo "export BOOTSTRAP_CMAKE_OPTS=\"${BOOTSTRAP_CMAKE_OPTS}\"" >> ${destfile}
echo "export BOOTSTRAP_MESON_OPTS=\"${BOOTSTRAP_MESON_OPTS}\"" >> ${destfile}
echo "# Path:" >> ${destfile}
echo "export PATH=\"${PATH}\"" >> ${destfile}
echo "# Build script executes target cmake-make as:" >> ${destfile}
echo "# cmake ${TARGET_CMAKE_OPTS} ${PKG_CMAKE_OPTS_TARGET} ${PKG_CMAKE_SCRIPT%/*}" | tr -s " " >> ${destfile}
echo "# Build script executes target make as:" >> ${destfile}
echo "# make ${PKG_MAKE_OPTS_TARGET}" | tr -s " " >> ${destfile}
echo "The variables have been printed to ${destfile} ready to be sourced"
sed "s~$BUILD_ROOT~\$JELOS_TOOLCHAIN~g" "${destfile}" > ${PKG_BUILD}/build-vars-portable.sh
echo "The portable variant uses the \$JELOS_TOOLCHAIN environment variable as base dir for the toolchain, use this if you want to build out of tree."
echo "~$ JELOS_TOOLCHAIN=/foo/bar source ./build-vars-portable.sh"
echo "WARNING: Be aware that these variables substantially modify your environment, including \$PATH, please have a look at the generated files before using!"
echo "Compressing toolchain..."
tar -C ${BUILD_ROOT} -czf ${PKG_BUILD}/$(basename ${BUILD})-toolchain.tar.gz $(basename ${BUILD})/toolchain
echo "Done compressing.Toolchain export done in ${PKG_BUILD}:"
ls -d ${PKG_BUILD}/*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment