Skip to content

Commit 3c1edb4

Browse files
authored
Add files via upload
1 parent 6534ea5 commit 3c1edb4

24 files changed

+6835
-0
lines changed

unpacker.eclass

Lines changed: 655 additions & 0 deletions
Large diffs are not rendered by default.

user-info.eclass

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Copyright 1999-2025 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
# @ECLASS: user-info.eclass
5+
# @MAINTAINER:
6+
7+
# Michał Górny <[email protected]> (NetBSD)
8+
# @SUPPORTED_EAPIS: 7 8
9+
# @BLURB: Read-only access to user and group information
10+
11+
case ${EAPI} in
12+
7|8) ;;
13+
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
14+
esac
15+
16+
if [[ -z ${_USER_INFO_ECLASS} ]]; then
17+
_USER_INFO_ECLASS=1
18+
19+
# @FUNCTION: egetent
20+
# @USAGE: <database> <key>
21+
# @DESCRIPTION:
22+
# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5),
23+
# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
24+
#
25+
# Supported databases: group passwd
26+
# Warning: This function can be used only in pkg_* phases when ROOT is valid.
27+
egetent() {
28+
local db=$1 key=$2
29+
30+
[[ $# -ge 3 ]] && die "usage: egetent <database> <key>"
31+
32+
case ${db} in
33+
passwd|group) ;;
34+
*) die "sorry, database '${db}' not yet supported; file a bug" ;;
35+
esac
36+
37+
case ${CHOST} in
38+
*-freebsd*|*-dragonfly*)
39+
case ${db} in
40+
passwd) db="user" ;;
41+
*) ;;
42+
esac
43+
44+
# lookup by uid/gid
45+
local opts
46+
if [[ ${key} == [[:digit:]]* ]] ; then
47+
[[ ${db} == "user" ]] && opts=( -u ) || opts=( -g )
48+
fi
49+
50+
# Handle different ROOT
51+
[[ -n ${ROOT} ]] && opts+=( -R "${ROOT}" )
52+
53+
pw show ${db} ${opts} "${key}" -q
54+
;;
55+
*-openbsd*)
56+
grep "${key}:\*:" "${EROOT}/etc/${db}"
57+
;;
58+
*)
59+
# getent does not support -R option, if we are working on a different
60+
# ROOT than /, fallback to grep technique.
61+
if [[ -z ${ROOT} ]]; then
62+
# ignore nscd output if we're not running as root
63+
type -p nscd >/dev/null && nscd -i "${db}" 2>/dev/null
64+
getent "${db}" "${key}"
65+
else
66+
if [[ ${key} =~ ^[[:digit:]]+$ ]]; then
67+
grep -E "^([^:]*:){2}${key}:" "${ROOT}/etc/${db}"
68+
else
69+
grep "^${key}:" "${ROOT}/etc/${db}"
70+
fi
71+
fi
72+
;;
73+
esac
74+
}
75+
76+
# @FUNCTION: egetusername
77+
# @USAGE: <uid>
78+
# @DESCRIPTION:
79+
# Gets the username for given UID.
80+
egetusername() {
81+
[[ $# -eq 1 ]] || die "usage: egetusername <uid>"
82+
83+
egetent passwd "$1" | cut -d: -f1
84+
}
85+
86+
# @FUNCTION: egetgroupname
87+
# @USAGE: <gid>
88+
# @DESCRIPTION:
89+
# Gets the group name for given GID.
90+
egetgroupname() {
91+
[[ $# -eq 1 ]] || die "usage: egetgroupname <gid>"
92+
93+
egetent group "$1" | cut -d: -f1
94+
}
95+
96+
# @FUNCTION: egethome
97+
# @USAGE: <user>
98+
# @DESCRIPTION:
99+
# Gets the home directory for the specified user.
100+
egethome() {
101+
local pos
102+
103+
[[ $# -eq 1 ]] || die "usage: egethome <user>"
104+
105+
case ${CHOST} in
106+
*-freebsd*|*-dragonfly*)
107+
pos=9
108+
;;
109+
*) # Linux, NetBSD, OpenBSD, etc...
110+
pos=6
111+
;;
112+
esac
113+
114+
egetent passwd "$1" | cut -d: -f${pos}
115+
}
116+
117+
# @FUNCTION: egetshell
118+
# @USAGE: <user>
119+
# @DESCRIPTION:
120+
# Gets the shell for the specified user.
121+
egetshell() {
122+
local pos
123+
124+
[[ $# -eq 1 ]] || die "usage: egetshell <user>"
125+
126+
case ${CHOST} in
127+
*-freebsd*|*-dragonfly*)
128+
pos=10
129+
;;
130+
*) # Linux, NetBSD, OpenBSD, etc...
131+
pos=7
132+
;;
133+
esac
134+
135+
egetent passwd "$1" | cut -d: -f${pos}
136+
}
137+
138+
# @FUNCTION: egetcomment
139+
# @USAGE: <user>
140+
# @DESCRIPTION:
141+
# Gets the comment field for the specified user.
142+
egetcomment() {
143+
local pos
144+
145+
[[ $# -eq 1 ]] || die "usage: egetcomment <user>"
146+
147+
case ${CHOST} in
148+
*-freebsd*|*-dragonfly*)
149+
pos=8
150+
;;
151+
*) # Linux, NetBSD, OpenBSD, etc...
152+
pos=5
153+
;;
154+
esac
155+
156+
egetent passwd "$1" | cut -d: -f${pos}
157+
}
158+
159+
# @FUNCTION: egetgroups
160+
# @USAGE: <user>
161+
# @DESCRIPTION:
162+
# Gets all the groups user belongs to. The primary group is returned
163+
# first, then all supplementary groups. Groups are ','-separated.
164+
egetgroups() {
165+
[[ $# -eq 1 ]] || die "usage: egetgroups <user>"
166+
167+
local egroups_arr
168+
169+
if [[ -n "${ROOT}" ]]; then
170+
local pgid=$(egetent passwd "$1" | cut -d: -f4)
171+
local pgroup=$(egetent group "${pgid}" | cut -d: -f1)
172+
local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) )
173+
egroups_arr=( "${pgroup}" )
174+
local sg
175+
for sg in "${sgroups[@]}"; do
176+
if [[ ${sg} != ${pgroup} ]]; then
177+
egroups_arr+=( "${sg}" )
178+
fi
179+
done
180+
else
181+
read -r -a egroups_arr < <(id -G -n "$1")
182+
fi
183+
184+
local g groups=${egroups_arr[0]}
185+
# sort supplementary groups to make comparison possible
186+
while read -r g; do
187+
[[ -n ${g} ]] && groups+=",${g}"
188+
done < <(printf '%s\n' "${egroups_arr[@]:1}" | sort)
189+
echo "${groups}"
190+
}
191+
192+
fi

usr-ldscript.eclass

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Copyright 2019-2023 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
# @ECLASS: usr-ldscript.eclass
5+
# @MAINTAINER:
6+
# Toolchain Ninjas <[email protected]>
7+
# @SUPPORTED_EAPIS: 7 8
8+
# @BLURB: Defines the gen_usr_ldscript function.
9+
10+
case ${EAPI} in
11+
7|8) ;;
12+
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
13+
esac
14+
15+
if [[ -z ${_USR_LDSCRIPT_ECLASS} ]]; then
16+
_USR_LDSCRIPT_ECLASS=1
17+
18+
inherit multilib toolchain-funcs
19+
20+
IUSE="split-usr"
21+
22+
# @FUNCTION: gen_usr_ldscript
23+
# @USAGE: [-a] <list of libs to create linker scripts for>
24+
# @DESCRIPTION:
25+
# This function generate linker scripts in /usr/lib for dynamic
26+
# libs in /lib. This is to fix linking problems when you have
27+
# the .so in /lib, and the .a in /usr/lib. What happens is that
28+
# in some cases when linking dynamic, the .a in /usr/lib is used
29+
# instead of the .so in /lib due to gcc/libtool tweaking ld's
30+
# library search path. This causes many builds to fail.
31+
# See bug #4411 for more info.
32+
#
33+
# Note that you should in general use the unversioned name of
34+
# the library (libfoo.so), as ldconfig should usually update it
35+
# correctly to point to the latest version of the library present.
36+
gen_usr_ldscript() {
37+
local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname)
38+
39+
tc-is-static-only && return
40+
use prefix && return
41+
42+
# The toolchain's sysroot is automatically prepended to paths in this
43+
# script. We therefore need to omit EPREFIX on standalone prefix (RAP)
44+
# systems. prefix-guest (non-RAP) systems don't apply a sysroot so EPREFIX
45+
# is still needed in that case. This is moot because the above line makes
46+
# the function a noop on prefix, but we keep this in case that changes.
47+
local prefix=$(usex prefix-guest "${EPREFIX}" "")
48+
49+
# We only care about stuffing / for the native ABI. #479448
50+
if [[ $(type -t multilib_is_native_abi) == "function" ]] ; then
51+
multilib_is_native_abi || return 0
52+
fi
53+
54+
# Eventually we'd like to get rid of this func completely #417451
55+
case ${CTARGET:-${CHOST}} in
56+
*-darwin*) ;;
57+
*-android*) return 0 ;;
58+
*linux*)
59+
use split-usr || return 0
60+
;;
61+
*) return 0 ;;
62+
esac
63+
64+
# Just make sure it exists
65+
dodir /usr/${libdir}
66+
67+
if [[ $1 == "-a" ]] ; then
68+
auto=true
69+
shift
70+
dodir /${libdir}
71+
fi
72+
73+
# OUTPUT_FORMAT gives hints to the linker as to what binary format
74+
# is referenced ... makes multilib saner
75+
local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
76+
if $(tc-getLD) --version | grep -q 'GNU gold' ; then
77+
# If they're using gold, manually invoke the old bfd. #487696
78+
local d="${T}/bfd-linker"
79+
mkdir -p "${d}"
80+
ln -sf $(type -P ${CHOST}-ld.bfd) "${d}"/ld
81+
flags+=( -B"${d}" )
82+
fi
83+
output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
84+
[[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
85+
86+
for lib in "$@" ; do
87+
local tlib
88+
if ${auto} ; then
89+
lib="lib${lib}${suffix}"
90+
else
91+
# Ensure /lib/${lib} exists to avoid dangling scripts/symlinks.
92+
# This especially is for AIX where $(get_libname) can return ".a",
93+
# so /lib/${lib} might be moved to /usr/lib/${lib} (by accident).
94+
[[ -r ${ED}/${libdir}/${lib} ]] || continue
95+
#TODO: better die here?
96+
fi
97+
98+
case ${CTARGET:-${CHOST}} in
99+
*-darwin*)
100+
if ${auto} ; then
101+
tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
102+
else
103+
tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib})
104+
fi
105+
[[ -z ${tlib} ]] && die "unable to read install_name from ${lib}"
106+
tlib=${tlib##*/}
107+
108+
if ${auto} ; then
109+
mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
110+
# some install_names are funky: they encode a version
111+
if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]] ; then
112+
mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
113+
fi
114+
rm -f "${ED}"/${libdir}/${lib}
115+
fi
116+
117+
# Mach-O files have an id, which is like a soname, it tells how
118+
# another object linking against this lib should reference it.
119+
# Since we moved the lib from usr/lib into lib this reference is
120+
# wrong. Hence, we update it here. We don't configure with
121+
# libdir=/lib because that messes up libtool files.
122+
# Make sure we don't lose the specific version, so just modify the
123+
# existing install_name
124+
if [[ ! -w "${ED}/${libdir}/${tlib}" ]] ; then
125+
chmod u+w "${ED}/${libdir}/${tlib}" || die # needed to write to it
126+
local nowrite=yes
127+
fi
128+
install_name_tool \
129+
-id "${EPREFIX}"/${libdir}/${tlib} \
130+
"${ED}"/${libdir}/${tlib} || die "install_name_tool failed"
131+
if [[ -n ${nowrite} ]] ; then
132+
chmod u-w "${ED}/${libdir}/${tlib}" || die
133+
fi
134+
# Now as we don't use GNU binutils and our linker doesn't
135+
# understand linker scripts, just create a symlink.
136+
pushd "${ED}/usr/${libdir}" > /dev/null
137+
ln -snf "../../${libdir}/${tlib}" "${lib}"
138+
popd > /dev/null
139+
;;
140+
*)
141+
if ${auto} ; then
142+
tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib})
143+
[[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}"
144+
mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die
145+
# some SONAMEs are funky: they encode a version before the .so
146+
if [[ ${tlib} != ${lib}* ]] ; then
147+
mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die
148+
fi
149+
rm -f "${ED}"/${libdir}/${lib}
150+
else
151+
tlib=${lib}
152+
fi
153+
cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
154+
/* GNU ld script
155+
Since Gentoo has critical dynamic libraries in /lib, and the static versions
156+
in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
157+
run into linking problems. This "fake" dynamic lib is a linker script that
158+
redirects the linker to the real lib. And yes, this works in the cross-
159+
compiling scenario as the sysroot-ed linker will prepend the real path.
160+
161+
See bug https://bugs.gentoo.org/4411 for more info.
162+
*/
163+
${output_format}
164+
GROUP ( ${prefix}/${libdir}/${tlib} )
165+
END_LDSCRIPT
166+
;;
167+
esac
168+
fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}"
169+
done
170+
}
171+
172+
fi # _USR_LDSCRIPT_ECLASS

0 commit comments

Comments
 (0)