Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question mark and exclamation point syntax in srpm spec file

I'm trying to understand how the Postgres 9.1 rpms are built on CentOS/RHEL 6, so I'm taking a look at the spec file from the source rpms.

What does the following syntax do/mean? Specifically, the question mark and exclamation point?

%{!?test:%define test 1}
%{!?plpython:%define plpython 1}
%{!?pltcl:%define pltcl 1}
%{!?plperl:%define plperl 1}
%{!?ssl:%define ssl 1}
%{!?intdatetimes:%define intdatetimes 1}
%{!?kerberos:%define kerberos 1}
%{!?nls:%define nls 1}
%{!?xml:%define xml 1}
%{!?pam:%define pam 1}
%{!?disablepgfts:%define disablepgfts 0}
%{!?runselftest:%define runselftest 0}
%{!?uuid:%define uuid 1}
%{!?ldap:%define ldap 1

I understand you can define a macro variable with %define <name>[(opts)] <value>, and I believe the exclamation mark is a logical negation operator. I can't find any info on the question mark or examples like the above though. Seems like some sort of test before defining the macro variable.

Here is a paste of the spec file.

like image 490
Banjer Avatar asked Jan 17 '13 16:01

Banjer


People also ask

What does an RPM contain?

What is an RPM? An RPM package is simply a file containing other files and information about them needed by the system. Specifically, an RPM package consists of the cpio archive, which contains the files, and the RPM header, which contains metadata about the package.

What is RPM build?

rpmbuild is used to build both binary and source software packages. A package consists of an archive of files and meta- data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package.


1 Answers

Lets review a single item here:

%{!?plpython:%define plpython 1}

On line 102 we also see this:

%if %plpython
BuildRequires:  python-devel
%endif

As you said, we know that this is a macro, that can also be confirmed via the Fedora docs. Now if we expand on our search into the Fedora documentation we find conditional macros. This states the following:

You can use a special syntax to test for the existence of macros. For example: %{?macro_to_test: expression} This syntax tells RPM to expand the expression if macro_to_test exists, otherwise ignore. A leading exclamation point, !, tests for the non-existence of a macro: %{!?macro_to_test: expression} In this example, if the macro_to_test macro does not exist, then expand the expression.

The Fedora docs have provided the answer, if the plpython macro doesn't exist, then

%define plython 1

If you look at line 38 you can also see this:

# In this file you can find the default build package list macros.  These can be overridden by defining
# on the rpm command line:
# rpm --define 'packagename 1' .... to force the package to build.
# rpm --define 'packagename 0' .... to force the package NOT to build.
# The base package, the lib package, the devel package, and the server package always get built.

So if you don't define the the macro when you build the package (I imagine this is what most users would do) it's going to ensure that the buildrequires are properly configured for what appears to be a standard PostgreSQL installation.

like image 173
Forrest Avatar answered Sep 28 '22 10:09

Forrest