Getting issue with rpmbuild

I am not able to create rpm package , getting below error.

/usr/lib/rpm/redhat/brp-ldconfig: line 5: RPM_BUILD_ROOT: unbound variable

My VM OS : Rocky Linux 9.3 (Blue Onyx)

I have tried to execute /usr/lib/rpm/redhat/brp-ldconfig and getting same error

/usr/lib/rpm/redhat/brp-ldconfig
/usr/lib/rpm/redhat/brp-ldconfig: line 5: RPM_BUILD_ROOT: unbound variable

Same issue with /usr/lib/rpm/redhat/brp-mangle-shebangs as well.

/usr/lib/rpm/redhat/brp-mangle-shebangs
/usr/lib/rpm/redhat/brp-mangle-shebangs: line 4: RPM_BUILD_ROOT: unbound variable

cat /usr/lib/rpm/redhat/brp-ldconfig

#!/usr/bin/sh -efu
# Force creating of DSO symlinks.

# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
  exit 0
fi

# Create an empty config file for ldconfig to shut up a warning
config=$(mktemp -p "$RPM_BUILD_ROOT")
/sbin/ldconfig -f $(basename "$config") -N -r "$RPM_BUILD_ROOT"
rm -f "$config"
# TODO: warn if it created new symlinks and guide people.

If I remove u from first line of the above file (#!/usr/bin/sh -efu), issue not reproducible.

I am able to create rpm package for RHEL 6/7/8, CentOS 6/7/8, Oracle Linux 6/7/8 , Rocky Linux 8 with same spec file but not with Rocky Linux 9.

There is a difference is in the /usr/lib/rpm/redhat/brp-ldconfig file for rocky linux 9.

Rocky Linux 8:
#!/bin/sh -f

Rocky Linux 9:
#!/usr/bin/sh -efu

I think issue is with option u

Please help me.

Thanks in advance.

$RPM_BUILD_ROOT not being defined is an issue that you need to solve. Removing -u is not the solution to the problem.

With that said, you should be using mock to build packages, not straight rpmbuild.

dnf install epel-release
crb enable
dnf install mock -y

@nazunalika but I am able to create rpm for other OS’s RHEL 6/7/8, CentOS 6/7/8, Oracle Linux 6/7/8 , Rocky Linux 8 with same spec file.

Summary: test
Name: test
Version: 1.0.0
Release: 20231212093200
License: test
Group: Applications
URL: http://www.test.com
Vendor: test, Inc.
Packager: test, Inc.
BuildRoot: /opt/test
AutoReqProv: no

%description
Best email money can buy

%define __spec_install_pre /bin/true

%prep

%build

%install

%pre

%post

%preun

%postun

%clean



$ rpmbuild --target x86_64 -bb test.spec
Building target platforms: x86_64
Building for target x86_64
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.ttQqpl
+ umask 022
+ cd /home/jenkins/rpmbuild/BUILD
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.Fympoe
+ umask 022
+ cd /home/jenkins/rpmbuild/BUILD
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.wbgnDB
/usr/lib/rpm/redhat/brp-ldconfig: line 5: RPM_BUILD_ROOT: unbound variable
error: Bad exit status from /var/tmp/rpm-tmp.wbgnDB (%install)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.wbgnDB (%install)

$ cat /var/tmp/rpm-tmp.wbgnDB
#!/bin/sh
/bin/true



     
    
    /usr/lib/rpm/check-buildroot
    
    /usr/lib/rpm/redhat/brp-ldconfig 
    /usr/lib/rpm/brp-compress 
    
    /usr/lib/rpm/brp-strip /usr/bin/strip 
    /usr/lib/rpm/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump 
     
    /usr/lib/rpm/redhat/brp-strip-lto /usr/bin/strip 
    /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip 
    /usr/lib/rpm/redhat/brp-python-bytecompile "" "1" "0" 
     
    /usr/lib/rpm/brp-python-hardlink 
    /usr/lib/rpm/redhat/brp-mangle-shebangs     

It is failing at /usr/lib/rpm/redhat/brp-ldconfig

You can easily reproduce with above spec file.

what I have to change to make it work with Rocky Linux 9

any thoughts and suggestions here ?

Don’t know what you are expecting with such a spec file

It seems you want to do bad things (such as setting BuildRoot, so probably trying to package its content)

This is NOT how rpmbuild works

The content of the package must be from sources, and installed in buildroot in %install section

And I cannot reproduce

I recommend you start by reading spec files from RPMs available in the distro and learn the proper way

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.