3

I have a spec (myspecfile.spec) file that looks similar to

Name: package-%{myname}
Version: %{myversion}
Release: %{myrelease}
License: gpl2

Summary: this is my package
BuildArch: noarch

%description
Some description of the package

%files

%changelog

I run rpmbuild like:

rpmbuild -bb new.spec --define 'myname my_name' --define 'myversion my_version' --define 'myrelease my_release' --define 'myprovide my_provide'

And /home/user/rpmbuild/RPMS/noarch/package-my_name-my_version-my_release.noarch.rpm is created.

All well and good, but is there any way to give one of my variables a default value? If I omit one of them?

Say, I run

rpmbuild -bb myfile.spec 

How can I get those variables listed to contain a default value?

If I do a %define myname my_name it will always contain this value no matter what I pass in via the command line.

2 Answers 2

5

You should be able to use a conditional

%if "%{?myname}" == ""
%define myname my_name
%endif

For example, using a very basic spec file:

% cat foo.spec 
%if "%{?foo}" == ""
%define foo  default
%endif

Name: package-%{foo}
Version: 1
Release: 1
License: gpl2
Summary: test
Source: foo

%description
gronk

%prep
%setup -q

%build

Now I can define foo or leave it at the default:

% rpmbuild -bs foo.spec             
Wrote: /home/sweh/rpmbuild/SRPMS/package-default-1-1.src.rpm

% rpmbuild -bs foo.spec -D 'foo bar'
Wrote: /home/sweh/rpmbuild/SRPMS/package-bar-1-1.src.rpm
1

See the documentation https://rpm-software-management.github.io/rpm/manual/macros.html

This will expand to content of variable my_name or to string default_name if variable my_name is not defined:

%{?my_name}%{!?my_name:default_name}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .