Advertisement
Guest User

Untitled

a guest
Oct 13th, 2024
33
0
116 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 160.43 KB | None | 0 0
  1. declare -x ABI="amd64"
  2. declare -x ABI_MIPS=""
  3. declare -x ABI_S390=""
  4. declare -x ABI_X86="64"
  5. declare -x ADA_TARGET=""
  6. declare -x ALSA_CARDS=""
  7. declare -x AMDGPU_TARGETS=""
  8. declare -x ANT_HOME="/usr/share/ant"
  9. declare -x APACHE2_MODULES=""
  10. declare -x APACHE2_MPMS=""
  11. declare -x ARCH="amd64"
  12. declare BDEPEND=$'initramfs? ( app-alternatives/cpio )\n\tcompress-xz? ( app-arch/xz-utils )\n\tcompress-zstd? ( app-arch/zstd )\n\tdeduplicate? ( app-misc/rdfind )\n\t|| ( dev-lang/python:3.13 dev-lang/python:3.12 dev-lang/python:3.11 dev-lang/python:3.10 ) >=dev-vcs/git-1.8.2.1[curl]'
  13. declare -x BINPKG_FORMAT="gpkg"
  14. declare -x BINPKG_GPG_SIGNING_BASE_COMMAND="/usr/bin/flock /run/lock/portage-binpkg-gpg.lock /usr/bin/gpg --sign --armor [PORTAGE_CONFIG]"
  15. declare -x BINPKG_GPG_SIGNING_DIGEST="SHA512"
  16. declare -x BINPKG_GPG_VERIFY_BASE_COMMAND="/usr/bin/gpg --verify --batch --no-tty --no-auto-check-trustdb --status-fd 2 [PORTAGE_CONFIG] [SIGNATURE]"
  17. declare -x BINPKG_GPG_VERIFY_GPG_HOME="/etc/portage/gnupg"
  18. declare -x BOOTSTRAP_USE="unicode pkg-config split-usr xml python_targets_python3_12 python_single_target_python3_12 multilib zstd cet systemd sysv-utils udev"
  19. declare -x CALLIGRA_FEATURES=""
  20. declare -x CAMERAS=""
  21. declare -x CBUILD="x86_64-pc-linux-gnu"
  22. declare -x CFLAGS="-march=znver4 -mtune=znver4 -O2 -pipe"
  23. declare -x CFLAGS_amd64="-m64"
  24. declare -x CFLAGS_default
  25. declare -x CFLAGS_x32="-mx32"
  26. declare -x CFLAGS_x86="-m32 -mfpmath=sse"
  27. declare -- CHECKCONFIG_DONOTHING=""
  28. declare -x CHOST="x86_64-pc-linux-gnu"
  29. declare -x CHOST_amd64="x86_64-pc-linux-gnu"
  30. declare -x CHOST_default="x86_64-pc-linux-gnu"
  31. declare -x CHOST_x32="x86_64-pc-linux-gnux32"
  32. declare -x CHOST_x86="i686-pc-linux-gnu"
  33. declare -x COLLECTD_PLUGINS=""
  34. declare -x COMMON_FLAGS="-march=znver4 -mtune=znver4 -O2 -pipe"
  35. declare -x CPU_FLAGS_ARM=""
  36. declare -x CPU_FLAGS_PPC=""
  37. declare -x CPU_FLAGS_X86=""
  38. declare -x CTARGET_default="x86_64-pc-linux-gnu"
  39. declare -x CURL_QUIC=""
  40. declare -x CURL_SSL=""
  41. declare -x CXXFLAGS="-march=znver4 -mtune=znver4 -O2 -pipe"
  42. declare -x DEBUGBUILD="1"
  43. declare -x DEFAULT_ABI="amd64"
  44. declare -x DEFINED_PHASES=" install postinst postrm preinst prepare prerm pretend setup unpack"
  45. declare DEPEND=""
  46. declare DESCRIPTION="Linux firmware files"
  47. declare -x DIROPTIONS="-m0755"
  48. declare -x DOTNET_ROOT="/usr/lib64/dotnet-sdk-8.0"
  49. declare -x EAPI="8"
  50. declare -- EGIT3_STORE_DIR="/var/cache/distfiles/git3-src"
  51. declare -- EGIT_BRANCH=""
  52. declare -- EGIT_CLONE_TYPE="single"
  53. declare -- EGIT_COMMIT=""
  54. declare -- EGIT_COMMIT_DATE=""
  55. declare -x EGIT_DIR="/var/cache/distfiles/git3-src/linux_kernel_git_firmware_linux-firmware.git"
  56. declare -- EGIT_LFS_CLONE_TYPE="shallow"
  57. declare -- EGIT_MIN_CLONE_TYPE="shallow"
  58. declare -- EGIT_REPO_URI="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"
  59. declare -x EGIT_VERSION="06bad2f17030ea91ca4c9b965c2131e468af9ddc"
  60. declare -x ELIBC="glibc"
  61. declare -x ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
  62. declare -- EPOCHREALTIME="1728871859.609774"
  63. declare -- EPOCHSECONDS="1728871859"
  64. declare -x EPYTHON="python3.12"
  65. declare -a EVCS_STORE_DIRS=([0]="/var/cache/distfiles/git3-src/linux_kernel_git_firmware_linux-firmware.git" [1]="/var/cache/distfiles/git3-src/linux_kernel_git_firmware_linux-firmware.git")
  66. declare -x EXEOPTIONS="-m0755"
  67. declare -x FCFLAGS="-march=znver4 -mtune=znver4 -O2 -pipe"
  68. declare -x FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port= ; exec rsync --rsh=\\\"ssh \\\${port:+-p\\\${port}} \\\${3}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\" \"\${PORTAGE_SSH_OPTS}\""
  69. declare -x FFLAGS="-march=znver4 -mtune=znver4 -O2 -pipe"
  70. declare -x FFTOOLS=""
  71. declare -x GCC_SPECS=""
  72. declare -x GPG_VERIFY_GROUP_DROP="nogroup"
  73. declare -x GPG_VERIFY_USER_DROP="nobody"
  74. declare -x GPSD_PROTOCOLS=""
  75. declare -x GRUB_PLATFORMS=""
  76. declare -x GSETTINGS_BACKEND="dconf"
  77. declare -x GUILE_SINGLE_TARGET=""
  78. declare -x GUILE_TARGETS=""
  79. declare HOMEPAGE="https://git.kernel.org/?p=linux/kernel/git/firmware/linux-firmware.git"
  80. declare IDEPEND=$'\n\tdist-kernel? (\n\t\tinitramfs? ( sys-kernel/installkernel )\n\t)\n '
  81. declare -x INHERITED=" mount-boot-utils toolchain-funcs multilib dist-kernel-utils linux-info mount-boot multiprocessing python-utils-r1 python-any-r1 portability savedconfig git-r3"
  82. declare -x INPUT_DEVICES=""
  83. declare -x INSOPTIONS="-m0644"
  84. declare IUSE="compress-xz compress-zstd deduplicate dist-kernel +initramfs +redistributable savedconfig unknown-license savedconfig"
  85. declare -x IUSE_EFFECTIVE="abi_x86_64 alpha amd64 amd64-linux arm arm64 arm64-macos compress-xz compress-zstd deduplicate dist-kernel elibc_Darwin elibc_SunOS elibc_bionic elibc_glibc elibc_mingw elibc_musl hppa initramfs kernel_Darwin kernel_SunOS kernel_linux loong m68k mips ppc ppc-macos ppc64 ppc64-linux prefix prefix-guest prefix-stack redistributable riscv s390 savedconfig sparc unknown-license x64-macos x64-solaris x86 x86-linux"
  86. declare -x IUSE_IMPLICIT="abi_x86_64 prefix prefix-guest prefix-stack"
  87. declare -x KERNEL="linux"
  88. declare -x KERNEL_ABI="amd64"
  89. declare -- KERNEL_DIR="/usr/src/linux"
  90. declare -- KERNEL_MAKEFILE="/usr/src/linux/Makefile"
  91. declare -x KEYWORDS=""
  92. declare -- KV_DIR="/usr/src/linux"
  93. declare -- KV_EXTRA="-rc3-mainline"
  94. declare -- KV_FULL="6.12.0-rc3-mainline-byw-gcc-znver4"
  95. declare -- KV_LOCAL="-byw-gcc-znver4"
  96. declare -- KV_MAJOR="6"
  97. declare -- KV_MINOR="12"
  98. declare -- KV_OUT_DIR="/usr/src/linux"
  99. declare -- KV_PATCH="0"
  100. declare -x L10N=""
  101. declare -x LADSPA_PATH="/usr/lib64/ladspa"
  102. declare -x LANG="en_GB.utf8"
  103. declare -x LANGUAGE=""
  104. declare -x LCD_DEVICES=""
  105. declare -x LC_ADDRESS="en_GB.utf8"
  106. declare -x LC_COLLATE="C"
  107. declare -x LC_CTYPE="en_GB.utf8"
  108. declare -x LC_IDENTIFICATION="en_GB.utf8"
  109. declare -x LC_MEASUREMENT="en_GB.utf8"
  110. declare -x LC_MESSAGES="en_GB.utf8"
  111. declare -x LC_MONETARY="en_GB.utf8"
  112. declare -x LC_NAME="en_GB.utf8"
  113. declare -x LC_NUMERIC="en_GB.utf8"
  114. declare -x LC_PAPER="en_GB.utf8"
  115. declare -x LC_TELEPHONE="en_GB.utf8"
  116. declare -x LC_TIME="en_GB.utf8"
  117. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-O2 -Wl,--as-needed -Wl,-z,pack-relative-relocs"
  118. declare -x LDFLAGS_amd64="-m elf_x86_64"
  119. declare -x LDFLAGS_default
  120. declare -x LDFLAGS_x32="-m elf32_x86_64"
  121. declare -x LDFLAGS_x86="-m elf_i386"
  122. declare -x LEX="flex"
  123. declare -x LIBDIR_amd64="lib64"
  124. declare -x LIBDIR_default="lib"
  125. declare -x LIBDIR_x32="libx32"
  126. declare -x LIBDIR_x86="lib"
  127. declare -x LIBOPTIONS="-m0644"
  128. declare -x LIBREOFFICE_EXTENSIONS=""
  129. declare -x LICENSE=$'GPL-2 GPL-2+ GPL-3 BSD MIT || ( MPL-1.1 GPL-2 )\n\tredistributable? ( linux-fw-redistributable BSD-2 BSD BSD-4 ISC MIT )\n\tunknown-license? ( all-rights-reserved )'
  130. declare -x LINGUAS="en en-GB"
  131. declare -x LLVM_SLOT=""
  132. declare -x LLVM_TARGETS=""
  133. declare -x LUA_SINGLE_TARGET=""
  134. declare -x LUA_TARGETS=""
  135. declare -x LV2_PATH="/usr/lib64/lv2"
  136. declare -x MAIL="/var/mail/root"
  137. declare -x MAKEOPTS="-j16"
  138. declare -x MANPAGER="manpager"
  139. declare -x MODULES_SIGN_CERT="/path/to/cert.crt"
  140. declare -x MODULES_SIGN_HASH="sha512"
  141. declare -x MODULES_SIGN_KEY="/patch/to/key.key"
  142. declare -x MOZ_GMP_PATH="/usr/lib64/nsbrowser/plugins/gmp-gmpopenh264/system-installed"
  143. declare -x MULTILIB_ABIS="amd64 x86"
  144. declare -x MULTILIB_STRICT_DENY="64-bit.*shared object"
  145. declare -x MULTILIB_STRICT_DIRS="/lib32 /lib /usr/lib32 /usr/lib /usr/kde/*/lib32 /usr/kde/*/lib /usr/qt/*/lib32 /usr/qt/*/lib /usr/X11R6/lib32 /usr/X11R6/lib"
  146. declare -x MULTILIB_STRICT_EXEMPT="(perl5|gcc|binutils|eclipse-3|debug|portage|udev|systemd|clang|python-exec|llvm)"
  147. declare -- MY_COMMIT=""
  148. declare -x NGINX_MODULES_HTTP=""
  149. declare -x NGINX_MODULES_MAIL=""
  150. declare -x NGINX_MODULES_STREAM=""
  151. declare -x NPM_CONFIG_GLOBALCONFIG="/etc/npm/npmrc"
  152. declare -x OFFICE_IMPLEMENTATION=""
  153. declare -x OPENMPI_FABRICS=""
  154. declare -x OPENMPI_OFED_FEATURES=""
  155. declare -x OPENMPI_RM=""
  156. declare -x PATH="/var/tmp/portage/sys-kernel/linux-firmware-99999999/temp/python3.12/bin:/usr/lib/portage/python3.12/ebuild-helpers/xattr:/usr/lib/portage/python3.12/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin"
  157. declare PDEPEND=""
  158. declare -x PERL_FEATURES=""
  159. declare -x PHP_TARGETS=""
  160. declare -x PKG_CONFIG_PATH="/var/tmp/portage/sys-kernel/linux-firmware-99999999/temp/python3.12/pkgconfig"
  161. declare -x POLICY_TYPES="strict targeted"
  162. declare -x PORTAGE_COMPRESSION_COMMAND="zstd -T16"
  163. declare -a PORTAGE_DOCOMPRESS=([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")
  164. declare -x PORTAGE_DOCOMPRESS_SIZE_LIMIT="128"
  165. declare -a PORTAGE_DOCOMPRESS_SKIP=([0]="/usr/share/doc/linux-firmware-99999999/html")
  166. declare -a PORTAGE_DOSTRIP=()
  167. declare -a PORTAGE_DOSTRIP_SKIP=()
  168. declare -x PORTAGE_REPO_REVISIONS="{\"gentoo\": \"9d918b2e05ed14586665dace425cd116bf917d91\"}"
  169. declare -x POSTGRES_TARGETS=""
  170. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC IUSE_IMPLICIT KERNEL USE_EXPAND_IMPLICIT USE_EXPAND_UNPREFIXED USE_EXPAND_VALUES_ARCH USE_EXPAND_VALUES_ELIBC USE_EXPAND_VALUES_KERNEL"
  171. declare -- PROPERTIES="live"
  172. declare -x PYTHON="/usr/bin/python3.12"
  173. declare -x PYTHONDONTWRITEBYTECODE="1"
  174. declare -a PYTHON_COMPAT=([0]="python3_10" [1]="python3_11" [2]="python3_12" [3]="python3_13")
  175. declare -- PYTHON_DEPS="|| ( dev-lang/python:3.13 dev-lang/python:3.12 dev-lang/python:3.11 dev-lang/python:3.10 )"
  176. declare -- PYTHON_REQUIRED_USE="I-DO-NOT-EXIST-IN-PYTHON-ANY-R1"
  177. declare -x PYTHON_SINGLE_TARGET=""
  178. declare -x PYTHON_TARGETS=""
  179. declare -- QA_PREBUILT="*"
  180. declare -x QEMU_SOFTMMU_TARGETS=""
  181. declare -x QEMU_USER_TARGETS=""
  182. declare RDEPEND=$'!savedconfig? (\n\t\tredistributable? (\n\t\t\t!sys-firmware/alsa-firmware[alsa_cards_ca0132]\n\t\t\t!sys-block/qla-fc-firmware\n\t\t\t!sys-firmware/raspberrypi-wifi-ucode\n\t\t)\n\t\tunknown-license? (\n\t\t\t!sys-firmware/alsa-firmware[alsa_cards_korg1212]\n\t\t\t!sys-firmware/alsa-firmware[alsa_cards_maestro3]\n\t\t\t!sys-firmware/alsa-firmware[alsa_cards_sb16]\n\t\t\t!sys-firmware/alsa-firmware[alsa_cards_ymfpci]\n\t\t)\n\t)\n\tdist-kernel? (\n\t\tvirtual/dist-kernel\n\t\tinitramfs? (\n\t\t\tapp-alternatives/cpio\n\t\t)\n\t)\n '
  183. declare REPOSITORY
  184. declare REQUIRED_USE=$'initramfs? ( redistributable )\n\t?? ( compress-xz compress-zstd )\n\tsavedconfig? ( !deduplicate ) '
  185. declare RESTRICT="binchecks strip test"
  186. declare -x RESUMECOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port= ; exec rsync --rsh=\\\"ssh \\\${port:+-p\\\${port}} \\\${3}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\" \"\${PORTAGE_SSH_OPTS}\""
  187. declare -x RUBY_TARGETS=""
  188. declare -x RUSTFLAGS="-C target-cpu=znver4 -C link-arg=-Wl,-z,pack-relative-relocs -C opt-level=3"
  189. declare -x S="/var/tmp/portage/sys-kernel/linux-firmware-99999999/work/linux-firmware-99999999"
  190. declare -x SANDBOX_DEBUG="0"
  191. declare -x SANDBOX_DENY=""
  192. declare -x SANDBOX_METHOD="any"
  193. declare -x SANDBOX_PREDICT="/var/tmp/portage/sys-kernel/linux-firmware-99999999/homedir:/dev/crypto:/var/cache/man:/dev/random:/proc/self/coredump_filter:/dev/random:/proc/self/coredump_filter:/var/cache/fontconfig"
  194. declare -x SANDBOX_READ="/:/var/tmp/portage"
  195. declare -x SANDBOX_VERBOSE="1"
  196. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/ptmx:/dev/pts/:/dev/pty:/dev/shm:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/tmp/:/usr/lib/cf:/usr/lib/conftest:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/tmp/:/usr/tmp/cf:/usr/tmp/conftest:/var/cache/distfiles/git3-src:/var/tmp/:/var/tmp/portage:/var/tmp/portage/sys-kernel/linux-firmware-99999999/homedir/.bash_history"
  197. declare -x SANE_BACKENDS=""
  198. declare -x SECUREBOOT_SIGN_CERT="/path/to/cert.crt"
  199. declare -x SECUREBOOT_SIGN_KEY="/path/to/key.key"
  200. declare -x SHELL="/bin/bash"
  201. declare -- SKIP_KERNEL_CHECK=""
  202. declare -x SLOT="0"
  203. declare -i SRANDOM="219354349"
  204. declare SRC_URI
  205. declare -x SUDO_COMMAND="/usr/sbin/emerge linux-firmware"
  206. declare -x SUDO_GID="0"
  207. declare -x SUDO_UID="0"
  208. declare -x SUDO_USER="root"
  209. declare -x SYMLINK_LIB="no"
  210. declare -x TWISTED_DISABLE_WRITING_OF_PLUGIN_CACHE="1"
  211. declare -x USE="abi_x86_64 amd64 elibc_glibc kernel_linux redistributable"
  212. declare -x USERLAND="GNU"
  213. declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL"
  214. declare -x USE_EXPAND_UNPREFIXED="ARCH"
  215. declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-linux arm arm64 arm64-macos hppa loong m68k mips ppc ppc64 ppc64-linux ppc-macos riscv s390 sparc x64-macos x64-solaris x86 x86-linux"
  216. declare -x USE_EXPAND_VALUES_ELIBC="bionic Darwin glibc mingw musl SunOS"
  217. declare -x USE_EXPAND_VALUES_KERNEL="Darwin linux SunOS"
  218. declare -x UWSGI_PLUGINS=""
  219. declare -x VIDEO_CARDS=""
  220. declare -x VISUAL="vim"
  221. declare -x VOICEMAIL_STORAGE=""
  222. declare -x XDG_CONFIG_DIRS="/etc/xdg"
  223. declare -x XDG_CURRENT_DESKTOP="KDE"
  224. declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share"
  225. declare -x XTABLES_ADDONS=""
  226. declare -- _DIST_KERNEL_UTILS="1"
  227. declare -- _GIT_R3_ECLASS="1"
  228. declare -- _LINUX_CONFIG_EXISTS_DONE=""
  229. declare -- _LINUX_INFO_ECLASS="1"
  230. declare -- _MULTILIB_ECLASS="1"
  231. declare -- _MULTIPROCESSING_ECLASS="1"
  232. declare -- _PORTABILITY_ECLASS="1"
  233. declare -a _PYTHON_ALL_IMPLS=([0]="pypy3" [1]="python3_10" [2]="python3_11" [3]="python3_12" [4]="python3_13")
  234. declare -- _PYTHON_ANY_R1_ECLASS="1"
  235. declare -a _PYTHON_HISTORICAL_IMPLS=([0]="jython2_7" [1]="pypy" [2]="pypy1_8" [3]="pypy1_9" [4]="pypy2_0" [5]="python2_5" [6]="python2_6" [7]="python2_7" [8]="python3_1" [9]="python3_2" [10]="python3_3" [11]="python3_4" [12]="python3_5" [13]="python3_6" [14]="python3_7" [15]="python3_8" [16]="python3_9")
  236. declare -- _PYTHON_SANITY_CHECKED="1"
  237. declare -a _PYTHON_SUPPORTED_IMPLS=([0]="python3_10" [1]="python3_11" [2]="python3_12" [3]="python3_13")
  238. declare -a _PYTHON_UNSUPPORTED_IMPLS=([0]="pypy3")
  239. declare -- _PYTHON_UTILS_R1_ECLASS="1"
  240. declare -- _SAVEDCONFIG_ECLASS="1"
  241. declare -- _TOOLCHAIN_FUNCS_ECLASS="1"
  242. declare -x __E_DESTTREE="/usr"
  243. declare -x __E_DOCDESTTREE=""
  244. declare -x __E_EXEDESTTREE=""
  245. declare -x __E_INSDESTTREE=""
  246. declare -x ac_cv_c_undeclared_builtin_options="none needed"
  247. declare -x enable_year2038="no"
  248. declare -- get_version_warning_done=""
  249. declare -x gl_cv_compiler_check_decl_option="-Werror=implicit-function-declaration"
  250. declare -x gl_cv_func_getcwd_path_max="yes"
  251. __eapi6_src_install ()
  252. {
  253. if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then
  254. emake DESTDIR="${D}" install;
  255. fi;
  256. einstalldocs
  257. }
  258. __eapi6_src_prepare ()
  259. {
  260. if ___is_indexed_array_var PATCHES; then
  261. [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}";
  262. else
  263. if [[ -n ${PATCHES} ]]; then
  264. eapply ${PATCHES};
  265. fi;
  266. fi;
  267. eapply_user
  268. }
  269. __eapi7_ver_compare ()
  270. {
  271. local va=${1} vb=${2} a an al as ar b bn bl bs br re LC_ALL=C;
  272. re="^([0-9]+(\.[0-9]+)*)([a-z]?)((_(alpha|beta|pre|rc|p)[0-9]*)*)(-r[0-9]+)?$";
  273. [[ ${va} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${va}";
  274. an=${BASH_REMATCH[1]};
  275. al=${BASH_REMATCH[3]};
  276. as=${BASH_REMATCH[4]};
  277. ar=${BASH_REMATCH[7]};
  278. [[ ${vb} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${vb}";
  279. bn=${BASH_REMATCH[1]};
  280. bl=${BASH_REMATCH[3]};
  281. bs=${BASH_REMATCH[4]};
  282. br=${BASH_REMATCH[7]};
  283. __eapi7_ver_compare_int "${an%%.*}" "${bn%%.*}" || return;
  284. while [[ ${an} == *.* && ${bn} == *.* ]]; do
  285. an=${an#*.};
  286. bn=${bn#*.};
  287. a=${an%%.*};
  288. b=${bn%%.*};
  289. if [[ ${a} == 0* || ${b} == 0* ]]; then
  290. [[ ${a} =~ 0+$ ]] && a=${a%"${BASH_REMATCH[0]}"};
  291. [[ ${b} =~ 0+$ ]] && b=${b%"${BASH_REMATCH[0]}"};
  292. [[ ${a} > ${b} ]] && return 3;
  293. [[ ${a} < ${b} ]] && return 1;
  294. else
  295. __eapi7_ver_compare_int "${a}" "${b}" || return;
  296. fi;
  297. done;
  298. [[ ${an} == *.* ]] && return 3;
  299. [[ ${bn} == *.* ]] && return 1;
  300. [[ ${al} > ${bl} ]] && return 3;
  301. [[ ${al} < ${bl} ]] && return 1;
  302. as=${as#_}${as:+_};
  303. bs=${bs#_}${bs:+_};
  304. while [[ -n ${as} && -n ${bs} ]]; do
  305. a=${as%%_*};
  306. b=${bs%%_*};
  307. if [[ ${a%%[0-9]*} == "${b%%[0-9]*}" ]]; then
  308. __eapi7_ver_compare_int "${a##*[a-z]}" "${b##*[a-z]}" || return;
  309. else
  310. [[ ${a%%[0-9]*} == p ]] && return 3;
  311. [[ ${b%%[0-9]*} == p ]] && return 1;
  312. [[ ${a} > ${b} ]] && return 3 || return 1;
  313. fi;
  314. as=${as#*_};
  315. bs=${bs#*_};
  316. done;
  317. if [[ -n ${as} ]]; then
  318. [[ ${as} == p[_0-9]* ]] && return 3 || return 1;
  319. else
  320. if [[ -n ${bs} ]]; then
  321. [[ ${bs} == p[_0-9]* ]] && return 1 || return 3;
  322. fi;
  323. fi;
  324. __eapi7_ver_compare_int "${ar#-r}" "${br#-r}" || return;
  325. return 2
  326. }
  327. __eapi7_ver_compare_int ()
  328. {
  329. local a=$1 b=$2 d=$(( ${#1}-${#2} ));
  330. if [[ ${d} -gt 0 ]]; then
  331. printf -v b "%0${d}d%s" 0 "${b}";
  332. else
  333. if [[ ${d} -lt 0 ]]; then
  334. printf -v a "%0$(( -d ))d%s" 0 "${a}";
  335. fi;
  336. fi;
  337. [[ ${a} > ${b} ]] && return 3;
  338. [[ ${a} == "${b}" ]]
  339. }
  340. __eapi7_ver_parse_range ()
  341. {
  342. local range=${1};
  343. local max=${2};
  344. [[ ${range} == [0-9]* ]] || die "${FUNCNAME}: range must start with a number";
  345. start=${range%-*};
  346. [[ ${range} == *-* ]] && end=${range#*-} || end=${start};
  347. if [[ -n ${end} ]]; then
  348. [[ ${start} -le ${end} ]] || die "${FUNCNAME}: end of range must be >= start";
  349. [[ ${end} -le ${max} ]] || end=${max};
  350. else
  351. end=${max};
  352. fi
  353. }
  354. __eapi7_ver_split ()
  355. {
  356. local v=${1} LC_ALL=C;
  357. comp=();
  358. local s c;
  359. while [[ -n ${v} ]]; do
  360. s=${v%%[a-zA-Z0-9]*};
  361. v=${v:${#s}};
  362. [[ ${v} == [0-9]* ]] && c=${v%%[^0-9]*} || c=${v%%[^a-zA-Z]*};
  363. v=${v:${#c}};
  364. comp+=("${s}" "${c}");
  365. done
  366. }
  367. __eapi8_src_prepare ()
  368. {
  369. local f;
  370. if ___is_indexed_array_var PATCHES; then
  371. [[ ${#PATCHES[@]} -gt 0 ]] && eapply -- "${PATCHES[@]}";
  372. else
  373. if [[ -n ${PATCHES} ]]; then
  374. eapply -- ${PATCHES};
  375. fi;
  376. fi;
  377. eapply_user
  378. }
  379. _clang_fullversion ()
  380. {
  381. local ver="$1";
  382. shift;
  383. set -- $($(tc-getCPP "$@") -E -P - <<< "__clang_major__ __clang_minor__ __clang_patchlevel__");
  384. eval echo "${ver}"
  385. }
  386. _gcc-install-dir ()
  387. {
  388. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  389. }
  390. _gcc-specs-directive_raw ()
  391. {
  392. local cc=$(tc-getCC);
  393. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  394. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  395. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  396. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  397. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  398. { spec=spec $0 }
  399. END { print spec }';
  400. return 0
  401. }
  402. _gcc-specs-exists ()
  403. {
  404. [[ -f $(_gcc-install-dir)/$1 ]]
  405. }
  406. _gcc_fullversion ()
  407. {
  408. local ver="$1";
  409. shift;
  410. set -- $($(tc-getCPP "$@") -E -P - <<< "__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__");
  411. eval echo "${ver}"
  412. }
  413. _get_all_makeopts ()
  414. {
  415. echo "${MAKEOPTS} ${GNUMAKEFLAGS} ${MAKEFLAGS}"
  416. }
  417. _git-r3_env_setup ()
  418. {
  419. debug-print-function ${FUNCNAME} "$@";
  420. case "${EGIT_CLONE_TYPE}" in
  421. mirror | single+tags | single | shallow)
  422.  
  423. ;;
  424. *)
  425. die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
  426. ;;
  427. esac;
  428. case "${EGIT_MIN_CLONE_TYPE}" in
  429. shallow)
  430.  
  431. ;;
  432. single)
  433. if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
  434. einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting";
  435. EGIT_CLONE_TYPE=single;
  436. fi
  437. ;;
  438. single+tags)
  439. if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
  440. einfo "git-r3: ebuild needs to be cloned in 'single+tags' mode, adjusting";
  441. EGIT_CLONE_TYPE=single+tags;
  442. fi
  443. ;;
  444. mirror)
  445. if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
  446. einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting";
  447. EGIT_CLONE_TYPE=mirror;
  448. fi
  449. ;;
  450. *)
  451. die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
  452. ;;
  453. esac;
  454. if [[ -n ${EGIT_SUBMODULES[@]+1} && $(declare -p EGIT_SUBMODULES) != "declare -a"* ]]; then
  455. die 'EGIT_SUBMODULES must be an array.';
  456. fi;
  457. local esc_pn livevar;
  458. esc_pn=${PN//[-+]/_};
  459. [[ ${esc_pn} == [0-9]* ]] && esc_pn=_${esc_pn};
  460. livevar=${esc_pn}_LIVE_REPO;
  461. EGIT_REPO_URI=${!livevar-${EGIT_REPO_URI}};
  462. [[ -n ${!livevar} ]] && ewarn "Using ${livevar}, no support will be provided";
  463. livevar=${esc_pn}_LIVE_BRANCH;
  464. EGIT_BRANCH=${!livevar-${EGIT_BRANCH}};
  465. [[ -n ${!livevar} ]] && ewarn "Using ${livevar}, no support will be provided";
  466. livevar=${esc_pn}_LIVE_COMMIT;
  467. EGIT_COMMIT=${!livevar-${EGIT_COMMIT}};
  468. [[ -n ${!livevar} ]] && ewarn "Using ${livevar}, no support will be provided";
  469. livevar=${esc_pn}_LIVE_COMMIT_DATE;
  470. EGIT_COMMIT_DATE=${!livevar-${EGIT_COMMIT_DATE}};
  471. [[ -n ${!livevar} ]] && ewarn "Using ${livevar}, no support will be provided";
  472. if [[ -n ${EGIT_COMMIT} && -n ${EGIT_COMMIT_DATE} ]]; then
  473. die "EGIT_COMMIT and EGIT_COMMIT_DATE can not be specified simultaneously";
  474. fi
  475. }
  476. _git-r3_is_local_repo ()
  477. {
  478. debug-print-function ${FUNCNAME} "$@";
  479. local uri=${1};
  480. [[ ${uri} == file://* || ${uri} == /* ]]
  481. }
  482. _git-r3_set_gitdir ()
  483. {
  484. debug-print-function ${FUNCNAME} "$@";
  485. local repo_name=${1#*://*/};
  486. repo_name=${repo_name%/};
  487. case "${repo_name}" in
  488. browse/*)
  489. repo_name=${repo_name#browse/}
  490. ;;
  491. cgit/*)
  492. repo_name=${repo_name#cgit/}
  493. ;;
  494. git/*)
  495. repo_name=${repo_name#git/}
  496. ;;
  497. gitroot/*)
  498. repo_name=${repo_name#gitroot/}
  499. ;;
  500. p/*)
  501. repo_name=${repo_name#p/}
  502. ;;
  503. pub/scm/*)
  504. repo_name=${repo_name#pub/scm/}
  505. ;;
  506. esac;
  507. repo_name=${repo_name%.git}.git;
  508. repo_name=${repo_name//\//_};
  509. local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}};
  510. : "${EGIT3_STORE_DIR:=${distdir}/git3-src}";
  511. GIT_DIR=${EGIT3_STORE_DIR}/${repo_name};
  512. EVCS_STORE_DIRS+=("${GIT_DIR}");
  513. if [[ ! -d ${EGIT3_STORE_DIR} && ! -n ${EVCS_OFFLINE} ]]; then
  514. ( addwrite /;
  515. mkdir -p "${EGIT3_STORE_DIR}" ) || die "Unable to create ${EGIT3_STORE_DIR}";
  516. fi;
  517. addwrite "${EGIT3_STORE_DIR}";
  518. if [[ ! -d ${GIT_DIR} ]]; then
  519. if [[ -n ${EVCS_OFFLINE} ]]; then
  520. eerror "A clone of the following repository is required to proceed:";
  521. eerror " ${1}";
  522. eerror "However, networking activity has been disabled using EVCS_OFFLINE and there";
  523. eerror "is no local clone available.";
  524. die "No local clone of ${1}. Unable to proceed with EVCS_OFFLINE.";
  525. fi;
  526. local saved_umask;
  527. if [[ -n ${EVCS_UMASK} ]]; then
  528. saved_umask=$(umask);
  529. umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}";
  530. fi;
  531. mkdir "${GIT_DIR}" || die;
  532. git init --bare -b __init__ || die;
  533. if [[ -n ${saved_umask} ]]; then
  534. umask "${saved_umask}" || die;
  535. fi;
  536. fi
  537. }
  538. _git-r3_set_submodules ()
  539. {
  540. debug-print-function ${FUNCNAME} "$@";
  541. local parent_path=${1};
  542. local data=${2};
  543. [[ -z ${parent_path} || ${parent_path} == */ ]] || die;
  544. submodules=();
  545. local l;
  546. while read l; do
  547. [[ ${l} == submodule.*.url=* ]] || continue;
  548. l=${l#submodule.};
  549. local subname=${l%%.url=*};
  550. local is_manually_specified=;
  551. if declare -p EGIT_SUBMODULES &> /dev/null; then
  552. local p l_res res=;
  553. for p in "${EGIT_SUBMODULES[@]}";
  554. do
  555. if [[ ${p} == -* ]]; then
  556. p=${p#-};
  557. l_res=;
  558. else
  559. l_res=1;
  560. fi;
  561. [[ ${parent_path}${subname} == ${p} ]] && res=${l_res};
  562. done;
  563. if [[ ! -n ${res} ]]; then
  564. einfo "Skipping submodule ${parent_path}${subname}";
  565. continue;
  566. else
  567. einfo "Using submodule ${parent_path}${subname}";
  568. is_manually_specified=1;
  569. fi;
  570. fi;
  571. local upd=$(echo "${data}" | git config -f /dev/fd/0 submodule."${subname}".update);
  572. [[ ${upd} == none && ! -n ${is_manually_specified} ]] && continue;
  573. local enc_subname=${subname//[^a-zA-Z0-9-]/_};
  574. submodules+=("${enc_subname}" "$(echo "${data}" | git config -f /dev/fd/0 submodule."${subname}".url || die)" "$(echo "${data}" | git config -f /dev/fd/0 submodule."${subname}".path || die)");
  575. done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
  576. }
  577. _git-r3_set_subrepos ()
  578. {
  579. debug-print-function ${FUNCNAME} "$@";
  580. local suburl=${1};
  581. subrepos=("${@:2}");
  582. if [[ ${suburl} == ./* || ${suburl} == ../* ]]; then
  583. subrepos=("${subrepos[@]%%/}");
  584. while true; do
  585. if [[ ${suburl} == ./* ]]; then
  586. suburl=${suburl:2};
  587. else
  588. if [[ ${suburl} == ../* ]]; then
  589. suburl=${suburl:3};
  590. subrepos=("${subrepos[@]%/*}");
  591. subrepos=("${subrepos[@]%%/}");
  592. else
  593. break;
  594. fi;
  595. fi;
  596. done;
  597. subrepos=("${subrepos[@]/%//${suburl}}");
  598. else
  599. subrepos=("${suburl}");
  600. fi
  601. }
  602. _python_check_EPYTHON ()
  603. {
  604. if [[ -z ${EPYTHON} ]]; then
  605. die "EPYTHON unset, invalid call context";
  606. fi
  607. }
  608. _python_check_locale_sanity ()
  609. {
  610. local -x LC_ALL=${1};
  611. local IFS=;
  612. local lc=({a..z});
  613. local uc=({A..Z});
  614. local input="${lc[*]}${uc[*]}";
  615. local output=$(tr '[:lower:][:upper:]' '[:upper:][:lower:]' <<< "${input}");
  616. [[ ${output} == "${uc[*]}${lc[*]}" ]]
  617. }
  618. _python_check_occluded_packages ()
  619. {
  620. debug-print-function ${FUNCNAME} "$@";
  621. [[ -z ${BUILD_DIR} || ! -d ${BUILD_DIR}/install ]] && return;
  622. local sitedir="${BUILD_DIR}/install$(python_get_sitedir)";
  623. [[ ${sitedir} -ef . ]] && return;
  624. local f fn diff l;
  625. for f in "${sitedir}"/*/;
  626. do
  627. f=${f%/};
  628. fn=${f##*/};
  629. [[ ${fn} == *.dist-info || ${fn} == *.egg-info ]] && continue;
  630. if [[ -d ${fn} ]]; then
  631. diff=$(comm -1 -3 <(find "${fn}" -type f -not -path '*/__pycache__/*' | sort
  632. assert) <(cd "${sitedir}" && find "${fn}" -type f -not -path '*/__pycache__/*' | sort
  633. assert));
  634. if [[ -n ${diff} ]]; then
  635. eqawarn "The directory ${fn} occludes package installed for ${EPYTHON}.";
  636. eqawarn "The installed package includes additional files:";
  637. eqawarn;
  638. while IFS= read -r l; do
  639. eqawarn " ${l}";
  640. done <<< "${diff}";
  641. eqawarn;
  642. if [[ ! -n ${_PYTHON_WARNED_OCCLUDED_PACKAGES} ]]; then
  643. eqawarn "For more information on occluded packages, please see:";
  644. eqawarn "https://projects.gentoo.org/python/guide/test.html#importerrors-for-c-extensions";
  645. _PYTHON_WARNED_OCCLUDED_PACKAGES=1;
  646. fi;
  647. fi;
  648. fi;
  649. done
  650. }
  651. _python_export ()
  652. {
  653. debug-print-function ${FUNCNAME} "$@";
  654. local impl var;
  655. case "${1}" in
  656. python* | jython*)
  657. impl=${1/_/.};
  658. shift
  659. ;;
  660. pypy | pypy3)
  661. impl=${1};
  662. shift
  663. ;;
  664. *)
  665. impl=${EPYTHON};
  666. if [[ -z ${impl} ]]; then
  667. die "_python_export called without a python implementation and EPYTHON is unset";
  668. fi
  669. ;;
  670. esac;
  671. debug-print "${FUNCNAME}: implementation: ${impl}";
  672. for var in "$@";
  673. do
  674. case "${var}" in
  675. EPYTHON)
  676. export EPYTHON=${impl};
  677. debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
  678. ;;
  679. PYTHON)
  680. export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl};
  681. debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
  682. ;;
  683. PYTHON_STDLIB)
  684. [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it";
  685. PYTHON_STDLIB=$("${PYTHON}" - "${EPREFIX}/usr" <<-EOF ||
  686. import sys, sysconfig
  687. print(sysconfig.get_path("stdlib", vars={"installed_base": sys.argv[1]}))
  688. EOF
  689. die);
  690. export PYTHON_STDLIB;
  691. debug-print "${FUNCNAME}: PYTHON_STDLIB = ${PYTHON_STDLIB}"
  692. ;;
  693. PYTHON_SITEDIR)
  694. [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it";
  695. PYTHON_SITEDIR=$("${PYTHON}" - "${EPREFIX}/usr" <<-EOF ||
  696. import sys, sysconfig
  697. print(sysconfig.get_path("purelib", vars={"base": sys.argv[1]}))
  698. EOF
  699. die);
  700. export PYTHON_SITEDIR;
  701. debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
  702. ;;
  703. PYTHON_INCLUDEDIR)
  704. [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it";
  705. PYTHON_INCLUDEDIR=$("${PYTHON}" - "${ESYSROOT}/usr" <<-EOF ||
  706. import sys, sysconfig
  707. print(sysconfig.get_path("platinclude", vars={"installed_platbase": sys.argv[1]}))
  708. EOF
  709. die);
  710. export PYTHON_INCLUDEDIR;
  711. debug-print "${FUNCNAME}: PYTHON_INCLUDEDIR = ${PYTHON_INCLUDEDIR}";
  712. if [[ ! -d ${PYTHON_INCLUDEDIR} ]]; then
  713. die "${impl} does not install any header files!";
  714. fi
  715. ;;
  716. PYTHON_LIBPATH)
  717. [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it";
  718. PYTHON_LIBPATH=$("${PYTHON}" - <<-EOF ||
  719. import os.path, sysconfig
  720. print(
  721. os.path.join(
  722. sysconfig.get_config_var("LIBDIR"),
  723. sysconfig.get_config_var("LDLIBRARY"))
  724. if sysconfig.get_config_var("LDLIBRARY")
  725. else "")
  726. EOF
  727. die);
  728. export PYTHON_LIBPATH;
  729. debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}";
  730. if [[ ! -n ${PYTHON_LIBPATH} ]]; then
  731. die "${impl} lacks a (usable) dynamic library";
  732. fi
  733. ;;
  734. PYTHON_CFLAGS)
  735. local val;
  736. case "${impl}" in
  737. python*)
  738. val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-}) || die
  739. ;;
  740. *)
  741. die "${impl}: obtaining ${var} not supported"
  742. ;;
  743. esac;
  744. export PYTHON_CFLAGS=${val};
  745. debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}"
  746. ;;
  747. PYTHON_LIBS)
  748. local val;
  749. case "${impl}" in
  750. python*)
  751. val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-}-embed) || die
  752. ;;
  753. *)
  754. die "${impl}: obtaining ${var} not supported"
  755. ;;
  756. esac;
  757. export PYTHON_LIBS=${val};
  758. debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
  759. ;;
  760. PYTHON_CONFIG)
  761. local flags val;
  762. case "${impl}" in
  763. python*)
  764. [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it";
  765. flags=$("${PYTHON}" - <<-EOF ||
  766. import sysconfig
  767. print(sysconfig.get_config_var("ABIFLAGS")
  768. or "")
  769. EOF
  770. die);
  771. val=${PYTHON}${flags}-config
  772. ;;
  773. *)
  774. die "${impl}: obtaining ${var} not supported"
  775. ;;
  776. esac;
  777. export PYTHON_CONFIG=${val};
  778. debug-print "${FUNCNAME}: PYTHON_CONFIG = ${PYTHON_CONFIG}"
  779. ;;
  780. PYTHON_PKG_DEP)
  781. local d;
  782. case ${impl} in
  783. python*)
  784. PYTHON_PKG_DEP="dev-lang/python:${impl#python}"
  785. ;;
  786. pypy3)
  787. PYTHON_PKG_DEP="dev-python/${impl}:="
  788. ;;
  789. *)
  790. die "Invalid implementation: ${impl}"
  791. ;;
  792. esac;
  793. if [[ -n ${PYTHON_REQ_USE} ]]; then
  794. PYTHON_PKG_DEP+=[${PYTHON_REQ_USE}];
  795. fi;
  796. export PYTHON_PKG_DEP;
  797. debug-print "${FUNCNAME}: PYTHON_PKG_DEP = ${PYTHON_PKG_DEP}"
  798. ;;
  799. PYTHON_SCRIPTDIR)
  800. local dir;
  801. export PYTHON_SCRIPTDIR=${EPREFIX}/usr/lib/python-exec/${impl};
  802. debug-print "${FUNCNAME}: PYTHON_SCRIPTDIR = ${PYTHON_SCRIPTDIR}"
  803. ;;
  804. *)
  805. die "_python_export: unknown variable ${var}"
  806. ;;
  807. esac;
  808. done
  809. }
  810. _python_impl_matches ()
  811. {
  812. [[ ${#} -ge 1 ]] || die "${FUNCNAME}: takes at least 1 parameter";
  813. [[ ${#} -eq 1 ]] && return 0;
  814. local impl=${1/./_} pattern;
  815. shift;
  816. for pattern in "$@";
  817. do
  818. case ${pattern} in
  819. -2 | python2* | pypy)
  820. if [[ ${EAPI} != 7 ]]; then
  821. eerror;
  822. eerror "Python 2 is no longer supported in Gentoo, please remove Python 2";
  823. eerror "${FUNCNAME[1]} calls.";
  824. die "Passing ${pattern} to ${FUNCNAME[1]} is banned in EAPI ${EAPI}";
  825. fi
  826. ;;
  827. -3)
  828. if [[ ${EAPI} != 7 ]]; then
  829. eerror;
  830. eerror "Python 2 is no longer supported in Gentoo, please remove Python 2";
  831. eerror "${FUNCNAME[1]} calls.";
  832. die "Passing ${pattern} to ${FUNCNAME[1]} is banned in EAPI ${EAPI}";
  833. fi;
  834. return 0
  835. ;;
  836. 3.10)
  837. [[ ${impl} == python${pattern/./_} || ${impl} == pypy3 ]] && return 0
  838. ;;
  839. 3.8 | 3.9 | 3.1[1-3])
  840. [[ ${impl} == python${pattern/./_} ]] && return 0
  841. ;;
  842. *)
  843. [[ ${impl} == ${pattern/./_} ]] && return 0
  844. ;;
  845. esac;
  846. done;
  847. return 1
  848. }
  849. _python_run_check_deps ()
  850. {
  851. debug-print-function ${FUNCNAME} "$@";
  852. local impl=${1};
  853. einfo "Checking whether ${impl} is suitable ...";
  854. local PYTHON_PKG_DEP;
  855. _python_export "${impl}" PYTHON_PKG_DEP;
  856. ebegin " ${PYTHON_PKG_DEP}";
  857. has_version -b "${PYTHON_PKG_DEP}";
  858. eend ${?} || return 1;
  859. declare -f python_check_deps > /dev/null || return 0;
  860. local PYTHON_USEDEP="python_targets_${impl}(-)";
  861. local PYTHON_SINGLE_USEDEP="python_single_target_${impl}(-)";
  862. ebegin " python_check_deps";
  863. python_check_deps;
  864. eend ${?}
  865. }
  866. _python_sanity_checks ()
  867. {
  868. debug-print-function ${FUNCNAME} "$@";
  869. [[ -n ${_PYTHON_SANITY_CHECKED} ]] && return;
  870. if [[ -v PYTHONPATH ]]; then
  871. local x paths=();
  872. mapfile -d ':' -t paths <<< ${PYTHONPATH};
  873. for x in "${paths[@]}";
  874. do
  875. if [[ ${x} != /* ]]; then
  876. eerror "Relative path found in PYTHONPATH:";
  877. eerror;
  878. eerror " PYTHONPATH=${PYTHONPATH@Q}";
  879. eerror;
  880. eerror "This is guaranteed to cause random breakage. Please make sure that";
  881. eerror "your PYTHONPATH contains absolute paths only (and only if necessary).";
  882. eerror "Note that empty values (including ':' at either end and an empty";
  883. eerror "PYTHONPATH) count as the current directory. If no PYTHONPATH";
  884. eerror "is intended, it needs to be unset instead.";
  885. die "Relative paths in PYTHONPATH are forbidden: ${x@Q}";
  886. fi;
  887. done;
  888. elog "PYTHONPATH=${PYTHONPATH@Q}";
  889. fi;
  890. _PYTHON_SANITY_CHECKED=1
  891. }
  892. _python_set_impls ()
  893. {
  894. local i;
  895. if [[ ${BASH_VERSINFO[0]} -ge 5 ]]; then
  896. [[ ${PYTHON_COMPAT@a} == *a* ]];
  897. else
  898. [[ $(declare -p PYTHON_COMPAT) == "declare -a"* ]];
  899. fi;
  900. if [[ ${?} -ne 0 ]]; then
  901. if ! declare -p PYTHON_COMPAT &> /dev/null; then
  902. die 'PYTHON_COMPAT not declared.';
  903. else
  904. die 'PYTHON_COMPAT must be an array.';
  905. fi;
  906. fi;
  907. local obsolete=();
  908. if [[ ! -n ${PYTHON_COMPAT_NO_STRICT} ]]; then
  909. for i in "${PYTHON_COMPAT[@]}";
  910. do
  911. case ${i} in
  912. pypy3 | python3_9 | python3_1[0-3])
  913.  
  914. ;;
  915. jython2_7 | pypy | pypy1_[89] | pypy2_0 | python2_[5-7] | python3_[1-9])
  916. obsolete+=("${i}")
  917. ;;
  918. *)
  919. if has "${i}" "${_PYTHON_ALL_IMPLS[@]}" "${_PYTHON_HISTORICAL_IMPLS[@]}"; then
  920. die "Mis-synced patterns in _python_set_impls: missing ${i}";
  921. else
  922. die "Invalid implementation in PYTHON_COMPAT: ${i}";
  923. fi
  924. ;;
  925. esac;
  926. done;
  927. fi;
  928. local supp=() unsupp=();
  929. for i in "${_PYTHON_ALL_IMPLS[@]}";
  930. do
  931. if has "${i}" "${PYTHON_COMPAT[@]}"; then
  932. supp+=("${i}");
  933. else
  934. unsupp+=("${i}");
  935. fi;
  936. done;
  937. if [[ ! -n ${supp[@]} ]]; then
  938. die "No supported implementation in PYTHON_COMPAT.";
  939. fi;
  940. if [[ -n ${_PYTHON_SUPPORTED_IMPLS[@]} ]]; then
  941. if [[ ${_PYTHON_SUPPORTED_IMPLS[@]} != ${supp[@]} ]]; then
  942. eerror "Supported impls (PYTHON_COMPAT) changed between inherits!";
  943. eerror "Before: ${_PYTHON_SUPPORTED_IMPLS[*]}";
  944. eerror "Now : ${supp[*]}";
  945. die "_PYTHON_SUPPORTED_IMPLS integrity check failed";
  946. fi;
  947. if [[ ${_PYTHON_UNSUPPORTED_IMPLS[@]} != ${unsupp[@]} ]]; then
  948. eerror "Unsupported impls changed between inherits!";
  949. eerror "Before: ${_PYTHON_UNSUPPORTED_IMPLS[*]}";
  950. eerror "Now : ${unsupp[*]}";
  951. die "_PYTHON_UNSUPPORTED_IMPLS integrity check failed";
  952. fi;
  953. else
  954. _PYTHON_SUPPORTED_IMPLS=("${supp[@]}");
  955. _PYTHON_UNSUPPORTED_IMPLS=("${unsupp[@]}");
  956. readonly _PYTHON_SUPPORTED_IMPLS _PYTHON_UNSUPPORTED_IMPLS;
  957. fi
  958. }
  959. _python_verify_patterns ()
  960. {
  961. debug-print-function ${FUNCNAME} "$@";
  962. local impl pattern;
  963. for pattern in "$@";
  964. do
  965. case ${pattern} in
  966. -[23] | 3.[89] | 3.1[0-3])
  967. continue
  968. ;;
  969. esac;
  970. for impl in "${_PYTHON_ALL_IMPLS[@]}" "${_PYTHON_HISTORICAL_IMPLS[@]}";
  971. do
  972. [[ ${impl} == ${pattern/./_} ]] && continue 2;
  973. done;
  974. die "Invalid implementation pattern: ${pattern}";
  975. done
  976. }
  977. _python_wrapper_setup ()
  978. {
  979. debug-print-function ${FUNCNAME} "$@";
  980. local workdir=${1:-${T}/${EPYTHON}};
  981. local impl=${2:-${EPYTHON}};
  982. [[ -n ${workdir} ]] || die "${FUNCNAME}: no workdir specified.";
  983. [[ -n ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified.";
  984. if [[ ! -x ${workdir}/bin/python ]]; then
  985. mkdir -p "${workdir}"/{bin,pkgconfig} || die;
  986. rm -f "${workdir}"/bin/python{,2,3}{,-config} || die;
  987. rm -f "${workdir}"/bin/2to3 || die;
  988. rm -f "${workdir}"/pkgconfig/python{2,3}{,-embed}.pc || die;
  989. local EPYTHON PYTHON;
  990. _python_export "${impl}" EPYTHON PYTHON;
  991. cat > "${workdir}/bin/python" <<-_EOF_ ||
  992. #!/bin/sh
  993. exec "${PYTHON}" "\${@}"
  994. _EOF_
  995. die
  996. cp "${workdir}/bin/python" "${workdir}/bin/python3" || die;
  997. chmod +x "${workdir}/bin/python" "${workdir}/bin/python3" || die;
  998. local nonsupp=(python2 python2-config);
  999. if [[ ${EPYTHON} == python* ]]; then
  1000. cat > "${workdir}/bin/python-config" <<-_EOF_ ||
  1001. #!/bin/sh
  1002. exec "${PYTHON}-config" "\${@}"
  1003. _EOF_
  1004. die
  1005. cp "${workdir}/bin/python-config" "${workdir}/bin/python3-config" || die;
  1006. chmod +x "${workdir}/bin/python-config" "${workdir}/bin/python3-config" || die;
  1007. ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die;
  1008. ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc "${workdir}"/pkgconfig/python3.pc || die;
  1009. ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}-embed.pc "${workdir}"/pkgconfig/python3-embed.pc || die;
  1010. else
  1011. nonsupp+=(2to3 python-config python3-config);
  1012. fi;
  1013. local x;
  1014. for x in "${nonsupp[@]}";
  1015. do
  1016. cat > "${workdir}"/bin/${x} <<-_EOF_ ||
  1017. #!/bin/sh
  1018. echo "${ECLASS}: ${FUNCNAME}: ${x} is not supported by ${EPYTHON} (PYTHON_COMPAT)" >&2
  1019. exit 127
  1020. _EOF_
  1021. die
  1022. chmod +x "${workdir}"/bin/${x} || die;
  1023. done;
  1024. fi;
  1025. if [[ ${PATH##:*} != ${workdir}/bin ]]; then
  1026. PATH=${workdir}/bin${PATH:+:${PATH}};
  1027. fi;
  1028. if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
  1029. PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}};
  1030. fi;
  1031. export PATH PKG_CONFIG_PATH
  1032. }
  1033. _tc-getPROG ()
  1034. {
  1035. local tuple=$1;
  1036. local v var vars=$2;
  1037. local prog=($3);
  1038. var=${vars%% *};
  1039. for v in ${vars};
  1040. do
  1041. if [[ -n ${!v} ]]; then
  1042. export ${var}="${!v}";
  1043. echo "${!v}";
  1044. return 0;
  1045. fi;
  1046. done;
  1047. local search=;
  1048. [[ -n $4 ]] && search=$(type -p $4-${prog[0]});
  1049. [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p ${!tuple}-${prog[0]});
  1050. [[ -n ${search} ]] && prog[0]=${search##*/};
  1051. export ${var}="${prog[*]}";
  1052. echo "${!var}"
  1053. }
  1054. _tc-has-openmp ()
  1055. {
  1056. local base="${T}/test-tc-openmp";
  1057. cat <<-EOF > "${base}.c"
  1058. #include <omp.h>
  1059. int main(void) {
  1060. int nthreads, tid, ret = 0;
  1061. #pragma omp parallel private(nthreads, tid)
  1062. {
  1063. tid = omp_get_thread_num();
  1064. nthreads = omp_get_num_threads();
  1065. ret += tid + nthreads;
  1066. }
  1067. return ret;
  1068. }
  1069. EOF
  1070.  
  1071. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null;
  1072. local ret=$?;
  1073. rm -f "${base}"*;
  1074. return ${ret}
  1075. }
  1076. build_sphinx ()
  1077. {
  1078. debug-print-function ${FUNCNAME} "$@";
  1079. [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes 1 arg: <directory>";
  1080. local dir=${1};
  1081. sed -i -e 's:^intersphinx_mapping:disabled_&:' "${dir}"/conf.py || die;
  1082. local command=("${EPYTHON}" -m sphinx.cmd.build);
  1083. if ! "${EPYTHON}" -c "import sphinx.cmd.build" 2> /dev/null; then
  1084. command=(sphinx-build);
  1085. fi;
  1086. command+=(-b html -d "${dir}"/_build/doctrees "${dir}" "${dir}"/_build/html);
  1087. echo "${command[@]}" 1>&2;
  1088. "${command[@]}" || die;
  1089. HTML_DOCS+=("${dir}/_build/html/.")
  1090. }
  1091. check_extra_config ()
  1092. {
  1093. use kernel_linux || return;
  1094. local config negate die error reworkmodulenames;
  1095. local soft_errors_count=0 hard_errors_count=0 config_required=0;
  1096. local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}";
  1097. linux-info_get_any_version;
  1098. for config in ${CONFIG_CHECK};
  1099. do
  1100. if [[ "${config:0:1}" != "~" ]]; then
  1101. config_required=1;
  1102. break;
  1103. fi;
  1104. done;
  1105. if [[ ${config_required} == 0 ]]; then
  1106. if ! linux_config_exists; then
  1107. ewarn "Unable to check for the following kernel config options due";
  1108. ewarn "to absence of any configured kernel sources or compiled";
  1109. ewarn "config:";
  1110. for config in ${CONFIG_CHECK};
  1111. do
  1112. config=${config#\~};
  1113. config=${config#\!};
  1114. local_error="ERROR_${config}";
  1115. msg="${!local_error}";
  1116. if [[ -z ${msg} ]]; then
  1117. local_error="WARNING_${config}";
  1118. msg="${!local_error}";
  1119. fi;
  1120. ewarn " - ${config}${msg:+ - }${msg}";
  1121. done;
  1122. ewarn "You're on your own to make sure they are set if needed.";
  1123. export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}";
  1124. return 0;
  1125. fi;
  1126. else
  1127. if ! linux_config_exists; then
  1128. qeerror "Could not find a neither a usable .config in the kernel source directory";
  1129. qeerror "nor a /proc/config.gz file,";
  1130. qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources.";
  1131. qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that";
  1132. qeerror "it points to the necessary object directory so that it might find .config";
  1133. qeerror "or have a properly configured kernel to produce a config.gz file. (CONFIG_IKCONFIG).";
  1134. die "Kernel not configured; no .config found in ${KV_OUT_DIR} or /proc/config.gz found";
  1135. fi;
  1136. fi;
  1137. ebegin "Checking for suitable kernel configuration options";
  1138. for config in ${CONFIG_CHECK};
  1139. do
  1140. die=1;
  1141. error=0;
  1142. negate=0;
  1143. reworkmodulenames=0;
  1144. if [[ ${config:0:1} == "~" ]]; then
  1145. die=0;
  1146. config=${config:1};
  1147. else
  1148. if [[ ${config:0:1} == "@" ]]; then
  1149. die=0;
  1150. reworkmodulenames=1;
  1151. config=${config:1};
  1152. fi;
  1153. fi;
  1154. if [[ ${config:0:1} == "!" ]]; then
  1155. negate=1;
  1156. config=${config:1};
  1157. fi;
  1158. if [[ ${negate} == 1 ]]; then
  1159. linux_chkconfig_present ${config} && error=2;
  1160. else
  1161. if [[ ${reworkmodulenames} == 1 ]]; then
  1162. local temp_config="${config//*:}" i n;
  1163. config="${config//:*}";
  1164. if linux_chkconfig_present ${config}; then
  1165. for i in ${MODULE_NAMES};
  1166. do
  1167. n="${i//${temp_config}}";
  1168. [[ -z ${n//\(*} ]] && MODULE_IGNORE="${MODULE_IGNORE} ${temp_config}";
  1169. done;
  1170. error=2;
  1171. fi;
  1172. else
  1173. linux_chkconfig_present ${config} || error=1;
  1174. fi;
  1175. fi;
  1176. if [[ ${error} -gt 0 ]]; then
  1177. local report_func="eerror" local_error;
  1178. local_error="ERROR_${config}";
  1179. local_error="${!local_error}";
  1180. if [[ -z "${local_error}" ]]; then
  1181. local_error="${config}_ERROR";
  1182. local_error="${!local_error}";
  1183. fi;
  1184. if [[ ${die} == 0 && -z "${local_error}" ]]; then
  1185. local_error="WARNING_${config}";
  1186. local_error="${!local_error}";
  1187. if [[ -n "${local_error}" ]]; then
  1188. report_func="ewarn";
  1189. fi;
  1190. fi;
  1191. if [[ -z "${local_error}" ]]; then
  1192. [[ ${error} == 1 ]] && local_error="is not set when it should be." || local_error="should not be set. But it is.";
  1193. local_error="CONFIG_${config}:\t ${local_error}";
  1194. fi;
  1195. if [[ ${die} == 0 ]]; then
  1196. ${report_func} " ${local_error}";
  1197. soft_errors_count=$[soft_errors_count + 1];
  1198. else
  1199. ${report_func} " ${local_error}";
  1200. hard_errors_count=$[hard_errors_count + 1];
  1201. fi;
  1202. fi;
  1203. done;
  1204. if [[ ${hard_errors_count} -gt 0 ]]; then
  1205. eend 1;
  1206. eerror "Please check to make sure these options are set correctly.";
  1207. eerror "Failure to do so may cause unexpected problems.";
  1208. eerror "Once you have satisfied these options, please try merging";
  1209. eerror "this package again.";
  1210. export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}";
  1211. die "Incorrect kernel configuration options";
  1212. else
  1213. if [[ ${soft_errors_count} -gt 0 ]]; then
  1214. eend 1;
  1215. ewarn "Please check to make sure these options are set correctly.";
  1216. ewarn "Failure to do so may cause unexpected problems.";
  1217. else
  1218. eend 0;
  1219. fi;
  1220. fi;
  1221. export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
  1222. }
  1223. check_kernel_built ()
  1224. {
  1225. if ! use kernel_linux; then
  1226. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  1227. fi;
  1228. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  1229. require_configured_kernel;
  1230. local versionh_path;
  1231. if kernel_is -ge 3 7; then
  1232. versionh_path="include/generated/uapi/linux/version.h";
  1233. else
  1234. versionh_path="include/linux/version.h";
  1235. fi;
  1236. if [[ ! -f "${KV_OUT_DIR}/${versionh_path}" ]]; then
  1237. eerror "These sources have not yet been prepared.";
  1238. eerror "We cannot build against an unprepared tree.";
  1239. eerror "To resolve this, please type the following:";
  1240. eerror;
  1241. eerror "# cd ${KV_DIR}";
  1242. eerror "# make oldconfig";
  1243. eerror "# make modules_prepare";
  1244. eerror;
  1245. eerror "Then please try merging this module again.";
  1246. die "Kernel sources need compiling first";
  1247. fi
  1248. }
  1249. check_modules_supported ()
  1250. {
  1251. if ! use kernel_linux; then
  1252. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  1253. fi;
  1254. require_configured_kernel;
  1255. if ! linux_chkconfig_builtin "MODULES"; then
  1256. eerror "These sources do not support loading external modules.";
  1257. eerror "to be able to use this module please enable \"Loadable modules support\"";
  1258. eerror "in your kernel, recompile and then try merging this module again.";
  1259. die "No support for external modules in ${KV_FULL} config";
  1260. fi
  1261. }
  1262. check_zlibinflate ()
  1263. {
  1264. if ! use kernel_linux; then
  1265. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  1266. fi;
  1267. require_configured_kernel;
  1268. local INFLATE;
  1269. local DEFLATE;
  1270. einfo "Determining the usability of ZLIB_INFLATE support in your kernel";
  1271. ebegin "checking ZLIB_INFLATE";
  1272. linux_chkconfig_builtin CONFIG_ZLIB_INFLATE;
  1273. eend $? || die;
  1274. ebegin "checking ZLIB_DEFLATE";
  1275. linux_chkconfig_builtin CONFIG_ZLIB_DEFLATE;
  1276. eend $? || die;
  1277. local LINENO_START;
  1278. local LINENO_END;
  1279. local SYMBOLS;
  1280. local x;
  1281. LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)";
  1282. LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)";
  1283. (( LINENO_AMOUNT = ${LINENO_END} - ${LINENO_START} ));
  1284. (( LINENO_END = ${LINENO_END} - 1 ));
  1285. SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')";
  1286. for x in ${SYMBOLS};
  1287. do
  1288. if [[ "${!x}" = "y" ]]; then
  1289. einfo "${x} ensures zlib is linked into your kernel - excellent";
  1290. return 0;
  1291. fi;
  1292. done;
  1293. eerror;
  1294. eerror "This kernel module requires ZLIB library support.";
  1295. eerror "You have enabled zlib support in your kernel, but haven't enabled";
  1296. eerror "enabled any option that will ensure that zlib is linked into your";
  1297. eerror "kernel.";
  1298. eerror;
  1299. eerror "Please ensure that you enable at least one of these options:";
  1300. eerror;
  1301. for x in ${SYMBOLS};
  1302. do
  1303. eerror " * $x";
  1304. done;
  1305. eerror;
  1306. eerror "Please remember to recompile and install your kernel, and reboot";
  1307. eerror "into your new kernel before attempting to load this kernel module.";
  1308. die "Kernel doesn't include zlib support"
  1309. }
  1310. clang-fullversion ()
  1311. {
  1312. _clang_fullversion '$1.$2.$3' "$@"
  1313. }
  1314. clang-major-version ()
  1315. {
  1316. _clang_fullversion '$1' "$@"
  1317. }
  1318. clang-micro-version ()
  1319. {
  1320. _clang_fullversion '$3' "$@"
  1321. }
  1322. clang-minor-version ()
  1323. {
  1324. _clang_fullversion '$2' "$@"
  1325. }
  1326. clang-version ()
  1327. {
  1328. _clang_fullversion '$1.$2' "$@"
  1329. }
  1330. dist-kernel_PV_to_KV ()
  1331. {
  1332. debug-print-function ${FUNCNAME} "$@";
  1333. [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments";
  1334. local pv=${1};
  1335. local kv=${pv%%_*};
  1336. [[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0";
  1337. [[ ${pv} == *_* ]] && kv+=-${pv#*_};
  1338. echo "${kv}"
  1339. }
  1340. dist-kernel_compressed_module_cleanup ()
  1341. {
  1342. debug-print-function ${FUNCNAME} "$@";
  1343. [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments";
  1344. local path=${1};
  1345. local config_path=/usr/src/linux-${KV_FULL}/.config;
  1346. local option;
  1347. for option in config source/.config build/.config;
  1348. do
  1349. if [[ -f ${path}/${option} ]]; then
  1350. config_path=${path}/${option};
  1351. break;
  1352. fi;
  1353. done;
  1354. local preferred=;
  1355. [[ -f ${config_path} ]] && preferred=$(dist-kernel_get_module_suffix "${config_path}");
  1356. local basename suffix;
  1357. while read -r basename; do
  1358. local prev=;
  1359. for suffix in .ko .ko.gz .ko.xz .ko.zst;
  1360. do
  1361. [[ ${suffix} == ${preferred} ]] && continue;
  1362. local current=${path}/${basename}${suffix};
  1363. [[ -f ${current} ]] || continue;
  1364. if [[ -f ${path}/${basename}${preferred} ]]; then
  1365. rm -v "${current}" || die;
  1366. else
  1367. if [[ -z ${prev} ]]; then
  1368. prev=${current};
  1369. else
  1370. if [[ ${current} -nt ${prev} ]]; then
  1371. rm -v "${prev}" || die;
  1372. prev=${current};
  1373. else
  1374. rm -v "${current}" || die;
  1375. fi;
  1376. fi;
  1377. fi;
  1378. done;
  1379. done < <(cd "${path}" && find -type f \( -name '*.ko' -o -name '*.ko.gz' -o -name '*.ko.xz' -o -name '*.ko.zst' \) | sed -e 's:[.]ko\(\|[.]gz\|[.]xz\|[.]zst\)$::' | sort | uniq -d || die)
  1380. }
  1381. dist-kernel_get_image_path ()
  1382. {
  1383. case ${ARCH} in
  1384. amd64 | x86)
  1385. echo arch/x86/boot/bzImage
  1386. ;;
  1387. arm64 | riscv)
  1388. if [[ -n ${KERNEL_EFI_ZBOOT} ]]; then
  1389. echo arch/${ARCH}/boot/vmlinuz.efi;
  1390. else
  1391. echo arch/${ARCH}/boot/Image.gz;
  1392. fi
  1393. ;;
  1394. loong)
  1395. if [[ -n ${KERNEL_EFI_ZBOOT} ]]; then
  1396. echo arch/loongarch/boot/vmlinuz.efi;
  1397. else
  1398. echo arch/loongarch/boot/vmlinux.elf;
  1399. fi
  1400. ;;
  1401. arm)
  1402. echo arch/arm/boot/zImage
  1403. ;;
  1404. hppa | ppc | ppc64 | sparc)
  1405. echo ./vmlinux
  1406. ;;
  1407. *)
  1408. die "${FUNCNAME}: unsupported ARCH=${ARCH}"
  1409. ;;
  1410. esac
  1411. }
  1412. dist-kernel_get_module_suffix ()
  1413. {
  1414. debug-print-function ${FUNCNAME} "$@";
  1415. [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments";
  1416. local config=${1};
  1417. if ! in_iuse modules-compress || ! use modules-compress; then
  1418. echo .ko;
  1419. else
  1420. if [[ ! -r ${config} ]]; then
  1421. die "Cannot find kernel config ${config}";
  1422. else
  1423. if grep -q "CONFIG_MODULE_COMPRESS_NONE=y" "${config}"; then
  1424. echo .ko;
  1425. else
  1426. if grep -q "CONFIG_MODULE_COMPRESS_GZIP=y" "${config}"; then
  1427. echo .ko.gz;
  1428. else
  1429. if grep -q "CONFIG_MODULE_COMPRESS_XZ=y" "${config}"; then
  1430. echo .ko.xz;
  1431. else
  1432. if grep -q "CONFIG_MODULE_COMPRESS_ZSTD=y" "${config}"; then
  1433. echo .ko.zst;
  1434. else
  1435. die "Module compression is enabled, but compressor not known";
  1436. fi;
  1437. fi;
  1438. fi;
  1439. fi;
  1440. fi;
  1441. fi
  1442. }
  1443. dist-kernel_install_kernel ()
  1444. {
  1445. debug-print-function ${FUNCNAME} "$@";
  1446. [[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments";
  1447. local version=${1};
  1448. local image=${2};
  1449. local map=${3};
  1450. local success=;
  1451. while true; do
  1452. nonfatal mount-boot_check_status || break;
  1453. ebegin "Installing the kernel via installkernel";
  1454. ARCH=$(tc-arch-kernel) installkernel "${version}" "${image}" "${map}" || break;
  1455. eend ${?} || die -n "Installing the kernel failed";
  1456. success=1;
  1457. break;
  1458. done;
  1459. if [[ ! -n ${success} ]]; then
  1460. local kernel="<name of your kernel pakcage>:<kernel version>";
  1461. local k_id_file=${image%$(dist-kernel_get_image_path)}/dist-kernel;
  1462. if [[ -f ${k_id_file} ]]; then
  1463. kernel=\'\=$(< ${k_id_file})\';
  1464. fi;
  1465. eerror;
  1466. eerror "The kernel was not deployed successfully. Inspect the failure";
  1467. eerror "in the logs above and once you resolve the problems please";
  1468. eerror "run the equivalent of the following command to try again:";
  1469. eerror;
  1470. eerror " emerge --config ${kernel}";
  1471. die "Kernel install failed, please fix the problems and run emerge --config";
  1472. fi
  1473. }
  1474. dist-kernel_reinstall_initramfs ()
  1475. {
  1476. debug-print-function ${FUNCNAME} "$@";
  1477. [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments";
  1478. local kernel_dir=${1};
  1479. local ver=${2};
  1480. local image_path=${kernel_dir}/$(dist-kernel_get_image_path);
  1481. if [[ ! -f ${image_path} ]]; then
  1482. eerror "Kernel install missing, image not found:";
  1483. eerror " ${image_path}";
  1484. eerror "Initramfs will not be updated. Please reinstall your kernel.";
  1485. return;
  1486. fi;
  1487. dist-kernel_install_kernel "${ver}" "${image_path}" "${kernel_dir}/System.map"
  1488. }
  1489. dlopen_lib ()
  1490. {
  1491. case "${CHOST}" in
  1492. *-linux-gnu* | *-linux-uclibc)
  1493. echo "-ldl"
  1494. ;;
  1495. esac
  1496. }
  1497. eapply ()
  1498. {
  1499. local failed patch_cmd=patch;
  1500. local -x LC_COLLATE=POSIX;
  1501. type -P gpatch > /dev/null && patch_cmd=gpatch;
  1502. function _eapply_patch ()
  1503. {
  1504. local f=${1};
  1505. local prefix=${2};
  1506. ebegin "${prefix:-Applying }${f##*/}";
  1507. local all_opts=(-p1 -f -g0 --no-backup-if-mismatch "${patch_options[@]}");
  1508. if ${patch_cmd} "${all_opts[@]}" --dry-run -s -F0 < "${f}" &> /dev/null; then
  1509. all_opts+=(-s -F0);
  1510. fi;
  1511. ${patch_cmd} "${all_opts[@]}" < "${f}";
  1512. failed=${?};
  1513. if ! eend "${failed}"; then
  1514. __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}";
  1515. fi
  1516. };
  1517. local patch_options=() files=();
  1518. local i found_doublehyphen;
  1519. for ((i = 1; i <= ${#@}; ++i ))
  1520. do
  1521. if [[ ${@:i:1} == -- ]]; then
  1522. patch_options=("${@:1:i-1}");
  1523. files=("${@:i+1}");
  1524. found_doublehyphen=1;
  1525. break;
  1526. fi;
  1527. done;
  1528. if [[ -z ${found_doublehyphen} ]]; then
  1529. for ((i = 1; i <= ${#@}; ++i ))
  1530. do
  1531. if [[ ${@:i:1} != -* ]]; then
  1532. patch_options=("${@:1:i-1}");
  1533. files=("${@:i}");
  1534. break;
  1535. fi;
  1536. done;
  1537. for i in "${files[@]}";
  1538. do
  1539. if [[ ${i} == -* ]]; then
  1540. die "eapply: all options must be passed before non-options";
  1541. fi;
  1542. done;
  1543. fi;
  1544. if [[ ${#files[@]} -eq 0 ]]; then
  1545. die "eapply: no files specified";
  1546. fi;
  1547. local f;
  1548. for f in "${files[@]}";
  1549. do
  1550. if [[ -d ${f} ]]; then
  1551. function _eapply_get_files ()
  1552. {
  1553. local LC_ALL=POSIX;
  1554. local prev_shopt=$(shopt -p nullglob);
  1555. shopt -s nullglob;
  1556. local f;
  1557. for f in "${1}"/*;
  1558. do
  1559. if [[ ${f} == *.diff || ${f} == *.patch ]]; then
  1560. files+=("${f}");
  1561. fi;
  1562. done;
  1563. ${prev_shopt}
  1564. };
  1565. local files=();
  1566. _eapply_get_files "${f}";
  1567. [[ ${#files[@]} -eq 0 ]] && die "No *.{patch,diff} files in directory ${f}";
  1568. einfo "Applying patches from ${f} ...";
  1569. local f2;
  1570. for f2 in "${files[@]}";
  1571. do
  1572. _eapply_patch "${f2}" ' ';
  1573. [[ ${failed} -ne 0 ]] && return "${failed}";
  1574. done;
  1575. else
  1576. _eapply_patch "${f}";
  1577. [[ ${failed} -ne 0 ]] && return "${failed}";
  1578. fi;
  1579. done;
  1580. return 0
  1581. }
  1582. eapply_user ()
  1583. {
  1584. [[ ${EBUILD_PHASE} == prepare ]] || die "eapply_user() called during invalid phase: ${EBUILD_PHASE}";
  1585. local tagfile=${T}/.portage_user_patches_applied;
  1586. [[ -f ${tagfile} ]] && return;
  1587. >> "${tagfile}";
  1588. local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  1589. local columns=${COLUMNS:-0};
  1590. [[ ${columns} == 0 ]] && columns=$(set -- $( ( stty size < /dev/tty ) 2> /dev/null || echo 24 80); echo $2);
  1591. (( columns > 0 )) || (( columns = 80 ));
  1592. local applied d f;
  1593. local -A _eapply_user_patches;
  1594. local prev_shopt=$(shopt -p nullglob);
  1595. shopt -s nullglob;
  1596. for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},};
  1597. do
  1598. for f in "${d}"/*;
  1599. do
  1600. if [[ ( ${f} == *.diff || ${f} == *.patch ) && -z ${_eapply_user_patches[${f##*/}]} ]]; then
  1601. _eapply_user_patches[${f##*/}]=${f};
  1602. fi;
  1603. done;
  1604. done;
  1605. if [[ ${#_eapply_user_patches[@]} -gt 0 ]]; then
  1606. while read -r -d '' f; do
  1607. f=${_eapply_user_patches[${f}]};
  1608. if [[ -s ${f} ]]; then
  1609. if [[ -z ${applied} ]]; then
  1610. einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++))
  1611. do
  1612. echo -n =;
  1613. done)${PORTAGE_COLOR_NORMAL}";
  1614. einfo "Applying user patches from ${basedir} ...";
  1615. fi;
  1616. eapply "${f}";
  1617. applied=1;
  1618. fi;
  1619. done < <(printf -- '%s\0' "${!_eapply_user_patches[@]}" | LC_ALL=C sort -z);
  1620. fi;
  1621. ${prev_shopt};
  1622. if [[ -n ${applied} ]]; then
  1623. einfo "User patches applied.";
  1624. einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++))
  1625. do
  1626. echo -n =;
  1627. done)${PORTAGE_COLOR_NORMAL}";
  1628. fi
  1629. }
  1630. econf_build ()
  1631. {
  1632. local CBUILD=${CBUILD:-${CHOST}};
  1633. function econf_env ()
  1634. {
  1635. CHOST=${CBUILD} econf "$@"
  1636. };
  1637. tc-env_build econf_env "$@"
  1638. }
  1639. einstalldocs ()
  1640. {
  1641. ( if [[ $(declare -p DOCS 2> /dev/null) != *=* ]]; then
  1642. local d;
  1643. for d in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS BUGS FAQ CREDITS CHANGELOG;
  1644. do
  1645. [[ -f ${d} && -s ${d} ]] && docinto / && dodoc "${d}";
  1646. done;
  1647. else
  1648. if ___is_indexed_array_var DOCS; then
  1649. [[ ${#DOCS[@]} -gt 0 ]] && docinto / && dodoc -r "${DOCS[@]}";
  1650. else
  1651. [[ -n ${DOCS} ]] && docinto / && dodoc -r ${DOCS};
  1652. fi;
  1653. fi );
  1654. ( if ___is_indexed_array_var HTML_DOCS; then
  1655. [[ ${#HTML_DOCS[@]} -gt 0 ]] && docinto html && dodoc -r "${HTML_DOCS[@]}";
  1656. else
  1657. [[ -n ${HTML_DOCS} ]] && docinto html && dodoc -r ${HTML_DOCS};
  1658. fi )
  1659. }
  1660. epytest ()
  1661. {
  1662. debug-print-function ${FUNCNAME} "$@";
  1663. _python_check_EPYTHON;
  1664. _python_check_occluded_packages;
  1665. local color=yes;
  1666. [[ -n ${NO_COLOR} ]] && color=no;
  1667. local args=(-vv -ra -l -Wdefault -Werror::pytest.PytestUnhandledCoroutineWarning "--color=${color}" -o console_output_style=count -o tmp_path_retention_count=0 -o tmp_path_retention_policy=failed);
  1668. if [[ ! -n ${PYTEST_DISABLE_PLUGIN_AUTOLOAD} ]]; then
  1669. args+=(-p no:cov -p no:flake8 -p no:flakes -p no:pylint -p no:markdown -p no:sugar -p no:xvfb -p no:pytest-describe -p no:plus -p no:tavern -p no:salt-factories);
  1670. fi;
  1671. if [[ -n ${EPYTEST_TIMEOUT} ]]; then
  1672. if [[ ${PYTEST_PLUGINS} != *pytest_timeout* ]]; then
  1673. args+=(-p timeout);
  1674. fi;
  1675. args+=("--timeout=${EPYTEST_TIMEOUT}");
  1676. fi;
  1677. if [[ -n ${EPYTEST_XDIST} ]]; then
  1678. local jobs=${EPYTEST_JOBS:-$(makeopts_jobs)};
  1679. if [[ ${jobs} -gt 1 ]]; then
  1680. if [[ ${PYTEST_PLUGINS} != *xdist.plugin* ]]; then
  1681. args+=(-p xdist);
  1682. fi;
  1683. args+=(-n "${jobs}" --dist=worksteal);
  1684. fi;
  1685. fi;
  1686. local x;
  1687. for x in "${EPYTEST_DESELECT[@]}";
  1688. do
  1689. args+=(--deselect "${x}");
  1690. done;
  1691. for x in "${EPYTEST_IGNORE[@]}";
  1692. do
  1693. args+=(--ignore "${x}");
  1694. done;
  1695. set -- "${EPYTHON}" -m pytest "${args[@]}" "${@}" ${EPYTEST_FLAGS};
  1696. echo "${@}" 1>&2;
  1697. "${@}";
  1698. local ret=${?};
  1699. rm -rf .hypothesis .pytest_cache || die;
  1700. if [[ -n ${BUILD_DIR} && -d ${BUILD_DIR} ]]; then
  1701. find "${BUILD_DIR}" -name '*-pytest-*.pyc' -delete || die;
  1702. fi;
  1703. [[ ${ret} -ne 0 ]] && die -n "pytest failed with ${EPYTHON}";
  1704. return ${ret}
  1705. }
  1706. eunittest ()
  1707. {
  1708. debug-print-function ${FUNCNAME} "$@";
  1709. _python_check_EPYTHON;
  1710. _python_check_occluded_packages;
  1711. local runner=unittest;
  1712. if _python_impl_matches "${EPYTHON}" 3.{9..11}; then
  1713. runner=unittest_or_fail;
  1714. fi;
  1715. set -- "${EPYTHON}" -m "${runner}" discover -v "${@}";
  1716. echo "${@}" 1>&2;
  1717. "${@}" || die -n "Tests failed with ${EPYTHON}";
  1718. return ${?}
  1719. }
  1720. gcc-fullversion ()
  1721. {
  1722. _gcc_fullversion '$1.$2.$3' "$@"
  1723. }
  1724. gcc-major-version ()
  1725. {
  1726. _gcc_fullversion '$1' "$@"
  1727. }
  1728. gcc-micro-version ()
  1729. {
  1730. _gcc_fullversion '$3' "$@"
  1731. }
  1732. gcc-minor-version ()
  1733. {
  1734. _gcc_fullversion '$2' "$@"
  1735. }
  1736. gcc-specs-directive ()
  1737. {
  1738. local directive subdname subdirective;
  1739. directive="$(_gcc-specs-directive_raw $1)";
  1740. while [[ ${directive} == *%\(*\)* ]]; do
  1741. subdname=${directive/*%\(};
  1742. subdname=${subdname/\)*};
  1743. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  1744. directive="${directive//\%(${subdname})/${subdirective}}";
  1745. done;
  1746. echo "${directive}";
  1747. return 0
  1748. }
  1749. gcc-specs-nostrict ()
  1750. {
  1751. local directive;
  1752. directive=$(gcc-specs-directive cc1);
  1753. [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
  1754. }
  1755. gcc-specs-now ()
  1756. {
  1757. local directive;
  1758. directive=$(gcc-specs-directive link_command);
  1759. [[ "${directive/\{!nonow:}" != "${directive}" ]]
  1760. }
  1761. gcc-specs-pie ()
  1762. {
  1763. local directive;
  1764. directive=$(gcc-specs-directive cc1);
  1765. [[ "${directive/\{!nopie:}" != "${directive}" ]]
  1766. }
  1767. gcc-specs-relro ()
  1768. {
  1769. local directive;
  1770. directive=$(gcc-specs-directive link_command);
  1771. [[ "${directive/\{!norelro:}" != "${directive}" ]]
  1772. }
  1773. gcc-specs-ssp ()
  1774. {
  1775. local directive;
  1776. directive=$(gcc-specs-directive cc1);
  1777. [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
  1778. }
  1779. gcc-specs-ssp-to-all ()
  1780. {
  1781. local directive;
  1782. directive=$(gcc-specs-directive cc1);
  1783. [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
  1784. }
  1785. gcc-specs-stack-check ()
  1786. {
  1787. local directive;
  1788. directive=$(gcc-specs-directive cc1);
  1789. [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
  1790. }
  1791. gcc-version ()
  1792. {
  1793. _gcc_fullversion '$1.$2' "$@"
  1794. }
  1795. gen_usr_ldscript ()
  1796. {
  1797. ewarn "${FUNCNAME}: Please migrate to usr-ldscript.eclass";
  1798. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  1799. tc-is-static-only && return;
  1800. use prefix && return;
  1801. if [[ $(type -t multilib_is_native_abi) == "function" ]]; then
  1802. multilib_is_native_abi || return 0;
  1803. fi;
  1804. case ${CTARGET:-${CHOST}} in
  1805. *-darwin*)
  1806.  
  1807. ;;
  1808. *-android*)
  1809. return 0
  1810. ;;
  1811. *linux*)
  1812. use prefix && return 0
  1813. ;;
  1814. *)
  1815. return 0
  1816. ;;
  1817. esac;
  1818. dodir /usr/${libdir};
  1819. if [[ $1 == "-a" ]]; then
  1820. auto=true;
  1821. shift;
  1822. dodir /${libdir};
  1823. fi;
  1824. local flags=(${CFLAGS} ${LDFLAGS} -Wl,--verbose);
  1825. if $(tc-getLD) --version | grep -q 'GNU gold'; then
  1826. local d="${T}/bfd-linker";
  1827. mkdir -p "${d}";
  1828. ln -sf $(type -P ${CHOST}-ld.bfd) "${d}"/ld;
  1829. flags+=(-B"${d}");
  1830. fi;
  1831. output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  1832. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  1833. for lib in "$@";
  1834. do
  1835. local tlib;
  1836. if ${auto}; then
  1837. lib="lib${lib}${suffix}";
  1838. else
  1839. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  1840. fi;
  1841. case ${CTARGET:-${CHOST}} in
  1842. *-darwin*)
  1843. if ${auto}; then
  1844. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1845. else
  1846. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  1847. fi;
  1848. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  1849. tlib=${tlib##*/};
  1850. if ${auto}; then
  1851. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1852. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  1853. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1854. fi;
  1855. rm -f "${ED}"/${libdir}/${lib};
  1856. fi;
  1857. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  1858. chmod u+w "${ED}${libdir}/${tlib}";
  1859. local nowrite=yes;
  1860. fi;
  1861. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  1862. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  1863. pushd "${ED}/usr/${libdir}" > /dev/null;
  1864. ln -snf "../../${libdir}/${tlib}" "${lib}";
  1865. popd > /dev/null
  1866. ;;
  1867. *)
  1868. if ${auto}; then
  1869. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1870. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  1871. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1872. if [[ ${tlib} != ${lib}* ]]; then
  1873. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1874. fi;
  1875. rm -f "${ED}"/${libdir}/${lib};
  1876. else
  1877. tlib=${lib};
  1878. fi;
  1879. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  1880. /* GNU ld script
  1881. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  1882. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  1883. run into linking problems. This "fake" dynamic lib is a linker script that
  1884. redirects the linker to the real lib. And yes, this works in the cross-
  1885. compiling scenario as the sysroot-ed linker will prepend the real path.
  1886.  
  1887. See bug https://bugs.gentoo.org/4411 for more info.
  1888. */
  1889. ${output_format}
  1890. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  1891. END_LDSCRIPT
  1892.  
  1893. ;;
  1894. esac
  1895. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  1896. done
  1897. }
  1898. get_abi_CFLAGS ()
  1899. {
  1900. get_abi_var CFLAGS "$@"
  1901. }
  1902. get_abi_CHOST ()
  1903. {
  1904. get_abi_var CHOST "$@"
  1905. }
  1906. get_abi_CTARGET ()
  1907. {
  1908. get_abi_var CTARGET "$@"
  1909. }
  1910. get_abi_FAKE_TARGETS ()
  1911. {
  1912. get_abi_var FAKE_TARGETS "$@"
  1913. }
  1914. get_abi_LDFLAGS ()
  1915. {
  1916. get_abi_var LDFLAGS "$@"
  1917. }
  1918. get_abi_LIBDIR ()
  1919. {
  1920. get_abi_var LIBDIR "$@"
  1921. }
  1922. get_abi_var ()
  1923. {
  1924. local flag=$1;
  1925. local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  1926. local var="${flag}_${abi}";
  1927. echo ${!var}
  1928. }
  1929. get_all_abis ()
  1930. {
  1931. local x order="" mvar dvar;
  1932. mvar="MULTILIB_ABIS";
  1933. dvar="DEFAULT_ABI";
  1934. if [[ -n $1 ]]; then
  1935. mvar="$1_${mvar}";
  1936. dvar="$1_${dvar}";
  1937. fi;
  1938. if [[ -z ${!mvar} ]]; then
  1939. echo "default";
  1940. return 0;
  1941. fi;
  1942. for x in ${!mvar};
  1943. do
  1944. if [[ ${x} != ${!dvar} ]]; then
  1945. order="${order:+${order} }${x}";
  1946. fi;
  1947. done;
  1948. order="${order:+${order} }${!dvar}";
  1949. echo ${order};
  1950. return 0
  1951. }
  1952. get_all_libdirs ()
  1953. {
  1954. local libdirs abi;
  1955. for abi in ${MULTILIB_ABIS};
  1956. do
  1957. libdirs+=" $(get_abi_LIBDIR ${abi})";
  1958. done;
  1959. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  1960. echo "${libdirs}"
  1961. }
  1962. get_bmake ()
  1963. {
  1964. if [[ ${CBUILD:-${CHOST}} == *bsd* ]]; then
  1965. echo make;
  1966. else
  1967. if [[ ${CBUILD:-${CHOST}} == *darwin* ]]; then
  1968. echo bsdmake;
  1969. else
  1970. echo bmake;
  1971. fi;
  1972. fi
  1973. }
  1974. get_exeext ()
  1975. {
  1976. case ${CHOST} in
  1977. mingw* | *-mingw*)
  1978. echo ".exe"
  1979. ;;
  1980. esac
  1981. }
  1982. get_install_abis ()
  1983. {
  1984. local x order="";
  1985. if [[ -z ${MULTILIB_ABIS} ]]; then
  1986. echo "default";
  1987. return 0;
  1988. fi;
  1989. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  1990. for x in ${MULTILIB_ABIS};
  1991. do
  1992. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  1993. has ${x} ${ABI_DENY} || order="${order} ${x}";
  1994. fi;
  1995. done;
  1996. has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  1997. if [[ -n ${ABI_ALLOW} ]]; then
  1998. local ordera="";
  1999. for x in ${order};
  2000. do
  2001. if has ${x} ${ABI_ALLOW}; then
  2002. ordera="${ordera} ${x}";
  2003. fi;
  2004. done;
  2005. order=${ordera};
  2006. fi;
  2007. else
  2008. order=${DEFAULT_ABI};
  2009. fi;
  2010. if [[ -z ${order} ]]; then
  2011. die "The ABI list is empty. Are you using a proper multilib profile? Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package.";
  2012. fi;
  2013. echo ${order};
  2014. return 0
  2015. }
  2016. get_libdir ()
  2017. {
  2018. local libdir_var="LIBDIR_${ABI}";
  2019. local libdir="lib";
  2020. [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var};
  2021. echo "${libdir}"
  2022. }
  2023. get_libname ()
  2024. {
  2025. local libname;
  2026. local ver=$1;
  2027. case ${CHOST} in
  2028. mingw* | *-mingw*)
  2029. libname="dll"
  2030. ;;
  2031. *-darwin*)
  2032. libname="dylib"
  2033. ;;
  2034. *)
  2035. libname="so"
  2036. ;;
  2037. esac;
  2038. if [[ -z $* ]]; then
  2039. echo ".${libname}";
  2040. else
  2041. for ver in "$@";
  2042. do
  2043. case ${CHOST} in
  2044. *-darwin*)
  2045. echo ".${ver}.${libname}"
  2046. ;;
  2047. *)
  2048. echo ".${libname}.${ver}"
  2049. ;;
  2050. esac;
  2051. done;
  2052. fi
  2053. }
  2054. get_makefile_extract_function ()
  2055. {
  2056. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2057. local a='' b='' mkfunc='getfilevar';
  2058. a="$(getfilevar VERSION ${KERNEL_MAKEFILE})";
  2059. b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})";
  2060. [[ "${a}" != "${b}" ]] && mkfunc='getfilevar_noexec';
  2061. echo "${mkfunc}"
  2062. }
  2063. get_makeopts_jobs ()
  2064. {
  2065. makeopts_jobs "$(_get_all_makeopts)" "${1:-1}"
  2066. }
  2067. get_makeopts_loadavg ()
  2068. {
  2069. makeopts_loadavg "$(_get_all_makeopts)" "${1:-999}"
  2070. }
  2071. get_modname ()
  2072. {
  2073. local modname;
  2074. local ver=$1;
  2075. case ${CHOST} in
  2076. *-darwin*)
  2077. modname="bundle"
  2078. ;;
  2079. *)
  2080. modname="so"
  2081. ;;
  2082. esac;
  2083. echo ".${modname}"
  2084. }
  2085. get_mounts ()
  2086. {
  2087. local point= node= fs= opts= foo=;
  2088. if [[ $(uname -s) == "Linux" ]]; then
  2089. while read node point fs opts foo; do
  2090. echo "${point} ${node} ${fs} ${opts}";
  2091. done < /proc/mounts;
  2092. return;
  2093. fi;
  2094. local IFS=' ';
  2095. LC_ALL=C mount -p | while read node point fs foo; do
  2096. opts=${fs#* };
  2097. fs=${fs%% *};
  2098. echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}";
  2099. done
  2100. }
  2101. get_nproc ()
  2102. {
  2103. local nproc;
  2104. if type -P nproc &> /dev/null; then
  2105. nproc=$(nproc);
  2106. fi;
  2107. if [[ -z ${nproc} ]] && type -P sysctl &> /dev/null; then
  2108. nproc=$(sysctl -n hw.ncpu 2> /dev/null);
  2109. fi;
  2110. if [[ -z ${nproc} ]] && type -P python &> /dev/null; then
  2111. nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2> /dev/null);
  2112. fi;
  2113. if [[ -n ${nproc} ]]; then
  2114. echo "${nproc}";
  2115. else
  2116. echo "${1:-1}";
  2117. fi
  2118. }
  2119. get_running_version ()
  2120. {
  2121. if ! use kernel_linux; then
  2122. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  2123. fi;
  2124. local kv=$(uname -r);
  2125. if [[ -f ${ROOT}/lib/modules/${kv}/source/Makefile ]]; then
  2126. KERNEL_DIR=$(readlink -f "${ROOT}/lib/modules/${kv}/source");
  2127. if [[ -f ${ROOT}/lib/modules/${kv}/build/Makefile ]]; then
  2128. KBUILD_OUTPUT=$(readlink -f "${ROOT}/lib/modules/${kv}/build");
  2129. fi;
  2130. get_version && return 0;
  2131. fi;
  2132. KV_FULL=${kv};
  2133. local kv_full=${KV_FULL//[-+_]*};
  2134. KV_MAJOR=$(ver_cut 1 ${kv_full});
  2135. KV_MINOR=$(ver_cut 2 ${kv_full});
  2136. KV_PATCH=$(ver_cut 3 ${kv_full});
  2137. KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}";
  2138. : "${KV_PATCH:=0}";
  2139. return 0
  2140. }
  2141. get_version ()
  2142. {
  2143. if ! use kernel_linux; then
  2144. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  2145. fi;
  2146. local tmplocal;
  2147. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2148. [[ -n "${KV_FULL}" ]] && return 0;
  2149. unset KV_DIR;
  2150. [[ -z "${get_version_warning_done}" ]] && qeinfo "Determining the location of the kernel source code";
  2151. [[ -d "${KERNEL_DIR}" ]] && KV_DIR="${KERNEL_DIR}";
  2152. if [[ -z "${KV_DIR}" ]]; then
  2153. if [[ -z "${get_version_warning_done}" ]]; then
  2154. get_version_warning_done=1;
  2155. qewarn "Unable to find kernel sources at ${KERNEL_DIR}";
  2156. if [[ "${KERNEL_DIR}" == "/usr/src/linux" ]]; then
  2157. qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, ";
  2158. qeinfo "(or the kernel you wish to build against).";
  2159. qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location";
  2160. else
  2161. qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against.";
  2162. fi;
  2163. fi;
  2164. return 1;
  2165. fi;
  2166. if [[ -z "${KBUILD_OUTPUT}" && -L "${KERNEL_DIR}/source" ]]; then
  2167. KBUILD_OUTPUT=${KERNEL_DIR};
  2168. KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source");
  2169. KV_DIR=${KERNEL_DIR};
  2170. fi;
  2171. if [[ -z "${get_version_warning_done}" ]]; then
  2172. qeinfo "Found kernel source directory:";
  2173. qeinfo " ${KV_DIR}";
  2174. fi;
  2175. kernel_get_makefile;
  2176. if [[ ! -s ${KERNEL_MAKEFILE} ]]; then
  2177. if [[ -z "${get_version_warning_done}" ]]; then
  2178. get_version_warning_done=1;
  2179. qeerror "Could not find a Makefile in the kernel source directory.";
  2180. qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources";
  2181. fi;
  2182. return 1;
  2183. fi;
  2184. local OUTPUT_DIR=${KBUILD_OUTPUT};
  2185. if [[ -z ${OUTPUT_DIR} ]]; then
  2186. local mkfunc=$(get_makefile_extract_function "${KERNEL_MAKEFILE}");
  2187. OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}");
  2188. fi;
  2189. KV_MAJOR=$(getfilevar VERSION "${KERNEL_MAKEFILE}");
  2190. KV_MINOR=$(getfilevar PATCHLEVEL "${KERNEL_MAKEFILE}");
  2191. KV_PATCH=$(getfilevar SUBLEVEL "${KERNEL_MAKEFILE}");
  2192. KV_EXTRA=$(getfilevar EXTRAVERSION "${KERNEL_MAKEFILE}");
  2193. if [[ -z "${KV_MAJOR}" || -z "${KV_MINOR}" || -z "${KV_PATCH}" ]]; then
  2194. if [[ -z "${get_version_warning_done}" ]]; then
  2195. get_version_warning_done=1;
  2196. qeerror "Could not detect kernel version.";
  2197. qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources.";
  2198. fi;
  2199. return 1;
  2200. fi;
  2201. [[ -d "${OUTPUT_DIR}" ]] && KV_OUT_DIR="${OUTPUT_DIR}";
  2202. if [[ -n "${KV_OUT_DIR}" ]]; then
  2203. qeinfo "Found kernel object directory:";
  2204. qeinfo " ${KV_OUT_DIR}";
  2205. fi;
  2206. KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}";
  2207. if [[ -s "${KV_OUT_DIR}"/include/config/kernel.release ]]; then
  2208. KV_LOCAL=$(< "${KV_OUT_DIR}"/include/config/kernel.release);
  2209. else
  2210. if [[ -s "${KV_OUT_DIR}"/.kernelrelease ]]; then
  2211. KV_LOCAL=$(< "${KV_OUT_DIR}"/.kernelrelease);
  2212. else
  2213. KV_LOCAL=;
  2214. fi;
  2215. fi;
  2216. tmplocal=${KV_LOCAL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}};
  2217. if [[ "${KV_LOCAL}" = "${tmplocal}" ]]; then
  2218. KV_LOCAL=;
  2219. else
  2220. KV_LOCAL=${tmplocal};
  2221. fi;
  2222. if [[ -z ${OUTPUT_DIR} ]]; then
  2223. for OUTPUT_DIR in "${SYSROOT}" "${ROOT}" "";
  2224. do
  2225. OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}/build";
  2226. if [[ -e ${OUTPUT_DIR} ]]; then
  2227. break;
  2228. fi;
  2229. done;
  2230. fi;
  2231. KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}";
  2232. qeinfo "Found sources for kernel version:";
  2233. qeinfo " ${KV_FULL}";
  2234. return 0
  2235. }
  2236. getfilevar ()
  2237. {
  2238. local ERROR basefname basedname myARCH="${ARCH}";
  2239. ERROR=0;
  2240. [[ -z "${1}" ]] && ERROR=1;
  2241. [[ ! -f "${2}" ]] && ERROR=1;
  2242. if [[ "${ERROR}" = 1 ]]; then
  2243. echo -e "\n";
  2244. eerror "getfilevar requires 2 variables, with the second a valid file.";
  2245. eerror " getfilevar <VARIABLE> <CONFIGFILE>";
  2246. else
  2247. basefname="$(basename ${2})";
  2248. basedname="$(dirname ${2})";
  2249. unset ARCH;
  2250. echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | nonfatal emake -C "${basedname}" --no-print-directory M="${T}" dot-config=0 need-config= need-compiler= -s -f - 2> /dev/null;
  2251. ARCH=${myARCH};
  2252. fi
  2253. }
  2254. getfilevar_noexec ()
  2255. {
  2256. local ERROR basefname basedname mycat myARCH="${ARCH}";
  2257. ERROR=0;
  2258. mycat='cat';
  2259. [[ -z "${1}" ]] && ERROR=1;
  2260. [[ ! -f "${2}" ]] && ERROR=1;
  2261. [[ "${2%.gz}" != "${2}" ]] && mycat='zcat';
  2262. if [[ "${ERROR}" = 1 ]]; then
  2263. echo -e "\n";
  2264. eerror "getfilevar_noexec requires 2 variables, with the second a valid file.";
  2265. eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>";
  2266. else
  2267. ${mycat} "${2}" | sed -n -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{
  2268. s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
  2269. s,[[:space:]]*\$,,g ;
  2270. p
  2271. }";
  2272. fi
  2273. }
  2274. git-r3_checkout ()
  2275. {
  2276. debug-print-function ${FUNCNAME} "$@";
  2277. local repos;
  2278. if [[ -n ${1} ]]; then
  2279. repos=(${1});
  2280. else
  2281. if [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
  2282. repos=("${EGIT_REPO_URI[@]}");
  2283. else
  2284. repos=(${EGIT_REPO_URI});
  2285. fi;
  2286. fi;
  2287. local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}};
  2288. local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}};
  2289. local checkout_paths=("${@:4}");
  2290. local -x GIT_DIR;
  2291. _git-r3_set_gitdir "${repos[0]}";
  2292. einfo "Checking out ${repos[0]} to ${out_dir} ...";
  2293. if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
  2294. die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?";
  2295. fi;
  2296. local remote_ref=$(git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__);
  2297. local new_commit_id=$(git rev-parse --verify refs/git-r3/"${local_id}"/__main__);
  2298. function git-r3_sub_checkout ()
  2299. {
  2300. local orig_repo=${GIT_DIR};
  2301. local -x GIT_DIR=${out_dir}/.git;
  2302. local -x GIT_WORK_TREE=${out_dir};
  2303. mkdir -p "${out_dir}" || die;
  2304. git init --quiet -b __init__ || die;
  2305. if [[ -n ${EGIT_LFS} ]]; then
  2306. git lfs install --local --skip-repo || die;
  2307. fi;
  2308. echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die;
  2309. cp -R "${orig_repo}"/refs/* "${GIT_DIR}"/refs/ || die;
  2310. if [[ -f ${orig_repo}/packed-refs ]]; then
  2311. cp "${orig_repo}"/packed-refs "${GIT_DIR}"/packed-refs || die;
  2312. fi;
  2313. git config --global --add safe.directory "$(cd "${out_dir}" && echo "${PWD}")" || die;
  2314. if [[ -f ${orig_repo}/shallow ]]; then
  2315. cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die;
  2316. fi;
  2317. set -- git checkout --quiet;
  2318. if [[ -n ${remote_ref} ]]; then
  2319. set -- "${@}" "${remote_ref#refs/heads/}";
  2320. else
  2321. set -- "${@}" "${new_commit_id}";
  2322. fi;
  2323. if [[ -n ${checkout_paths[@]} ]]; then
  2324. set -- "${@}" -- "${checkout_paths[@]}";
  2325. fi;
  2326. echo "${@}" 1>&2;
  2327. "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed";
  2328. local has_git_lfs_filters=$(git grep "filter=lfs" -- ".gitattributes" "**/.gitattributes");
  2329. if [[ -n $has_git_lfs_filters ]]; then
  2330. _EGIT_LFS_FILTERS_FOUND="yes";
  2331. fi
  2332. };
  2333. git-r3_sub_checkout;
  2334. unset -f git-r3_sub_checkout;
  2335. local old_commit_id=$(git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__);
  2336. if [[ ! -n ${old_commit_id} ]]; then
  2337. echo "GIT NEW branch -->";
  2338. echo " repository: ${repos[0]}";
  2339. echo " at the commit: ${new_commit_id}";
  2340. else
  2341. echo "GIT update -->";
  2342. echo " repository: ${repos[0]}";
  2343. if [[ "${old_commit_id}" != "${new_commit_id}" ]]; then
  2344. echo " updating from commit: ${old_commit_id}";
  2345. echo " to commit: ${new_commit_id}";
  2346. set -- git --no-pager diff --stat ${old_commit_id}..${new_commit_id};
  2347. if [[ -n ${checkout_paths[@]} ]]; then
  2348. set -- "${@}" -- "${checkout_paths[@]}";
  2349. fi;
  2350. "${@}";
  2351. else
  2352. echo " at the commit: ${new_commit_id}";
  2353. fi;
  2354. fi;
  2355. git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die;
  2356. if [[ -f ${out_dir}/.gitmodules && ! -n ${checkout_paths} ]]; then
  2357. local submodules;
  2358. _git-r3_set_submodules "${_GIT_SUBMODULE_PATH}" "$(< "${out_dir}"/.gitmodules)";
  2359. while [[ -n ${submodules[@]} ]]; do
  2360. local subname=${submodules[0]};
  2361. local url=${submodules[1]};
  2362. local path=${submodules[2]};
  2363. if [[ -d ${out_dir}/${path} ]]; then
  2364. local subrepos;
  2365. _git-r3_set_subrepos "${url}" "${repos[@]}";
  2366. _GIT_SUBMODULE_PATH=${_GIT_SUBMODULE_PATH}${path}/ git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" "${local_id}/${subname}";
  2367. fi;
  2368. submodules=("${submodules[@]:3}");
  2369. done;
  2370. fi;
  2371. export EGIT_DIR=${GIT_DIR};
  2372. export EGIT_VERSION=${new_commit_id}
  2373. }
  2374. git-r3_fetch ()
  2375. {
  2376. debug-print-function ${FUNCNAME} "$@";
  2377. local -x GIT_TERMINAL_PROMPT=0;
  2378. local repos;
  2379. if [[ -n ${1} ]]; then
  2380. repos=(${1});
  2381. else
  2382. if [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
  2383. repos=("${EGIT_REPO_URI[@]}");
  2384. else
  2385. repos=(${EGIT_REPO_URI});
  2386. fi;
  2387. fi;
  2388. [[ -n ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset";
  2389. local r;
  2390. for r in "${repos[@]}";
  2391. do
  2392. if [[ ${r} == git:* || ${r} == http:* ]]; then
  2393. ewarn "git-r3: ${r%%:*} protocol is completely insecure and may render the ebuild";
  2394. ewarn "easily susceptible to MITM attacks (even if used only as fallback). Please";
  2395. ewarn "use https instead.";
  2396. ewarn "[URI: ${r}]";
  2397. fi;
  2398. done;
  2399. local -x GIT_DIR;
  2400. _git-r3_set_gitdir "${repos[0]}";
  2401. einfo "Repository id: ${GIT_DIR##*/}";
  2402. if [[ -n ${EGIT_MIRROR_URI} ]]; then
  2403. repos=("${EGIT_MIRROR_URI%/}/${GIT_DIR##*/}" "${repos[@]}");
  2404. fi;
  2405. local branch_name=${EGIT_BRANCH};
  2406. local commit_id=${2:-${EGIT_COMMIT}};
  2407. local commit_date=${4:-${EGIT_COMMIT_DATE}};
  2408. local override_name=${GIT_DIR##*/};
  2409. override_name=${override_name%.git};
  2410. override_name=${override_name//[^a-zA-Z0-9_]/_};
  2411. override_name=${override_name^^};
  2412. local varmap=(REPO:repos BRANCH:branch_name COMMIT:commit_id COMMIT_DATE:commit_date);
  2413. local localvar livevar live_warn= override_vars=();
  2414. for localvar in "${varmap[@]}";
  2415. do
  2416. livevar=EGIT_OVERRIDE_${localvar%:*}_${override_name};
  2417. localvar=${localvar#*:};
  2418. override_vars+=("${livevar}");
  2419. if [[ -n ${!livevar} ]]; then
  2420. [[ ${localvar} == repos ]] && repos=();
  2421. live_warn=1;
  2422. ewarn "Using ${livevar}=${!livevar}";
  2423. declare "${localvar}=${!livevar}";
  2424. fi;
  2425. done;
  2426. if [[ -n ${live_warn} ]]; then
  2427. ewarn "No support will be provided.";
  2428. else
  2429. einfo "To override fetched repository properties, use:";
  2430. local x;
  2431. for x in "${override_vars[@]}";
  2432. do
  2433. einfo " ${x}";
  2434. done;
  2435. einfo;
  2436. fi;
  2437. local branch=${branch_name:+refs/heads/${branch_name}};
  2438. local remote_ref=${commit_id:-${branch:-HEAD}};
  2439. local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}};
  2440. local local_ref=refs/git-r3/${local_id}/__main__;
  2441. local success saved_umask;
  2442. if [[ -n ${EVCS_UMASK} ]]; then
  2443. saved_umask=$(umask);
  2444. umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}";
  2445. fi;
  2446. for r in "${repos[@]}";
  2447. do
  2448. if [[ ! -n ${EVCS_OFFLINE} ]]; then
  2449. einfo "Fetching ${r} ...";
  2450. local fetch_command=(git fetch "${r}");
  2451. local clone_type=${EGIT_CLONE_TYPE};
  2452. if [[ ${clone_type} == mirror ]]; then
  2453. fetch_command+=(--prune "+refs/heads/*:refs/heads/*" "+refs/tags/*:refs/tags/*" "+refs/notes/*:refs/notes/*" "+refs/pull/*/head:refs/pull/*" "+HEAD:refs/git-r3/HEAD" "${remote_ref}");
  2454. else
  2455. local fetch_l fetch_r;
  2456. if [[ ${remote_ref} == HEAD ]]; then
  2457. fetch_l=HEAD;
  2458. else
  2459. if [[ ${remote_ref} == refs/* ]]; then
  2460. fetch_l=${remote_ref};
  2461. else
  2462. local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}");
  2463. if [[ -n ${tagref} ]]; then
  2464. fetch_l=refs/tags/${remote_ref};
  2465. else
  2466. if [[ -n ${branch} ]]; then
  2467. fetch_l=${branch};
  2468. else
  2469. fetch_l=HEAD;
  2470. fi;
  2471. if [[ ${clone_type} == shallow ]]; then
  2472. clone_type=single;
  2473. fi;
  2474. fi;
  2475. fi;
  2476. fi;
  2477. if [[ -n ${commit_date} && ${clone_type} == shallow ]]; then
  2478. clone_type=single;
  2479. fi;
  2480. if [[ ${fetch_l} == HEAD ]]; then
  2481. fetch_r=refs/git-r3/HEAD;
  2482. else
  2483. fetch_r=${fetch_l};
  2484. fi;
  2485. fetch_command+=("+${fetch_l}:${fetch_r}");
  2486. if [[ ${clone_type} == single+tags ]]; then
  2487. fetch_command+=("+refs/tags/*:refs/tags/*");
  2488. fi;
  2489. fi;
  2490. if [[ ${clone_type} == shallow ]]; then
  2491. if _git-r3_is_local_repo; then
  2492. clone_type=single;
  2493. else
  2494. if [[ ! -n $(git rev-parse --quiet --verify "${fetch_r}") ]]; then
  2495. fetch_command+=(--depth 1);
  2496. fi;
  2497. fi;
  2498. else
  2499. if [[ -f ${GIT_DIR}/shallow ]]; then
  2500. fetch_command+=(--unshallow);
  2501. fi;
  2502. fi;
  2503. set -- "${fetch_command[@]}";
  2504. echo "${@}" 1>&2;
  2505. "${@}" || continue;
  2506. if [[ ${clone_type} == mirror || ${fetch_l} == HEAD ]]; then
  2507. git symbolic-ref HEAD refs/git-r3/HEAD || die "Unable to update HEAD";
  2508. fi;
  2509. fi;
  2510. if [[ -n ${commit_date} ]]; then
  2511. local dated_commit_id=$(git rev-list --first-parent --before="${commit_date}" -n 1 "${remote_ref}");
  2512. if [[ ${?} -ne 0 ]]; then
  2513. die "Listing ${remote_ref} failed (wrong ref?).";
  2514. else
  2515. if [[ ! -n ${dated_commit_id} ]]; then
  2516. die "Unable to find commit for date ${commit_date}.";
  2517. else
  2518. set -- git update-ref --no-deref "${local_ref}" "${dated_commit_id}";
  2519. fi;
  2520. fi;
  2521. else
  2522. local full_remote_ref=$(git rev-parse --verify --symbolic-full-name "${remote_ref}");
  2523. if [[ -n ${full_remote_ref} ]]; then
  2524. set -- git symbolic-ref "${local_ref}" "${full_remote_ref}";
  2525. else
  2526. set -- git update-ref --no-deref "${local_ref}" "${remote_ref}";
  2527. fi;
  2528. fi;
  2529. echo "${@}" 1>&2;
  2530. if ! "${@}"; then
  2531. if [[ -n ${EVCS_OFFLINE} ]]; then
  2532. eerror "A clone of the following repository is required to proceed:";
  2533. eerror " ${r}";
  2534. eerror "However, networking activity has been disabled using EVCS_OFFLINE and the local";
  2535. eerror "clone does not have requested ref:";
  2536. eerror " ${remote_ref}";
  2537. die "Local clone of ${r} does not have requested ref: ${remote_ref}. Unable to proceed with EVCS_OFFLINE.";
  2538. else
  2539. die "Referencing ${remote_ref} failed (wrong ref?).";
  2540. fi;
  2541. fi;
  2542. if [[ -n ${EGIT_LFS} ]]; then
  2543. local lfs_fetch_command=(git lfs fetch "${r}" "${remote_ref}");
  2544. case "${EGIT_LFS_CLONE_TYPE}" in
  2545. shallow)
  2546. if [[ -d ${GIT_DIR}/lfs/objects ]] && ! rmdir "${GIT_DIR}"/lfs/objects 2> /dev/null; then
  2547. lfs_fetch_command+=(--prune);
  2548. fi
  2549. ;;
  2550. single)
  2551.  
  2552. ;;
  2553. mirror)
  2554. lfs_fetch_command+=(--all)
  2555. ;;
  2556. *)
  2557. die "Invalid EGIT_LFS_CLONE_TYPE=${EGIT_LFS_CLONE_TYPE}"
  2558. ;;
  2559. esac;
  2560. set -- "${lfs_fetch_command[@]}";
  2561. echo "${@}" 1>&2;
  2562. "${@}" || die;
  2563. else
  2564. if [[ -d ${GIT_DIR}/lfs && ${EGIT_LFS_CLONE_TYPE} == shallow ]]; then
  2565. rm -fr ${GIT_DIR}/lfs || die;
  2566. fi;
  2567. fi;
  2568. success=1;
  2569. break;
  2570. done;
  2571. if [[ -n ${saved_umask} ]]; then
  2572. umask "${saved_umask}" || die;
  2573. fi;
  2574. [[ -n ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI";
  2575. local EGIT_CLONE_TYPE=mirror;
  2576. if git cat-file -e "${local_ref}":.gitmodules &> /dev/null; then
  2577. local submodules;
  2578. _git-r3_set_submodules "${_GIT_SUBMODULE_PATH}" "$(git cat-file -p "${local_ref}":.gitmodules || die)";
  2579. while [[ -n ${submodules[@]} ]]; do
  2580. local subname=${submodules[0]};
  2581. local url=${submodules[1]};
  2582. local path=${submodules[2]};
  2583. if [[ -n $(git ls-tree -d "${local_ref}" "${path}") ]]; then
  2584. local commit=$(git rev-parse "${local_ref}:${path}" || die);
  2585. if [[ ! -n ${commit} ]]; then
  2586. die "Unable to get commit id for submodule ${subname}";
  2587. fi;
  2588. local subrepos;
  2589. _git-r3_set_subrepos "${url}" "${repos[@]}";
  2590. _GIT_SUBMODULE_PATH=${_GIT_SUBMODULE_PATH}${path}/ git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" "";
  2591. fi;
  2592. submodules=("${submodules[@]:3}");
  2593. done;
  2594. fi
  2595. }
  2596. git-r3_peek_remote_ref ()
  2597. {
  2598. debug-print-function ${FUNCNAME} "$@";
  2599. local repos;
  2600. if [[ -n ${1} ]]; then
  2601. repos=(${1});
  2602. else
  2603. if [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
  2604. repos=("${EGIT_REPO_URI[@]}");
  2605. else
  2606. repos=(${EGIT_REPO_URI});
  2607. fi;
  2608. fi;
  2609. local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}};
  2610. local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}};
  2611. [[ -n ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset";
  2612. local r success;
  2613. for r in "${repos[@]}";
  2614. do
  2615. einfo "Peeking ${remote_ref} on ${r} ..." 1>&2;
  2616. local lookup_ref;
  2617. if [[ ${remote_ref} == refs/* || ${remote_ref} == HEAD ]]; then
  2618. lookup_ref=${remote_ref};
  2619. else
  2620. lookup_ref=refs/tags/${remote_ref};
  2621. fi;
  2622. local ref=($(git ls-remote "${r}" "${lookup_ref}"));
  2623. if [[ -n ${ref[0]} ]]; then
  2624. echo "${ref[0]}";
  2625. return 0;
  2626. fi;
  2627. done;
  2628. return 1
  2629. }
  2630. git-r3_pkg_needrebuild ()
  2631. {
  2632. debug-print-function ${FUNCNAME} "$@";
  2633. local new_commit_id=$(git-r3_peek_remote_ref);
  2634. [[ -n ${new_commit_id} && -n ${EGIT_VERSION} ]] || die "Lookup failed";
  2635. if [[ ${EGIT_VERSION} != ${new_commit_id} ]]; then
  2636. einfo "Update from ${EGIT_VERSION} to ${new_commit_id}";
  2637. else
  2638. einfo "Local and remote at ${EGIT_VERSION}";
  2639. fi;
  2640. [[ ${EGIT_VERSION} != ${new_commit_id} ]]
  2641. }
  2642. git-r3_src_fetch ()
  2643. {
  2644. debug-print-function ${FUNCNAME} "$@";
  2645. if [[ ! -n ${EGIT3_STORE_DIR} && -n ${EGIT_STORE_DIR} ]]; then
  2646. ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider";
  2647. ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use";
  2648. ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones";
  2649. ewarn "when git-2 eclass becomes deprecated.";
  2650. fi;
  2651. _git-r3_env_setup;
  2652. git-r3_fetch
  2653. }
  2654. git-r3_src_unpack ()
  2655. {
  2656. debug-print-function ${FUNCNAME} "$@";
  2657. _git-r3_env_setup;
  2658. git-r3_src_fetch;
  2659. git-r3_checkout;
  2660. if [[ ! -n ${EGIT_LFS} && -n ${_EGIT_LFS_FILTERS_FOUND} ]]; then
  2661. eqawarn "QA Notice: There are Git LFS filters setup in the cloned repo, consider using EGIT_LFS!";
  2662. fi;
  2663. if [[ -n ${EGIT_LFS} && ! -n ${_EGIT_LFS_FILTERS_FOUND} ]]; then
  2664. eqawarn "QA Notice: There are no Git LFS filters setup in the cloned repo. EGIT_LFS will do nothing!";
  2665. fi
  2666. }
  2667. has_multilib_profile ()
  2668. {
  2669. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  2670. }
  2671. in_iuse ()
  2672. {
  2673. local use=${1};
  2674. if [[ -z "${use}" ]]; then
  2675. echo "!!! in_iuse() called without a parameter." 1>&2;
  2676. echo "!!! in_iuse <USEFLAG>" 1>&2;
  2677. die "in_iuse() called without a parameter";
  2678. fi;
  2679. local liuse=(${IUSE_EFFECTIVE});
  2680. has "${use}" "${liuse[@]#[+-]}"
  2681. }
  2682. is_final_abi ()
  2683. {
  2684. has_multilib_profile || return 0;
  2685. set -- $(get_install_abis);
  2686. local LAST_ABI=$#;
  2687. [[ ${!LAST_ABI} == ${ABI} ]]
  2688. }
  2689. kernel_get_makefile ()
  2690. {
  2691. [[ -s ${KV_DIR}/GNUMakefile ]] && KERNEL_MAKEFILE="${KV_DIR}/GNUMakefile" && return;
  2692. [[ -s ${KV_DIR}/makefile ]] && KERNEL_MAKEFILE="${KV_DIR}/makefile" && return;
  2693. [[ -s ${KV_DIR}/Makefile ]] && KERNEL_MAKEFILE="${KV_DIR}/Makefile" && return
  2694. }
  2695. kernel_is ()
  2696. {
  2697. if ! use kernel_linux; then
  2698. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  2699. fi;
  2700. linux-info_get_any_version;
  2701. local operator;
  2702. case ${1#-} in
  2703. lt)
  2704. operator="-lt";
  2705. shift
  2706. ;;
  2707. gt)
  2708. operator="-gt";
  2709. shift
  2710. ;;
  2711. le)
  2712. operator="-le";
  2713. shift
  2714. ;;
  2715. ge)
  2716. operator="-ge";
  2717. shift
  2718. ;;
  2719. eq)
  2720. operator="-eq";
  2721. shift
  2722. ;;
  2723. *)
  2724. operator="-eq"
  2725. ;;
  2726. esac;
  2727. [[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters";
  2728. ver_test "${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" "${operator}" "${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}"
  2729. }
  2730. linux-info_get_any_version ()
  2731. {
  2732. if ! use kernel_linux; then
  2733. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  2734. fi;
  2735. if [[ ${MERGE_TYPE} == binary && -z ${SKIP_KERNEL_BINPKG_ENV_RESET} ]]; then
  2736. unset KV_FULL _LINUX_CONFIG_EXISTS_DONE KV_OUT_DIR;
  2737. SKIP_KERNEL_BINPKG_ENV_RESET=1;
  2738. fi;
  2739. if ! get_version; then
  2740. ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version";
  2741. fi;
  2742. if [[ -z ${KV_FULL} ]] && ! get_running_version; then
  2743. die "Unable to determine any Linux Kernel version, please report a bug";
  2744. fi
  2745. }
  2746. linux-info_pkg_setup ()
  2747. {
  2748. use kernel_linux || return;
  2749. linux-info_get_any_version;
  2750. [[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config
  2751. }
  2752. linux_chkconfig_builtin ()
  2753. {
  2754. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2755. linux_config_qa_check linux_chkconfig_builtin;
  2756. [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == y ]]
  2757. }
  2758. linux_chkconfig_module ()
  2759. {
  2760. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2761. linux_config_qa_check linux_chkconfig_module;
  2762. [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == m ]]
  2763. }
  2764. linux_chkconfig_present ()
  2765. {
  2766. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2767. linux_config_qa_check linux_chkconfig_present;
  2768. [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == [my] ]]
  2769. }
  2770. linux_chkconfig_string ()
  2771. {
  2772. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  2773. linux_config_qa_check linux_chkconfig_string;
  2774. getfilevar_noexec "CONFIG_$1" "$(linux_config_path)"
  2775. }
  2776. linux_config_bin_exists ()
  2777. {
  2778. export _LINUX_CONFIG_EXISTS_DONE=1;
  2779. use kernel_linux && [[ -s /proc/config.gz ]]
  2780. }
  2781. linux_config_exists ()
  2782. {
  2783. linux_config_src_exists || linux_config_bin_exists
  2784. }
  2785. linux_config_path ()
  2786. {
  2787. if linux_config_src_exists; then
  2788. echo "${KV_OUT_DIR}/.config";
  2789. else
  2790. if linux_config_bin_exists; then
  2791. echo "/proc/config.gz";
  2792. else
  2793. return 1;
  2794. fi;
  2795. fi
  2796. }
  2797. linux_config_qa_check ()
  2798. {
  2799. local f="$1";
  2800. if [[ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]]; then
  2801. ewarn "QA: You called $f before any linux_config_exists!";
  2802. ewarn "QA: The return value of $f will NOT guaranteed later!";
  2803. fi;
  2804. if ! use kernel_linux; then
  2805. die "$f called on non-Linux system, please fix the ebuild";
  2806. fi
  2807. }
  2808. linux_config_src_exists ()
  2809. {
  2810. export _LINUX_CONFIG_EXISTS_DONE=1;
  2811. use kernel_linux && [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
  2812. }
  2813. makeopts_jobs ()
  2814. {
  2815. [[ $# -eq 0 ]] && set -- "$(_get_all_makeopts)";
  2816. local jobs=$(echo " $* " | sed -r -n -e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-$(( $(get_nproc) + 1 ))}:p");
  2817. echo ${jobs:-1}
  2818. }
  2819. makeopts_loadavg ()
  2820. {
  2821. [[ $# -eq 0 ]] && set -- "$(_get_all_makeopts)";
  2822. local lavg=$(echo " $* " | sed -r -n -e 's:.*[[:space:]](-[a-z]*l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+(\.[0-9]+)?)[[:space:]].*:\3:p' -e "s:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:${2:-999}:p");
  2823. echo ${lavg:-${2:-999}}
  2824. }
  2825. mount-boot_check_status ()
  2826. {
  2827. mount-boot_is_disabled && return 0;
  2828. local partition=;
  2829. local part_is_not_mounted=;
  2830. local part_is_read_only=;
  2831. local candidates=(/boot);
  2832. if [[ -d /sys/firmware/efi ]]; then
  2833. candidates+=(/efi /boot/efi /boot/EFI);
  2834. fi;
  2835. for partition in ${candidates[@]};
  2836. do
  2837. local fstabstate=$(awk "!/^[[:blank:]]*#|^\/dev\/BOOT/ && \$2 == \"${partition}\" { print 1; exit }" /etc/fstab || die "awk failed");
  2838. if [[ -z ${fstabstate} ]]; then
  2839. einfo "Assuming you do not have a separate ${partition} partition.";
  2840. else
  2841. local procstate=$(awk "\$2 == \"${partition}\" { split(\$4, a, \",\"); for (i in a) if (a[i] ~ /^r[ow]\$/) { print a[i]; break }; exit }" /proc/mounts || die "awk failed");
  2842. if [[ -z ${procstate} ]]; then
  2843. eerror "Your ${partition} partition is not mounted";
  2844. eerror "Please mount it and retry.";
  2845. die -n "${partition} not mounted";
  2846. part_is_not_mounted=1;
  2847. else
  2848. if [[ ${procstate} == ro ]]; then
  2849. eerror "Your ${partition} partition, was detected as being mounted," "but is mounted read-only.";
  2850. eerror "Please remount it as read-write and retry.";
  2851. die -n "${partition} mounted read-only";
  2852. part_is_read_only=1;
  2853. else
  2854. einfo "Your ${partition} partition was detected as being mounted.";
  2855. einfo "Files will be installed there for ${PN} to function correctly.";
  2856. fi;
  2857. fi;
  2858. fi;
  2859. done;
  2860. if [[ -n ${part_is_not_mounted} ]]; then
  2861. return 1;
  2862. else
  2863. if [[ -n ${part_is_read_only} ]]; then
  2864. return 2;
  2865. else
  2866. return 0;
  2867. fi;
  2868. fi
  2869. }
  2870. mount-boot_is_disabled ()
  2871. {
  2872. if [[ -n ${EROOT} ]]; then
  2873. return 0;
  2874. fi;
  2875. if [[ ${MERGE_TYPE} == buildonly ]]; then
  2876. return 0;
  2877. fi;
  2878. if [[ -n ${DONT_MOUNT_BOOT} ]]; then
  2879. return 0;
  2880. fi;
  2881. return 1
  2882. }
  2883. mount-boot_pkg_postinst ()
  2884. {
  2885. :
  2886. }
  2887. mount-boot_pkg_postrm ()
  2888. {
  2889. :
  2890. }
  2891. mount-boot_pkg_preinst ()
  2892. {
  2893. mount-boot_check_status
  2894. }
  2895. mount-boot_pkg_prerm ()
  2896. {
  2897. mount-boot_check_status;
  2898. if [[ -z ${EPREFIX} ]] && ! ( shopt -s failglob;
  2899. : "${EROOT}"/boot/.keep* ) 2> /dev/null; then
  2900. touch "${EROOT}"/boot/.keep 2> /dev/null;
  2901. fi
  2902. }
  2903. mount-boot_pkg_pretend ()
  2904. {
  2905. mount-boot_check_status
  2906. }
  2907. multilib_env ()
  2908. {
  2909. local CTARGET=${1:-${CTARGET}};
  2910. local cpu=${CTARGET%%*-};
  2911. if [[ ${CTARGET} = *-musl* ]]; then
  2912. : "${MULTILIB_ABIS=default}";
  2913. : "${DEFAULT_ABI=default}";
  2914. export MULTILIB_ABIS DEFAULT_ABI;
  2915. return;
  2916. fi;
  2917. case ${cpu} in
  2918. aarch64*)
  2919. export CFLAGS_arm=${CFLAGS_arm-};
  2920. case ${cpu} in
  2921. aarch64*be)
  2922. export CHOST_arm="armv8b-${CTARGET#*-}"
  2923. ;;
  2924. *)
  2925. export CHOST_arm="armv8l-${CTARGET#*-}"
  2926. ;;
  2927. esac;
  2928. CHOST_arm=${CHOST_arm/%-gnu/-gnueabi};
  2929. export CTARGET_arm=${CHOST_arm};
  2930. export LIBDIR_arm="lib";
  2931. export CFLAGS_arm64=${CFLAGS_arm64-};
  2932. export CHOST_arm64=${CTARGET};
  2933. export CTARGET_arm64=${CHOST_arm64};
  2934. export LIBDIR_arm64="lib64";
  2935. : "${MULTILIB_ABIS=arm64}";
  2936. : "${DEFAULT_ABI=arm64}"
  2937. ;;
  2938. x86_64*)
  2939. export CFLAGS_x86=${CFLAGS_x86--m32};
  2940. export CHOST_x86=${CTARGET/x86_64/i686};
  2941. CHOST_x86=${CHOST_x86/%-gnux32/-gnu};
  2942. export CTARGET_x86=${CHOST_x86};
  2943. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  2944. export LIBDIR_x86="lib32";
  2945. else
  2946. export LIBDIR_x86="lib";
  2947. fi;
  2948. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  2949. export CHOST_amd64=${CTARGET/%-gnux32/-gnu};
  2950. export CTARGET_amd64=${CHOST_amd64};
  2951. export LIBDIR_amd64="lib64";
  2952. export CFLAGS_x32=${CFLAGS_x32--mx32};
  2953. export CHOST_x32=${CTARGET/%-gnu/-gnux32};
  2954. export CTARGET_x32=${CHOST_x32};
  2955. export LIBDIR_x32="libx32";
  2956. case ${CTARGET} in
  2957. *-gnux32)
  2958. : "${MULTILIB_ABIS=x32 amd64 x86}";
  2959. : "${DEFAULT_ABI=x32}"
  2960. ;;
  2961. *)
  2962. : "${MULTILIB_ABIS=amd64 x86}";
  2963. : "${DEFAULT_ABI=amd64}"
  2964. ;;
  2965. esac
  2966. ;;
  2967. loongarch64*)
  2968. export CFLAGS_lp64d=${CFLAGS_lp64d--mabi=lp64d};
  2969. export CHOST_lp64d=${CTARGET};
  2970. export CTARGET_lp64d=${CTARGET};
  2971. export LIBDIR_lp64d=${LIBDIR_lp64d-lib64};
  2972. : "${MULTILIB_ABIS=lp64d}";
  2973. : "${DEFAULT_ABI=lp64d}"
  2974. ;;
  2975. mips64* | mipsisa64*)
  2976. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2977. export CHOST_o32=${CTARGET/mips64/mips};
  2978. export CHOST_o32=${CHOST_o32/mipsisa64/mipsisa32};
  2979. export CTARGET_o32=${CHOST_o32};
  2980. export LIBDIR_o32="lib";
  2981. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2982. export CHOST_n32=${CTARGET};
  2983. export CTARGET_n32=${CHOST_n32};
  2984. export LIBDIR_n32="lib32";
  2985. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  2986. export CHOST_n64=${CTARGET};
  2987. export CTARGET_n64=${CHOST_n64};
  2988. export LIBDIR_n64="lib64";
  2989. : "${MULTILIB_ABIS=n64 n32 o32}";
  2990. : "${DEFAULT_ABI=n32}"
  2991. ;;
  2992. powerpc64*)
  2993. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  2994. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  2995. export CTARGET_ppc=${CHOST_ppc};
  2996. export LIBDIR_ppc="lib";
  2997. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  2998. export CHOST_ppc64=${CTARGET};
  2999. export CTARGET_ppc64=${CHOST_ppc64};
  3000. export LIBDIR_ppc64="lib64";
  3001. : "${MULTILIB_ABIS=ppc64 ppc}";
  3002. : "${DEFAULT_ABI=ppc64}"
  3003. ;;
  3004. riscv64*)
  3005. : "${MULTILIB_ABIS=lp64d lp64 ilp32d ilp32}";
  3006. : "${DEFAULT_ABI=lp64d}";
  3007. local _libdir_riscvdefaultabi_variable="LIBDIR_${DEFAULT_ABI}";
  3008. local _libdir_riscvdefaultabi=${!_libdir_riscvdefaultabi_variable};
  3009. export ${_libdir_riscvdefaultabi_variable}=${_libdir_riscvdefaultabi:-lib64};
  3010. export CFLAGS_lp64d=${CFLAGS_lp64d--mabi=lp64d -march=rv64gc};
  3011. export CHOST_lp64d=${CTARGET};
  3012. export CTARGET_lp64d=${CTARGET};
  3013. export LIBDIR_lp64d=${LIBDIR_lp64d-lib64/lp64d};
  3014. export CFLAGS_lp64=${CFLAGS_lp64--mabi=lp64 -march=rv64imac};
  3015. export CHOST_lp64=${CTARGET};
  3016. export CTARGET_lp64=${CTARGET};
  3017. export LIBDIR_lp64=${LIBDIR_lp64-lib64/lp64};
  3018. export CFLAGS_ilp32d=${CFLAGS_ilp32d--mabi=ilp32d -march=rv32imafdc};
  3019. export CHOST_ilp32d=${CTARGET/riscv64/riscv32};
  3020. export CTARGET_ilp32d=${CTARGET/riscv64/riscv32};
  3021. export LIBDIR_ilp32d=${LIBDIR_ilp32d-lib32/ilp32d};
  3022. export CFLAGS_ilp32=${CFLAGS_ilp32--mabi=ilp32 -march=rv32imac};
  3023. export CHOST_ilp32=${CTARGET/riscv64/riscv32};
  3024. export CTARGET_ilp32=${CTARGET/riscv64/riscv32};
  3025. export LIBDIR_ilp32=${LIBDIR_ilp32-lib32/ilp32}
  3026. ;;
  3027. riscv32*)
  3028. : "${MULTILIB_ABIS=ilp32d ilp32}";
  3029. : "${DEFAULT_ABI=ilp32d}";
  3030. local _libdir_riscvdefaultabi_variable="LIBDIR_${DEFAULT_ABI}";
  3031. local _libdir_riscvdefaultabi=${!_libdir_riscvdefaultabi_variable};
  3032. export ${_libdir_riscvdefaultabi_variable}=${_libdir_riscvdefaultabi:-lib};
  3033. export CFLAGS_ilp32d=${CFLAGS_ilp32d--mabi=ilp32d -march=rv32imafdc};
  3034. export CHOST_ilp32d=${CTARGET};
  3035. export CTARGET_ilp32d=${CTARGET};
  3036. export LIBDIR_ilp32d=${LIBDIR_ilp32d-lib32/ilp32d};
  3037. export CFLAGS_ilp32=${CFLAGS_ilp32--mabi=ilp32 -march=rv32imac};
  3038. export CHOST_ilp32=${CTARGET};
  3039. export CTARGET_ilp32=${CTARGET};
  3040. export LIBDIR_ilp32=${LIBDIR_ilp32-lib32/ilp32}
  3041. ;;
  3042. s390x*)
  3043. export CFLAGS_s390=${CFLAGS_s390--m31};
  3044. export CHOST_s390=${CTARGET/s390x/s390};
  3045. export CTARGET_s390=${CHOST_s390};
  3046. export LIBDIR_s390="lib";
  3047. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  3048. export CHOST_s390x=${CTARGET};
  3049. export CTARGET_s390x=${CHOST_s390x};
  3050. export LIBDIR_s390x="lib64";
  3051. : "${MULTILIB_ABIS=s390x s390}";
  3052. : "${DEFAULT_ABI=s390x}"
  3053. ;;
  3054. sparc64*)
  3055. export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  3056. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  3057. export CTARGET_sparc32=${CHOST_sparc32};
  3058. export LIBDIR_sparc32="lib";
  3059. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  3060. export CHOST_sparc64=${CTARGET};
  3061. export CTARGET_sparc64=${CHOST_sparc64};
  3062. export LIBDIR_sparc64="lib64";
  3063. : "${MULTILIB_ABIS=sparc64 sparc32}";
  3064. : "${DEFAULT_ABI=sparc64}"
  3065. ;;
  3066. *)
  3067. : "${MULTILIB_ABIS=default}";
  3068. : "${DEFAULT_ABI=default}"
  3069. ;;
  3070. esac;
  3071. export MULTILIB_ABIS DEFAULT_ABI
  3072. }
  3073. multilib_toolchain_setup ()
  3074. {
  3075. local v vv;
  3076. export ABI=$1;
  3077. local save_restore_variables=(CBUILD CHOST AR CC CXX F77 FC LD NM OBJCOPY OBJDUMP PKG_CONFIG RANLIB READELF STRINGS STRIP PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG_SYSTEM_INCLUDE_PATH PKG_CONFIG_SYSTEM_LIBRARY_PATH);
  3078. if [[ ${_DEFAULT_ABI_SAVED} == "true" ]]; then
  3079. for v in "${save_restore_variables[@]}";
  3080. do
  3081. vv="_abi_saved_${v}";
  3082. [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v};
  3083. unset ${vv};
  3084. done;
  3085. unset _DEFAULT_ABI_SAVED;
  3086. fi;
  3087. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  3088. for v in "${save_restore_variables[@]}";
  3089. do
  3090. vv="_abi_saved_${v}";
  3091. [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv};
  3092. done;
  3093. export _DEFAULT_ABI_SAVED="true";
  3094. if [[ ${CBUILD} == "${CHOST}" ]]; then
  3095. export CBUILD=$(get_abi_CHOST $1);
  3096. fi;
  3097. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  3098. export AR="$(tc-getAR)";
  3099. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  3100. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  3101. export F77="$(tc-getF77) $(get_abi_CFLAGS)";
  3102. export FC="$(tc-getFC) $(get_abi_CFLAGS)";
  3103. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  3104. export NM="$(tc-getNM)";
  3105. export OBJCOPY="$(tc-getOBJCOPY)";
  3106. export OBJDUMP="$(tc-getOBJDUMP)";
  3107. export PKG_CONFIG="$(tc-getPKG_CONFIG)";
  3108. export RANLIB="$(tc-getRANLIB)";
  3109. export READELF="$(tc-getREADELF)";
  3110. export STRINGS="$(tc-getSTRINGS)";
  3111. export STRIP="$(tc-getSTRIP)";
  3112. export CHOST=$(get_abi_CHOST $1);
  3113. export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig;
  3114. export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig;
  3115. export PKG_CONFIG_SYSTEM_INCLUDE_PATH=${EPREFIX}/usr/include;
  3116. export PKG_CONFIG_SYSTEM_LIBRARY_PATH=${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir);
  3117. fi
  3118. }
  3119. number_abis ()
  3120. {
  3121. set -- `get_install_abis`;
  3122. echo $#
  3123. }
  3124. pkg_needrebuild ()
  3125. {
  3126. git-r3_pkg_needrebuild
  3127. }
  3128. pkg_nofetch ()
  3129. {
  3130. default
  3131. }
  3132. pkg_postinst ()
  3133. {
  3134. elog "If you are only interested in particular firmware files, edit the saved";
  3135. elog "configfile and remove those that you do not want.";
  3136. local ver;
  3137. for ver in ${REPLACING_VERSIONS};
  3138. do
  3139. if ver_test ${ver} -lt 20190514; then
  3140. elog;
  3141. elog 'Starting with version 20190514, installation of many firmware';
  3142. elog 'files is controlled by USE flags. Please review your USE flag';
  3143. elog 'and package.license settings if you are missing some files.';
  3144. break;
  3145. fi;
  3146. done;
  3147. if use initramfs; then
  3148. if use dist-kernel; then
  3149. [[ -z ${ROOT} ]] && dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}";
  3150. else
  3151. mount-boot_pkg_postinst;
  3152. fi;
  3153. fi
  3154. }
  3155. pkg_postrm ()
  3156. {
  3157. use initramfs && ! use dist-kernel && mount-boot_pkg_postrm
  3158. }
  3159. pkg_preinst ()
  3160. {
  3161. if use savedconfig; then
  3162. ewarn "USE=savedconfig is active. You must handle file collisions manually.";
  3163. fi;
  3164. if has_version "<${CATEGORY}/${PN}-20220913-r2"; then
  3165. rm -rf "${EROOT}"/lib/firmware/qcom/LENOVO/21BX;
  3166. fi;
  3167. use initramfs && ! use dist-kernel && mount-boot_pkg_preinst
  3168. }
  3169. pkg_prerm ()
  3170. {
  3171. use initramfs && ! use dist-kernel && mount-boot_pkg_prerm
  3172. }
  3173. pkg_pretend ()
  3174. {
  3175. if use initramfs; then
  3176. if use dist-kernel; then
  3177. [[ -z ${ROOT} ]] && nonfatal mount-boot_check_status;
  3178. else
  3179. mount-boot_pkg_pretend;
  3180. fi;
  3181. fi
  3182. }
  3183. pkg_setup ()
  3184. {
  3185. python_setup;
  3186. if use compress-xz || use compress-zstd; then
  3187. local CONFIG_CHECK;
  3188. if kernel_is -ge 5 19; then
  3189. use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS_XZ";
  3190. use compress-zstd && CONFIG_CHECK="~FW_LOADER_COMPRESS_ZSTD";
  3191. else
  3192. use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS";
  3193. if use compress-zstd; then
  3194. eerror "Kernels <5.19 do not support ZSTD-compressed firmware files";
  3195. fi;
  3196. fi;
  3197. fi;
  3198. linux-info_pkg_setup
  3199. }
  3200. python-any-r1_pkg_setup ()
  3201. {
  3202. debug-print-function ${FUNCNAME} "$@";
  3203. [[ ${MERGE_TYPE} != binary ]] && python_setup
  3204. }
  3205. python_doexe ()
  3206. {
  3207. debug-print-function ${FUNCNAME} "$@";
  3208. [[ ${EBUILD_PHASE} != install ]] && die "${FUNCNAME} can only be used in src_install";
  3209. local f;
  3210. for f in "$@";
  3211. do
  3212. python_newexe "${f}" "${f##*/}";
  3213. done
  3214. }
  3215. python_doheader ()
  3216. {
  3217. debug-print-function ${FUNCNAME} "$@";
  3218. [[ ${EBUILD_PHASE} != install ]] && die "${FUNCNAME} can only be used in src_install";
  3219. [[ -n ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).';
  3220. local includedir=$(python_get_includedir);
  3221. local d=${includedir#${ESYSROOT}};
  3222. ( insopts -m 0644;
  3223. insinto "${d}";
  3224. doins -r "${@}" || return ${?} )
  3225. }
  3226. python_domodule ()
  3227. {
  3228. debug-print-function ${FUNCNAME} "$@";
  3229. [[ -n ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).';
  3230. local d;
  3231. if [[ ${_PYTHON_MODULEROOT} == /* ]]; then
  3232. d=${_PYTHON_MODULEROOT};
  3233. else
  3234. local sitedir=$(python_get_sitedir);
  3235. d=${sitedir#${EPREFIX}}/${_PYTHON_MODULEROOT//.//};
  3236. fi;
  3237. if [[ ${EBUILD_PHASE} == install ]]; then
  3238. ( insopts -m 0644;
  3239. insinto "${d}";
  3240. doins -r "${@}" || return ${?} );
  3241. python_optimize "${ED}${d}";
  3242. else
  3243. if [[ -n ${BUILD_DIR} ]]; then
  3244. local dest=${BUILD_DIR}/install${EPREFIX}/${d};
  3245. mkdir -p "${dest}" || die;
  3246. cp -pR "${@}" "${dest}/" || die;
  3247. ( cd "${dest}" || die;
  3248. chmod -R a+rX "${@##*/}" || die );
  3249. else
  3250. die "${FUNCNAME} can only be used in src_install or with BUILD_DIR set";
  3251. fi;
  3252. fi
  3253. }
  3254. python_doscript ()
  3255. {
  3256. debug-print-function ${FUNCNAME} "$@";
  3257. [[ ${EBUILD_PHASE} != install ]] && die "${FUNCNAME} can only be used in src_install";
  3258. local _PYTHON_REWRITE_SHEBANG=1;
  3259. python_doexe "${@}"
  3260. }
  3261. python_export_utf8_locale ()
  3262. {
  3263. debug-print-function ${FUNCNAME} "$@";
  3264. type locale &> /dev/null || return 0;
  3265. if [[ $(locale charmap) != UTF-8 ]]; then
  3266. local lang locales="C.UTF-8 en_US.UTF-8 en_GB.UTF-8 $(locale -a)";
  3267. for lang in ${locales};
  3268. do
  3269. if [[ $(LC_ALL=${lang} locale charmap 2> /dev/null) == UTF-8 ]]; then
  3270. if _python_check_locale_sanity "${lang}"; then
  3271. export LC_CTYPE=${lang};
  3272. if [[ -n ${LC_ALL} ]]; then
  3273. export LC_NUMERIC=${LC_ALL};
  3274. export LC_TIME=${LC_ALL};
  3275. export LC_COLLATE=${LC_ALL};
  3276. export LC_MONETARY=${LC_ALL};
  3277. export LC_MESSAGES=${LC_ALL};
  3278. export LC_PAPER=${LC_ALL};
  3279. export LC_NAME=${LC_ALL};
  3280. export LC_ADDRESS=${LC_ALL};
  3281. export LC_TELEPHONE=${LC_ALL};
  3282. export LC_MEASUREMENT=${LC_ALL};
  3283. export LC_IDENTIFICATION=${LC_ALL};
  3284. export LC_ALL=;
  3285. fi;
  3286. return 0;
  3287. fi;
  3288. fi;
  3289. done;
  3290. ewarn "Could not find a UTF-8 locale. This may trigger build failures in";
  3291. ewarn "some python packages. Please ensure that a UTF-8 locale is listed in";
  3292. ewarn "/etc/locale.gen and run locale-gen.";
  3293. return 1;
  3294. fi;
  3295. return 0
  3296. }
  3297. python_fix_shebang ()
  3298. {
  3299. debug-print-function ${FUNCNAME} "$@";
  3300. [[ -n ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)";
  3301. local force quiet;
  3302. while [[ -n ${@} ]]; do
  3303. case "${1}" in
  3304. -f | --force)
  3305. force=1;
  3306. shift
  3307. ;;
  3308. -q | --quiet)
  3309. quiet=1;
  3310. shift
  3311. ;;
  3312. --)
  3313. shift;
  3314. break
  3315. ;;
  3316. *)
  3317. break
  3318. ;;
  3319. esac;
  3320. done;
  3321. [[ -n ${1} ]] || die "${FUNCNAME}: no paths given";
  3322. local path f;
  3323. for path in "$@";
  3324. do
  3325. local any_fixed is_recursive;
  3326. [[ -d ${path} ]] && is_recursive=1;
  3327. while IFS= read -r -d '' f; do
  3328. local shebang i;
  3329. local error= match=;
  3330. IFS= read -r shebang < "${f}";
  3331. if [[ ${shebang} == '#!'* ]]; then
  3332. local split_shebang=();
  3333. read -r -a split_shebang <<< ${shebang#"#!"} || die;
  3334. local in_path=${split_shebang[0]};
  3335. local from='^#! *[^ ]*';
  3336. if [[ ${in_path} == */env ]]; then
  3337. in_path=${split_shebang[1]};
  3338. from+=' *[^ ]*';
  3339. fi;
  3340. case ${in_path##*/} in
  3341. "${EPYTHON}")
  3342. match=1
  3343. ;;
  3344. python | python3)
  3345. match=1
  3346. ;;
  3347. python2 | python[23].[0-9] | python3.[1-9][0-9] | pypy | pypy3 | jython[23].[0-9])
  3348. match=1;
  3349. error=1
  3350. ;;
  3351. esac;
  3352. fi;
  3353. [[ -n ${force} ]] && error=;
  3354. if [[ ! -n ${match} ]]; then
  3355. [[ -n ${is_recursive} ]] && continue;
  3356. error=1;
  3357. fi;
  3358. if [[ ! -n ${quiet} ]]; then
  3359. einfo "Fixing shebang in ${f#${D}}.";
  3360. fi;
  3361. if [[ ! -n ${error} ]]; then
  3362. debug-print "${FUNCNAME}: in file ${f#${D}}";
  3363. debug-print "${FUNCNAME}: rewriting shebang: ${shebang}";
  3364. sed -i -e "1s@${from}@#!${EPREFIX}/usr/bin/${EPYTHON}@" "${f}" || die;
  3365. any_fixed=1;
  3366. else
  3367. eerror "The file has incompatible shebang:";
  3368. eerror " file: ${f#${D}}";
  3369. eerror " current shebang: ${shebang}";
  3370. eerror " requested impl: ${EPYTHON}";
  3371. die "${FUNCNAME}: conversion of incompatible shebang requested";
  3372. fi;
  3373. done < <(find -H "${path}" -type f -print0 || die);
  3374. if [[ ! -n ${any_fixed} ]]; then
  3375. eerror "QA error: ${FUNCNAME}, ${path#${D}} did not match any fixable files.";
  3376. eerror "There are no Python files in specified directory.";
  3377. die "${FUNCNAME} did not match any fixable files";
  3378. fi;
  3379. done
  3380. }
  3381. python_gen_any_dep ()
  3382. {
  3383. debug-print-function ${FUNCNAME} "$@";
  3384. local depstr=${1};
  3385. [[ -n ${depstr} ]] || die "No dependency string provided";
  3386. local i PYTHON_PKG_DEP out=;
  3387. for i in "${_PYTHON_SUPPORTED_IMPLS[@]}";
  3388. do
  3389. local PYTHON_USEDEP="python_targets_${i}(-)";
  3390. local PYTHON_SINGLE_USEDEP="python_single_target_${i}(-)";
  3391. _python_export "${i}" PYTHON_PKG_DEP;
  3392. local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}};
  3393. i_depstr=${i_depstr//\$\{PYTHON_SINGLE_USEDEP\}/${PYTHON_SINGLE_USEDEP}};
  3394. out="( ${PYTHON_PKG_DEP%:=} ${i_depstr} ) ${out}";
  3395. done;
  3396. echo "|| ( ${out})"
  3397. }
  3398. python_get_CFLAGS ()
  3399. {
  3400. debug-print-function ${FUNCNAME} "$@";
  3401. _python_export "${@}" PYTHON_CFLAGS;
  3402. echo "${PYTHON_CFLAGS}"
  3403. }
  3404. python_get_LIBS ()
  3405. {
  3406. debug-print-function ${FUNCNAME} "$@";
  3407. _python_export "${@}" PYTHON_LIBS;
  3408. echo "${PYTHON_LIBS}"
  3409. }
  3410. python_get_PYTHON_CONFIG ()
  3411. {
  3412. debug-print-function ${FUNCNAME} "$@";
  3413. _python_export "${@}" PYTHON_CONFIG;
  3414. echo "${PYTHON_CONFIG}"
  3415. }
  3416. python_get_includedir ()
  3417. {
  3418. debug-print-function ${FUNCNAME} "$@";
  3419. _python_export "${@}" PYTHON_INCLUDEDIR;
  3420. echo "${PYTHON_INCLUDEDIR}"
  3421. }
  3422. python_get_library_path ()
  3423. {
  3424. debug-print-function ${FUNCNAME} "$@";
  3425. _python_export "${@}" PYTHON_LIBPATH;
  3426. echo "${PYTHON_LIBPATH}"
  3427. }
  3428. python_get_scriptdir ()
  3429. {
  3430. debug-print-function ${FUNCNAME} "$@";
  3431. _python_export "${@}" PYTHON_SCRIPTDIR;
  3432. echo "${PYTHON_SCRIPTDIR}"
  3433. }
  3434. python_get_sitedir ()
  3435. {
  3436. debug-print-function ${FUNCNAME} "$@";
  3437. _python_export "${@}" PYTHON_SITEDIR;
  3438. echo "${PYTHON_SITEDIR}"
  3439. }
  3440. python_get_stdlib ()
  3441. {
  3442. debug-print-function ${FUNCNAME} "$@";
  3443. _python_export "${@}" PYTHON_STDLIB;
  3444. echo "${PYTHON_STDLIB}"
  3445. }
  3446. python_has_version ()
  3447. {
  3448. debug-print-function ${FUNCNAME} "$@";
  3449. local root_arg=(-b);
  3450. case ${1} in
  3451. -b | -d | -r)
  3452. root_arg=("${1}");
  3453. shift
  3454. ;;
  3455. esac;
  3456. local pkg;
  3457. for pkg in "$@";
  3458. do
  3459. ebegin " ${pkg}";
  3460. has_version "${root_arg[@]}" "${pkg}";
  3461. eend ${?} || return;
  3462. done;
  3463. return 0
  3464. }
  3465. python_moduleinto ()
  3466. {
  3467. debug-print-function ${FUNCNAME} "$@";
  3468. _PYTHON_MODULEROOT=${1}
  3469. }
  3470. python_newexe ()
  3471. {
  3472. debug-print-function ${FUNCNAME} "$@";
  3473. [[ ${EBUILD_PHASE} != install ]] && die "${FUNCNAME} can only be used in src_install";
  3474. [[ -n ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).';
  3475. [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>";
  3476. local wrapd=${_PYTHON_SCRIPTROOT:-/usr/bin};
  3477. local f=${1};
  3478. local newfn=${2};
  3479. local scriptdir=$(python_get_scriptdir);
  3480. local d=${scriptdir#${EPREFIX}};
  3481. ( dodir "${wrapd}";
  3482. exeopts -m 0755;
  3483. exeinto "${d}";
  3484. newexe "${f}" "${newfn}" || return ${?} );
  3485. local dosym=dosym;
  3486. [[ ${EAPI} == 7 ]] && dosym=dosym8;
  3487. "${dosym}" -r /usr/lib/python-exec/python-exec2 "${wrapd}/${newfn}";
  3488. if [[ -n ${_PYTHON_REWRITE_SHEBANG} ]]; then
  3489. python_fix_shebang -q "${ED}${d}/${newfn}";
  3490. fi
  3491. }
  3492. python_newscript ()
  3493. {
  3494. debug-print-function ${FUNCNAME} "$@";
  3495. [[ ${EBUILD_PHASE} != install ]] && die "${FUNCNAME} can only be used in src_install";
  3496. local _PYTHON_REWRITE_SHEBANG=1;
  3497. python_newexe "${@}"
  3498. }
  3499. python_optimize ()
  3500. {
  3501. debug-print-function ${FUNCNAME} "$@";
  3502. [[ -n ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).';
  3503. local PYTHON=${PYTHON};
  3504. [[ -n ${PYTHON} ]] || _python_export PYTHON;
  3505. [[ -x ${PYTHON} ]] || die "PYTHON (${PYTHON}) is not executable";
  3506. if [[ ${#} -eq 0 ]]; then
  3507. local f;
  3508. while IFS= read -r -d '' f; do
  3509. if [[ ${f} == /* && -d ${D}${f} ]]; then
  3510. set -- "${D}${f}" "${@}";
  3511. fi;
  3512. done < <("${PYTHON}" - <<-EOF ||
  3513. import sys
  3514. print("".join(x + "\0" for x in sys.path))
  3515. EOF
  3516. die);
  3517. debug-print "${FUNCNAME}: using sys.path: ${*/%/;}";
  3518. fi;
  3519. local jobs=$(makeopts_jobs);
  3520. local d;
  3521. for d in "$@";
  3522. do
  3523. local instpath=${d#${D}};
  3524. instpath=/${instpath##/};
  3525. einfo "Optimize Python modules for ${instpath}";
  3526. case "${EPYTHON}" in
  3527. python3.8)
  3528. "${PYTHON}" -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}";
  3529. "${PYTHON}" -O -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}";
  3530. "${PYTHON}" -OO -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}"
  3531. ;;
  3532. python* | pypy3)
  3533. "${PYTHON}" -m compileall -j "${jobs}" -o 0 -o 1 -o 2 --hardlink-dupes -q -f -d "${instpath}" "${d}"
  3534. ;;
  3535. pypy | jython2.7)
  3536. "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
  3537. ;;
  3538. *)
  3539. die "${FUNCNAME}: unexpected EPYTHON=${EPYTHON}"
  3540. ;;
  3541. esac;
  3542. done
  3543. }
  3544. python_scriptinto ()
  3545. {
  3546. debug-print-function ${FUNCNAME} "$@";
  3547. _PYTHON_SCRIPTROOT=${1}
  3548. }
  3549. python_setup ()
  3550. {
  3551. debug-print-function ${FUNCNAME} "$@";
  3552. _python_sanity_checks;
  3553. if [[ -n ${PYTHON_COMPAT_OVERRIDE} ]]; then
  3554. local impls=(${PYTHON_COMPAT_OVERRIDE});
  3555. [[ ${#impls[@]} -eq 1 ]] || die "PYTHON_COMPAT_OVERRIDE must name exactly one implementation for python-any-r1";
  3556. ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python";
  3557. ewarn "implementation will be used:";
  3558. ewarn;
  3559. ewarn " ${PYTHON_COMPAT_OVERRIDE}";
  3560. ewarn;
  3561. ewarn "Dependencies won't be satisfied, and EPYTHON/eselect-python will be ignored.";
  3562. _python_export "${impls[0]}" EPYTHON PYTHON;
  3563. _python_wrapper_setup;
  3564. einfo "Using ${EPYTHON} to build (via PYTHON_COMPAT_OVERRIDE)";
  3565. return;
  3566. fi;
  3567. local epython_impl=${EPYTHON/./_};
  3568. if [[ -n ${epython_impl} ]]; then
  3569. if ! has "${epython_impl}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then
  3570. if ! has "${epython_impl}" "${_PYTHON_ALL_IMPLS[@]}"; then
  3571. ewarn "Invalid EPYTHON: ${EPYTHON}";
  3572. else
  3573. einfo "EPYTHON (${EPYTHON}) not supported by the package";
  3574. fi;
  3575. else
  3576. if _python_run_check_deps "${epython_impl}"; then
  3577. _python_export EPYTHON PYTHON;
  3578. _python_wrapper_setup;
  3579. einfo "Using ${EPYTHON} to build (via EPYTHON)";
  3580. return;
  3581. fi;
  3582. fi;
  3583. fi;
  3584. local i;
  3585. for ((i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- ))
  3586. do
  3587. local impl=${_PYTHON_SUPPORTED_IMPLS[i]};
  3588. [[ ${impl} == ${epython_impl} ]] && continue;
  3589. _python_export "${impl}" EPYTHON PYTHON;
  3590. if _python_run_check_deps "${impl}"; then
  3591. _python_wrapper_setup;
  3592. einfo "Using ${EPYTHON} to build (via PYTHON_COMPAT iteration)";
  3593. return;
  3594. fi;
  3595. done;
  3596. eerror "No Python implementation found for the build. This is usually";
  3597. eerror "a bug in the ebuild. Please report it to bugs.gentoo.org";
  3598. eerror "along with the build log.";
  3599. echo;
  3600. die "No supported Python implementation installed."
  3601. }
  3602. qeerror ()
  3603. {
  3604. qout eerror "${@}"
  3605. }
  3606. qeinfo ()
  3607. {
  3608. qout einfo "${@}"
  3609. }
  3610. qewarn ()
  3611. {
  3612. qout ewarn "${@}"
  3613. }
  3614. qout ()
  3615. {
  3616. local outputmsg type;
  3617. type=${1};
  3618. shift;
  3619. outputmsg="${@}";
  3620. case "${EBUILD_PHASE}" in
  3621. depend)
  3622. unset outputmsg
  3623. ;;
  3624. clean)
  3625. unset outputmsg
  3626. ;;
  3627. preinst)
  3628. unset outputmsg
  3629. ;;
  3630. esac;
  3631. [[ -n "${outputmsg}" ]] && ${type} "${outputmsg}"
  3632. }
  3633. require_configured_kernel ()
  3634. {
  3635. [[ -n ${SKIP_KERNEL_CHECK} ]] && return;
  3636. if ! use kernel_linux; then
  3637. die "${FUNCNAME}() called on non-Linux system, please fix the ebuild";
  3638. fi;
  3639. if ! linux_config_src_exists; then
  3640. qeerror "Could not find a usable .config in the kernel source directory.";
  3641. qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources.";
  3642. qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that";
  3643. qeerror "it points to the necessary object directory so that it might find .config.";
  3644. die "Kernel not configured; no .config found in ${KV_OUT_DIR}";
  3645. fi;
  3646. get_version || die "Unable to determine configured kernel version"
  3647. }
  3648. restore_config ()
  3649. {
  3650. case ${EBUILD_PHASE} in
  3651. unpack | compile | configure | prepare)
  3652.  
  3653. ;;
  3654. *)
  3655. die "Bad package! restore_config only for use in src_{unpack,compile,configure,prepare} functions!"
  3656. ;;
  3657. esac;
  3658. use savedconfig || return;
  3659. local found check checked configfile;
  3660. local base=${PORTAGE_CONFIGROOT%/}/etc/portage/savedconfig;
  3661. for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}};
  3662. do
  3663. configfile=${base}/${CTARGET:+"${CTARGET}/"}${check};
  3664. [[ -r ${configfile} ]] || configfile=${base}/${CHOST:+"${CHOST}/"}${check};
  3665. [[ -r ${configfile} ]] || configfile=${base}/${check};
  3666. [[ "${checked}" == *"${configfile} "* ]] && continue;
  3667. einfo "Checking existence of \"${configfile}\" ...";
  3668. if [[ -r "${configfile}" ]]; then
  3669. einfo "Found \"${configfile}\"";
  3670. found=${configfile};
  3671. break;
  3672. fi;
  3673. checked+="${configfile} ";
  3674. done;
  3675. if [[ -f ${found} ]]; then
  3676. elog "Building using saved configfile \"${found}\"";
  3677. if [ $# -gt 0 ]; then
  3678. cp -pPR "${found}" "$1" || die "Failed to restore ${found} to $1";
  3679. else
  3680. die "need to know the restoration filename";
  3681. fi;
  3682. else
  3683. if [[ -d ${found} ]]; then
  3684. elog "Building using saved config directory \"${found}\"";
  3685. local dest=${PWD};
  3686. pushd "${found}" > /dev/null;
  3687. treecopy . "${dest}" || die "Failed to restore ${found} to $1";
  3688. popd > /dev/null;
  3689. else
  3690. ewarn "No saved config to restore - please remove USE=savedconfig or";
  3691. ewarn "provide a configuration file in ${PORTAGE_CONFIGROOT%/}/etc/portage/savedconfig/${CATEGORY}/${PN}";
  3692. ewarn "and ensure the build process has permission to access it.";
  3693. ewarn "Your config file(s) will not be used this time.";
  3694. fi;
  3695. fi
  3696. }
  3697. save_config ()
  3698. {
  3699. if [[ ${EBUILD_PHASE} != "install" ]]; then
  3700. die "Bad package! save_config only for use in src_install functions!";
  3701. fi;
  3702. [[ $# -eq 0 ]] && die "Usage: save_config <files>";
  3703. local configfile="/etc/portage/savedconfig/${CATEGORY}/${PF}";
  3704. if [[ $# -eq 1 && -f $1 ]]; then
  3705. dodir "${configfile%/*}";
  3706. cp "$@" "${ED}/${configfile}" || die "failed to save $*";
  3707. else
  3708. dodir "${configfile}";
  3709. treecopy "$@" "${ED}/${configfile}" || die "failed to save $*";
  3710. fi;
  3711. elog "Your configuration for ${CATEGORY}/${PF} has been saved in ";
  3712. elog "\"${configfile}\" for your editing pleasure.";
  3713. elog "You can edit these files by hand and remerge this package with";
  3714. elog "USE=savedconfig to customise the configuration.";
  3715. elog "You can rename this file/directory to one of the following for";
  3716. elog "its configuration to apply to multiple versions:";
  3717. elog '${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/';
  3718. elog '[${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]'
  3719. }
  3720. savedconfig_pkg_postinst ()
  3721. {
  3722. if use savedconfig; then
  3723. find "${EROOT}/etc/portage/savedconfig/${CATEGORY}/${PF}" -exec touch {} + 2> /dev/null;
  3724. fi
  3725. }
  3726. seq ()
  3727. {
  3728. local p=$(type -P seq);
  3729. if [[ -n ${p} ]]; then
  3730. "${p}" "$@" || die;
  3731. return $?;
  3732. fi;
  3733. local min max step;
  3734. case $# in
  3735. 1)
  3736. min=1 max=$1 step=1
  3737. ;;
  3738. 2)
  3739. min=$1 max=$2 step=1
  3740. ;;
  3741. 3)
  3742. min=$1 max=$3 step=$2
  3743. ;;
  3744. *)
  3745. die "seq called with wrong number of arguments"
  3746. ;;
  3747. esac;
  3748. p=$(type -P jot);
  3749. if [[ -n ${p} ]]; then
  3750. local reps;
  3751. if [[ ${step} != 0 ]]; then
  3752. reps=$(( (max - min) / step + 1 ));
  3753. else
  3754. reps=0;
  3755. fi;
  3756. jot $reps $min $max $step || die;
  3757. return $?;
  3758. fi;
  3759. while :; do
  3760. [[ $max -lt $min && $step -gt 0 ]] && break;
  3761. [[ $min -lt $max && $step -gt 0 ]] && break;
  3762. echo $min;
  3763. : $(( min += step ));
  3764. done;
  3765. return 0
  3766. }
  3767. set_arch_to_kernel ()
  3768. {
  3769. export ARCH=$(tc-arch-kernel)
  3770. }
  3771. set_arch_to_pkgmgr ()
  3772. {
  3773. export ARCH=$(tc-arch)
  3774. }
  3775. src_compile ()
  3776. {
  3777. default
  3778. }
  3779. src_configure ()
  3780. {
  3781. default
  3782. }
  3783. src_install ()
  3784. {
  3785. local FW_OPTIONS=("-v");
  3786. if use compress-xz; then
  3787. FW_OPTIONS+=("--xz");
  3788. else
  3789. if use compress-zstd; then
  3790. FW_OPTIONS+=("--zstd");
  3791. fi;
  3792. fi;
  3793. FW_OPTIONS+=("${ED}/lib/firmware");
  3794. ./copy-firmware.sh "${FW_OPTIONS[@]}" || die;
  3795. use deduplicate && ./dedup-firmware.sh "${ED}/lib/firmware" || die;
  3796. pushd "${ED}/lib/firmware" &> /dev/null || die;
  3797. einfo "Removing broken symlinks ...";
  3798. find * -xtype l -print -delete || die;
  3799. if use savedconfig; then
  3800. if [[ -s "${S}/${PN}.conf" ]]; then
  3801. local files_to_keep="${T}/files_to_keep.lst";
  3802. grep -v '^#' "${S}/${PN}.conf" 2> /dev/null > "${files_to_keep}" || die;
  3803. [[ -s "${files_to_keep}" ]] || die "grep failed, empty config file?";
  3804. einfo "Applying USE=savedconfig; Removing all files not listed in config ...";
  3805. find ! -type d -printf "%P\n" | grep -Fvx -f "${files_to_keep}" | xargs -d '\n' --no-run-if-empty rm -v;
  3806. if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
  3807. die "Find failed to print installed files";
  3808. else
  3809. if [[ ${PIPESTATUS[1]} -eq 2 ]]; then
  3810. die "Grep failed to select files to keep";
  3811. else
  3812. if [[ ${PIPESTATUS[2]} -ne 0 ]]; then
  3813. die "Failed to remove files not listed in config";
  3814. fi;
  3815. fi;
  3816. fi;
  3817. fi;
  3818. fi;
  3819. find -type d -empty -delete || die;
  3820. if ! ( shopt -s failglob;
  3821. : * ) 2> /dev/null; then
  3822. eerror "No files to install. Check your USE flag settings";
  3823. eerror "and the list of files in your saved configuration.";
  3824. die "Refusing to install an empty package";
  3825. fi;
  3826. echo "# Remove files that shall not be installed from this list." > "${S}"/${PN}.conf || die;
  3827. find * ! -type d >> "${S}"/${PN}.conf || die;
  3828. save_config "${S}"/${PN}.conf;
  3829. popd &> /dev/null || die;
  3830. ( insinto /usr/lib/dracut/dracut.conf.d;
  3831. newins - 10-${PN}.conf <<< "early_microcode=$(usex initramfs)" );
  3832. if use initramfs; then
  3833. dobin "${T}/make-amd-ucode-img";
  3834. ( exeinto /usr/lib/kernel/preinst.d;
  3835. doexe "${FILESDIR}/35-amd-microcode.install";
  3836. exeinto /usr/lib/kernel/install.d;
  3837. doexe "${FILESDIR}/35-amd-microcode-systemd.install" );
  3838. fi;
  3839. if use initramfs && ! use dist-kernel; then
  3840. insinto /boot;
  3841. doins "${S}"/amd-uc.img;
  3842. fi
  3843. }
  3844. src_prepare ()
  3845. {
  3846. default;
  3847. find . -type f -not -perm 0644 -print0 | xargs --null --no-run-if-empty chmod 0644 || die;
  3848. chmod +x copy-firmware.sh || die;
  3849. chmod +x dedup-firmware.sh || die;
  3850. chmod +x check_whence.py || die;
  3851. cp "${FILESDIR}/${PN}-make-amd-ucode-img.bash" "${T}/make-amd-ucode-img" || die;
  3852. chmod +x "${T}/make-amd-ucode-img" || die;
  3853. if use initramfs && ! use dist-kernel; then
  3854. if [[ -d "${S}/amd-ucode" ]]; then
  3855. "${T}/make-amd-ucode-img" "${S}" "${S}/amd-ucode" || die;
  3856. else
  3857. die "'${S}/amd-ucode' not found!";
  3858. fi;
  3859. fi;
  3860. local misc_files=(copy-firmware.sh dedup-firmware.sh check_whence.py WHENCE README);
  3861. local free_software=(keyspan_pda/keyspan_pda.fw keyspan_pda/xircom_pgs.fw dsp56k/bootstrap.bin ath9k_htc/htc_7010-1.4.0.fw ath9k_htc/htc_9271-1.4.0.fw cis/LA-PCM.cis cis/PCMLM28.cis cis/DP83903.cis cis/NE2K.cis cis/tamarack.cis cis/PE-200.cis cis/PE520.cis cis/3CXEM556.cis cis/3CCFEM556.cis cis/MT5634ZLX.cis cis/RS-COM-2P.cis cis/COMpad2.cis cis/COMpad4.cis cis/SW_555_SER.cis cis/SW_7xx_SER.cis cis/SW_8xx_SER.cis av7110/bootcode.bin usbdux_firmware.bin usbduxfast_firmware.bin usbduxsigma_firmware.bin brcm/brcmfmac4330-sdio.Prowise-PT301.txt brcm/brcmfmac43340-sdio.meegopad-t08.txt brcm/brcmfmac43362-sdio.cubietech,cubietruck.txt brcm/brcmfmac43362-sdio.lemaker,bananapro.txt brcm/brcmfmac43430a0-sdio.jumper-ezpad-mini3.txt "brcm/brcmfmac43430a0-sdio.ONDA-V80 PLUS.txt" brcm/brcmfmac43430-sdio.AP6212.txt brcm/brcmfmac43430-sdio.Hampoo-D2D3_Vi8A1.txt brcm/brcmfmac43430-sdio.MUR1DX.txt brcm/brcmfmac43430-sdio.raspberrypi,3-model-b.txt brcm/brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt brcm/brcmfmac4356-pcie.gpd-win-pocket.txt isci/isci_firmware.bin carl9170-1.fw atusb/atusb-0.2.dfu atusb/atusb-0.3.dfu atusb/rzusb-0.3.bin mellanox/mlxsw_spectrum-13.1420.122.mfa2 mellanox/mlxsw_spectrum-13.1530.152.mfa2 mellanox/mlxsw_spectrum-13.1620.192.mfa2 mellanox/mlxsw_spectrum-13.1702.6.mfa2 mellanox/mlxsw_spectrum-13.1703.4.mfa2 mellanox/mlxsw_spectrum-13.1910.622.mfa2 mellanox/mlxsw_spectrum-13.2000.1122.mfa2);
  3862. local unknown_license=(korg/k1212.dsp ess/maestro3_assp_kernel.fw ess/maestro3_assp_minisrc.fw yamaha/ds1_ctrl.fw yamaha/ds1_dsp.fw yamaha/ds1e_ctrl.fw ttusb-budget/dspbootcode.bin emi62/bitstream.fw emi62/loader.fw emi62/midi.fw emi62/spdif.fw ti_3410.fw ti_5052.fw mts_mt9234mu.fw mts_mt9234zba.fw whiteheat.fw whiteheat_loader.fw cpia2/stv0672_vp4.bin vicam/firmware.fw edgeport/boot.fw edgeport/boot2.fw edgeport/down.fw edgeport/down2.fw edgeport/down3.bin sb16/mulaw_main.csp sb16/alaw_main.csp sb16/ima_adpcm_init.csp sb16/ima_adpcm_playback.csp sb16/ima_adpcm_capture.csp sun/cassini.bin acenic/tg1.bin acenic/tg2.bin adaptec/starfire_rx.bin adaptec/starfire_tx.bin yam/1200.bin yam/9600.bin ositech/Xilinx7OD.bin qlogic/isp1000.bin myricom/lanai.bin yamaha/yss225_registers.bin lgs8g75.fw);
  3863. if use !unknown-license; then
  3864. einfo "Removing files with unknown license ...";
  3865. rm -v "${unknown_license[@]}" || die;
  3866. fi;
  3867. if use !redistributable; then
  3868. einfo "Removing non-redistributable files ...";
  3869. local OLDIFS="${IFS}";
  3870. local IFS='
  3871. ';
  3872. set -o pipefail;
  3873. find ! -type d -printf "%P\n" | grep -Fvx -e "${misc_files[*]}" -e "${free_software[*]}" -e "${unknown_license[*]}" | xargs -d '\n' --no-run-if-empty rm -v;
  3874. [[ ${?} -ne 0 ]] && die "Failed to remove non-redistributable files";
  3875. IFS="${OLDIFS}";
  3876. fi;
  3877. restore_config ${PN}.conf
  3878. }
  3879. src_test ()
  3880. {
  3881. default
  3882. }
  3883. src_unpack ()
  3884. {
  3885. if [[ ${PV} == 99999999* ]]; then
  3886. git-r3_src_unpack;
  3887. else
  3888. default;
  3889. if [[ ${#GIT_COMMIT} -gt 8 ]]; then
  3890. mv ${PN}-*/ ${P} || die;
  3891. fi;
  3892. fi
  3893. }
  3894. tc-arch ()
  3895. {
  3896. tc-ninja_magic_to_arch portage "$@"
  3897. }
  3898. tc-arch-kernel ()
  3899. {
  3900. tc-ninja_magic_to_arch kern "$@"
  3901. }
  3902. tc-check-openmp ()
  3903. {
  3904. if ! _tc-has-openmp; then
  3905. eerror "Your current compiler does not support OpenMP!";
  3906. if tc-is-gcc; then
  3907. eerror "Enable OpenMP support by building sys-devel/gcc with USE=\"openmp\".";
  3908. else
  3909. if tc-is-clang; then
  3910. eerror "OpenMP support in sys-devel/clang is provided by sys-libs/libomp.";
  3911. fi;
  3912. fi;
  3913. die "Active compiler does not have required support for OpenMP";
  3914. fi
  3915. }
  3916. tc-cpp-is-true ()
  3917. {
  3918. local CONDITION=${1};
  3919. shift;
  3920. $(tc-getTARGET_CPP) "${@}" -P - <<-EOF > /dev/null 2>&1
  3921. #if ${CONDITION}
  3922. true
  3923. #else
  3924. #error false
  3925. #endif
  3926. EOF
  3927.  
  3928. }
  3929. tc-detect-is-softfloat ()
  3930. {
  3931. [[ $(tc-getTARGET_CPP) == "gcc -E" ]] && return 1;
  3932. case ${CTARGET:-${CHOST}} in
  3933. *-newlib | *-elf | *-eabi | arm64-apple-darwin*)
  3934. return 1
  3935. ;;
  3936. arm*)
  3937. if tc-cpp-is-true "defined(__ARM_PCS_VFP)"; then
  3938. echo "no";
  3939. else
  3940. if tc-cpp-is-true "defined(__SOFTFP__)"; then
  3941. echo "yes";
  3942. else
  3943. echo "softfp";
  3944. fi;
  3945. fi;
  3946. return 0
  3947. ;;
  3948. *)
  3949. return 1
  3950. ;;
  3951. esac
  3952. }
  3953. tc-enables-cxx-assertions ()
  3954. {
  3955. tc-cpp-is-true "defined(_GLIBCXX_ASSERTIONS) || defined(_LIBCPP_ENABLE_ASSERTIONS) || defined(_LIBCPP_ENABLE_HARDENED_MODE)" ${CPPFLAGS} ${CXXFLAGS}
  3956. }
  3957. tc-enables-fortify-source ()
  3958. {
  3959. tc-cpp-is-true "defined(_FORTIFY_SOURCE)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
  3960. }
  3961. tc-enables-pie ()
  3962. {
  3963. tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
  3964. }
  3965. tc-enables-ssp ()
  3966. {
  3967. tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
  3968. }
  3969. tc-enables-ssp-all ()
  3970. {
  3971. tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
  3972. }
  3973. tc-enables-ssp-strong ()
  3974. {
  3975. tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
  3976. }
  3977. tc-endian ()
  3978. {
  3979. local host=$1;
  3980. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3981. host=${host%%-*};
  3982. case ${host} in
  3983. aarch64*be)
  3984. echo big
  3985. ;;
  3986. aarch64)
  3987. echo little
  3988. ;;
  3989. alpha*)
  3990. echo little
  3991. ;;
  3992. arc*b*)
  3993. echo big
  3994. ;;
  3995. arc*)
  3996. echo little
  3997. ;;
  3998. arm*b*)
  3999. echo big
  4000. ;;
  4001. arm*)
  4002. echo little
  4003. ;;
  4004. cris*)
  4005. echo little
  4006. ;;
  4007. hppa*)
  4008. echo big
  4009. ;;
  4010. i?86*)
  4011. echo little
  4012. ;;
  4013. ia64*)
  4014. echo little
  4015. ;;
  4016. loongarch*)
  4017. echo little
  4018. ;;
  4019. m68*)
  4020. echo big
  4021. ;;
  4022. mips*l*)
  4023. echo little
  4024. ;;
  4025. mips*)
  4026. echo big
  4027. ;;
  4028. powerpc*le)
  4029. echo little
  4030. ;;
  4031. powerpc*)
  4032. echo big
  4033. ;;
  4034. riscv*)
  4035. echo little
  4036. ;;
  4037. s390*)
  4038. echo big
  4039. ;;
  4040. sh*b*)
  4041. echo big
  4042. ;;
  4043. sh*)
  4044. echo little
  4045. ;;
  4046. sparc*)
  4047. echo big
  4048. ;;
  4049. x86_64*)
  4050. echo little
  4051. ;;
  4052. *)
  4053. echo wtf
  4054. ;;
  4055. esac
  4056. }
  4057. tc-env_build ()
  4058. {
  4059. tc-export_build_env;
  4060. CFLAGS=${BUILD_CFLAGS} CXXFLAGS=${BUILD_CXXFLAGS} CPPFLAGS=${BUILD_CPPFLAGS} LDFLAGS=${BUILD_LDFLAGS} AR=$(tc-getBUILD_AR) AS=$(tc-getBUILD_AS) CC=$(tc-getBUILD_CC) CPP=$(tc-getBUILD_CPP) CXX=$(tc-getBUILD_CXX) LD=$(tc-getBUILD_LD) NM=$(tc-getBUILD_NM) PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) RANLIB=$(tc-getBUILD_RANLIB) READELF=$(tc-getBUILD_READELF) "$@"
  4061. }
  4062. tc-export ()
  4063. {
  4064. local var;
  4065. for var in "$@";
  4066. do
  4067. [[ $(type -t "tc-get${var}") != "function" ]] && die "tc-export: invalid export variable '${var}'";
  4068. "tc-get${var}" > /dev/null;
  4069. done
  4070. }
  4071. tc-export_build_env ()
  4072. {
  4073. tc-export "$@";
  4074. if tc-is-cross-compiler; then
  4075. : "${BUILD_CFLAGS:=-O1 -pipe}";
  4076. : "${BUILD_CXXFLAGS:=-O1 -pipe}";
  4077. : "${BUILD_CPPFLAGS:= }";
  4078. : "${BUILD_LDFLAGS:= }";
  4079. else
  4080. : "${BUILD_CFLAGS:=${CFLAGS}}";
  4081. : "${BUILD_CXXFLAGS:=${CXXFLAGS}}";
  4082. : "${BUILD_CPPFLAGS:=${CPPFLAGS}}";
  4083. : "${BUILD_LDFLAGS:=${LDFLAGS}}";
  4084. fi;
  4085. export BUILD_{C,CXX,CPP,LD}FLAGS;
  4086. local v;
  4087. for v in BUILD_{C,CXX,CPP,LD}FLAGS;
  4088. do
  4089. export ${v#BUILD_}_FOR_BUILD="${!v}";
  4090. done
  4091. }
  4092. tc-get-build-ptr-size ()
  4093. {
  4094. $(tc-getBUILD_CPP) -P - <<< __SIZEOF_POINTER__ || die "Could not determine CBUILD pointer size"
  4095. }
  4096. tc-get-c-rtlib ()
  4097. {
  4098. local res=$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -print-libgcc-file-name 2> /dev/null);
  4099. case ${res} in
  4100. *libclang_rt*)
  4101. echo compiler-rt
  4102. ;;
  4103. *libgcc*)
  4104. echo libgcc
  4105. ;;
  4106. *)
  4107. return 1
  4108. ;;
  4109. esac;
  4110. return 0
  4111. }
  4112. tc-get-compiler-type ()
  4113. {
  4114. local code='
  4115. #if defined(__PATHSCALE__)
  4116. HAVE_PATHCC
  4117. #elif defined(__clang__)
  4118. HAVE_CLANG
  4119. #elif defined(__GNUC__)
  4120. HAVE_GCC
  4121. #endif
  4122. ';
  4123. local res=$($(tc-getCPP "$@") -E -P - <<< "${code}");
  4124. case ${res} in
  4125. *HAVE_PATHCC*)
  4126. echo pathcc
  4127. ;;
  4128. *HAVE_CLANG*)
  4129. echo clang
  4130. ;;
  4131. *HAVE_GCC*)
  4132. echo gcc
  4133. ;;
  4134. *)
  4135. echo unknown
  4136. ;;
  4137. esac
  4138. }
  4139. tc-get-cxx-stdlib ()
  4140. {
  4141. local code='#include <ciso646>
  4142.  
  4143. #if defined(_LIBCPP_VERSION)
  4144. HAVE_LIBCXX
  4145. #elif defined(__GLIBCXX__)
  4146. HAVE_LIBSTDCPP
  4147. #endif
  4148. ';
  4149. local res=$($(tc-getCXX) ${CPPFLAGS} ${CXXFLAGS} -x c++ -E -P - <<< "${code}" 2> /dev/null);
  4150. case ${res} in
  4151. *HAVE_LIBCXX*)
  4152. echo libc++
  4153. ;;
  4154. *HAVE_LIBSTDCPP*)
  4155. echo libstdc++
  4156. ;;
  4157. *)
  4158. return 1
  4159. ;;
  4160. esac;
  4161. return 0
  4162. }
  4163. tc-get-ptr-size ()
  4164. {
  4165. $(tc-getCPP) -P - <<< __SIZEOF_POINTER__ || die "Could not determine CHOST pointer size"
  4166. }
  4167. tc-getAR ()
  4168. {
  4169. tc-getPROG AR ar "$@"
  4170. }
  4171. tc-getAS ()
  4172. {
  4173. tc-getPROG AS as "$@"
  4174. }
  4175. tc-getBUILD_AR ()
  4176. {
  4177. tc-getBUILD_PROG AR ar "$@"
  4178. }
  4179. tc-getBUILD_AS ()
  4180. {
  4181. tc-getBUILD_PROG AS as "$@"
  4182. }
  4183. tc-getBUILD_CC ()
  4184. {
  4185. tc-getBUILD_PROG CC gcc "$@"
  4186. }
  4187. tc-getBUILD_CPP ()
  4188. {
  4189. tc-getBUILD_PROG CPP "$(tc-getBUILD_CC) -E" "$@"
  4190. }
  4191. tc-getBUILD_CXX ()
  4192. {
  4193. tc-getBUILD_PROG CXX g++ "$@"
  4194. }
  4195. tc-getBUILD_LD ()
  4196. {
  4197. tc-getBUILD_PROG LD ld "$@"
  4198. }
  4199. tc-getBUILD_NM ()
  4200. {
  4201. tc-getBUILD_PROG NM nm "$@"
  4202. }
  4203. tc-getBUILD_OBJCOPY ()
  4204. {
  4205. tc-getBUILD_PROG OBJCOPY objcopy "$@"
  4206. }
  4207. tc-getBUILD_PKG_CONFIG ()
  4208. {
  4209. tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  4210. }
  4211. tc-getBUILD_PROG ()
  4212. {
  4213. local vars="BUILD_$1 $1_FOR_BUILD HOST$1";
  4214. tc-is-cross-compiler || vars+=" $1";
  4215. _tc-getPROG CBUILD "${vars}" "${@:2}"
  4216. }
  4217. tc-getBUILD_RANLIB ()
  4218. {
  4219. tc-getBUILD_PROG RANLIB ranlib "$@"
  4220. }
  4221. tc-getBUILD_READELF ()
  4222. {
  4223. tc-getBUILD_PROG READELF readelf "$@"
  4224. }
  4225. tc-getBUILD_STRINGS ()
  4226. {
  4227. tc-getBUILD_PROG STRINGS strings "$@"
  4228. }
  4229. tc-getBUILD_STRIP ()
  4230. {
  4231. tc-getBUILD_PROG STRIP strip "$@"
  4232. }
  4233. tc-getCC ()
  4234. {
  4235. tc-getPROG CC gcc "$@"
  4236. }
  4237. tc-getCPP ()
  4238. {
  4239. tc-getPROG CPP "${CC:-gcc} -E" "$@"
  4240. }
  4241. tc-getCXX ()
  4242. {
  4243. tc-getPROG CXX g++ "$@"
  4244. }
  4245. tc-getDLLWRAP ()
  4246. {
  4247. tc-getPROG DLLWRAP dllwrap "$@"
  4248. }
  4249. tc-getF77 ()
  4250. {
  4251. tc-getPROG F77 gfortran "$@"
  4252. }
  4253. tc-getFC ()
  4254. {
  4255. tc-getPROG FC gfortran "$@"
  4256. }
  4257. tc-getGCJ ()
  4258. {
  4259. tc-getPROG GCJ gcj "$@"
  4260. }
  4261. tc-getGO ()
  4262. {
  4263. tc-getPROG GO gccgo "$@"
  4264. }
  4265. tc-getLD ()
  4266. {
  4267. tc-getPROG LD ld "$@"
  4268. }
  4269. tc-getNM ()
  4270. {
  4271. tc-getPROG NM nm "$@"
  4272. }
  4273. tc-getOBJCOPY ()
  4274. {
  4275. tc-getPROG OBJCOPY objcopy "$@"
  4276. }
  4277. tc-getOBJDUMP ()
  4278. {
  4279. tc-getPROG OBJDUMP objdump "$@"
  4280. }
  4281. tc-getPKG_CONFIG ()
  4282. {
  4283. tc-getPROG PKG_CONFIG pkg-config "$@"
  4284. }
  4285. tc-getPROG ()
  4286. {
  4287. _tc-getPROG CHOST "$@"
  4288. }
  4289. tc-getRANLIB ()
  4290. {
  4291. tc-getPROG RANLIB ranlib "$@"
  4292. }
  4293. tc-getRC ()
  4294. {
  4295. tc-getPROG RC windres "$@"
  4296. }
  4297. tc-getREADELF ()
  4298. {
  4299. tc-getPROG READELF readelf "$@"
  4300. }
  4301. tc-getSTRINGS ()
  4302. {
  4303. tc-getPROG STRINGS strings "$@"
  4304. }
  4305. tc-getSTRIP ()
  4306. {
  4307. tc-getPROG STRIP strip "$@"
  4308. }
  4309. tc-getTARGET_CPP ()
  4310. {
  4311. if [[ -n ${CTARGET} ]]; then
  4312. _tc-getPROG CTARGET TARGET_CPP "gcc -E" "$@";
  4313. else
  4314. tc-getCPP "$@";
  4315. fi
  4316. }
  4317. tc-has-64bit-time_t ()
  4318. {
  4319. $(tc-getCC) ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &> /dev/null
  4320. #include <sys/types.h>
  4321. int test[sizeof(time_t) >= 8 ? 1 : -1];
  4322. EOF
  4323.  
  4324. return $?
  4325. }
  4326. tc-has-tls ()
  4327. {
  4328. local base="${T}/test-tc-tls";
  4329. cat <<-EOF > "${base}.c"
  4330. int foo(int *i) {
  4331. static __thread int j = 0;
  4332. return *i ? j : *i;
  4333. }
  4334. EOF
  4335.  
  4336. local flags;
  4337. case $1 in
  4338. -s)
  4339. flags="-S"
  4340. ;;
  4341. -c)
  4342. flags="-c"
  4343. ;;
  4344. -l)
  4345.  
  4346. ;;
  4347. -*)
  4348. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  4349. ;;
  4350. esac;
  4351. case "${CHOST}" in
  4352. *-darwin*)
  4353. : ${flags:=-dynamiclib}
  4354. ;;
  4355. *)
  4356. : ${flags:=-fPIC -shared -Wl,-z,defs}
  4357. ;;
  4358. esac;
  4359. [[ $1 == -* ]] && shift;
  4360. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" >&/dev/null;
  4361. local ret=$?;
  4362. rm -f "${base}"*;
  4363. return ${ret}
  4364. }
  4365. tc-is-clang ()
  4366. {
  4367. [[ $(tc-get-compiler-type) == clang ]]
  4368. }
  4369. tc-is-cross-compiler ()
  4370. {
  4371. [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
  4372. }
  4373. tc-is-gcc ()
  4374. {
  4375. [[ $(tc-get-compiler-type) == gcc ]]
  4376. }
  4377. tc-is-lto ()
  4378. {
  4379. local f="${T}/test-lto.o";
  4380. local ret=1;
  4381. case $(tc-get-compiler-type) in
  4382. clang)
  4383. $(tc-getCC) ${CFLAGS} -c -o "${f}" -x c - <<< "" || die;
  4384. llvm-bcanalyzer "${f}" &> /dev/null && ret=0
  4385. ;;
  4386. gcc)
  4387. $(tc-getCC) ${CFLAGS} -c -o "${f}" -x c - <<< "" || die;
  4388. [[ $($(tc-getREADELF) -S "${f}") == *.gnu.lto* ]] && ret=0
  4389. ;;
  4390. esac;
  4391. rm -f "${f}" || die;
  4392. return "${ret}"
  4393. }
  4394. tc-is-softfloat ()
  4395. {
  4396. tc-detect-is-softfloat || tc-tuple-is-softfloat
  4397. }
  4398. tc-is-static-only ()
  4399. {
  4400. local host=${CTARGET:-${CHOST}};
  4401. [[ ${host} == *-mint* ]]
  4402. }
  4403. tc-ld-disable-gold ()
  4404. {
  4405. tc-ld-is-gold "$@" && tc-ld-force-bfd "$@"
  4406. }
  4407. tc-ld-force-bfd ()
  4408. {
  4409. if tc-ld-is-bfd "$@"; then
  4410. return;
  4411. fi;
  4412. ewarn "Forcing usage of the BFD linker";
  4413. local ld=$(unset LD; tc-getLD "$@");
  4414. local bfd_ld="${ld}.bfd";
  4415. local path_ld=$(type -P "${bfd_ld}" 2> /dev/null);
  4416. [[ -e ${path_ld} ]] && export LD=${bfd_ld};
  4417. if tc-is-gcc || tc-is-clang; then
  4418. export CFLAGS="${CFLAGS} -fuse-ld=bfd";
  4419. export CXXFLAGS="${CXXFLAGS} -fuse-ld=bfd";
  4420. export LDFLAGS="${LDFLAGS} -fuse-ld=bfd";
  4421. fi
  4422. }
  4423. tc-ld-is-bfd ()
  4424. {
  4425. local out;
  4426. local -x LC_ALL=C;
  4427. out=$($(tc-getLD "$@") --version 2>&1);
  4428. if [[ ${out} != "GNU ld"* ]]; then
  4429. return 1;
  4430. fi;
  4431. local base="${T}/test-tc-linker";
  4432. cat <<-EOF > "${base}.c"
  4433. int main(void) { return 0; }
  4434. EOF
  4435.  
  4436. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  4437. rm -f "${base}"*;
  4438. if [[ ! ${out} =~ .*^"GNU ld".* ]]; then
  4439. return 1;
  4440. fi;
  4441. return 0
  4442. }
  4443. tc-ld-is-gold ()
  4444. {
  4445. local out;
  4446. local -x LC_ALL=C;
  4447. out=$($(tc-getLD "$@") --version 2>&1);
  4448. if [[ ${out} == *"GNU gold"* ]]; then
  4449. return 0;
  4450. fi;
  4451. local base="${T}/test-tc-linker";
  4452. cat <<-EOF > "${base}.c"
  4453. int main(void) { return 0; }
  4454. EOF
  4455.  
  4456. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  4457. rm -f "${base}"*;
  4458. if [[ ${out} == *"GNU gold"* ]]; then
  4459. return 0;
  4460. fi;
  4461. return 1
  4462. }
  4463. tc-ld-is-lld ()
  4464. {
  4465. local out;
  4466. local -x LC_ALL=C;
  4467. out=$($(tc-getLD "$@") --version 2>&1);
  4468. if [[ ${out} == *"LLD"* ]]; then
  4469. return 0;
  4470. fi;
  4471. local base="${T}/test-tc-linker";
  4472. cat <<-EOF > "${base}.c"
  4473. int main(void) { return 0; }
  4474. EOF
  4475.  
  4476. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  4477. rm -f "${base}"*;
  4478. if [[ ${out} == *"LLD"* ]]; then
  4479. return 0;
  4480. fi;
  4481. return 1
  4482. }
  4483. tc-ld-is-mold ()
  4484. {
  4485. local out;
  4486. local -x LC_ALL=C;
  4487. out=$($(tc-getLD "$@") --version 2>&1);
  4488. if [[ ${out} == *"mold"* ]]; then
  4489. return 0;
  4490. fi;
  4491. local base="${T}/test-tc-linker";
  4492. cat <<-EOF > "${base}.c"
  4493. int main(void) { return 0; }
  4494. EOF
  4495.  
  4496. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  4497. rm -f "${base}"*;
  4498. if [[ ${out} == *"mold"* ]]; then
  4499. return 0;
  4500. fi;
  4501. return 1
  4502. }
  4503. tc-ninja_magic_to_arch ()
  4504. {
  4505. function _tc_echo_kernel_alias ()
  4506. {
  4507. [[ ${type} == "kern" ]] && echo $1 || echo $2
  4508. };
  4509. local type=$1;
  4510. local host=$2;
  4511. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  4512. case ${host} in
  4513. arm64*)
  4514. echo arm64
  4515. ;;
  4516. aarch64*)
  4517. echo arm64
  4518. ;;
  4519. alpha*)
  4520. echo alpha
  4521. ;;
  4522. arc*)
  4523. echo arc
  4524. ;;
  4525. arm*)
  4526. echo arm
  4527. ;;
  4528. avr*)
  4529. _tc_echo_kernel_alias avr32 avr
  4530. ;;
  4531. bfin*)
  4532. _tc_echo_kernel_alias blackfin bfin
  4533. ;;
  4534. c6x*)
  4535. echo c6x
  4536. ;;
  4537. cris*)
  4538. echo cris
  4539. ;;
  4540. frv*)
  4541. echo frv
  4542. ;;
  4543. hexagon*)
  4544. echo hexagon
  4545. ;;
  4546. hppa*)
  4547. _tc_echo_kernel_alias parisc hppa
  4548. ;;
  4549. i?86*)
  4550. echo x86
  4551. ;;
  4552. ia64*)
  4553. echo ia64
  4554. ;;
  4555. loongarch*)
  4556. _tc_echo_kernel_alias loongarch loong
  4557. ;;
  4558. m68*)
  4559. echo m68k
  4560. ;;
  4561. metag*)
  4562. echo metag
  4563. ;;
  4564. microblaze*)
  4565. echo microblaze
  4566. ;;
  4567. mips*)
  4568. echo mips
  4569. ;;
  4570. nios2*)
  4571. echo nios2
  4572. ;;
  4573. nios*)
  4574. echo nios
  4575. ;;
  4576. or1k* | or32*)
  4577. echo openrisc
  4578. ;;
  4579. powerpc*)
  4580. if [[ ${type} == "kern" ]]; then
  4581. echo powerpc;
  4582. else
  4583. if [[ ${host} == powerpc64* ]]; then
  4584. echo ppc64;
  4585. else
  4586. echo ppc;
  4587. fi;
  4588. fi
  4589. ;;
  4590. riscv*)
  4591. echo riscv
  4592. ;;
  4593. s390*)
  4594. echo s390
  4595. ;;
  4596. score*)
  4597. echo score
  4598. ;;
  4599. sh64*)
  4600. _tc_echo_kernel_alias sh64 sh
  4601. ;;
  4602. sh*)
  4603. echo sh
  4604. ;;
  4605. sparc64*)
  4606. _tc_echo_kernel_alias sparc64 sparc
  4607. ;;
  4608. sparc*)
  4609. [[ ${PROFILE_ARCH} == "sparc64" ]] && _tc_echo_kernel_alias sparc64 sparc || echo sparc
  4610. ;;
  4611. tile*)
  4612. echo tile
  4613. ;;
  4614. vax*)
  4615. echo vax
  4616. ;;
  4617. x86_64*)
  4618. if [[ ${type} == "kern" ]]; then
  4619. echo x86;
  4620. else
  4621. echo amd64;
  4622. fi
  4623. ;;
  4624. xtensa*)
  4625. echo xtensa
  4626. ;;
  4627. *)
  4628. echo unknown
  4629. ;;
  4630. esac
  4631. }
  4632. tc-stack-grows-down ()
  4633. {
  4634. case ${ARCH} in
  4635. hppa | metag)
  4636. return 1
  4637. ;;
  4638. esac;
  4639. return 0
  4640. }
  4641. tc-tuple-is-softfloat ()
  4642. {
  4643. local CTARGET=${CTARGET:-${CHOST}};
  4644. case ${CTARGET//_/-} in
  4645. bfin* | h8300*)
  4646. echo "only"
  4647. ;;
  4648. *-softfloat-*)
  4649. echo "yes"
  4650. ;;
  4651. *-softfp-*)
  4652. echo "softfp"
  4653. ;;
  4654. arm*-hardfloat-* | arm*eabihf)
  4655. echo "no"
  4656. ;;
  4657. *-newlib | *-elf | *-eabi)
  4658. echo "no"
  4659. ;;
  4660. arm64-apple-darwin*)
  4661. echo "no"
  4662. ;;
  4663. arm*)
  4664. echo "yes"
  4665. ;;
  4666. *)
  4667. echo "no"
  4668. ;;
  4669. esac
  4670. }
  4671. treecopy ()
  4672. {
  4673. local dest=${!#};
  4674. local files_count=$#;
  4675. while (( $# > 1 )); do
  4676. local dirstruct=$(dirname "$1");
  4677. mkdir -p "${dest}/${dirstruct}" || die;
  4678. cp -pPR "$1" "${dest}/${dirstruct}" || die;
  4679. shift;
  4680. done
  4681. }
  4682. ver_cut ()
  4683. {
  4684. local range=${1};
  4685. local v=${2:-${PV}};
  4686. local start end;
  4687. local -a comp;
  4688. __eapi7_ver_split "${v}";
  4689. local max=$((${#comp[@]}/2));
  4690. __eapi7_ver_parse_range "${range}" "${max}";
  4691. local IFS=;
  4692. if [[ ${start} -gt 0 ]]; then
  4693. start=$(( start*2 - 1 ));
  4694. fi;
  4695. echo "${comp[*]:start:end*2-start}"
  4696. }
  4697. ver_rs ()
  4698. {
  4699. local v;
  4700. (( ${#} & 1 )) && v=${@: -1} || v=${PV};
  4701. local start end i;
  4702. local -a comp;
  4703. __eapi7_ver_split "${v}";
  4704. local max=$((${#comp[@]}/2 - 1));
  4705. while [[ ${#} -ge 2 ]]; do
  4706. __eapi7_ver_parse_range "${1}" "${max}";
  4707. for ((i = start*2; i <= end*2; i+=2 ))
  4708. do
  4709. [[ ${i} -eq 0 && -z ${comp[i]} ]] && continue;
  4710. comp[i]=${2};
  4711. done;
  4712. shift 2;
  4713. done;
  4714. local IFS=;
  4715. echo "${comp[*]}"
  4716. }
  4717. ver_test ()
  4718. {
  4719. local va op vb;
  4720. if [[ $# -eq 3 ]]; then
  4721. va=${1};
  4722. shift;
  4723. else
  4724. va=${PVR};
  4725. fi;
  4726. [[ $# -eq 2 ]] || die "${FUNCNAME}: bad number of arguments";
  4727. op=${1};
  4728. vb=${2};
  4729. case ${op} in
  4730. -eq | -ne | -lt | -le | -gt | -ge)
  4731.  
  4732. ;;
  4733. *)
  4734. die "${FUNCNAME}: invalid operator: ${op}"
  4735. ;;
  4736. esac;
  4737. __eapi7_ver_compare "${va}" "${vb}";
  4738. test $? "${op}" 2
  4739. }
  4740.  
Tags: log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement