GenPi64 / Build.Dist

Build scripts for building GenPi64 images.
Other
11 stars 10 forks source link

Resolve package issues that depend on the SCRIPTS environment variable. #206

Closed tin-machine closed 1 year ago

tin-machine commented 1 year ago

Overview

net-misc/dhcpcd-9.5.1 fails to emerge at JOB emerge_new_profile.

Changes

parsers/emerge/emerge

I want to unset $SCRIPTS just before an emerge done in a child process.

My environment

Issues

Log of failed emerge of net-misc/dhcpcd-9.5.1 at JOB emerge_new_profile.

make[1]: *** No rule to make target '/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/scripts', needed by 'all'.  Stop.

The logs before and after are shown below.

aarch64-unknown-linux-gnu-gcc -march=armv8-a+crc -mtune=cortex-a72 -ftree-vectorize -O2 -pipe -march=native -O2 -pipe -std=c99 -DHAVE_C
ONFIG_H -DNDEBUG -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DINET -DARP -DARPING -DIPV4LL -DINET6 -DDHCP6 -DAUTH -DPLUGIN_DEV -I.. -I../src -I./crypt -c ../compat/rb.c -o ../compat/rb.o
make[1]: *** No rule to make target '/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/scripts', needed by 'all'.  Stop.
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/var/tmp/portage/net-misc/dhcpcd-9.5.1/work/dhcpcd-9.5.1/src'
make: *** [Makefile:24: all] Error 2
 * ERROR: net-misc/dhcpcd-9.5.1::gentoo failed (compile phase):
 *   emake failed
 *
 * If you need support, post the output of `emerge --info '=net-misc/dhcpcd-9.5.1::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=net-misc/dhcpcd-9.5.1::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/net-misc/dhcpcd-9.5.1/temp/build.log.gz'.
 * The ebuild environment file is located at '/var/tmp/portage/net-misc/dhcpcd-9.5.1/temp/environment'.
 * Working directory: '/var/tmp/portage/net-misc/dhcpcd-9.5.1/work/dhcpcd-9.5.1'
 * S: '/var/tmp/portage/net-misc/dhcpcd-9.5.1/work/dhcpcd-9.5.1'

 * Messages for package net-misc/dhcpcd-9.5.1:

 * ERROR: net-misc/dhcpcd-9.5.1::gentoo failed (compile phase):
 *   emake failed
 *
 * If you need support, post the output of `emerge --info '=net-misc/dhcpcd-9.5.1::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=net-misc/dhcpcd-9.5.1::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/net-misc/dhcpcd-9.5.1/temp/build.log.gz'.
 * The ebuild environment file is located at '/var/tmp/portage/net-misc/dhcpcd-9.5.1/temp/environment'.
 * Working directory: '/var/tmp/portage/net-misc/dhcpcd-9.5.1/work/dhcpcd-9.5.1'
 * S: '/var/tmp/portage/net-misc/dhcpcd-9.5.1/work/dhcpcd-9.5.1'

Checking the Makefile in net-misc/dhcpcd, uses $SCRIPTS as the target for all.

This seems to cause net-misc/dhcpcd-9.5.1 to refer to Build.Dist/scripts when building. ( It appears that you are trying to reference an area outside of the chroot. I would appreciate it if you could point out if this is a problem in my environment )

I thought there are two approaches to improve this problem.

  1. prefix all $SCRIPTS in the GenPi64 side scripts
  2. unset $SCRIPTS just before emerge. Either approach seemed to work, but with approach 1
    • There are a lot of things to fix.
    • Prefixing the $SCRIPTS does not look beautiful.
    • There is concern that some prefixes may have similar problems in the future. I decided to go with 2 for this reason.

If there are any dangers I am unaware of, please reject.

Additional Information

I have confirmed that unsetting in the child process does not affect the parent process as follows.

Parent script

#!/bin/bash

export MyVar="MyVar"
echo "Parent process: MyVar=$MyVar"
./child_script.sh
echo "Parent process: MyVar=$MyVar"

child script( child_script.sh )

#!/bin/bash

echo "Child process: MyVar=$MyVar"
unset MyVar
echo "Child process after unset: MyVar=$MyVar"
jonesmz commented 1 year ago

I'm a little confused how this could be impacting your build of the dhcpd package.

The file

"${PROJECT_DIR}/chroot/em-$$"

is written into the chroot's directory, and then executed inside of the chroot, without the environment from the host.

The SCRIPTS environment variable shouldn't be set when em-$$ is running, unless it's coming from something inside of the chroot.

Notably, I don't run into this, and i'm pretty sure dhcpd is emerged as part of the default set of packages.

This isn't to say that we can't unset the SCRIPTS variable. But before doing that, i'd like to understand what's setting it in the first place?

E.g. what value does it have when it's breaking?

tin-machine commented 1 year ago

Thanks for checking. I tried to share the following file but it disappeared. Build.Dist/build/GenPi64Systemd/chroot/var/tmp/portage/net-misc/dhcpcd-9.5.1/temp/environment

It will take a few days to get back to you. Please take your time.

tin-machine commented 1 year ago

Sorry for the delay in getting back to you. I don't think this pull request is appropriate and I will close it.

However, I will leave my confirmation result as a verification result. I have stopped at a different package, which may be due to a change in the status of the Gentoo repositories. The logs are for a different package.

I built with build.sh and got an error in dev-util/cmake This error seems to be a general error, not one caused by an environment variable.

All of the environment variables seem to be taken over. I think chroot is the ideal way to do this in a clean environment.

