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