Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | inherit toolchain-scripts-base siteinfo kernel-arch |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | # We want to be able to change the value of MULTIMACH_TARGET_SYS, because it |
| 4 | # doesn't always match our expectations... but we default to the stock value |
| 5 | REAL_MULTIMACH_TARGET_SYS ?= "${MULTIMACH_TARGET_SYS}" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 6 | TARGET_CC_ARCH:append:libc-musl = " -mmusl" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | # default debug prefix map isn't valid in the SDK |
| 9 | DEBUG_PREFIX_MAP = "" |
| 10 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 11 | EXPORT_SDK_PS1 = "${@ 'export PS1=\\"%s\\"' % d.getVar('SDK_PS1') if d.getVar('SDK_PS1') else ''}" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 12 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | # This function creates an environment-setup-script for use in a deployable SDK |
| 14 | toolchain_create_sdk_env_script () { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | # Create environment setup script. Remember that $SDKTARGETSYSROOT should |
| 16 | # only be expanded on the target at runtime. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 17 | base_sbindir=${10:-${base_sbindir_nativesdk}} |
| 18 | base_bindir=${9:-${base_bindir_nativesdk}} |
| 19 | sbindir=${8:-${sbindir_nativesdk}} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | sdkpathnative=${7:-${SDKPATHNATIVE}} |
| 21 | prefix=${6:-${prefix_nativesdk}} |
| 22 | bindir=${5:-${bindir_nativesdk}} |
| 23 | libdir=${4:-${libdir}} |
| 24 | sysroot=${3:-${SDKTARGETSYSROOT}} |
| 25 | multimach_target_sys=${2:-${REAL_MULTIMACH_TARGET_SYS}} |
| 26 | script=${1:-${SDK_OUTPUT}/${SDKPATH}/environment-setup-$multimach_target_sys} |
| 27 | rm -f $script |
| 28 | touch $script |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | |
| 30 | echo '# Check for LD_LIBRARY_PATH being set, which can break SDK and generally is a bad practice' >> $script |
| 31 | echo '# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80' >> $script |
| 32 | echo '# http://xahlee.info/UnixResource_dir/_/ldpath.html' >> $script |
| 33 | echo '# Only disable this check if you are absolutely know what you are doing!' >> $script |
| 34 | echo 'if [ ! -z "$LD_LIBRARY_PATH" ]; then' >> $script |
| 35 | echo " echo \"Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH'\"" >> $script |
| 36 | echo " echo \"but please check why this was set in the first place and that it's safe to unset.\"" >> $script |
| 37 | echo ' echo "The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set."' >> $script |
| 38 | echo ' echo "For more references see:"' >> $script |
| 39 | echo ' echo " http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80"' >> $script |
| 40 | echo ' echo " http://xahlee.info/UnixResource_dir/_/ldpath.html"' >> $script |
| 41 | echo ' return 1' >> $script |
| 42 | echo 'fi' >> $script |
| 43 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 44 | echo "${EXPORT_SDK_PS1}" >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | echo 'export SDKTARGETSYSROOT='"$sysroot" >> $script |
| 46 | EXTRAPATH="" |
| 47 | for i in ${CANADIANEXTRAOS}; do |
| 48 | EXTRAPATH="$EXTRAPATH:$sdkpathnative$bindir/${TARGET_ARCH}${TARGET_VENDOR}-$i" |
| 49 | done |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | echo "export PATH=$sdkpathnative$bindir:$sdkpathnative$sbindir:$sdkpathnative$base_bindir:$sdkpathnative$base_sbindir:$sdkpathnative$bindir/../${HOST_SYS}/bin:$sdkpathnative$bindir/${TARGET_SYS}"$EXTRAPATH':$PATH' >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | echo 'export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT' >> $script |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 52 | echo 'export PKG_CONFIG_PATH=$SDKTARGETSYSROOT'"$libdir"'/pkgconfig:$SDKTARGETSYSROOT'"$prefix"'/share/pkgconfig' >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | echo 'export CONFIG_SITE=${SDKPATH}/site-config-'"${multimach_target_sys}" >> $script |
| 54 | echo "export OECORE_NATIVE_SYSROOT=\"$sdkpathnative\"" >> $script |
| 55 | echo 'export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"' >> $script |
| 56 | echo "export OECORE_ACLOCAL_OPTS=\"-I $sdkpathnative/usr/share/aclocal\"" >> $script |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 57 | echo 'export OECORE_BASELIB="${baselib}"' >> $script |
| 58 | echo 'export OECORE_TARGET_ARCH="${TARGET_ARCH}"' >>$script |
| 59 | echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script |
| 60 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 61 | echo 'unset command_not_found_handle' >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | |
| 63 | toolchain_shared_env_script |
| 64 | } |
| 65 | |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 66 | # This function creates an environment-setup-script in B which enables |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | # a OE-core IDE to integrate with the build tree |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 68 | # Caller must ensure CONFIG_SITE is setup |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | toolchain_create_tree_env_script () { |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 70 | script=${B}/environment-setup-${REAL_MULTIMACH_TARGET_SYS} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | rm -f $script |
| 72 | touch $script |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 73 | echo 'standalone_sysroot_target="${STAGING_DIR}/${MACHINE}"' >> $script |
| 74 | echo 'standalone_sysroot_native="${STAGING_DIR}/${BUILD_ARCH}"' >> $script |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 75 | echo 'orig=`pwd`; cd ${COREBASE}; . ./oe-init-build-env ${TOPDIR}; cd $orig' >> $script |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 76 | echo 'export PATH=$standalone_sysroot_native/${bindir_native}:$standalone_sysroot_native/${bindir_native}/${TARGET_SYS}:$PATH' >> $script |
| 77 | echo 'export PKG_CONFIG_SYSROOT_DIR=$standalone_sysroot_target' >> $script |
| 78 | echo 'export PKG_CONFIG_PATH=$standalone_sysroot_target'"$libdir"'/pkgconfig:$standalone_sysroot_target'"$prefix"'/share/pkgconfig' >> $script |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 79 | echo 'export CONFIG_SITE="${CONFIG_SITE}"' >> $script |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 80 | echo 'export SDKTARGETSYSROOT=$standalone_sysroot_target' >> $script |
| 81 | echo 'export OECORE_NATIVE_SYSROOT=$standalone_sysroot_native' >> $script |
| 82 | echo 'export OECORE_TARGET_SYSROOT=$standalone_sysroot_target' >> $script |
| 83 | echo 'export OECORE_ACLOCAL_OPTS="-I $standalone_sysroot_native/usr/share/aclocal"' >> $script |
| 84 | echo 'export OECORE_BASELIB="${baselib}"' >> $script |
| 85 | echo 'export OECORE_TARGET_ARCH="${TARGET_ARCH}"' >>$script |
| 86 | echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | |
| 88 | toolchain_shared_env_script |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 89 | |
| 90 | cat >> $script <<EOF |
| 91 | |
| 92 | if [ -d "\$OECORE_NATIVE_SYSROOT/${datadir}/post-relocate-setup.d/" ]; then |
| 93 | for s in \$OECORE_NATIVE_SYSROOT/${datadir}/post-relocate-setup.d/*; do |
| 94 | if [ ! -x \$s ]; then |
| 95 | continue |
| 96 | fi |
| 97 | \$s "\$1" |
| 98 | status=\$? |
| 99 | if [ \$status != 0 ]; then |
| 100 | echo "post-relocate command \"\$s \$1\" failed with status \$status" >&2 |
| 101 | exit \$status |
| 102 | fi |
| 103 | done |
| 104 | fi |
| 105 | EOF |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | toolchain_shared_env_script () { |
| 109 | echo 'export CC="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script |
| 110 | echo 'export CXX="${TARGET_PREFIX}g++ ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script |
| 111 | echo 'export CPP="${TARGET_PREFIX}gcc -E ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script |
| 112 | echo 'export AS="${TARGET_PREFIX}as ${TARGET_AS_ARCH}"' >> $script |
| 113 | echo 'export LD="${TARGET_PREFIX}ld ${TARGET_LD_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script |
| 114 | echo 'export GDB=${TARGET_PREFIX}gdb' >> $script |
| 115 | echo 'export STRIP=${TARGET_PREFIX}strip' >> $script |
| 116 | echo 'export RANLIB=${TARGET_PREFIX}ranlib' >> $script |
| 117 | echo 'export OBJCOPY=${TARGET_PREFIX}objcopy' >> $script |
| 118 | echo 'export OBJDUMP=${TARGET_PREFIX}objdump' >> $script |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 119 | echo 'export READELF=${TARGET_PREFIX}readelf' >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | echo 'export AR=${TARGET_PREFIX}ar' >> $script |
| 121 | echo 'export NM=${TARGET_PREFIX}nm' >> $script |
| 122 | echo 'export M4=m4' >> $script |
| 123 | echo 'export TARGET_PREFIX=${TARGET_PREFIX}' >> $script |
| 124 | echo 'export CONFIGURE_FLAGS="--target=${TARGET_SYS} --host=${TARGET_SYS} --build=${SDK_ARCH}-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"' >> $script |
| 125 | echo 'export CFLAGS="${TARGET_CFLAGS}"' >> $script |
| 126 | echo 'export CXXFLAGS="${TARGET_CXXFLAGS}"' >> $script |
| 127 | echo 'export LDFLAGS="${TARGET_LDFLAGS}"' >> $script |
| 128 | echo 'export CPPFLAGS="${TARGET_CPPFLAGS}"' >> $script |
| 129 | echo 'export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"' >> $script |
| 130 | echo 'export OECORE_DISTRO_VERSION="${DISTRO_VERSION}"' >> $script |
| 131 | echo 'export OECORE_SDK_VERSION="${SDK_VERSION}"' >> $script |
| 132 | echo 'export ARCH=${ARCH}' >> $script |
| 133 | echo 'export CROSS_COMPILE=${TARGET_PREFIX}' >> $script |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 134 | echo 'export OECORE_TUNE_CCARGS="${TUNE_CCARGS}"' >> $script |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | |
| 136 | cat >> $script <<EOF |
| 137 | |
| 138 | # Append environment subscripts |
| 139 | if [ -d "\$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then |
| 140 | for envfile in \$OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 141 | . \$envfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | done |
| 143 | fi |
| 144 | if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then |
| 145 | for envfile in \$OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | . \$envfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | done |
| 148 | fi |
| 149 | EOF |
| 150 | } |
| 151 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 152 | toolchain_create_post_relocate_script() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 153 | relocate_script=$1 |
| 154 | env_dir=$2 |
| 155 | rm -f $relocate_script |
| 156 | touch $relocate_script |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 157 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 158 | cat >> $relocate_script <<EOF |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 159 | if [ -d "${SDKPATHNATIVE}/post-relocate-setup.d/" ]; then |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 160 | # Source top-level SDK env scripts in case they are needed for the relocate |
| 161 | # scripts. |
| 162 | for env_setup_script in ${env_dir}/environment-setup-*; do |
| 163 | . \$env_setup_script |
| 164 | status=\$? |
| 165 | if [ \$status != 0 ]; then |
| 166 | echo "\$0: Failed to source \$env_setup_script with status \$status" |
| 167 | exit \$status |
| 168 | fi |
| 169 | |
| 170 | for s in ${SDKPATHNATIVE}/post-relocate-setup.d/*; do |
| 171 | if [ ! -x \$s ]; then |
| 172 | continue |
| 173 | fi |
| 174 | \$s "\$1" |
| 175 | status=\$? |
| 176 | if [ \$status != 0 ]; then |
| 177 | echo "post-relocate command \"\$s \$1\" failed with status \$status" >&2 |
| 178 | exit \$status |
| 179 | fi |
| 180 | done |
| 181 | done |
| 182 | rm -rf "${SDKPATHNATIVE}/post-relocate-setup.d" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 183 | fi |
| 184 | EOF |
| 185 | } |
| 186 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | #we get the cached site config in the runtime |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 188 | TOOLCHAIN_CONFIGSITE_NOCACHE = "${@' '.join(siteinfo_get_files(d)[0])}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | TOOLCHAIN_CONFIGSITE_SYSROOTCACHE = "${STAGING_DIR}/${MLPREFIX}${MACHINE}/${target_datadir}/${TARGET_SYS}_config_site.d" |
| 190 | TOOLCHAIN_NEED_CONFIGSITE_CACHE ??= "virtual/${MLPREFIX}libc ncurses" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 191 | DEPENDS += "${TOOLCHAIN_NEED_CONFIGSITE_CACHE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | |
| 193 | #This function create a site config file |
| 194 | toolchain_create_sdk_siteconfig () { |
| 195 | local siteconfig=$1 |
| 196 | |
| 197 | rm -f $siteconfig |
| 198 | touch $siteconfig |
| 199 | |
| 200 | for sitefile in ${TOOLCHAIN_CONFIGSITE_NOCACHE} ; do |
| 201 | cat $sitefile >> $siteconfig |
| 202 | done |
| 203 | |
| 204 | #get cached site config |
| 205 | for sitefile in ${TOOLCHAIN_NEED_CONFIGSITE_CACHE}; do |
| 206 | # Resolve virtual/* names to the real recipe name using sysroot-providers info |
| 207 | case $sitefile in virtual/*) |
| 208 | sitefile=`echo $sitefile | tr / _` |
| 209 | sitefile=`cat ${STAGING_DIR_TARGET}/sysroot-providers/$sitefile` |
| 210 | esac |
| 211 | |
| 212 | if [ -r ${TOOLCHAIN_CONFIGSITE_SYSROOTCACHE}/${sitefile}_config ]; then |
| 213 | cat ${TOOLCHAIN_CONFIGSITE_SYSROOTCACHE}/${sitefile}_config >> $siteconfig |
| 214 | fi |
| 215 | done |
| 216 | } |
| 217 | # The immediate expansion above can result in unwanted path dependencies here |
| 218 | toolchain_create_sdk_siteconfig[vardepsexclude] = "TOOLCHAIN_CONFIGSITE_SYSROOTCACHE" |
| 219 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | python __anonymous () { |
| 221 | import oe.classextend |
| 222 | deps = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 223 | for dep in (d.getVar('TOOLCHAIN_NEED_CONFIGSITE_CACHE') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | deps += " %s:do_populate_sysroot" % dep |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | for variant in (d.getVar('MULTILIB_VARIANTS') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | clsextend = oe.classextend.ClassExtender(variant, d) |
| 227 | newdep = clsextend.extend_name(dep) |
| 228 | deps += " %s:do_populate_sysroot" % newdep |
| 229 | d.appendVarFlag('do_configure', 'depends', deps) |
| 230 | } |