I wondered why and looked into it. I thought "os.environ.clear()" might be necessary (I could be wrong, I'm not sure...). For example, the script below.

import os
import pychroot

chroot_path = "/var/tmp"
with pychroot.Chroot(chroot_path):
    os.environ.clear()
    os.environ["PATH"] = "/bin:/usr/bin"
    os.environ["TERM"] = "xterm"
    for key, value in os.environ.items():
        print(f"{key}={value}")

print("Back in host environment")

os.environ.clear() is commented out, the environment variables are inherited. So I would like to close my pullrequest. I will try another way.

Build.Dist/build/GenPi64Systemd//chroot/var/tmp/portage/dev-util/cmake-3.26.4-r2/temp/environment # cat Build.Dist*/build/GenPi64Systemd//chroot/var/tmp/portage/dev-util/cmake-3.26.4-r2/temp/environment declare -x ABI="arm64" declare -x ABI_MIPS="" declare -x ABI_S390="" declare -x ABI_X86="" declare -x ADA_TARGET="" declare -x ALSA_CARDS="" declare -x AMDGPU_TARGETS="" declare -x APACHE2_MODULES="" declare -x APACHE2_MPMS="" declare -x ARCH="arm64" declare -x BASEDIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist" declare BDEPEND="verify-sig? ( sec-keys/openpgp-keys-bradking ) doc? ( dev-python/requests dev-python/sphinx ) test? ( app-arch/libarchive[zstd] ) sys-devel/make test? ( x11-base/xorg-server[xvfb] x11-apps/xhost ) verify-sig? ( app-crypt/gnupg >=app-portage/gemato-16 )" declare -x BINARY_ASSETS="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/build-binary-assets" declare -x BINPKGS_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/packages" declare -x BINPKG_FORMAT="gpkg" declare -x BINPKG_GPG_SIGNING_BASE_COMMAND="/usr/bin/flock /run/lock/portage-binpkg-gpg.lock /usr/bin/gpg --sign --armor [PORTAGE_CONFIG]" declare -x BINPKG_GPG_SIGNING_DIGEST="SHA512" declare -x BINPKG_GPG_VERIFY_BASE_COMMAND="/usr/bin/gpg --verify --batch --no-tty --no-auto-check-trustdb --status-fd 2 [PORTAGE_CONFIG] [SIGNATURE]" declare -x BINPKG_GPG_VERIFY_GPG_HOME="/etc/portage/gnupg" declare -x BOOTSTRAP_USE="unicode internal-glib pkg-config split-usr xml python_targets_python3_11 python_single_target_python3_11 systemd sysv-utils udev" declare -- BUILD_DIR="/var/tmp/portage/dev-util/cmake-3.26.4-r2/work/cmake-3.26.4_build" declare -- BYTECOMPFLAGS="-L ." declare -x CALLBACKS="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/callbacks" declare -x CALLIGRA_FEATURES="" declare -x CAMERAS="" declare -x CBUILD="aarch64-unknown-linux-gnu" declare -x CFLAGS="-O2 -march=native -O2 -pipe" declare -x CFLAGS_default declare -x CHOST="aarch64-unknown-linux-gnu" declare -x CHOST_arm64="aarch64-unknown-linux-gnu" declare -x CHOST_default="aarch64-unknown-linux-gnu" declare -x CHROOT_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/chroot" declare -- CMAKE_BINARY="cmake" declare -- CMAKE_BUILD_TYPE="RelWithDebInfo" declare -- CMAKE_DOCS_PREBUILT="1" declare -- CMAKE_DOCS_PREBUILT_DEV="sam" declare -- CMAKE_DOCS_USEFLAG="doc" declare -- CMAKE_DOCS_VERSION="3.26.4" declare -- CMAKE_MAKEFILE_GENERATOR="emake" declare -a CMAKE_REMOVE_MODULES_LIST=([0]="none") declare -- CMAKE_USE_DIR="/var/tmp/portage/dev-util/cmake-3.26.4-r2/work/cmake-3.26.4" declare -- CMAKE_VERBOSE="ON" declare -- CMAKE_WARN_UNUSED_CLI="yes" declare -x COLLECTD_PLUGINS="" declare -x CONFIG_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/config" declare -x CPU_FLAGS_ARM="" declare -x CPU_FLAGS_PPC="" declare -x CPU_FLAGS_X86="" declare -x CTARGET_default="aarch64-unknown-linux-gnu" declare -x CURL_SSL="" declare -x CXXFLAGS="-O2 -march=native -O2 -pipe" declare -x DEFAULT_ABI="arm64" declare -x DEFINED_PHASES=" compile configure install postinst postrm prepare test unpack" declare DEPEND=" >=app-arch/libarchive-3.3.3:= app-crypt/rhash:0= >=dev-libs/expat-2.0.1 >=dev-libs/jsoncpp-1.9.2-r2:0= >=dev-libs/libuv-1.10.0:= >=net-misc/curl-7.21.5[ssl] sys-libs/zlib virtual/pkgconfig emacs? ( >=app-editors/emacs-23.1:* ) ncurses? ( sys-libs/ncurses:0= ) qt5? ( dev-qt/qtcore:5 dev-qt/qtgui:5 dev-qt/qtwidgets:5 ) " declare DESCRIPTION="Cross platform Make" declare -- DESKTOP_DATABASE_DIR="/usr/share/applications" declare -x DIROPTIONS="-m0755" declare -x DISTFILES_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/distfiles" declare -x EAPI="8" declare -x ELIBC="glibc" declare -- EMACS="/usr/bin/emacs" declare -- EMACSFLAGS="-batch -q --no-site-file" declare -- EMACSMODULES="/usr/@libdir@/emacs/modules" 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" declare -- EPOCHREALTIME="1691792937.107679" declare -- EPOCHSECONDS="1691792937" declare -x EXEOPTIONS="-m0755" declare -x FCFLAGS="-O2 -march=native -O2 -pipe" 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}\"" declare -x FFLAGS="-O2 -march=native -O2 -pipe" declare -x FFTOOLS="" declare -x GCC_SPECS="" declare -x GPG_VERIFY_GROUP_DROP="nogroup" declare -x GPG_VERIFY_USER_DROP="nobody" declare -x GPSD_PROTOCOLS="" declare -x GRUB_PLATFORMS="" declare HOMEPAGE="https://cmake.org/" declare IDEPEND="" declare -x INHERITED=" toolchain-funcs multilib bash-completion-r1 flag-o-matic multiprocessing ninja-utils xdg-utils cmake elisp-common virtualx verify-sig" declare -x INPUT_DEVICES="" declare -x INSOPTIONS="-m0644" declare IUSE="doc emacs ncurses qt5 test test verify-sig" declare -x IUSE_EFFECTIVE="alpha amd64 amd64-linux arm arm64 arm64-macos doc elibc_Darwin elibc_SunOS elibc_bionic elibc_glibc elibc_mingw elibc_musl emacs hppa ia64 kernel_Darwin kernel_SunOS kernel_linux loong m68k mips ncurses ppc ppc-macos ppc64 ppc64-linux prefix prefix-guest prefix-stack qt5 riscv s390 sparc test verify-sig x64-macos x64-solaris x86 x86-linux" declare -x IUSE_IMPLICIT="prefix prefix-guest prefix-stack" declare -x KERNEL="linux" declare -x KERNEL_ABI="arm64" declare -x KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" declare -x L10N="" declare -x LANG="en_US.utf8" declare -x LCD_DEVICES="" declare -x LC_COLLATE="C" declare -x LC_CTYPE="C.UTF-8" declare -x LC_MESSAGES="C" declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed" declare -x LDFLAGS_default declare -x LEX="flex" declare -x LIBDIR_arm64="lib64" declare -x LIBDIR_default="lib" declare -x LIBOPTIONS="-m0644" declare -x LIBREOFFICE_EXTENSIONS="" declare -x LICENSE="CMake" declare -x LLVM_TARGETS="" declare -x LUA_SINGLE_TARGET="" declare -x LUA_TARGETS="" declare -x MAKEOPTS="-j4 -l4" declare -x MANPAGER="manpager" declare -- MIMEINFO_DATABASE_DIR="/usr/share/mime" declare -x MONKEYD_PLUGINS="" declare -x MULTILIB_ABIS="arm64" declare -- MY_P="cmake-3.26.4" declare -- NEED_EMACS="25.3" declare -x NGINX_MODULES_HTTP="" declare -x NGINX_MODULES_MAIL="" declare -x NGINX_MODULES_STREAM="" declare -- NINJA="ninja" declare -- NINJA_DEPEND=">=dev-util/ninja-1.8.2" declare -- NINJA_VERBOSE="ON" declare -x OFFICE_IMPLEMENTATION="" declare -x OPENMPI_FABRICS="" declare -x OPENMPI_OFED_FEATURES="" declare -x OPENMPI_RM="" declare -x OVERLAYS_CACHE_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/overlays-cache" declare -x PARSERS="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/parsers" declare -a PATCHES=([0]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.16.0_rc4-darwin-bundle.patch" [1]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.14.0_rc3-prefix-dirs.patch" [2]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.19.1-darwin-gcc.patch" [3]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.17.0_rc1-FindBLAS.patch" [4]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.5.2-FindQt4.patch" [5]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-2.8.10.2-FindPythonLibs.patch" [6]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.9.0_rc2-FindPythonInterp.patch" [7]="/var/tmp/portage/dev-util/cmake-3.26.4-r2/files/cmake-3.18.0-filter_distcc_warning.patch") declare -x PATH="/usr/lib/ccache/bin:/var/tmp/portage/._portage_reinstall_.lwqjrspz/bin/ebuild-helpers/xattr:/usr/lib/portage/python3.11/ebuild-helpers/xattr:/var/tmp/portage/._portage_reinstall_.lwqjrspz/bin/ebuild-helpers:/usr/lib/portage/python3.11/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin" declare PDEPEND="" declare -x PHP_TARGETS="" declare -x PORTAGE_COMPRESSION_COMMAND="zstd -T4 -15" declare -x PORTAGE_COMPRESS_FLAGS="-15" declare -a PORTAGE_DOCOMPRESS=([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man") declare -x PORTAGE_DOCOMPRESS_SIZE_LIMIT="128" declare -a PORTAGE_DOCOMPRESS_SKIP=([0]="/usr/share/doc/cmake-3.26.4-r2/html") declare -a PORTAGE_DOSTRIP=([0]="/") declare -a PORTAGE_DOSTRIP_SKIP=() declare -x PORTAGE_NICENESS="20" declare -x POSTGRES_TARGETS="" 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" declare -x PROJECT="GenPi64Systemd" declare -x PROJECT_DIR="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd" declare -- PROPERTIES="" declare -x PYTHONDONTWRITEBYTECODE="1" declare -x PYTHON_SINGLE_TARGET="" declare -x PYTHON_TARGETS="" declare -x QEMU_SOFTMMU_TARGETS="" declare -x QEMU_USER_TARGETS="" declare RDEPEND=" >=app-arch/libarchive-3.3.3:= app-crypt/rhash:0= >=dev-libs/expat-2.0.1 >=dev-libs/jsoncpp-1.9.2-r2:0= >=dev-libs/libuv-1.10.0:= >=net-misc/curl-7.21.5[ssl] sys-libs/zlib virtual/pkgconfig emacs? ( >=app-editors/emacs-23.1:* ) ncurses? ( sys-libs/ncurses:0= ) qt5? ( dev-qt/qtcore:5 dev-qt/qtgui:5 dev-qt/qtwidgets:5 ) " declare REPOSITORY declare REQUIRED_USE="" declare RESTRICT="test" 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}\"" declare -x ROS_MESSAGES="" declare -x RUBY_TARGETS="" declare -x S="/var/tmp/portage/dev-util/cmake-3.26.4-r2/work/cmake-3.26.4" declare -x SANDBOX_DEBUG="0" declare -x SANDBOX_DENY="" declare -x SANDBOX_METHOD="any" declare -x SANDBOX_PREDICT="/var/tmp/portage/dev-util/cmake-3.26.4-r2/homedir:/dev/crypto:/var/cache/man" declare -x SANDBOX_READ="/:/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/ccache:/var/tmp/portage" declare -x SANDBOX_VERBOSE="1" 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:/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/build/GenPi64Systemd/ccache:/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/tmp/:/var/tmp/portage:/var/tmp/portage/dev-util/cmake-3.26.4-r2/homedir/.bash_history" declare -x SANE_BACKENDS="" declare -x SCRIPTS="/net/10.10.254.10/homes/kaoru/workspace/git/github.com/tin-machine/Build.Dist/scripts" declare -x SHELL="/bin/bash" declare -- SITEETC="/usr/share/emacs/etc" declare -- SITEFILE="50cmake-gentoo.el" declare -- SITELISP="/usr/share/emacs/site-lisp" declare -x SLOT="0" declare -i SRANDOM="743018986" declare SRC_URI="https://cmake.org/files/v3.26/cmake-3.26.4.tar.gz !doc? ( https://dev.gentoo.org/~sam/distfiles/dev-util/cmake/cmake-3.26.4-docs.tar.xz ) verify-sig? ( https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-SHA-256.txt https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-SHA-256.txt.asc )" declare -x TWISTED_DISABLE_WRITING_OF_PLUGIN_CACHE="1" declare -x USE="arm64 elibc_glibc kernel_linux ncurses" declare -x USERLAND="GNU" declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL" declare -x USE_EXPAND_UNPREFIXED="ARCH" declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-linux arm arm64 arm64-macos hppa ia64 loong m68k mips ppc ppc64 ppc64-linux ppc-macos riscv s390 sparc x64-macos x64-solaris x86 x86-linux" declare -x USE_EXPAND_VALUES_ELIBC="bionic Darwin glibc mingw musl SunOS" declare -x USE_EXPAND_VALUES_KERNEL="Darwin linux SunOS" declare -x UWSGI_PLUGINS="" declare -- VERIFY_SIG_METHOD="openpgp" declare -- VERIFY_SIG_OPENPGP_KEY_PATH="/usr/share/openpgp-keys/bradking.asc" declare -- VERIFY_SIG_OPENPGP_KEY_REFRESH="no" declare -x VIDEO_CARDS="" declare -- VIRTUALX_DEPEND=" x11-base/xorg-server[xvfb] x11-apps/xhost " declare -- VIRTUALX_REQUIRED="test" declare -x VOICEMAIL_STORAGE="" declare -x XTABLES_ADDONS="" declare -- _BASH_COMPLETION_R1_ECLASS="1" declare -- _CMAKE_ECLASS="1" declare -- _CMAKE_SRC_PREPARE_HAS_RUN="1" declare -- _ELISP_EMACS_VERSION="" declare -- _FLAG_O_MATIC_ECLASS="1" declare -- _MULTILIB_ECLASS="1" declare -- _MULTIPROCESSING_ECLASS="1" declare -- _NINJA_UTILS_ECLASS="1" declare -- _TOOLCHAIN_FUNCS_ECLASS="1" declare -- _VERIFY_SIG_ECLASS="1" declare -- _VIRTUALX_ECLASS="1" declare -x __E_DESTTREE="/usr" declare -x __E_DOCDESTTREE="" declare -x __E_EXEDESTTREE="" declare -x __E_INSDESTTREE="" declare -x ac_cv_c_undeclared_builtin_options="none needed" declare -x enable_year2038="no" declare -x gl_cv_compiler_check_decl_option="-Werror=implicit-function-declaration" __eapi6_src_install () { if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then emake DESTDIR="${D}" install; fi; einstalldocs } __eapi6_src_prepare () { if ___is_indexed_array_var PATCHES; then [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"; else if [[ -n ${PATCHES} ]]; then eapply ${PATCHES}; fi; fi; eapply_user } __eapi7_ver_compare () { local va=${1} vb=${2} a an al as ar b bn bl bs br re LC_ALL=C; re="^([0-9]+(\.[0-9]+)*)([a-z]?)((_(alpha|beta|pre|rc|p)[0-9]*)*)(-r[0-9]+)?$"; [[ ${va} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${va}"; an=${BASH_REMATCH[1]}; al=${BASH_REMATCH[3]}; as=${BASH_REMATCH[4]}; ar=${BASH_REMATCH[7]}; [[ ${vb} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${vb}"; bn=${BASH_REMATCH[1]}; bl=${BASH_REMATCH[3]}; bs=${BASH_REMATCH[4]}; br=${BASH_REMATCH[7]}; __eapi7_ver_compare_int "${an%%.*}" "${bn%%.*}" || return; while [[ ${an} == *.* && ${bn} == *.* ]]; do an=${an#*.}; bn=${bn#*.}; a=${an%%.*}; b=${bn%%.*}; if [[ ${a} == 0* || ${b} == 0* ]]; then [[ ${a} =~ 0+$ ]] && a=${a%"${BASH_REMATCH[0]}"}; [[ ${b} =~ 0+$ ]] && b=${b%"${BASH_REMATCH[0]}"}; [[ ${a} > ${b} ]] && return 3; [[ ${a} < ${b} ]] && return 1; else __eapi7_ver_compare_int "${a}" "${b}" || return; fi; done; [[ ${an} == *.* ]] && return 3; [[ ${bn} == *.* ]] && return 1; [[ ${al} > ${bl} ]] && return 3; [[ ${al} < ${bl} ]] && return 1; as=${as#_}${as:+_}; bs=${bs#_}${bs:+_}; while [[ -n ${as} && -n ${bs} ]]; do a=${as%%_*}; b=${bs%%_*}; if [[ ${a%%[0-9]*} == "${b%%[0-9]*}" ]]; then __eapi7_ver_compare_int "${a##*[a-z]}" "${b##*[a-z]}" || return; else [[ ${a%%[0-9]*} == p ]] && return 3; [[ ${b%%[0-9]*} == p ]] && return 1; [[ ${a} > ${b} ]] && return 3 || return 1; fi; as=${as#*_}; bs=${bs#*_}; done; if [[ -n ${as} ]]; then [[ ${as} == p[_0-9]* ]] && return 3 || return 1; else if [[ -n ${bs} ]]; then [[ ${bs} == p[_0-9]* ]] && return 1 || return 3; fi; fi; __eapi7_ver_compare_int "${ar#-r}" "${br#-r}" || return; return 2 } __eapi7_ver_compare_int () { local a=$1 b=$2 d=$(( ${#1}-${#2} )); if [[ ${d} -gt 0 ]]; then printf -v b "%0${d}d%s" 0 "${b}"; else if [[ ${d} -lt 0 ]]; then printf -v a "%0$(( -d ))d%s" 0 "${a}"; fi; fi; [[ ${a} > ${b} ]] && return 3; [[ ${a} == "${b}" ]] } __eapi7_ver_parse_range () { local range=${1}; local max=${2}; [[ ${range} == [0-9]* ]] || die "${FUNCNAME}: range must start with a number"; start=${range%-*}; [[ ${range} == *-* ]] && end=${range#*-} || end=${start}; if [[ -n ${end} ]]; then [[ ${start} -le ${end} ]] || die "${FUNCNAME}: end of range must be >= start"; [[ ${end} -le ${max} ]] || end=${max}; else end=${max}; fi } __eapi7_ver_split () { local v=${1} LC_ALL=C; comp=(); local s c; while [[ -n ${v} ]]; do s=${v%%[a-zA-Z0-9]*}; v=${v:${#s}}; [[ ${v} == [0-9]* ]] && c=${v%%[^0-9]*} || c=${v%%[^a-zA-Z]*}; v=${v:${#c}}; comp+=("${s}" "${c}"); done } __eapi8_src_prepare () { local f; if ___is_indexed_array_var PATCHES; then [[ ${#PATCHES[@]} -gt 0 ]] && eapply -- "${PATCHES[@]}"; else if [[ -n ${PATCHES} ]]; then eapply -- ${PATCHES}; fi; fi; eapply_user } _bash-completion-r1_get_bashcompdir () { debug-print-function ${FUNCNAME} "${@}"; _bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion/completions } _bash-completion-r1_get_bashdir () { debug-print-function ${FUNCNAME} "${@}"; if $(tc-getPKG_CONFIG) --exists bash-completion &> /dev/null; then local path; path=$($(tc-getPKG_CONFIG) --variable="${1}" bash-completion) || die; echo "${path#${EPREFIX}}"; else echo "${2}"; fi } _bash-completion-r1_get_bashhelpersdir () { debug-print-function ${FUNCNAME} "${@}"; _bash-completion-r1_get_bashdir helpersdir /usr/share/bash-completion/helpers } _clang_fullversion () { local ver="$1"; shift; set -- $($(tc-getCPP "$@") -E -P - <<<"__clang_major__ __clang_minor__ __clang_patchlevel__"); eval echo "${ver}" } _cmake_banned_func () { die "${FUNCNAME[1]} is banned. use -D$1=\"\$(usex $2)\" instead" } _cmake_check_build_dir () { if [[ ${EAPI} == 7 ]]; then : "${CMAKE_USE_DIR:=${S}}"; else : "${CMAKE_USE_DIR:=${PWD}}"; fi; if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then BUILD_DIR="${CMAKE_USE_DIR}"; else : "${BUILD_DIR:=${CMAKE_USE_DIR}_build}"; if [[ ${S} == "${WORKDIR}" && ${BUILD_DIR} == "${WORKDIR}_build" ]]; then eqawarn "QA notice: S=WORKDIR is deprecated for cmake.eclass."; eqawarn "Please relocate the sources in src_unpack."; BUILD_DIR="${WORKDIR}"/${P}_build; fi; fi; einfo "Source directory (CMAKE_USE_DIR): \"${CMAKE_USE_DIR}\""; einfo "Build directory (BUILD_DIR): \"${BUILD_DIR}\""; mkdir -p "${BUILD_DIR}" || die } _cmake_modify-cmakelists () { debug-print-function ${FUNCNAME} "$@"; grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0; find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec sed -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' -i {} + || die "${LINENO}: failed to disable hardcoded settings"; local x; for x in $(find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec grep -l "^#_cmake_modify_IGNORE" {} +;); do einfo "Hardcoded definition(s) removed in $(echo "${x}" | cut -c $((${#CMAKE_USE_DIR}+2))-):"; einfo "$(grep -se '^#_cmake_modify_IGNORE' ${x} | cut -c 22-99)"; done; cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<-_EOF_ || message(STATUS "<<< Gentoo configuration >>> Build type \${CMAKE_BUILD_TYPE} Install path \${CMAKE_INSTALL_PREFIX} Compiler flags: C \${CMAKE_C_FLAGS} C++ \${CMAKE_CXX_FLAGS} Linker flags: Executable \${CMAKE_EXE_LINKER_FLAGS} Module \${CMAKE_MODULE_LINKER_FLAGS} Shared \${CMAKE_SHARED_LINKER_FLAGS}\n") _EOF_ die } _eapply_patch () { local f=${1}; local prefix=${2}; ebegin "${prefix:-Applying }${f##*/}"; local all_opts=(-p1 -f -g0 --no-backup-if-mismatch "${patch_options[@]}"); if ${patch_cmd} "${all_opts[@]}" --dry-run -s -F0 < "${f}" &> /dev/null; then all_opts+=(-s -F0); fi; ${patch_cmd} "${all_opts[@]}" < "${f}"; failed=${?}; if ! eend "${failed}"; then __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}"; fi } _filter-hardened () { local f; for f in "$@"; do case "${f}" in -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie) gcc-specs-pie || continue; if ! is-flagq -nopie && ! is-flagq -no-pie; then if test-flags -nopie > /dev/null; then append-flags -nopie; else append-flags -no-pie; fi; fi ;; -fstack-protector) gcc-specs-ssp || continue; is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector) ;; -fstack-protector-all) gcc-specs-ssp-to-all || continue; is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all) ;; -fno-strict-overflow) gcc-specs-nostrict || continue; is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow) ;; esac; done } _filter-var () { local f x var=$1 new=(); shift; for f in ${!var}; do for x in "$@"; do [[ ${f} == ${x} ]] && continue 2; done; new+=("${f}"); done; export ${var}="${new[*]}" } _gcc-install-dir () { echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')" } _gcc-specs-directive_raw () { local cc=$(tc-getCC); local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}'); ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 } $1=="*"directive":" { pspec=spec; spec=""; outside=0; next } outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next } spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next } { spec=spec $0 } END { print spec }'; return 0 } _gcc-specs-exists () { [[ -f $(_gcc-install-dir)/$1 ]] } _gcc_fullversion () { local ver="$1"; shift; set -- $($(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"); eval echo "${ver}" } _gpg_verify_signed_checksums () { local checksum_file=${1}; local algo=${2}; local files=${3}; local key=${4:-${VERIFY_SIG_OPENPGP_KEY_PATH}}; verify-sig_verify_unsigned_checksums - "${algo}" "${files}" < <( verify-sig_verify_message "${checksum_file}" - "${key}" ) } _is_flagq () { local x var="$1[*]"; for x in ${!var}; do [[ ${x} == $2 ]] && return 0; done; return 1 } _setup-allowed-flags () { ALLOWED_FLAGS=(-pipe -O '-O[123szg]' '-mcpu=*' '-march=*' '-mtune=*' -flto '-flto=*' -fno-lto '-fstack-protector*' -fstack-clash-protection '-fcf-protection=*' -fbounds-check -fbounds-checking -fno-PIE -fno-pie -nopie -no-pie '-mindirect-branch=*' -mindirect-branch-register '-mfunction-return=*' -mretpoline -fno-unit-at-a-time -fno-strict-overflow '-fsanitize*' '-fno-sanitize*' -g '-g[0-9]' -ggdb '-ggdb[0-9]' -gdwarf '-gdwarf-*' -gstabs -gstabs+ -gz -glldb -fno-diagnostics-color '-fmessage-length=*' -fno-ident -fpermissive -frecord-gcc-switches -frecord-command-line '-fdiagnostics*' '-fplugin*' '-W*' -w '-[DUILR]*' '-Wl,*' '-fuse-ld=*'); ALLOWED_FLAGS+=('-fno-stack-protector*' '-fabi-version=*' -fno-strict-aliasing -fno-bounds-check -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer '-fno-builtin*'); ALLOWED_FLAGS+=('-mregparm=*' -mno-app-regs -mapp-regs -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt -msoft-float -mno-soft-float -mhard-float -mno-hard-float '-mfpu=*' -mieee -mieee-with-inexact '-mschedule=*' -mfloat-gprs -mspe -mno-spe -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 '-mabi=*' -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 '-mcmodel=*' -mstack-bias -mno-stack-bias -msecure-plt '-m*-toc' '-mfloat-abi=*' -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400 -mfix-rm7000 -mno-fix-rm7000 -mfix-r10000 -mno-fix-r10000 '-mr10k-cache-barrier=*' -mthumb -marm -ffixed-x18 -mno-fma4 -mno-movbe -mno-xop -mno-lwp -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm -mno-avx2 -mno-bmi2 -mno-fma -mno-lzcnt -mno-fxsr -mno-hle -mno-rtm -mno-xsave -mno-xsaveopt -mno-avx512cd -mno-avx512er -mno-avx512f -mno-avx512pf -mno-sha); ALLOWED_FLAGS+=(-mstackrealign) } _tc-getPROG () { local tuple=$1; local v var vars=$2; local prog=($3); var=${vars%% *}; for v in ${vars}; do if [[ -n ${!v} ]]; then export ${var}="${!v}"; echo "${!v}"; return 0; fi; done; local search=; [[ -n $4 ]] && search=$(type -p $4-${prog[0]}); [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p ${!tuple}-${prog[0]}); [[ -n ${search} ]] && prog[0]=${search##*/}; export ${var}="${prog[*]}"; echo "${!var}" } _tc-has-openmp () { local base="${T}/test-tc-openmp"; cat <<-EOF > "${base}.c" #include int main(void) { int nthreads, tid, ret = 0; #pragma omp parallel private(nthreads, tid) { tid = omp_get_thread_num(); nthreads = omp_get_num_threads(); ret += tid + nthreads; } return ret; } EOF $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &> /dev/null; local ret=$?; rm -f "${base}"*; return ${ret} } _test-flag-PROG () { local comp=$1; local lang=$2; shift 2; if [[ -z ${comp} ]]; then return 1; fi; if [[ -z $1 ]]; then return 1; fi; comp=($(tc-get${comp})); if ! type -p ${comp[0]} > /dev/null; then return 1; fi; local in_src in_ext cmdline_extra=(); case "${lang}" in c) in_ext='c'; in_src='int main(void) { return 0; }'; cmdline_extra+=(-xc -c) ;; c++) in_ext='cc'; in_src='int main(void) { return 0; }'; cmdline_extra+=(-xc++ -c) ;; f77) in_ext='f'; in_src=' end'; cmdline_extra+=(-xf77 -c) ;; f95) in_ext='f90'; in_src='end'; cmdline_extra+=(-xf95 -c) ;; c+ld) in_ext='c'; in_src='int main(void) { return 0; }'; if is-ldflagq -fuse-ld=*; then fuse_ld_value=$(get-flag -fuse-ld=*); cmdline_extra+=(${fuse_ld_value}); fi; cmdline_extra+=(-xc) ;; esac; local test_in=${T}/test-flag.${in_ext}; local test_out=${T}/test-flag.exe; printf "%s\n" "${in_src}" > "${test_in}" || die "Failed to create '${test_in}'"; local cmdline=("${comp[@]}" -Werror "$@" "${cmdline_extra[@]}" "${test_in}" -o "${test_out}"); "${cmdline[@]}" &> /dev/null } _test-flags-PROG () { local comp=$1; local flags=(); local x; shift; [[ -z ${comp} ]] && return 1; while (( $# )); do case "$1" in --param | -B) if test-flag-${comp} "$1" "$2"; then flags+=("$1" "$2"); fi; shift 2 ;; *) if test-flag-${comp} "$1"; then flags+=("$1"); fi; shift 1 ;; esac; done; echo "${flags[*]}"; [[ ${#flags[@]} -gt 0 ]] } all-flag-vars () { echo {ADA,C,CPP,CXX,CCAS,F,FC,LD}FLAGS } append-atomic-flags () { local code; read -r -d '' code <<-EOF int main(void) { return 0; } EOF test-compile "c+ld" "${code}" || return; local bytesizes; [[ "${#}" == "0" ]] && bytesizes=("1" "2" "4" "8") || bytesizes="${@}"; for bytesize in ${bytesizes[@]}; do read -r -d '' code <<-EOF #include int main(void) { uint$((${bytesize} * 8))_t a = 0; __atomic_add_fetch(&a, 3, __ATOMIC_RELAXED); __atomic_compare_exchange_n(&a, &a, 2, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return 0; } EOF test-compile "c+ld" "${code}" && continue test-flags-CCLD "-latomic" &> /dev/null || die "-latomic is required but not supported by $(tc-getCC)"; append-libs "-latomic"; test-compile "c+ld" "${code}" || die "libatomic does not include an implementation of ${bytesize}-byte atomics for this toolchain"; return; done } append-cflags () { [[ $# -eq 0 ]] && return 0; export CFLAGS+=" $*"; return 0 } append-cppflags () { [[ $# -eq 0 ]] && return 0; export CPPFLAGS+=" $*"; return 0 } append-cxxflags () { [[ $# -eq 0 ]] && return 0; export CXXFLAGS+=" $*"; return 0 } append-fflags () { [[ $# -eq 0 ]] && return 0; export FFLAGS+=" $*"; export FCFLAGS+=" $*"; return 0 } append-flags () { [[ $# -eq 0 ]] && return 0; case " $* " in *' '-[DIU]*) eqawarn 'Please use append-cppflags for preprocessor flags' ;; *' '-L* | *' '-Wl,*) eqawarn 'Please use append-ldflags for linker flags' ;; esac; append-cflags "$@"; append-cxxflags "$@"; append-fflags "$@"; return 0 } append-ldflags () { [[ $# -eq 0 ]] && return 0; local flag; for flag in "$@"; do [[ ${flag} == -l* ]] && eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"; done; export LDFLAGS="${LDFLAGS} $*"; return 0 } append-lfs-flags () { [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments"; append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE } append-libs () { [[ $# -eq 0 ]] && return 0; local flag; for flag in "$@"; do if [[ -z "${flag// }" ]]; then eqawarn "Appending an empty argument to LIBS is invalid! Skipping."; continue; fi; case $flag in -[lL]*) export LIBS="${LIBS} ${flag}" ;; -*) eqawarn "Appending non-library to LIBS (${flag}); Other linker flags should be passed via LDFLAGS"; export LIBS="${LIBS} ${flag}" ;; *) export LIBS="${LIBS} -l${flag}" ;; esac; done; return 0 } bashcomp_alias () { debug-print-function ${FUNCNAME} "${@}"; [[ ${#} -lt 2 ]] && die "Usage: ${FUNCNAME} ..."; local base=${1} f; shift; for f in "$@"; do dosym "${base}" "$(_bash-completion-r1_get_bashcompdir)/${f}" || return; done } clang-fullversion () { _clang_fullversion '$1.$2.$3' "$@" } clang-major-version () { _clang_fullversion '$1' "$@" } clang-micro-version () { _clang_fullversion '$3' "$@" } clang-minor-version () { _clang_fullversion '$2' "$@" } clang-version () { _clang_fullversion '$1.$2' "$@" } cmake-utils_src_make () { die "cmake-utils_src_make is banned. Use cmake_build instead" } cmake-utils_use () { _cmake_banned_func "" "$@" } cmake-utils_use_build () { _cmake_banned_func BUILD_ "$@" } cmake-utils_use_disable () { _cmake_banned_func DISABLE_ "$@" } cmake-utils_use_enable () { _cmake_banned_func ENABLE_ "$@" } cmake-utils_use_has () { _cmake_banned_func HAVE_ "$@" } cmake-utils_use_no () { _cmake_banned_func NO_ "$@" } cmake-utils_use_use () { _cmake_banned_func USE_ "$@" } cmake-utils_use_want () { _cmake_banned_func WANT_ "$@" } cmake-utils_use_with () { _cmake_banned_func WITH_ "$@" } cmake-utils_useno () { _cmake_banned_func "" "$@" } cmake_build () { debug-print-function ${FUNCNAME} "$@"; _cmake_check_build_dir; pushd "${BUILD_DIR}" > /dev/null || die; case ${CMAKE_MAKEFILE_GENERATOR} in emake) [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."; case ${CMAKE_VERBOSE} in OFF) emake "$@" ;; *) emake VERBOSE=1 "$@" ;; esac ;; ninja) [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."; case ${CMAKE_VERBOSE} in OFF) NINJA_VERBOSE=OFF eninja "$@" ;; *) eninja "$@" ;; esac; eninja "$@" ;; esac; popd > /dev/null || die } cmake_comment_add_subdirectory () { if [[ -z ${1} ]]; then die "${FUNCNAME[0]} must be passed at least one directory name to comment"; fi; [[ -e "CMakeLists.txt" ]] || return; local d; for d in $@; do d=${d//\//\\/}; sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${d}[[:space:]]*)/I s/^/#DONOTCOMPILE /" -i CMakeLists.txt || die "failed to comment add_subdirectory(${d})"; done } cmake_run_in () { if [[ -z ${2} ]]; then die "${FUNCNAME[0]} must be passed at least two arguments"; fi; [[ -e ${1} ]] || die "${FUNCNAME[0]}: Nonexistent path: ${1}"; pushd ${1} > /dev/null || die; "${@:2}"; popd > /dev/null || die } cmake_src_bootstrap () { sed -i -e '/"${cmake_bootstrap_dir}\/cmake"/s/^/#DONOTRUN /' bootstrap || die "sed failed"; if [[ ${CHOST} == *-solaris* ]]; then sed -i -e 's/execinfo\.h/blablabla.h/' Source/kwsys/CMakeLists.txt || die; fi; tc-env_build ${CONFIG_SHELL:-sh} ./bootstrap --prefix="${T}/cmakestrap/" --parallel=$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)") || die "Bootstrap failed" } cmake_src_compile () { debug-print-function ${FUNCNAME} "$@"; cmake_build "$@" } cmake_src_configure () { debug-print-function ${FUNCNAME} "$@"; [[ -n ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || die "FATAL: cmake_src_prepare has not been run"; _cmake_check_build_dir; xdg_environment_reset; local build_rules=${BUILD_DIR}/gentoo_rules.cmake; cat > "${build_rules}" <<-_EOF_ || set(CMAKE_ASM_COMPILE_OBJECT " ${CPPFLAGS} -o -c " CACHE STRING "ASM compile command" FORCE) set(CMAKE_ASM-ATT_COMPILE_OBJECT " ${CPPFLAGS} -o -c -x assembler " CACHE STRING "ASM-ATT compile command" FORCE) set(CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE) set(CMAKE_C_COMPILE_OBJECT " ${CPPFLAGS} -o -c " CACHE STRING "C compile command" FORCE) set(CMAKE_CXX_COMPILE_OBJECT " ${CPPFLAGS} -o -c " CACHE STRING "C++ compile command" FORCE) set(CMAKE_Fortran_COMPILE_OBJECT " ${FCFLAGS} -o -c " CACHE STRING "Fortran compile command" FORCE) _EOF_ die local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC); local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake; cat > ${toolchain_file} <<-_EOF_ || set(CMAKE_ASM_COMPILER "${myCC/ /;}") set(CMAKE_ASM-ATT_COMPILER "${myCC/ /;}") set(CMAKE_C_COMPILER "${myCC/ /;}") set(CMAKE_CXX_COMPILER "${myCXX/ /;}") set(CMAKE_Fortran_COMPILER "${myFC/ /;}") set(CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE) set(CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE) set(CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}") _EOF_ die local -x ASMFLAGS=${CFLAGS}; local -x PKG_CONFIG=$(tc-getPKG_CONFIG); if tc-is-cross-compiler; then local sysname; case "${KERNEL:-linux}" in Cygwin) sysname="CYGWIN_NT-5.1" ;; HPUX) sysname="HP-UX" ;; linux) sysname="Linux" ;; Winnt) sysname="Windows"; cat >> "${toolchain_file}" <<-_EOF_ || set(CMAKE_RC_COMPILER $(tc-getRC)) _EOF_ die ;; *) sysname="${KERNEL}" ;; esac cat >> "${toolchain_file}" <<-_EOF_ || set(CMAKE_SYSTEM_NAME "${sysname}") _EOF_ die; fi if [[ ${SYSROOT:-/} != / ]]; then cat >> "${toolchain_file}" <<-_EOF_ || set(CMAKE_SYSROOT "${ESYSROOT}") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) _EOF_ die; fi if use prefix-guest; then cat >> "${build_rules}" <<-_EOF_ || # in Prefix we need rpath and must ensure cmake gets our default linker path # right ... except for Darwin hosts if(NOT APPLE) set(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) set(CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE) else() set(CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE) set(CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE) set(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE) set(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE) endif() _EOF_ die; fi local common_config=${BUILD_DIR}/gentoo_common_config.cmake; local libdir=$(get_libdir); cat > "${common_config}" <<-_EOF_ || set(CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build") set(LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) set(CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries") set(CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "") set(CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "") set(CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules") set(CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "") set(BUILD_SHARED_LIBS ON CACHE BOOL "") set(Python3_FIND_UNVERSIONED_NAMES FIRST CACHE STRING "") _EOF_ die if [[ -n ${_ECM_ECLASS} ]]; then echo 'set(ECM_DISABLE_QMLPLUGINDUMP ON CACHE BOOL "")' >> "${common_config}" || die; fi; if [[ "${ARCH}" == riscv ]]; then echo 'set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX '"${libdir#lib}"' CACHE STRING "library search suffix" FORCE)' >> "${common_config}" || die; fi; if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then echo 'set(CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die; fi; if [[ ${EAPI} != 7 ]]; then echo 'set(CMAKE_INSTALL_ALWAYS 1)' >> "${common_config}" || die; fi; if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then cat >> ${common_config} <<-_EOF_ || set(CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") _EOF_ die; fi [[ -z ${mycmakeargs} ]] && declare -a mycmakeargs=(); local mycmakeargstype=$(declare -p mycmakeargs 2>&-); if [[ "${mycmakeargstype}" != "declare -a mycmakeargs="* ]]; then die "mycmakeargs must be declared as array"; fi; local mycmakeargs_local=("${mycmakeargs[@]}"); local warn_unused_cli=""; if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]]; then warn_unused_cli="--no-warn-unused-cli"; fi; local generator_name; case ${CMAKE_MAKEFILE_GENERATOR} in ninja) generator_name="Ninja" ;; emake) generator_name="Unix Makefiles" ;; esac; local cmakeargs=(${warn_unused_cli} -C "${common_config}" -G "${generator_name}" -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr" "${mycmakeargs_local[@]}" -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"); eval "local -a MYCMAKEARGS=( ${MYCMAKEARGS} )"; cmakeargs+=("${MYCMAKEARGS[@]}"); if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]]; then cmakeargs+=(-C "${CMAKE_EXTRA_CACHE_FILE}"); fi; pushd "${BUILD_DIR}" > /dev/null || die; debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"; echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"; "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"; popd > /dev/null || die } cmake_src_install () { debug-print-function ${FUNCNAME} "$@"; DESTDIR="${D}" cmake_build install "$@"; if [[ ${EAPI} == 7 ]]; then pushd "${S}" > /dev/null || die; einstalldocs; popd > /dev/null || die; else pushd "${CMAKE_USE_DIR}" > /dev/null || die; einstalldocs; popd > /dev/null || die; fi } cmake_src_prepare () { debug-print-function ${FUNCNAME} "$@"; if [[ ${EAPI} == 7 ]]; then pushd "${S}" > /dev/null || die; fi; _cmake_check_build_dir; default_src_prepare; if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]]; then eerror "Unable to locate CMakeLists.txt under:"; eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""; eerror "Consider not inheriting the cmake eclass."; die "FATAL: Unable to find CMakeLists.txt"; fi; local modules_list; if [[ ${EAPI} == 7 && $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then modules_list=(${CMAKE_REMOVE_MODULES_LIST}); else modules_list=("${CMAKE_REMOVE_MODULES_LIST[@]}"); fi; local name; for name in "${modules_list[@]}"; do if [[ ${EAPI} == 7 ]]; then find "${S}" -name ${name}.cmake -exec rm -v {} + || die; else find -name "${name}.cmake" -exec rm -v {} + || die; fi; done; _cmake_modify-cmakelists; if [[ ${EAPI} == 7 ]]; then popd > /dev/null || die; fi; if [[ -n ${CMAKE_QA_SRC_DIR_READONLY} && ! -n ${CMAKE_IN_SOURCE_BUILD} ]]; then if [[ ${EAPI} == 7 ]]; then chmod -R a-w "${S}"; else chmod -R a-w "${CMAKE_USE_DIR}"; fi; fi; _CMAKE_SRC_PREPARE_HAS_RUN=1 } cmake_src_test () { debug-print-function ${FUNCNAME} "$@"; _cmake_check_build_dir; pushd "${BUILD_DIR}" > /dev/null || die; [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 }; [[ -n ${TEST_VERBOSE} ]] && myctestargs+=(--extra-verbose --output-on-failure); set -- ctest -j "$(makeopts_jobs "${MAKEOPTS}" 999)" --test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@"; echo "$@" 1>&2; if "$@"; then einfo "Tests succeeded."; popd > /dev/null || die; return 0; else if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]]; then eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"; eerror "--START TEST LOG--------------------------------------------------------------"; cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"; eerror "--END TEST LOG----------------------------------------------------------------"; die "Tests failed."; else die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"; fi; popd > /dev/null || die; return 1; fi } cmake_use_find_package () { debug-print-function ${FUNCNAME} "$@"; if [[ "$#" != 2 || -z $1 ]]; then die "Usage: cmake_use_find_package "; fi; echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)" } comment_add_subdirectory () { die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead" } dobashcomp () { debug-print-function ${FUNCNAME} "${@}"; ( insopts -m 0644; insinto "$(_bash-completion-r1_get_bashcompdir)"; doins "${@}" ) } eapply () { local failed patch_cmd=patch; local -x LC_COLLATE=POSIX; type -P gpatch > /dev/null && patch_cmd=gpatch; function _eapply_patch () { local f=${1}; local prefix=${2}; ebegin "${prefix:-Applying }${f##*/}"; local all_opts=(-p1 -f -g0 --no-backup-if-mismatch "${patch_options[@]}"); if ${patch_cmd} "${all_opts[@]}" --dry-run -s -F0 < "${f}" &> /dev/null; then all_opts+=(-s -F0); fi; ${patch_cmd} "${all_opts[@]}" < "${f}"; failed=${?}; if ! eend "${failed}"; then __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}"; fi }; local patch_options=() files=(); local i found_doublehyphen; for ((i = 1; i <= ${#@}; ++i )) do if [[ ${@:i:1} == -- ]]; then patch_options=("${@:1:i-1}"); files=("${@:i+1}"); found_doublehyphen=1; break; fi; done; if [[ -z ${found_doublehyphen} ]]; then for ((i = 1; i <= ${#@}; ++i )) do if [[ ${@:i:1} != -* ]]; then patch_options=("${@:1:i-1}"); files=("${@:i}"); break; fi; done; for i in "${files[@]}"; do if [[ ${i} == -* ]]; then die "eapply: all options must be passed before non-options"; fi; done; fi; if [[ ${#files[@]} -eq 0 ]]; then die "eapply: no files specified"; fi; local f; for f in "${files[@]}"; do if [[ -d ${f} ]]; then function _eapply_get_files () { local LC_ALL=POSIX; local prev_shopt=$(shopt -p nullglob); shopt -s nullglob; local f; for f in "${1}"/*; do if [[ ${f} == *.diff || ${f} == *.patch ]]; then files+=("${f}"); fi; done; ${prev_shopt} }; local files=(); _eapply_get_files "${f}"; [[ ${#files[@]} -eq 0 ]] && die "No *.{patch,diff} files in directory ${f}"; einfo "Applying patches from ${f} ..."; local f2; for f2 in "${files[@]}"; do _eapply_patch "${f2}" ' '; [[ ${failed} -ne 0 ]] && return "${failed}"; done; else _eapply_patch "${f}"; [[ ${failed} -ne 0 ]] && return "${failed}"; fi; done; return 0 } eapply_user () { [[ ${EBUILD_PHASE} == prepare ]] || die "eapply_user() called during invalid phase: ${EBUILD_PHASE}"; local tagfile=${T}/.portage_user_patches_applied; [[ -f ${tagfile} ]] && return; >> "${tagfile}"; local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches; local columns=${COLUMNS:-0}; [[ ${columns} == 0 ]] && columns=$(set -- $( ( stty size /dev/null || echo 24 80 ) ; echo $2); (( columns > 0 )) || (( columns = 80 )); local applied d f; local -A _eapply_user_patches; local prev_shopt=$(shopt -p nullglob); shopt -s nullglob; for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},}; do for f in "${d}"/*; do if [[ ( ${f} == *.diff || ${f} == *.patch ) && -z ${_eapply_user_patches[${f##*/}]} ]]; then _eapply_user_patches[${f##*/}]=${f}; fi; done; done; if [[ ${#_eapply_user_patches[@]} -gt 0 ]]; then while read -r -d '' f; do f=${_eapply_user_patches[${f}]}; if [[ -s ${f} ]]; then if [[ -z ${applied} ]]; then einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++)); do echo -n =; done)${PORTAGE_COLOR_NORMAL}"; einfo "Applying user patches from ${basedir} ..."; fi; eapply "${f}"; applied=1; fi; done < <(printf -- '%s\0' "${!_eapply_user_patches[@]}" | LC_ALL=C sort -z); fi; ${prev_shopt}; if [[ -n ${applied} ]]; then einfo "User patches applied."; einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++)); do echo -n =; done)${PORTAGE_COLOR_NORMAL}"; fi } econf_build () { local CBUILD=${CBUILD:-${CHOST}}; function econf_env () { CHOST=${CBUILD} econf "$@" }; tc-env_build econf_env "$@" } einstalldocs () { ( if [[ $(declare -p DOCS 2>/dev/null) != *=* ]]; then local d; for d in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS BUGS FAQ CREDITS CHANGELOG; do [[ -f ${d} && -s ${d} ]] && docinto / && dodoc "${d}"; done; else if ___is_indexed_array_var DOCS; then [[ ${#DOCS[@]} -gt 0 ]] && docinto / && dodoc -r "${DOCS[@]}"; else [[ -n ${DOCS} ]] && docinto / && dodoc -r ${DOCS}; fi; fi ); ( if ___is_indexed_array_var HTML_DOCS; then [[ ${#HTML_DOCS[@]} -gt 0 ]] && docinto html && dodoc -r "${HTML_DOCS[@]}"; else [[ -n ${HTML_DOCS} ]] && docinto html && dodoc -r ${HTML_DOCS}; fi ) } elisp-check-emacs-version () { if [[ -z ${_ELISP_EMACS_VERSION} ]]; then local have_emacs; have_emacs=$(elisp-emacs-version) || die "Could not determine Emacs version"; einfo "Emacs version: ${have_emacs}"; if [[ ${have_emacs} =~ XEmacs|Lucid ]]; then die "XEmacs detected. This package needs GNU Emacs."; fi; if ! [[ ${have_emacs} =~ ^[0-9]+(\.[0-9]+)*$ ]]; then die "Malformed version string: ${have_emacs}"; fi; _ELISP_EMACS_VERSION=${have_emacs}; fi; if ! ver_test "${_ELISP_EMACS_VERSION}" -ge "${NEED_EMACS}"; then eerror "This package needs at least Emacs ${NEED_EMACS}."; eerror "Use \"eselect emacs\" to select the active version."; die "Emacs version too low"; fi } elisp-compile () { elisp-check-emacs-version; ebegin "Compiling GNU Emacs Elisp files"; ${EMACS} ${EMACSFLAGS} ${BYTECOMPFLAGS} -f batch-byte-compile "$@"; eend $? "elisp-compile: batch-byte-compile failed" || die } elisp-emacs-version () { local version ret tmout="timeout -k 5 55"; ${tmout} true &> /dev/null || tmout=""; echo "(princ emacs-version)" > "${T}"/emacs-version.el; version=$( # EMACS could be a microemacs variant that ignores the -batch # option and would therefore hang, waiting for user interaction. # Redirecting stdin and unsetting TERM and DISPLAY will cause # most of them to exit with an error. unset TERM DISPLAY ${tmout} ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el /dev/null) == */emacs* ]] || eerror "This package needs GNU Emacs"; return ${ret}; fi; if [[ -z ${version} ]]; then eerror "elisp-emacs-version: Could not determine Emacs version"; return 1; fi; echo "${version}" } elisp-enable-tests () { debug-print-function ${FUNCNAME} "$@"; local optional; if [[ ${1} = "--optional" ]]; then optional=YES; shift; fi; local test_pkg; local test_runner=${1}; shift; _ELISP_TEST_OPTS=("$@"); case ${test_runner} in buttercup) test_pkg="app-emacs/buttercup"; _ELISP_TEST_FUNCTION=elisp-test-buttercup ;; ert-runner) test_pkg="app-emacs/ert-runner"; _ELISP_TEST_FUNCTION=elisp-test-ert-runner ;; ert) _ELISP_TEST_FUNCTION=elisp-test-ert ;; *) die "${FUNCNAME}: unknown test runner, given ${test_runner}" ;; esac; if [[ -n ${test_pkg} ]]; then IUSE+=" test "; RESTRICT+=" !test? ( test ) "; if [[ -n ${optional} ]]; then IUSE+=" emacs "; BDEPEND+=" test? ( emacs? ( ${test_pkg} ) ) "; else BDEPEND+=" test? ( ${test_pkg} ) "; fi; fi; return 0 } elisp-install () { local subdir="$1"; shift; ebegin "Installing Elisp files for GNU Emacs support"; ( insinto "${SITELISP}/${subdir}"; doins "$@" ); eend $? "elisp-install: doins failed" || die } elisp-make-autoload-file () { local f="${1:-${PN}-autoloads.el}" null="" page=' '; shift; elisp-check-emacs-version; ebegin "Generating autoload file for GNU Emacs"; cat > "${f}" <<-EOF ;;; ${f##*/} --- autoloads for ${PN} ;;; Commentary: ;; Automatically generated by elisp-common.eclass ;; DO NOT EDIT THIS FILE ;;; Code: ${page} ;; Local ${null}Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t ;; End: ;;; ${f##*/} ends here EOF ${EMACS} ${EMACSFLAGS} --eval "(require 'autoload)" --eval "(setq make-backup-files nil)" --eval "(setq generated-autoload-file (expand-file-name \"${f}\"))" -f batch-update-autoloads "${@-.}"; eend $? "elisp-make-autoload-file: batch-update-autoloads failed" || die } elisp-make-site-file () { [[ $1 == [0-9][0-9]*-gentoo.el ]] || die "elisp-make-site-file: bad name of site-init file"; local f="${T}/$1" my_pn="${2:-${PN}}"; shift; shift; printf "%s\n" "(add-to-list 'load-path \"@SITELISP@\")" "$@" > "${f}" || die; elisp-site-file-install "${f}" "${my_pn}" } elisp-modules-install () { local subdir="$1"; shift; ebegin "Installing dynamic modules for GNU Emacs support"; ( exeinto "${EMACSMODULES//@libdir@/$(get_libdir)}/${subdir}"; doexe "$@" ); eend $? "elisp-modules-install: doins failed" || die } elisp-site-file-install () { local sf="${1##*/}" my_pn="${2:-${PN}}" modules ret; local header=";;; ${PN} site-lisp configuration"; [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] || ewarn "elisp-site-file-install: bad name of site-init file"; [[ ${sf%-gentoo*.el} != "${sf}" ]] && sf="${sf%-gentoo*.el}-gentoo.el"; sf="${T}/${sf}"; ebegin "Installing site initialisation file for GNU Emacs"; [[ $1 == "${sf}" ]] || cp "$1" "${sf}"; modules=${EMACSMODULES//@libdir@/$(get_libdir)}; sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" -e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" -e "s:@SITEETC@:${EPREFIX}${SITEETC}/${my_pn}:g" -e "s:@EMACSMODULES@:${EPREFIX}${modules}/${my_pn}:g;\$q" "${sf}"; ( insinto "${SITELISP}/site-gentoo.d"; doins "${sf}" ); ret=$?; rm -f "${sf}"; eend ${ret} "elisp-site-file-install: doins failed" || die } elisp-site-regen () { local sitelisp=${ROOT%/}${EPREFIX}${SITELISP}; local sf i ret=0 null="" page=' '; local -a sflist; if [[ ${EBUILD_PHASE} == *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."; return 0; fi; [[ -d ${sitelisp} ]] || die "elisp-site-regen: Directory ${sitelisp} does not exist"; [[ -d ${T} ]] || die "elisp-site-regen: Temporary directory ${T} does not exist"; ebegin "Regenerating site-gentoo.el for GNU Emacs (${EBUILD_PHASE})"; for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el; do [[ -r ${sf} ]] && sflist+=("${sf}"); done; cat <<-EOF > "${T}"/site-gentoo.el || ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages ;;; Commentary: ;; Automatically generated by elisp-common.eclass ;; DO NOT EDIT THIS FILE ;;; Code: EOF ret=$? sed '$q' "${sflist[@]}" < /dev/null >> "${T}"/site-gentoo.el || ret=$?; cat <<-EOF >> "${T}"/site-gentoo.el || ${page} (provide 'site-gentoo) ;; Local ${null}Variables: ;; no-byte-compile: t ;; buffer-read-only: t ;; End: ;;; site-gentoo.el ends here EOF ret=$? if [[ ${ret} -ne 0 ]]; then eend ${ret} "elisp-site-regen: Writing site-gentoo.el failed."; die; else if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then rm -f "${T}"/site-gentoo.el; eend 0; einfo "... no changes."; else mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el; eend $? "elisp-site-regen: Replacing site-gentoo.el failed" || die; case ${#sflist[@]} in 0) [[ ${PN} == emacs-common ]] || ewarn "... Huh? No site initialisation files found." ;; 1) einfo "... ${#sflist[@]} site initialisation file included." ;; *) einfo "... ${#sflist[@]} site initialisation files included." ;; esac; fi; fi; return 0 } elisp-test () { if [[ -n ${_ELISP_TEST_FUNCTION} ]]; then ${_ELISP_TEST_FUNCTION} "${_ELISP_TEST_OPTS[@]}"; fi } elisp-test-buttercup () { debug-print-function ${FUNCNAME} "$@"; local test_dir="${1:-$(pwd)}"; shift; local -a myopts=(${BYTECOMPFLAGS} -L "${test_dir}" --traceback full "$@"); ebegin "Running buttercup tests"; buttercup "${myopts[@]}" "${test_dir}"; eend $? "${FUNCNAME}: tests failed" || die } elisp-test-ert () { debug-print-function ${FUNCNAME} "$@"; local test_dir="${1:-$(pwd)}"; shift; local -a extra_load=(); local extra_load_file; for extra_load_file in "${test_dir}"/?*-test.el; do if [[ -f "${extra_load_file}" ]]; then extra_load+=(-l "${extra_load_file}"); fi; done; local -a myopts=(${EMACSFLAGS} ${BYTECOMPFLAGS} -L "${test_dir}" "${extra_load[@]}" "$@" -f ert-run-tests-batch-and-exit); ebegin "Running ert tests"; ${EMACS} "${myopts[@]}"; eend $? "${FUNCNAME}: tests failed" || die } elisp-test-ert-runner () { debug-print-function ${FUNCNAME} "$@"; local test_dir="${1:-$(pwd)}"; shift; local -a myopts=(${BYTECOMPFLAGS} --reporter ert+duration --script -L "${test_dir}" "$@"); ebegin "Running ert-runner tests"; ert-runner "${myopts[@]}" "${test_dir}"; eend $? "${FUNCNAME}: tests failed" || die } eninja () { [[ -n "${NINJA_DEPEND}" ]] || ewarn "Unknown value '${NINJA}' for \${NINJA}"; local v; case "${NINJA_VERBOSE}" in OFF) ;; *) v="-v" ;; esac; set -- "${NINJA}" ${v} $(get_NINJAOPTS) "$@"; echo "$@" 1>&2; "$@" || die -n "${*} failed" } filter-flags () { _filter-hardened "$@"; local v; for v in $(all-flag-vars); do _filter-var ${v} "$@"; done; return 0 } filter-ldflags () { _filter-var LDFLAGS "$@"; return 0 } filter-lfs-flags () { [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments"; filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_TIME_BITS=64 } filter-lto () { [[ $# -ne 0 ]] && die "filter-lto takes no arguments"; filter-flags '-flto*' -fwhole-program-vtables '-fsanitize=cfi*' } filter-mfpmath () { local orig_mfpmath new_math prune_math; orig_mfpmath=$(get-flag -mfpmath); new_math=$(get-flag mfpmath); new_math=${new_math/both/387,sse}; new_math=" ${new_math//[,+]/ } "; prune_math=""; for prune_math in "$@"; do new_math=${new_math/ ${prune_math} / }; done; new_math=$(echo ${new_math}); new_math=${new_math// /,}; if [[ -z ${new_math} ]]; then filter-flags ${orig_mfpmath}; else replace-flags ${orig_mfpmath} -mfpmath=${new_math}; fi; return 0 } gcc-fullversion () { _gcc_fullversion '$1.$2.$3' "$@" } gcc-major-version () { _gcc_fullversion '$1' "$@" } gcc-micro-version () { _gcc_fullversion '$3' "$@" } gcc-minor-version () { _gcc_fullversion '$2' "$@" } gcc-specs-directive () { local directive subdname subdirective; directive="$(_gcc-specs-directive_raw $1)"; while [[ ${directive} == *%\(*\)* ]]; do subdname=${directive/*%\(}; subdname=${subdname/\)*}; subdirective="$(_gcc-specs-directive_raw ${subdname})"; directive="${directive//\%(${subdname})/${subdirective}}"; done; echo "${directive}"; return 0 } gcc-specs-nostrict () { local directive; directive=$(gcc-specs-directive cc1); [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]] } gcc-specs-now () { local directive; directive=$(gcc-specs-directive link_command); [[ "${directive/\{!nonow:}" != "${directive}" ]] } gcc-specs-pie () { local directive; directive=$(gcc-specs-directive cc1); [[ "${directive/\{!nopie:}" != "${directive}" ]] } gcc-specs-relro () { local directive; directive=$(gcc-specs-directive link_command); [[ "${directive/\{!norelro:}" != "${directive}" ]] } gcc-specs-ssp () { local directive; directive=$(gcc-specs-directive cc1); [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]] } gcc-specs-ssp-to-all () { local directive; directive=$(gcc-specs-directive cc1); [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]] } gcc-specs-stack-check () { local directive; directive=$(gcc-specs-directive cc1); [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]] } gcc-version () { _gcc_fullversion '$1.$2' "$@" } gen_usr_ldscript () { ewarn "${FUNCNAME}: Please migrate to usr-ldscript.eclass"; local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname); [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/; tc-is-static-only && return; if [[ $(type -t multilib_is_native_abi) == "function" ]]; then multilib_is_native_abi || return 0; fi; case ${CTARGET:-${CHOST}} in *-darwin*) ;; *-android*) return 0 ;; *linux*) use prefix && return 0 ;; *) return 0 ;; esac; dodir /usr/${libdir}; if [[ $1 == "-a" ]]; then auto=true; shift; dodir /${libdir}; fi; local flags=(${CFLAGS} ${LDFLAGS} -Wl,--verbose); if $(tc-getLD) --version | grep -q 'GNU gold'; then local d="${T}/bfd-linker"; mkdir -p "${d}"; ln -sf $(type -P ${CHOST}-ld.bfd) "${d}"/ld; flags+=(-B"${d}"); fi; output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p'); [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"; for lib in "$@"; do local tlib; if ${auto}; then lib="lib${lib}${suffix}"; else [[ -r ${ED}/${libdir}/${lib} ]] || continue; fi; case ${CTARGET:-${CHOST}} in *-darwin*) if ${auto}; then tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib}); else tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib}); fi; [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"; tlib=${tlib##*/}; if ${auto}; then mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die; if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die; fi; rm -f "${ED}"/${libdir}/${lib}; fi; if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then chmod u+w "${ED}${libdir}/${tlib}"; local nowrite=yes; fi; install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed"; [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}"; pushd "${ED}/usr/${libdir}" > /dev/null; ln -snf "../../${libdir}/${tlib}" "${lib}"; popd > /dev/null ;; *) if ${auto}; then tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib}); [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"; mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die; if [[ ${tlib} != ${lib}* ]]; then mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die; fi; rm -f "${ED}"/${libdir}/${lib}; else tlib=${lib}; fi; cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT /* GNU ld script Since Gentoo has critical dynamic libraries in /lib, and the static versions in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we run into linking problems. This "fake" dynamic lib is a linker script that redirects the linker to the real lib. And yes, this works in the cross- compiling scenario as the sysroot-ed linker will prepend the real path. See bug https://bugs.gentoo.org/4411 for more info. */ ${output_format} GROUP ( ${EPREFIX}/${libdir}/${tlib} ) END_LDSCRIPT ;; esac fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"; done } get-flag () { [[ $# -ne 1 ]] && die "usage: "; local f var findflag="$1"; for var in $(all-flag-vars); do for f in ${!var}; do if [ "${f/${findflag}}" != "${f}" ]; then printf "%s\n" "${f/-${findflag}=}"; return 0; fi; done; done; return 1 } get_NINJAOPTS () { if [[ -z ${NINJAOPTS+set} ]]; then NINJAOPTS="-j$(makeopts_jobs "${MAKEOPTS}" 999) -l$(makeopts_loadavg "${MAKEOPTS}" 0)"; fi; echo "${NINJAOPTS}" } get_abi_CFLAGS () { get_abi_var CFLAGS "$@" } get_abi_CHOST () { get_abi_var CHOST "$@" } get_abi_CTARGET () { get_abi_var CTARGET "$@" } get_abi_FAKE_TARGETS () { get_abi_var FAKE_TARGETS "$@" } get_abi_LDFLAGS () { get_abi_var LDFLAGS "$@" } get_abi_LIBDIR () { get_abi_var LIBDIR "$@" } get_abi_var () { local flag=$1; local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}}; local var="${flag}_${abi}"; echo ${!var} } get_all_abis () { local x order="" mvar dvar; mvar="MULTILIB_ABIS"; dvar="DEFAULT_ABI"; if [[ -n $1 ]]; then mvar="$1_${mvar}"; dvar="$1_${dvar}"; fi; if [[ -z ${!mvar} ]]; then echo "default"; return 0; fi; for x in ${!mvar}; do if [[ ${x} != ${!dvar} ]]; then order="${order:+${order} }${x}"; fi; done; order="${order:+${order} }${!dvar}"; echo ${order}; return 0 } get_all_libdirs () { local libdirs abi; for abi in ${MULTILIB_ABIS}; do libdirs+=" $(get_abi_LIBDIR ${abi})"; done; [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib"; echo "${libdirs}" } get_bashcompdir () { debug-print-function ${FUNCNAME} "${@}"; echo "${EPREFIX}$(_bash-completion-r1_get_bashcompdir)" } get_bashhelpersdir () { debug-print-function ${FUNCNAME} "${@}"; echo "${EPREFIX}$(_bash-completion-r1_get_bashhelpersdir)" } get_exeext () { case ${CHOST} in mingw* | *-mingw*) echo ".exe" ;; esac } get_install_abis () { local x order=""; if [[ -z ${MULTILIB_ABIS} ]]; then echo "default"; return 0; fi; if [[ ${EMULTILIB_PKG} == "true" ]]; then for x in ${MULTILIB_ABIS}; do if [[ ${x} != "${DEFAULT_ABI}" ]]; then has ${x} ${ABI_DENY} || order="${order} ${x}"; fi; done; has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}"; if [[ -n ${ABI_ALLOW} ]]; then local ordera=""; for x in ${order}; do if has ${x} ${ABI_ALLOW}; then ordera="${ordera} ${x}"; fi; done; order=${ordera}; fi; else order=${DEFAULT_ABI}; fi; if [[ -z ${order} ]]; then 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."; fi; echo ${order}; return 0 } get_libdir () { local libdir_var="LIBDIR_${ABI}"; local libdir="lib"; [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var}; echo "${libdir}" } get_libname () { local libname; local ver=$1; case ${CHOST} in mingw* | *-mingw*) libname="dll" ;; *-darwin*) libname="dylib" ;; *) libname="so" ;; esac; if [[ -z $* ]]; then echo ".${libname}"; else for ver in "$@"; do case ${CHOST} in *-darwin*) echo ".${ver}.${libname}" ;; *) echo ".${libname}.${ver}" ;; esac; done; fi } get_modname () { local modname; local ver=$1; case ${CHOST} in *-darwin*) modname="bundle" ;; *) modname="so" ;; esac; echo ".${modname}" } get_nproc () { local nproc; if type -P nproc &> /dev/null; then nproc=$(nproc); fi; if [[ -z ${nproc} ]] && type -P sysctl &> /dev/null; then nproc=$(sysctl -n hw.ncpu 2>/dev/null); fi; if [[ -z ${nproc} ]] && type -P python &> /dev/null; then nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2>/dev/null); fi; if [[ -n ${nproc} ]]; then echo "${nproc}"; else echo "${1:-1}"; fi } has_multilib_profile () { [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ] } in_iuse () { local use=${1}; if [[ -z "${use}" ]]; then echo "!!! in_iuse() called without a parameter." 1>&2; echo "!!! in_iuse " 1>&2; die "in_iuse() called without a parameter"; fi; local liuse=(${IUSE_EFFECTIVE}); has "${use}" "${liuse[@]#[+-]}" } is-flag () { is-flagq "$@" && echo true } is-flagq () { [[ -n $2 ]] && die "Usage: is-flag "; local var; for var in $(all-flag-vars); do _is_flagq ${var} "$1" && return 0; done; return 1 } is-ldflag () { is-ldflagq "$@" && echo true } is-ldflagq () { [[ -n $2 ]] && die "Usage: is-ldflag "; _is_flagq LDFLAGS $1 } is_final_abi () { has_multilib_profile || return 0; set -- $(get_install_abis); local LAST_ABI=$#; [[ ${!LAST_ABI} == ${ABI} ]] } makeopts_jobs () { [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"; 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"); echo ${jobs:-1} } makeopts_loadavg () { [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"; 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"); echo ${lavg:-${2:-999}} } multilib_env () { local CTARGET=${1:-${CTARGET}}; local cpu=${CTARGET%%*-}; if [[ ${CTARGET} = *-musl* ]]; then : "${MULTILIB_ABIS=default}"; : "${DEFAULT_ABI=default}"; export MULTILIB_ABIS DEFAULT_ABI; return; fi; case ${cpu} in aarch64*) export CFLAGS_arm=${CFLAGS_arm-}; case ${cpu} in aarch64*be) export CHOST_arm="armv8b-${CTARGET#*-}" ;; *) export CHOST_arm="armv8l-${CTARGET#*-}" ;; esac; CHOST_arm=${CHOST_arm/%-gnu/-gnueabi}; export CTARGET_arm=${CHOST_arm}; export LIBDIR_arm="lib"; export CFLAGS_arm64=${CFLAGS_arm64-}; export CHOST_arm64=${CTARGET}; export CTARGET_arm64=${CHOST_arm64}; export LIBDIR_arm64="lib64"; : "${MULTILIB_ABIS=arm64}"; : "${DEFAULT_ABI=arm64}" ;; x86_64*) export CFLAGS_x86=${CFLAGS_x86--m32}; export CHOST_x86=${CTARGET/x86_64/i686}; CHOST_x86=${CHOST_x86/%-gnux32/-gnu}; export CTARGET_x86=${CHOST_x86}; if [[ ${SYMLINK_LIB} == "yes" ]]; then export LIBDIR_x86="lib32"; else export LIBDIR_x86="lib"; fi; export CFLAGS_amd64=${CFLAGS_amd64--m64}; export CHOST_amd64=${CTARGET/%-gnux32/-gnu}; export CTARGET_amd64=${CHOST_amd64}; export LIBDIR_amd64="lib64"; export CFLAGS_x32=${CFLAGS_x32--mx32}; export CHOST_x32=${CTARGET/%-gnu/-gnux32}; export CTARGET_x32=${CHOST_x32}; export LIBDIR_x32="libx32"; case ${CTARGET} in *-gnux32) : "${MULTILIB_ABIS=x32 amd64 x86}"; : "${DEFAULT_ABI=x32}" ;; *) : "${MULTILIB_ABIS=amd64 x86}"; : "${DEFAULT_ABI=amd64}" ;; esac ;; loongarch64*) export CFLAGS_lp64d=${CFLAGS_lp64d--mabi=lp64d}; export CHOST_lp64d=${CTARGET}; export CTARGET_lp64d=${CTARGET}; export LIBDIR_lp64d=${LIBDIR_lp64d-lib64}; : "${MULTILIB_ABIS=lp64d}"; : "${DEFAULT_ABI=lp64d}" ;; mips64* | mipsisa64*) export CFLAGS_o32=${CFLAGS_o32--mabi=32}; export CHOST_o32=${CTARGET/mips64/mips}; export CHOST_o32=${CHOST_o32/mipsisa64/mipsisa32}; export CTARGET_o32=${CHOST_o32}; export LIBDIR_o32="lib"; export CFLAGS_n32=${CFLAGS_n32--mabi=n32}; export CHOST_n32=${CTARGET}; export CTARGET_n32=${CHOST_n32}; export LIBDIR_n32="lib32"; export CFLAGS_n64=${CFLAGS_n64--mabi=64}; export CHOST_n64=${CTARGET}; export CTARGET_n64=${CHOST_n64}; export LIBDIR_n64="lib64"; : "${MULTILIB_ABIS=n64 n32 o32}"; : "${DEFAULT_ABI=n32}" ;; powerpc64*) export CFLAGS_ppc=${CFLAGS_ppc--m32}; export CHOST_ppc=${CTARGET/powerpc64/powerpc}; export CTARGET_ppc=${CHOST_ppc}; export LIBDIR_ppc="lib"; export CFLAGS_ppc64=${CFLAGS_ppc64--m64}; export CHOST_ppc64=${CTARGET}; export CTARGET_ppc64=${CHOST_ppc64}; export LIBDIR_ppc64="lib64"; : "${MULTILIB_ABIS=ppc64 ppc}"; : "${DEFAULT_ABI=ppc64}" ;; riscv64*) : "${MULTILIB_ABIS=lp64d lp64 ilp32d ilp32}"; : "${DEFAULT_ABI=lp64d}"; local _libdir_riscvdefaultabi_variable="LIBDIR_${DEFAULT_ABI}"; local _libdir_riscvdefaultabi=${!_libdir_riscvdefaultabi_variable}; export ${_libdir_riscvdefaultabi_variable}=${_libdir_riscvdefaultabi:-lib64}; export CFLAGS_lp64d=${CFLAGS_lp64d--mabi=lp64d -march=rv64gc}; export CHOST_lp64d=${CTARGET}; export CTARGET_lp64d=${CTARGET}; export LIBDIR_lp64d=${LIBDIR_lp64d-lib64/lp64d}; export CFLAGS_lp64=${CFLAGS_lp64--mabi=lp64 -march=rv64imac}; export CHOST_lp64=${CTARGET}; export CTARGET_lp64=${CTARGET}; export LIBDIR_lp64=${LIBDIR_lp64-lib64/lp64}; export CFLAGS_ilp32d=${CFLAGS_ilp32d--mabi=ilp32d -march=rv32imafdc}; export CHOST_ilp32d=${CTARGET/riscv64/riscv32}; export CTARGET_ilp32d=${CTARGET/riscv64/riscv32}; export LIBDIR_ilp32d=${LIBDIR_ilp32d-lib32/ilp32d}; export CFLAGS_ilp32=${CFLAGS_ilp32--mabi=ilp32 -march=rv32imac}; export CHOST_ilp32=${CTARGET/riscv64/riscv32}; export CTARGET_ilp32=${CTARGET/riscv64/riscv32}; export LIBDIR_ilp32=${LIBDIR_ilp32-lib32/ilp32} ;; riscv32*) : "${MULTILIB_ABIS=ilp32d ilp32}"; : "${DEFAULT_ABI=ilp32d}"; local _libdir_riscvdefaultabi_variable="LIBDIR_${DEFAULT_ABI}"; local _libdir_riscvdefaultabi=${!_libdir_riscvdefaultabi_variable}; export ${_libdir_riscvdefaultabi_variable}=${_libdir_riscvdefaultabi:-lib}; export CFLAGS_ilp32d=${CFLAGS_ilp32d--mabi=ilp32d -march=rv32imafdc}; export CHOST_ilp32d=${CTARGET}; export CTARGET_ilp32d=${CTARGET}; export LIBDIR_ilp32d=${LIBDIR_ilp32d-lib32/ilp32d}; export CFLAGS_ilp32=${CFLAGS_ilp32--mabi=ilp32 -march=rv32imac}; export CHOST_ilp32=${CTARGET}; export CTARGET_ilp32=${CTARGET}; export LIBDIR_ilp32=${LIBDIR_ilp32-lib32/ilp32} ;; s390x*) export CFLAGS_s390=${CFLAGS_s390--m31}; export CHOST_s390=${CTARGET/s390x/s390}; export CTARGET_s390=${CHOST_s390}; export LIBDIR_s390="lib"; export CFLAGS_s390x=${CFLAGS_s390x--m64}; export CHOST_s390x=${CTARGET}; export CTARGET_s390x=${CHOST_s390x}; export LIBDIR_s390x="lib64"; : "${MULTILIB_ABIS=s390x s390}"; : "${DEFAULT_ABI=s390x}" ;; sparc64*) export CFLAGS_sparc32=${CFLAGS_sparc32--m32}; export CHOST_sparc32=${CTARGET/sparc64/sparc}; export CTARGET_sparc32=${CHOST_sparc32}; export LIBDIR_sparc32="lib"; export CFLAGS_sparc64=${CFLAGS_sparc64--m64}; export CHOST_sparc64=${CTARGET}; export CTARGET_sparc64=${CHOST_sparc64}; export LIBDIR_sparc64="lib64"; : "${MULTILIB_ABIS=sparc64 sparc32}"; : "${DEFAULT_ABI=sparc64}" ;; *) : "${MULTILIB_ABIS=default}"; : "${DEFAULT_ABI=default}" ;; esac; export MULTILIB_ABIS DEFAULT_ABI } multilib_toolchain_setup () { local v vv; export ABI=$1; 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); if [[ ${_DEFAULT_ABI_SAVED} == "true" ]]; then for v in "${save_restore_variables[@]}"; do vv="_abi_saved_${v}"; [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v}; unset ${vv}; done; unset _DEFAULT_ABI_SAVED; fi; if [[ ${ABI} != ${DEFAULT_ABI} ]]; then for v in "${save_restore_variables[@]}"; do vv="_abi_saved_${v}"; [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv}; done; export _DEFAULT_ABI_SAVED="true"; if [[ ${CBUILD} == "${CHOST}" ]]; then export CBUILD=$(get_abi_CHOST $1); fi; export CHOST=$(get_abi_CHOST ${DEFAULT_ABI}); export AR="$(tc-getAR)"; export CC="$(tc-getCC) $(get_abi_CFLAGS)"; export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"; export F77="$(tc-getF77) $(get_abi_CFLAGS)"; export FC="$(tc-getFC) $(get_abi_CFLAGS)"; export LD="$(tc-getLD) $(get_abi_LDFLAGS)"; export NM="$(tc-getNM)"; export OBJCOPY="$(tc-getOBJCOPY)"; export OBJDUMP="$(tc-getOBJDUMP)"; export PKG_CONFIG="$(tc-getPKG_CONFIG)"; export RANLIB="$(tc-getRANLIB)"; export READELF="$(tc-getREADELF)"; export STRINGS="$(tc-getSTRINGS)"; export STRIP="$(tc-getSTRIP)"; export CHOST=$(get_abi_CHOST $1); export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig; export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig; export PKG_CONFIG_SYSTEM_INCLUDE_PATH=${EPREFIX}/usr/include; export PKG_CONFIG_SYSTEM_LIBRARY_PATH=${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir); fi } newbashcomp () { debug-print-function ${FUNCNAME} "${@}"; ( insopts -m 0644; insinto "$(_bash-completion-r1_get_bashcompdir)"; newins "${@}" ) } no-as-needed () { [[ $# -ne 0 ]] && die "no-as-needed takes no arguments"; case $($(tc-getLD) -v 2>&1 "; local f var new; for var in $(all-flag-vars); do new=(); for f in ${!var}; do [[ ${f} == ${1} ]] && f=${2}; new+=("${f}"); done; export ${var}="${new[*]}"; done; return 0 } replace-sparc64-flags () { [[ $# -ne 0 ]] && die "replace-sparc64-flags takes no arguments"; local SPARC64_CPUS="ultrasparc3 ultrasparc v9"; if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then for x in ${SPARC64_CPUS}; do CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"; done; else for x in ${SPARC64_CPUS}; do CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"; done; fi; if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then for x in ${SPARC64_CPUS}; do CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"; done; else for x in ${SPARC64_CPUS}; do CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"; done; fi; export CFLAGS CXXFLAGS } setup-allowed-flags () { [[ ${EAPI} == [67] ]] || die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."; _setup-allowed-flags "$@" } src_compile () { cmake_src_compile; use emacs && elisp-compile Auxiliary/cmake-mode.el } src_configure () { [[ ${CHOST} == *-solaris* ]] && append-ldflags -lsocket -lnsl; filter-lto; local mycmakeargs=(-DCMAKE_USE_SYSTEM_LIBRARIES=ON -DCMAKE_DOC_DIR=/share/doc/${PF} -DCMAKE_MAN_DIR=/share/man -DCMAKE_DATA_DIR=/share/${PN} -DSPHINX_MAN=$(usex doc) -DSPHINX_HTML=$(usex doc) -DBUILD_CursesDialog="$(usex ncurses)" -DBUILD_TESTING=$(usex test)); use qt5 && mycmakeargs+=(-DBUILD_QtDialog=ON); cmake_src_configure } src_install () { cmake_src_install; if ! use doc && [[ ${CMAKE_DOCS_PREBUILT} == 1 ]]; then doman "${WORKDIR}"/${PN}-${CMAKE_DOCS_VERSION}-docs/man*/*.[0-8]; fi; if use emacs; then elisp-install ${PN} Auxiliary/cmake-mode.el Auxiliary/cmake-mode.elc; elisp-site-file-install "${FILESDIR}/${SITEFILE}"; fi; insinto /usr/share/vim/vimfiles/syntax; doins Auxiliary/vim/syntax/cmake.vim; insinto /usr/share/vim/vimfiles/indent; doins Auxiliary/vim/indent/cmake.vim; insinto /usr/share/vim/vimfiles/ftdetect; doins "${FILESDIR}/${PN}.vim"; dobashcomp Auxiliary/bash-completion/{${PN},ctest,cpack} } src_prepare () { cmake_src_prepare; if [[ ${CHOST} == *-darwin* ]]; then sed -i -e 's/cm\(\|Global\|Local\)XCode[^.]\+\.\(cxx\|h\)//' Source/CMakeLists.txt || die; sed -i -e '/define CMAKE_USE_XCODE/s/XCODE/NO_XCODE/' -e '/cmGlobalXCodeGenerator.h/d' Source/cmake.cxx || die; sed -i -e '/cmake_gnu_set_sysroot_flag/d' Modules/Platform/Apple-GNU-*.cmake || die; sed -i -e '/_SYSROOT_FLAG/d' Modules/Platform/Apple-Clang.cmake || die; sed -i -e 's/^#if !defined(_WIN32) && !defined(__sun)/& \&\& !defined(__APPLE__)/' Source/cmLoadCommandCommand.cxx Source/cmStandardLexer.h Source/cmSystemTools.cxx Source/cmTimestamp.cxx; sed -i -e 's/^#if !defined(_POSIX_C_SOURCE) && !defined(_WIN32) && !defined(__sun)/& \&\& !defined(__APPLE__)/' Source/cmStandardLexer.h; fi; sed -i -e "s|@GENTOO_PORTAGE_GCCLIBDIR@|${EPREFIX}/usr/${CHOST}/lib/|g" -e "$(usex prefix-guest "s|@GENTOO_HOST@||" "/@GENTOO_HOST@/d")" -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}/|g" Modules/Platform/{UnixPaths,Darwin}.cmake || die "sed failed"; if ! has_version -b \>=${CATEGORY}/${PN}-3.13 || ! cmake --version &> /dev/null; then CMAKE_BINARY="${S}/Bootstrap.cmk/cmake"; cmake_src_bootstrap; fi } src_test () { sed -i -e 's:^#_cmake_modify_IGNORE ::g' "${S}"/Tests/{OutDir,CMakeOnly/SelectLibraryConfigurations}/CMakeLists.txt || die; pushd "${BUILD_DIR}" > /dev/null || die; local myctestargs=(--output-on-failure -E "(BootstrapTest|BundleUtilities|CMakeOnly.AllFindModules|CompileOptions|CTest.UpdateCVS|Fortran|RunCMake.CompilerLauncher|RunCMake.CPack_(DEB|RPM)|TestUpload|RunCMake.CMP0125)"); virtx cmake_src_test } src_unpack () { if [[ ${PV} == 9999 ]]; then git-r3_src_unpack; else if [[ ${PV} == *_rc* ]] || ! use verify-sig; then default; else cd "${DISTDIR}" || die; verify-sig_verify_detached ${MY_P}-SHA-256.txt{,.asc}; verify-sig_verify_unsigned_checksums ${MY_P}-SHA-256.txt sha256 ${MY_P}.tar.gz; cd "${WORKDIR}" || die; default; fi; fi } strip-flags () { [[ $# -ne 0 ]] && die "strip-flags takes no arguments"; local x y var; local ALLOWED_FLAGS; _setup-allowed-flags; set -f; for var in $(all-flag-vars); do local new=(); for x in ${!var}; do for y in "${ALLOWED_FLAGS[@]}"; do if [[ ${x} == ${y} ]]; then new+=("${x}"); break; fi; done; done; if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*"; then new+=(-O2); fi; if [[ ${!var} != "${new[*]}" ]]; then einfo "strip-flags: ${var}: changed '${!var}' to '${new[*]}'"; fi; export ${var}="${new[*]}"; done; set +f; return 0 } strip-unsupported-flags () { [[ $# -ne 0 ]] && die "strip-unsupported-flags takes no arguments"; export CFLAGS=$(test-flags-CC ${CFLAGS}); export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}); export FFLAGS=$(test-flags-F77 ${FFLAGS}); export FCFLAGS=$(test-flags-FC ${FCFLAGS}); export LDFLAGS=$(test-flags-CCLD ${LDFLAGS}) } tc-arch () { tc-ninja_magic_to_arch portage "$@" } tc-arch-kernel () { tc-ninja_magic_to_arch kern "$@" } tc-check-openmp () { if ! _tc-has-openmp; then eerror "Your current compiler does not support OpenMP!"; if tc-is-gcc; then eerror "Enable OpenMP support by building sys-devel/gcc with USE=\"openmp\"."; else if tc-is-clang; then eerror "OpenMP support in sys-devel/clang is provided by sys-libs/libomp."; fi; fi; die "Active compiler does not have required support for OpenMP"; fi } tc-cpp-is-true () { local CONDITION=${1}; shift; $(tc-getTARGET_CPP) "${@}" -P - <<-EOF > /dev/null 2>&1 #if ${CONDITION} true #else #error false #endif EOF } tc-detect-is-softfloat () { [[ $(tc-getTARGET_CPP) == "gcc -E" ]] && return 1; case ${CTARGET:-${CHOST}} in *-newlib | *-elf | *-eabi) return 1 ;; arm*) if tc-cpp-is-true "defined(__ARM_PCS_VFP)"; then echo "no"; else if tc-cpp-is-true "defined(__SOFTFP__)"; then echo "yes"; else echo "softfp"; fi; fi; return 0 ;; *) return 1 ;; esac } tc-enables-cxx-assertions () { tc-cpp-is-true "defined(_GLIBCXX_ASSERTIONS) || defined(_LIBCPP_ENABLE_ASSERTIONS)" ${CPPFLAGS} ${CXXFLAGS} } tc-enables-fortify-source () { tc-cpp-is-true "defined(_FORTIFY_SOURCE)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS} } tc-enables-pie () { tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS} } tc-enables-ssp () { tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS} } tc-enables-ssp-all () { tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS} } tc-enables-ssp-strong () { tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS} } tc-endian () { local host=$1; [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}; host=${host%%-*}; case ${host} in aarch64*be) echo big ;; aarch64) echo little ;; alpha*) echo little ;; arm*b*) echo big ;; arm*) echo little ;; cris*) echo little ;; hppa*) echo big ;; i?86*) echo little ;; ia64*) echo little ;; loongarch*) echo little ;; m68*) echo big ;; mips*l*) echo little ;; mips*) echo big ;; powerpc*le) echo little ;; powerpc*) echo big ;; riscv*) echo little ;; s390*) echo big ;; sh*b*) echo big ;; sh*) echo little ;; sparc*) echo big ;; x86_64*) echo little ;; *) echo wtf ;; esac } tc-env_build () { tc-export_build_env; 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) "$@" } tc-export () { local var; for var in "$@"; do [[ $(type -t "tc-get${var}") != "function" ]] && die "tc-export: invalid export variable '${var}'"; "tc-get${var}" > /dev/null; done } tc-export_build_env () { tc-export "$@"; if tc-is-cross-compiler; then : "${BUILD_CFLAGS:=-O1 -pipe}"; : "${BUILD_CXXFLAGS:=-O1 -pipe}"; : "${BUILD_CPPFLAGS:= }"; : "${BUILD_LDFLAGS:= }"; else : "${BUILD_CFLAGS:=${CFLAGS}}"; : "${BUILD_CXXFLAGS:=${CXXFLAGS}}"; : "${BUILD_CPPFLAGS:=${CPPFLAGS}}"; : "${BUILD_LDFLAGS:=${LDFLAGS}}"; fi; export BUILD_{C,CXX,CPP,LD}FLAGS; local v; for v in BUILD_{C,CXX,CPP,LD}FLAGS; do export ${v#BUILD_}_FOR_BUILD="${!v}"; done } tc-get-c-rtlib () { local res=$( $(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -print-libgcc-file-name 2>/dev/null ); case ${res} in *libclang_rt*) echo compiler-rt ;; *libgcc*) echo libgcc ;; *) return 1 ;; esac; return 0 } tc-get-compiler-type () { local code=' #if defined(__PATHSCALE__) HAVE_PATHCC #elif defined(__clang__) HAVE_CLANG #elif defined(__GNUC__) HAVE_GCC #endif '; local res=$($(tc-getCPP "$@") -E -P - <<<"${code}"); case ${res} in *HAVE_PATHCC*) echo pathcc ;; *HAVE_CLANG*) echo clang ;; *HAVE_GCC*) echo gcc ;; *) echo unknown ;; esac } tc-get-cxx-stdlib () { local code='#include #if defined(_LIBCPP_VERSION) HAVE_LIBCXX #elif defined(__GLIBCXX__) HAVE_LIBSTDCPP #endif '; local res=$( $(tc-getCXX) ${CPPFLAGS} ${CXXFLAGS} -x c++ -E -P - <<<"${code}" 2>/dev/null ); case ${res} in *HAVE_LIBCXX*) echo libc++ ;; *HAVE_LIBSTDCPP*) echo libstdc++ ;; *) return 1 ;; esac; return 0 } tc-getAR () { tc-getPROG AR ar "$@" } tc-getAS () { tc-getPROG AS as "$@" } tc-getBUILD_AR () { tc-getBUILD_PROG AR ar "$@" } tc-getBUILD_AS () { tc-getBUILD_PROG AS as "$@" } tc-getBUILD_CC () { tc-getBUILD_PROG CC gcc "$@" } tc-getBUILD_CPP () { tc-getBUILD_PROG CPP "$(tc-getBUILD_CC) -E" "$@" } tc-getBUILD_CXX () { tc-getBUILD_PROG CXX g++ "$@" } tc-getBUILD_LD () { tc-getBUILD_PROG LD ld "$@" } tc-getBUILD_NM () { tc-getBUILD_PROG NM nm "$@" } tc-getBUILD_OBJCOPY () { tc-getBUILD_PROG OBJCOPY objcopy "$@" } tc-getBUILD_PKG_CONFIG () { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@" } tc-getBUILD_PROG () { local vars="BUILD_$1 $1_FOR_BUILD HOST$1"; tc-is-cross-compiler || vars+=" $1"; _tc-getPROG CBUILD "${vars}" "${@:2}" } tc-getBUILD_RANLIB () { tc-getBUILD_PROG RANLIB ranlib "$@" } tc-getBUILD_READELF () { tc-getBUILD_PROG READELF readelf "$@" } tc-getBUILD_STRINGS () { tc-getBUILD_PROG STRINGS strings "$@" } tc-getBUILD_STRIP () { tc-getBUILD_PROG STRIP strip "$@" } tc-getCC () { tc-getPROG CC gcc "$@" } tc-getCPP () { tc-getPROG CPP "${CC:-gcc} -E" "$@" } tc-getCXX () { tc-getPROG CXX g++ "$@" } tc-getDLLWRAP () { tc-getPROG DLLWRAP dllwrap "$@" } tc-getF77 () { tc-getPROG F77 gfortran "$@" } tc-getFC () { tc-getPROG FC gfortran "$@" } tc-getGCJ () { tc-getPROG GCJ gcj "$@" } tc-getGO () { tc-getPROG GO gccgo "$@" } tc-getLD () { tc-getPROG LD ld "$@" } tc-getNM () { tc-getPROG NM nm "$@" } tc-getOBJCOPY () { tc-getPROG OBJCOPY objcopy "$@" } tc-getOBJDUMP () { tc-getPROG OBJDUMP objdump "$@" } tc-getPKG_CONFIG () { tc-getPROG PKG_CONFIG pkg-config "$@" } tc-getPROG () { _tc-getPROG CHOST "$@" } tc-getRANLIB () { tc-getPROG RANLIB ranlib "$@" } tc-getRC () { tc-getPROG RC windres "$@" } tc-getREADELF () { tc-getPROG READELF readelf "$@" } tc-getSTRINGS () { tc-getPROG STRINGS strings "$@" } tc-getSTRIP () { tc-getPROG STRIP strip "$@" } tc-getTARGET_CPP () { if [[ -n ${CTARGET} ]]; then _tc-getPROG CTARGET TARGET_CPP "gcc -E" "$@"; else tc-getCPP "$@"; fi } tc-has-tls () { local base="${T}/test-tc-tls"; cat <<-EOF > "${base}.c" int foo(int *i) { static __thread int j = 0; return *i ? j : *i; } EOF local flags; case $1 in -s) flags="-S" ;; -c) flags="-c" ;; -l) ;; -*) die "Usage: tc-has-tls [-c|-l] [toolchain prefix]" ;; esac; : "${flags:=-fPIC -shared -Wl,-z,defs}"; [[ $1 == -* ]] && shift; $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &> /dev/null; local ret=$?; rm -f "${base}"*; return ${ret} } tc-is-clang () { [[ $(tc-get-compiler-type) == clang ]] } tc-is-cross-compiler () { [[ ${CBUILD:-${CHOST}} != ${CHOST} ]] } tc-is-gcc () { [[ $(tc-get-compiler-type) == gcc ]] } tc-is-softfloat () { tc-detect-is-softfloat || tc-tuple-is-softfloat } tc-is-static-only () { local host=${CTARGET:-${CHOST}}; [[ ${host} == *-mint* ]] } tc-ld-disable-gold () { tc-ld-is-gold "$@" && tc-ld-force-bfd "$@" } tc-ld-force-bfd () { if ! tc-ld-is-gold "$@" && ! tc-ld-is-lld "$@"; then return; fi; ewarn "Forcing usage of the BFD linker"; local ld=$(tc-getLD "$@"); local bfd_ld="${ld%% *}.bfd"; local path_ld=$(type -P "${bfd_ld}" 2>/dev/null); [[ -e ${path_ld} ]] && export LD=${bfd_ld}; if tc-is-gcc || tc-is-clang; then export LDFLAGS="${LDFLAGS} -fuse-ld=bfd"; fi } tc-ld-is-gold () { local out; local -x LC_ALL=C; out=$($(tc-getLD "$@") --version 2>&1); if [[ ${out} == *"GNU gold"* ]]; then return 0; fi; local base="${T}/test-tc-gold"; cat <<-EOF > "${base}.c" int main(void) { return 0; } EOF out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1); rm -f "${base}"*; if [[ ${out} == *"GNU gold"* ]]; then return 0; fi; return 1 } tc-ld-is-lld () { local out; local -x LC_ALL=C; out=$($(tc-getLD "$@") --version 2>&1); if [[ ${out} == *"LLD"* ]]; then return 0; fi; local base="${T}/test-tc-lld"; cat <<-EOF > "${base}.c" int main(void) { return 0; } EOF out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1); rm -f "${base}"*; if [[ ${out} == *"LLD"* ]]; then return 0; fi; return 1 } tc-ninja_magic_to_arch () { function _tc_echo_kernel_alias () { [[ ${type} == "kern" ]] && echo $1 || echo $2 }; local type=$1; local host=$2; [[ -z ${host} ]] && host=${CTARGET:-${CHOST}}; case ${host} in aarch64*) echo arm64 ;; alpha*) echo alpha ;; arm*) echo arm ;; avr*) _tc_echo_kernel_alias avr32 avr ;; bfin*) _tc_echo_kernel_alias blackfin bfin ;; c6x*) echo c6x ;; cris*) echo cris ;; frv*) echo frv ;; hexagon*) echo hexagon ;; hppa*) _tc_echo_kernel_alias parisc hppa ;; i?86*) echo x86 ;; ia64*) echo ia64 ;; loongarch*) _tc_echo_kernel_alias loongarch loong ;; m68*) echo m68k ;; metag*) echo metag ;; microblaze*) echo microblaze ;; mips*) echo mips ;; nios2*) echo nios2 ;; nios*) echo nios ;; or1k* | or32*) echo openrisc ;; powerpc*) if [[ ${type} == "kern" ]]; then echo powerpc; else if [[ ${host} == powerpc64* ]]; then echo ppc64; else echo ppc; fi; fi ;; riscv*) echo riscv ;; s390*) echo s390 ;; score*) echo score ;; sh64*) _tc_echo_kernel_alias sh64 sh ;; sh*) echo sh ;; sparc64*) _tc_echo_kernel_alias sparc64 sparc ;; sparc*) [[ ${PROFILE_ARCH} == "sparc64" ]] && _tc_echo_kernel_alias sparc64 sparc || echo sparc ;; tile*) echo tile ;; vax*) echo vax ;; x86_64*) if [[ ${type} == "kern" ]]; then echo x86; else echo amd64; fi ;; xtensa*) echo xtensa ;; *) echo unknown ;; esac } tc-stack-grows-down () { case ${ARCH} in hppa | metag) return 1 ;; esac; return 0 } tc-tuple-is-softfloat () { local CTARGET=${CTARGET:-${CHOST}}; case ${CTARGET//_/-} in bfin* | h8300*) echo "only" ;; *-softfloat-*) echo "yes" ;; *-softfp-*) echo "softfp" ;; arm*-hardfloat-* | arm*eabihf) echo "no" ;; *-newlib | *-elf | *-eabi) echo "no" ;; arm*) echo "yes" ;; *) echo "no" ;; esac } test-compile () { local lang=$1; local code=$2; shift 2; [[ -z "${lang}" ]] && return 1; [[ -z "${code}" ]] && return 1; local compiler filename_in filename_out args=() libs=(); case "${lang}" in c) compiler="$(tc-getCC)"; filename_in="${T}/test.c"; filename_out="${T}/test.o"; args+=(${CFLAGS[@]} -xc -c) ;; c++) compiler="$(tc-getCXX)"; filename_in="${T}/test.cc"; filename_out="${T}/test.o"; args+=(${CXXFLAGS[@]} -xc++ -c) ;; f77) compiler="$(tc-getF77)"; filename_in="${T}/test.f"; filename_out="${T}/test.o"; args+=(${FFFLAGS[@]} -xf77 -c) ;; f95) compiler="$(tc-getFC)"; filename_in="${T}/test.f90"; filename_out="${T}/test.o"; args+=(${FCFLAGS[@]} -xf95 -c) ;; c+ld) compiler="$(tc-getCC)"; filename_in="${T}/test.c"; filename_out="${T}/test.exe"; args+=(${CFLAGS[@]} ${LDFLAGS[@]} -xc); libs+=(${LIBS[@]}) ;; c+++ld) compiler="$(tc-getCXX)"; filename_in="${T}/test.cc"; filename_out="${T}/test.exe"; args+=(${CXXFLAGS[@]} ${LDFLAGS[@]} -xc++); libs+=(${LIBS[@]}) ;; f77+ld) compiler="$(tc-getF77)"; filename_in="${T}/test.f"; filename_out="${T}/test.exe"; args+=(${FFLAGS[@]} ${LDFLAGS[@]} -xf77); libs+=(${LIBS[@]}) ;; f95+ld) compiler="$(tc-getFC)"; filename_in="${T}/test.f90"; filename_out="${T}/test.exe"; args+=(${FCFLAGS[@]} ${LDFLAGS[@]} -xf95); libs+=(${LIBS[@]}) ;; *) die "Unknown compiled language ${lang}" ;; esac; printf "%s\n" "${code}" > "${filename_in}" || die "Failed to create '${test_in}'"; "${compiler}" ${args[@]} "${filename_in}" -o "${filename_out}" ${libs[@]} &> /dev/null } test-flag-CC () { _test-flag-PROG CC c "$@" } test-flag-CCLD () { _test-flag-PROG CC c+ld "$@" } test-flag-CXX () { _test-flag-PROG CXX c++ "$@" } test-flag-F77 () { _test-flag-PROG F77 f77 "$@" } test-flag-FC () { _test-flag-PROG FC f95 "$@" } test-flag-PROG () { [[ ${EAPI} == [67] ]] || die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."; _test-flag-PROG "$@" } test-flags () { test-flags-CC "$@" } test-flags-CC () { _test-flags-PROG CC "$@" } test-flags-CCLD () { _test-flags-PROG CCLD "$@" } test-flags-CXX () { _test-flags-PROG CXX "$@" } test-flags-F77 () { _test-flags-PROG F77 "$@" } test-flags-FC () { _test-flags-PROG FC "$@" } test-flags-PROG () { [[ ${EAPI} == [67] ]] || die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."; _test-flags-PROG "$@" } test_version_info () { if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then return 0; else return 1; fi } ver_cut () { local range=${1}; local v=${2:-${PV}}; local start end; local -a comp; __eapi7_ver_split "${v}"; local max=$((${#comp[@]}/2)); __eapi7_ver_parse_range "${range}" "${max}"; local IFS=; if [[ ${start} -gt 0 ]]; then start=$(( start*2 - 1 )); fi; echo "${comp[*]:start:end*2-start}" } ver_rs () { local v; (( ${#} & 1 )) && v=${@: -1} || v=${PV}; local start end i; local -a comp; __eapi7_ver_split "${v}"; local max=$((${#comp[@]}/2 - 1)); while [[ ${#} -ge 2 ]]; do __eapi7_ver_parse_range "${1}" "${max}"; for ((i = start*2; i <= end*2; i+=2 )) do [[ ${i} -eq 0 && -z ${comp[i]} ]] && continue; comp[i]=${2}; done; shift 2; done; local IFS=; echo "${comp[*]}" } ver_test () { local va op vb; if [[ $# -eq 3 ]]; then va=${1}; shift; else va=${PVR}; fi; [[ $# -eq 2 ]] || die "${FUNCNAME}: bad number of arguments"; op=${1}; vb=${2}; case ${op} in -eq | -ne | -lt | -le | -gt | -ge) ;; *) die "${FUNCNAME}: invalid operator: ${op}" ;; esac; __eapi7_ver_compare "${va}" "${vb}"; test $? "${op}" 2 } verify-sig_src_unpack () { if use verify-sig; then local f suffix found; local distfiles=() signatures=() nosigfound=() straysigs=(); for f in ${A}; do found=; for suffix in .asc .sig; do if [[ ${f} == *${suffix} ]]; then signatures+=("${f}"); found=sig; break; else if has "${f}${suffix}" ${A}; then distfiles+=("${f}"); found=dist+sig; break; fi; fi; done; if [[ ! -n ${found} ]]; then nosigfound+=("${f}"); fi; done; if [[ ${#nosigfound[@]} -gt 0 ]]; then eerror "The following distfiles lack detached signatures:"; for f in "${nosigfound[@]}"; do eerror " ${f}"; done; die "Unsigned distfiles found"; fi; for f in "${signatures[@]}"; do if ! has "${f%.*}" "${distfiles[@]}"; then straysigs+=("${f}"); fi; done; if [[ ${#straysigs[@]} -gt 0 ]]; then eerror "The following signatures do not match any distfiles:"; for f in "${straysigs[@]}"; do eerror " ${f}"; done; die "Unused signatures found"; fi; for f in "${signatures[@]}"; do verify-sig_verify_detached "${DISTDIR}/${f%.*}" "${DISTDIR}/${f}"; done; fi; default_src_unpack } verify-sig_verify_detached () { local file=${1}; local sig=${2}; local key=${3:-${VERIFY_SIG_OPENPGP_KEY_PATH}}; [[ -n ${key} ]] || die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"; local extra_args=(); [[ ${VERIFY_SIG_OPENPGP_KEY_REFRESH} == yes ]] || extra_args+=(-R); if [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]]; then [[ ${VERIFY_SIG_METHOD} == openpgp ]] || die "${FUNCNAME}: VERIFY_SIG_OPENPGP_KEYSERVER is not supported"; extra_args+=(--keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"); fi; addpredict /run/user; local filename=${file##*/}; [[ ${file} == - ]] && filename='(stdin)'; einfo "Verifying ${filename} ..."; case ${VERIFY_SIG_METHOD} in openpgp) local -x TMPDIR=/tmp; if has_version ">=app-portage/gemato-20"; then gemato openpgp-verify-detached -K "${key}" "${extra_args[@]}" "${sig}" "${file}" || die "PGP signature verification failed"; else gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- gpg --verify "${sig}" "${file}" || die "PGP signature verification failed"; fi ;; signify) signify -V -p "${key}" -m "${file}" -x "${sig}" || die "Signify signature verification failed" ;; esac } verify-sig_verify_message () { local file=${1}; local output_file=${2}; local key=${3:-${VERIFY_SIG_OPENPGP_KEY_PATH}}; [[ -n ${key} ]] || die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"; local extra_args=(); [[ ${VERIFY_SIG_OPENPGP_KEY_REFRESH} == yes ]] || extra_args+=(-R); if [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]]; then [[ ${VERIFY_SIG_METHOD} == openpgp ]] || die "${FUNCNAME}: VERIFY_SIG_OPENPGP_KEYSERVER is not supported"; extra_args+=(--keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"); fi; addpredict /run/user; local filename=${file##*/}; [[ ${file} == - ]] && filename='(stdin)'; einfo "Verifying ${filename} ..."; case ${VERIFY_SIG_METHOD} in openpgp) local -x TMPDIR=/tmp; gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- gpg --verify --output="${output_file}" "${file}" || die "PGP signature verification failed" ;; signify) signify -V -e -p "${key}" -m "${output_file}" -x "${file}" || die "Signify signature verification failed" ;; esac } verify-sig_verify_signed_checksums () { local checksum_file=${1}; local algo=${2}; local files=(); read -r -d '' -a files <<< "${3}"; local key=${4:-${VERIFY_SIG_OPENPGP_KEY_PATH}}; [[ -n ${key} ]] || die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"; case ${VERIFY_SIG_METHOD} in openpgp) _gpg_verify_signed_checksums "${checksum_file}" "${algo}" "${files[@]}" "${key}" ;; signify) signify -C -p "${key}" -x "${checksum_file}" "${files[@]}" || die "Signify signature verification failed" ;; esac } verify-sig_verify_unsigned_checksums () { local checksum_file=${1}; local algo=${2}; local files=(); read -r -d '' -a files <<< "${3}"; local chksum_prog chksum_len; case ${algo} in sha256) chksum_prog=sha256sum; chksum_len=64 ;; *) die "${FUNCNAME}: unknown checksum algo ${algo}" ;; esac; [[ ${checksum_file} == - ]] && checksum_file=/dev/stdin; local checksum filename junk ret=0 count=0; while read -r checksum filename junk; do if [[ ${checksum} == "-----BEGIN" ]]; then die "${FUNCNAME}: PGP armor found, use verify-sig_verify_signed_checksums instead"; fi; [[ ${#checksum} -eq ${chksum_len} ]] || continue; [[ -z ${checksum//[0-9a-f]} ]] || continue; has "${filename}" "${files[@]}" || continue; [[ -z ${junk} ]] || continue; "${chksum_prog}" -c --strict - <<< "${checksum} ${filename}"; if [[ ${?} -eq 0 ]]; then (( count++ )); else ret=1; fi; done < "${checksum_file}"; [[ ${ret} -eq 0 ]] || die "${FUNCNAME}: at least one file did not verify successfully"; [[ ${count} -eq ${#files[@]} ]] || die "${FUNCNAME}: checksums for some of the specified files were missing" } virtx () { debug-print-function ${FUNCNAME} "$@"; [[ $# -lt 1 ]] && die "${FUNCNAME} needs at least one argument"; local i=0; local retval=0; local xvfbargs=(-screen 0 1280x1024x24 +extension RANDR); debug-print "${FUNCNAME}: running Xvfb hack"; export XAUTHORITY=; einfo "Starting Xvfb ..."; debug-print "${FUNCNAME}: Xvfb -displayfd 1 ${xvfbargs[*]}"; local logfile=${T}/Xvfb.log; local pidfile=${T}/Xvfb.pid; export DISPLAY=:$( Xvfb -displayfd 1 "${xvfbargs[@]}" 2>"${logfile}" & echo "$!" > "${pidfile}" ); if [[ ${DISPLAY} == : ]]; then eerror "Xvfb failed to start, reprinting error log"; cat "${logfile}"; die "Xvfb failed to start"; fi; einfo "Xvfb started on DISPLAY=${DISPLAY}"; debug-print "${FUNCNAME}: $@"; nonfatal "$@"; retval=$?; kill "$(<"${pidfile}")"; [[ ${retval} -ne 0 ]] && die "Failed to run '$@'"; return 0 } xdg_desktop_database_update () { if [[ ${EBUILD_PHASE} != post* ]]; then die "xdg_desktop_database_update must be used in pkg_post* phases."; fi; if ! type update-desktop-database &> /dev/null; then debug-print "update-desktop-database is not found"; return; fi; ebegin "Updating .desktop files database"; update-desktop-database -q "${EROOT%/}${DESKTOP_DATABASE_DIR}"; eend $? } xdg_environment_reset () { export XDG_DATA_HOME="${HOME}/.local/share"; export XDG_CONFIG_HOME="${HOME}/.config"; export XDG_CACHE_HOME="${HOME}/.cache"; export XDG_STATE_HOME="${HOME}/.local/state"; export XDG_RUNTIME_DIR="${T}/run"; mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" "${XDG_STATE_HOME}" "${XDG_RUNTIME_DIR}" || die; chmod 0700 "${XDG_RUNTIME_DIR}" || die; unset DBUS_SESSION_BUS_ADDRESS } xdg_icon_cache_update () { if [[ ${EBUILD_PHASE} != post* ]]; then die "xdg_icon_cache_update must be used in pkg_post* phases."; fi; if ! type gtk-update-icon-cache &> /dev/null; then debug-print "gtk-update-icon-cache is not found"; return; fi; ebegin "Updating icons cache"; local dir retval=0; local fails=(); for dir in "${EROOT%/}"/usr/share/icons/*; do if [[ -f ${dir}/index.theme ]]; then if ! gtk-update-icon-cache -qf "${dir}"; then debug-print "Updating cache failed on ${dir}"; fails+=("${dir}"); retval=2; fi; else if [[ $(ls "${dir}") = icon-theme.cache ]]; then rm "${dir}/icon-theme.cache"; fi; fi; if [[ -z $(ls "${dir}") ]]; then rmdir "${dir}"; fi; done; eend ${retval}; for dir in "${fails[@]}"; do eerror "Failed to update cache with icon ${dir}"; done } xdg_mimeinfo_database_update () { if [[ ${EBUILD_PHASE} != post* ]]; then die "xdg_mimeinfo_database_update must be used in pkg_post* phases."; fi; if ! type update-mime-database &> /dev/null; then debug-print "update-mime-database is not found"; return; fi; local -x PKGSYSTEM_ENABLE_FSYNC=0; ebegin "Updating shared mime info database"; update-mime-database "${EROOT%/}${MIMEINFO_DATABASE_DIR}"; eend $? }
tin-machine commented 1 year ago

I will try another method.