diff --git a/check_elf_files b/check_elf_files new file mode 100755 index 0000000000000000000000000000000000000000..986e96ec573863aed7a06502f0c45f5930b0c92f --- /dev/null +++ b/check_elf_files @@ -0,0 +1,85 @@ +#!/usr/bin/perl +# Strip files + +use strict; +use warnings; +use File::Find; +use File::Basename; + +my $buildroot = $ENV{RPM_BUILD_ROOT}; +die "No build root defined" unless $buildroot; +die "Invalid build root" unless -d $buildroot; +# normalize build root +$buildroot =~ s|/$||; + +# set LIBRARY_PATH to check libraries in build root +my $lib = `rpm --eval %_lib`; +chomp $lib; +$ENV{LD_LIBRARY_PATH}="$buildroot/$lib:$buildroot/usr/$lib"; + +my (@shared_libs, @executables, @static_libs); +find(\&keep_wanted, $buildroot); + +check_missing_or_unused_libs(); + +sub check_missing_or_unused_libs { + my $shift = length($buildroot); + foreach my $file (@shared_libs, @executables) { + my (undef, undef, @l) = `ldd -u -r $file 2>/dev/null`; + next unless @l; + my $file_ = substr($file, $shift); + print STDERR + "Warning: unused libraries in $file_: ", + join(' ', map { basename($_) } @l), "\n"; + } + foreach my $file (@shared_libs) { + my @l = `ldd -r $file 2>/dev/null`; + next unless @l; + my $file_ = substr($file, $shift); + print STDERR + "Warning: undefined symbols in $file_: ", + join(' ', map { /undefined symbol: (\S+)/ ? $1 : () } @l), "\n"; + } +} + +# TODO: we should write a binding for libfile... +sub expensive_test { + my ($file) = @_; + my $type = `file -- "$file"`; +} + +# Check if a file is an elf binary, shared library, or static library, +# for use by File::Find. It'll fill the following 3 arrays with anything +# it finds: +sub keep_wanted() { + # skip everything but files + return unless -f $_; + # skip symlinks + return if -l $_; + return if $File::Find::dir =~ m!/usr/lib/debug($|/)!; + + # Does its filename look like a shared library? + if (m/\.so/) { + # Ok, do the expensive test. + if (expensive_test($_) =~ m/ELF.*shared/) { + push @shared_libs, $File::Find::name; + return; + } + } + + # Is it executable? -x isn't good enough, so we need to use stat. + my (undef, undef, $mode, undef) = stat(_); + if ($mode & 0111) { + # Ok, expensive test. + if (expensive_test($_) =~ m/ELF.*executable/) { + push @executables, $File::Find::name; + return; + } + } + + # Is it a static library, and not a debug library? + if (m/lib.*\.a/ && ! m/_g\.a/) { + push @static_libs, $File::Find::name; + return; + } +} diff --git a/clean_perl b/clean_perl new file mode 100755 index 0000000000000000000000000000000000000000..b9da34592ffff0bb1973194520df2db6777a1220 --- /dev/null +++ b/clean_perl @@ -0,0 +1,21 @@ +#!/bin/sh + +for d in $RPM_BUILD_ROOT/usr/lib{,64}/perl5 $RPM_BUILD_ROOT/usr/share/perl5;do + +[ -d $d ] || continue + +find $d -name ".packlist" | xargs rm -f + +# remove file alike /usr/lib/perl5/5.8.*/i386-linux-thread-multi/perllocal.pod +perl -MConfig -e 'unlink "$ENV{RPM_BUILD_ROOT}$Config{installarchlib}/perllocal.pod"' + +for i in $(find $d -name "*.bs"); do + if [ -s $i ]; then + echo "non empty .bs file, please mail rgarciasuarez@mandriva.com about this!" + else + rm -f $i + fi +done + +find $d -depth -mindepth 2 -type d -empty -exec rmdir {} \; +done diff --git a/macros b/macros index 31429a0b3e42abd2ef840e87c7ebce47a55ec6eb..8fae00046bd7cf1bf30d5981c2141f48cd8e3327 100644 --- a/macros +++ b/macros @@ -49,6 +49,10 @@ %build_cxx %{__cxx} %build_cpp %{__cpp} +# Dynamic EVR tags macro for use with versioned provides/requires in place of +# '%{version}-%{release}', ie. to automatically add epoch if present +%EVR %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}} + #============================================================================== # ---- compiler flags. @@ -261,6 +265,10 @@ print(result) %__brp_check_desktop_files /usr/lib/rpm/anolis/check-desktop-files +%__brp_clean_perl_files /usr/lib/rpm/anolis/clean_perl + +%__brp_check_elf_files /usr/lib/rpm/anolis/check_elf_files + # note: %%__os_install_post_python is defined in python-srpm-macros and contains several policies # don't remove it from %%__os_install_post unless coordinating the change with Python maintainers # packagers, don't undefine the entire macro, see the individual macros in /usr/lib/rpm/macros.d/macros.python-srpm @@ -276,6 +284,8 @@ print(result) %{?__brp_strip_static_archive} \ %{?__brp_check_rpaths} \ %{?__brp_remove_la_files} \ + %{?__brp_clean_perl_files} \ + %{?__brp_check_elf_files} \ %{?__brp_mangle_shebangs} \ %{?__brp_remove_info_dir} \ %{?__brp_relink_symlinks} \ diff --git a/system-rpm-config.spec b/system-rpm-config.spec index a65ee94ea84031bab25ba9a0277b01daed024456..92e7d8bbf8045412b109c539f1051b884294ce3f 100644 --- a/system-rpm-config.spec +++ b/system-rpm-config.spec @@ -1,4 +1,4 @@ -%define anolis_release 22 +%define anolis_release 23 Summary: Anolis OS specific rpm configuration files Name: system-rpm-config @@ -60,6 +60,8 @@ Source403: fix-dlsearch-path-in-libtool Source404: generate-compatibility-deps Source405: relink_symlinks Source406: check-desktop-files +Source407: clean_perl +Source408: check_elf_files # 2022-05-25 Snapshots from http://git.savannah.gnu.org/gitweb/?p=config.git Source500: config.guess @@ -139,6 +141,8 @@ install -p -m 755 -t %{buildroot}%{rrcdir} fix-dlsearch-path-in-libtool install -p -m 755 -t %{buildroot}%{rrcdir} generate-compatibility-deps install -p -m 755 -t %{buildroot}%{rrcdir} relink_symlinks install -p -m 755 -t %{buildroot}%{rrcdir} check-desktop-files +install -p -m 755 -t %{buildroot}%{rrcdir} clean_perl +install -p -m 755 -t %{buildroot}%{rrcdir} check_elf_files install -p -m 755 -t %{buildroot}%{rrcdir} find-* mkdir -p %{buildroot}%{rrcdir}/find-provides.d @@ -168,6 +172,8 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/anolis/srpm forge.lua %{rrcdir}/anolis-annobin-* %{rrcdir}/config.* %{rrcdir}/check-desktop-files +%{rrcdir}/check_elf_files +%{rrcdir}/clean_perl %{rrcdir}/find-provides %{rrcdir}/find-requires %{rrcdir}/remove-info-dir @@ -192,6 +198,11 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/anolis/srpm forge.lua %license MulanPSL %changelog +* Sat Feb 4 2023 Funda Wang - 1:23-23 +- Add helper scripts from Mageia for clean perl files and display + warnings against shared libs +- Add EVR macro to simplify epoch:version-release usage + * Mon Jan 30 2023 Chunmei Xu - 1:23-22 - requires abi-dumper