blob: 1d7c703748d6148b57213ddc6e4e3392a4f2d7d6 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001inherit toolchain-scripts-base siteinfo kernel-arch
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
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
5REAL_MULTIMACH_TARGET_SYS ?= "${MULTIMACH_TARGET_SYS}"
Patrick Williams213cb262021-08-07 19:21:33 -05006TARGET_CC_ARCH:append:libc-musl = " -mmusl"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008# default debug prefix map isn't valid in the SDK
9DEBUG_PREFIX_MAP = ""
10
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000011EXPORT_SDK_PS1 = "${@ 'export PS1=\\"%s\\"' % d.getVar('SDK_PS1') if d.getVar('SDK_PS1') else ''}"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050012
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013# This function creates an environment-setup-script for use in a deployable SDK
14toolchain_create_sdk_env_script () {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015 # Create environment setup script. Remember that $SDKTARGETSYSROOT should
16 # only be expanded on the target at runtime.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050017 base_sbindir=${10:-${base_sbindir_nativesdk}}
18 base_bindir=${9:-${base_bindir_nativesdk}}
19 sbindir=${8:-${sbindir_nativesdk}}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020 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 Bishopd7bf8c12018-02-25 22:55:05 -050029
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 Geissler95ac1b82021-03-31 14:34:31 -050044 echo "${EXPORT_SDK_PS1}" >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 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 Williamsd8c66bc2016-06-20 12:57:21 -050050 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 Williamsc124f4f2015-09-15 14:41:29 -050051 echo 'export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT' >> $script
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 echo 'export PKG_CONFIG_PATH=$SDKTARGETSYSROOT'"$libdir"'/pkgconfig:$SDKTARGETSYSROOT'"$prefix"'/share/pkgconfig' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 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 Bishop1a4b7ee2018-12-16 17:11:34 -080057 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 Williamsf1e5d692016-03-30 15:21:19 -050061 echo 'unset command_not_found_handle' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062
63 toolchain_shared_env_script
64}
65
66# This function creates an environment-setup-script in the TMPDIR which enables
67# a OE-core IDE to integrate with the build tree
Andrew Geissler5199d832021-09-24 16:47:35 -050068# Caller must ensure CONFIG_SITE is setup
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069toolchain_create_tree_env_script () {
70 script=${TMPDIR}/environment-setup-${REAL_MULTIMACH_TARGET_SYS}
71 rm -f $script
72 touch $script
Brad Bishop316dfdd2018-06-25 12:45:53 -040073 echo 'orig=`pwd`; cd ${COREBASE}; . ./oe-init-build-env ${TOPDIR}; cd $orig' >> $script
74 echo 'export PATH=${STAGING_DIR_NATIVE}/usr/bin:${STAGING_BINDIR_TOOLCHAIN}:$PATH' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 echo 'export PKG_CONFIG_SYSROOT_DIR=${PKG_CONFIG_SYSROOT_DIR}' >> $script
76 echo 'export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}' >> $script
Andrew Geissler5199d832021-09-24 16:47:35 -050077 echo 'export CONFIG_SITE="${CONFIG_SITE}"' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 echo 'export SDKTARGETSYSROOT=${STAGING_DIR_TARGET}' >> $script
79 echo 'export OECORE_NATIVE_SYSROOT="${STAGING_DIR_NATIVE}"' >> $script
80 echo 'export OECORE_TARGET_SYSROOT="${STAGING_DIR_TARGET}"' >> $script
81 echo 'export OECORE_ACLOCAL_OPTS="-I ${STAGING_DIR_NATIVE}/usr/share/aclocal"' >> $script
82
83 toolchain_shared_env_script
84}
85
86toolchain_shared_env_script () {
87 echo 'export CC="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script
88 echo 'export CXX="${TARGET_PREFIX}g++ ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script
89 echo 'export CPP="${TARGET_PREFIX}gcc -E ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script
90 echo 'export AS="${TARGET_PREFIX}as ${TARGET_AS_ARCH}"' >> $script
91 echo 'export LD="${TARGET_PREFIX}ld ${TARGET_LD_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script
92 echo 'export GDB=${TARGET_PREFIX}gdb' >> $script
93 echo 'export STRIP=${TARGET_PREFIX}strip' >> $script
94 echo 'export RANLIB=${TARGET_PREFIX}ranlib' >> $script
95 echo 'export OBJCOPY=${TARGET_PREFIX}objcopy' >> $script
96 echo 'export OBJDUMP=${TARGET_PREFIX}objdump' >> $script
Brad Bishopf3f93bb2019-10-16 14:33:32 -040097 echo 'export READELF=${TARGET_PREFIX}readelf' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 echo 'export AR=${TARGET_PREFIX}ar' >> $script
99 echo 'export NM=${TARGET_PREFIX}nm' >> $script
100 echo 'export M4=m4' >> $script
101 echo 'export TARGET_PREFIX=${TARGET_PREFIX}' >> $script
102 echo 'export CONFIGURE_FLAGS="--target=${TARGET_SYS} --host=${TARGET_SYS} --build=${SDK_ARCH}-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"' >> $script
103 echo 'export CFLAGS="${TARGET_CFLAGS}"' >> $script
104 echo 'export CXXFLAGS="${TARGET_CXXFLAGS}"' >> $script
105 echo 'export LDFLAGS="${TARGET_LDFLAGS}"' >> $script
106 echo 'export CPPFLAGS="${TARGET_CPPFLAGS}"' >> $script
107 echo 'export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"' >> $script
108 echo 'export OECORE_DISTRO_VERSION="${DISTRO_VERSION}"' >> $script
109 echo 'export OECORE_SDK_VERSION="${SDK_VERSION}"' >> $script
110 echo 'export ARCH=${ARCH}' >> $script
111 echo 'export CROSS_COMPILE=${TARGET_PREFIX}' >> $script
Patrick Williams45852732022-04-02 08:58:32 -0500112 echo 'export OECORE_TUNE_CCARGS="${TUNE_CCARGS}"' >> $script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113
114 cat >> $script <<EOF
115
116# Append environment subscripts
117if [ -d "\$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
118 for envfile in \$OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600119 . \$envfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 done
121fi
122if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
123 for envfile in \$OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600124 . \$envfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 done
126fi
127EOF
128}
129
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130toolchain_create_post_relocate_script() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800131 relocate_script=$1
132 env_dir=$2
133 rm -f $relocate_script
134 touch $relocate_script
Brad Bishop316dfdd2018-06-25 12:45:53 -0400135
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800136 cat >> $relocate_script <<EOF
Brad Bishop316dfdd2018-06-25 12:45:53 -0400137if [ -d "${SDKPATHNATIVE}/post-relocate-setup.d/" ]; then
Brad Bishop977dc1a2019-02-06 16:01:43 -0500138 # Source top-level SDK env scripts in case they are needed for the relocate
139 # scripts.
140 for env_setup_script in ${env_dir}/environment-setup-*; do
141 . \$env_setup_script
142 status=\$?
143 if [ \$status != 0 ]; then
144 echo "\$0: Failed to source \$env_setup_script with status \$status"
145 exit \$status
146 fi
147
148 for s in ${SDKPATHNATIVE}/post-relocate-setup.d/*; do
149 if [ ! -x \$s ]; then
150 continue
151 fi
152 \$s "\$1"
153 status=\$?
154 if [ \$status != 0 ]; then
155 echo "post-relocate command \"\$s \$1\" failed with status \$status" >&2
156 exit \$status
157 fi
158 done
159 done
160 rm -rf "${SDKPATHNATIVE}/post-relocate-setup.d"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400161fi
162EOF
163}
164
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165#we get the cached site config in the runtime
Andrew Geissler5199d832021-09-24 16:47:35 -0500166TOOLCHAIN_CONFIGSITE_NOCACHE = "${@' '.join(siteinfo_get_files(d)[0])}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167TOOLCHAIN_CONFIGSITE_SYSROOTCACHE = "${STAGING_DIR}/${MLPREFIX}${MACHINE}/${target_datadir}/${TARGET_SYS}_config_site.d"
168TOOLCHAIN_NEED_CONFIGSITE_CACHE ??= "virtual/${MLPREFIX}libc ncurses"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500169DEPENDS += "${TOOLCHAIN_NEED_CONFIGSITE_CACHE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170
171#This function create a site config file
172toolchain_create_sdk_siteconfig () {
173 local siteconfig=$1
174
175 rm -f $siteconfig
176 touch $siteconfig
177
178 for sitefile in ${TOOLCHAIN_CONFIGSITE_NOCACHE} ; do
179 cat $sitefile >> $siteconfig
180 done
181
182 #get cached site config
183 for sitefile in ${TOOLCHAIN_NEED_CONFIGSITE_CACHE}; do
184 # Resolve virtual/* names to the real recipe name using sysroot-providers info
185 case $sitefile in virtual/*)
186 sitefile=`echo $sitefile | tr / _`
187 sitefile=`cat ${STAGING_DIR_TARGET}/sysroot-providers/$sitefile`
188 esac
189
190 if [ -r ${TOOLCHAIN_CONFIGSITE_SYSROOTCACHE}/${sitefile}_config ]; then
191 cat ${TOOLCHAIN_CONFIGSITE_SYSROOTCACHE}/${sitefile}_config >> $siteconfig
192 fi
193 done
194}
195# The immediate expansion above can result in unwanted path dependencies here
196toolchain_create_sdk_siteconfig[vardepsexclude] = "TOOLCHAIN_CONFIGSITE_SYSROOTCACHE"
197
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198python __anonymous () {
199 import oe.classextend
200 deps = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500201 for dep in (d.getVar('TOOLCHAIN_NEED_CONFIGSITE_CACHE') or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 deps += " %s:do_populate_sysroot" % dep
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203 for variant in (d.getVar('MULTILIB_VARIANTS') or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204 clsextend = oe.classextend.ClassExtender(variant, d)
205 newdep = clsextend.extend_name(dep)
206 deps += " %s:do_populate_sysroot" % newdep
207 d.appendVarFlag('do_configure', 'depends', deps)
208}