Files
glibc/source.sh
T
2025-07-11 17:57:02 +03:00

94 lines
3.7 KiB
Bash

# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
DOWNLOAD="https://ftp.gnu.org/gnu/glibc/glibc-${BPM_PKG_VERSION}.tar.xz"
FILENAME="${DOWNLOAD##*/}"
# The prepare function is executed in the root of the temp directory
# This function is used for downloading files and putting them into the correct location
prepare() {
wget "$DOWNLOAD"
tar -xvf "$FILENAME" --strip-components=1 -C "$BPM_SOURCE"
}
# The build function is executed in the source directory
# This function is used to compile the source code
build() {
mkdir -p build
cd build
# Install system binaries to /usr/sbin
echo "rootsbindir=/usr/sbin" > configparms
# _FORTIFY_SOURCE=3 can result in testsuite failures. It is instead enabled through --enable-fortify-source
CFLAGS=${CFLAGS/-Wp,-D_FORTIFY_SOURCE=3/}
../configure --prefix=/usr \
--with-headers=/usr/include \
--enable-bind-now \
--enable-fortify-source \
--enable-kernel=5.4 \
--enable-cet \
--enable-stack-protector=strong \
--enable-multi-arch \
--disable-nscd \
--disable-profile \
--disable-werror \
libc_cv_slibdir=/usr/lib
make
# Generate locales here because localedef does not work in fakeroot
make -C "$BPM_SOURCE"/localedata objdir="$BPM_SOURCE"/build DESTDIR="${BPM_WORKDIR}"/locales install-locale-files
}
# The check function is executed in the source directory
# This function is used to run tests to verify the package has been compiled correctly
check() {
# disable tests that take too long on most systems
sed -i "/tst-thread-affinity-pthread/d" nptl/Makefile
sed -i "/tst-thread-affinity-sched/d" nptl/Makefile
cd build
make check
}
# The package function is executed in the source directory
# This function is used to move the compiled files into the output directory
package() {
cd build
make DESTDIR="$BPM_OUTPUT" install
# Fix hardcoded path
sed '/RTLDLIST=/s@/usr@@g' -i "$BPM_OUTPUT"/usr/bin/ldd
# Install locale-gen script
install -Dm755 "$BPM_WORKDIR"/locale-gen "$BPM_OUTPUT"/usr/bin/locale-gen
# Create locale.gen file
install -dm755 "$BPM_OUTPUT"/etc
touch "$BPM_OUTPUT"/etc/locale.gen
sed -e '1,3d' -e 's|/| |g' -e 's|\\| |g' -e 's|^|#|g' "$BPM_SOURCE"/localedata/SUPPORTED >> "$BPM_OUTPUT"/etc/locale.gen
# Create SUPPORTED file
install -dm755 "$BPM_OUTPUT"/usr/share/i18n
sed -e '1,3d' -e 's|/| |g' -e 's| \\||g' "$BPM_SOURCE"/localedata/SUPPORTED > "$BPM_OUTPUT"/usr/share/i18n/SUPPORTED
# Install C.UTF-8 so that it is always available
install -dm55 "$BPM_OUTPUT"/usr/lib/locale
cp -r "$BPM_WORKDIR"/locales/usr/lib/locale/C.utf8 -t "$BPM_OUTPUT"/usr/lib/locale
sed -i '/#C\.UTF-8 /d' "$BPM_OUTPUT"/etc/locale.gen
# Symlink glibc dynamic linker to /lib64
install -dm755 "$BPM_OUTPUT"/lib64/
ln -sf ../lib/ld-linux-x86-64.so.2 "$BPM_OUTPUT"/lib64
ln -sf ../lib/ld-linux-x86-64.so.2 "$BPM_OUTPUT"/lib64/ld-lsb-x86_64.so.3
# Install package licenses
install -Dm644 "$BPM_SOURCE"/LICENSES "$BPM_OUTPUT"/usr/share/licenses/glibc/LICENSES
install -Dm644 "$BPM_SOURCE"/COPYING "$BPM_OUTPUT"/usr/share/licenses/glibc/COPYING
install -Dm644 "$BPM_SOURCE"/COPYING.LIB "$BPM_OUTPUT"/usr/share/licenses/glibc/COPYING.LIB
}