how to specify rpmbuild parameters? (e.g. --with-something)

Hi, I may be overlooking the obvious, but how can I specify the rpmbuild parameters? So far I have resorted to hardcoding the settings inside the spec file, but that does not work very well over a broader range of distro versions.

Any help is appreciated!
Rainer

rpmbuild --with/–without arguments are simply translated into macros at runtime. It is up to your spec file to check whether macro is set and change behavior accordingly.

https://rpm.org/user_doc/conditional_builds.html

Thx for the info, I tried hard to make use of it, but I think I did not understand…

Concrete example of what I am looking for:

I have in my spec file:

%if 0%{?suse_version} > 1500
%bcond_with kafka
%else
%bcond_without kafka
%endif

However, kafka is never defined, not even on Tumbleweed. So I thought I need to provide a --with-kafka to rpmbuild. But I do not know how to do that on “osc build” and much less on how to do that when submitting to the OBS web service (which is my ultimate goal to use).

I used

%if %{with_kafka}
%files kafka
%defattr(-,root,root)
%{_libdir}/rsyslog/omkafka.so
%{_libdir}/rsyslog/imkafka.so
%endif

etc to check for the macro - does not trigger.

The same is true if I put

%bcond_with kafka

into the spec without a conditional around it. Doesn’t work either.

I now tried to resort to

%define with_kafka 1

And checking with

%if %{with_kafka}

again, no success.

I see, however, that macros actually trigger for which the spec unconditionally says:

%bcond_without some_feature

Which means some_feature get’s activated albeit of the bcond_without.

This brings me to the conclusion that something external to the spec must turn these settings on or off. I am getting a bit desperate. I have “solved” the issue by doing different specs for other distros, but that’s really a bad hack.

Any advise would deeply be appreciated.

Rainer

Sorry, I have to correct myself. I had an issue with my test environment (specifc spec for tumbleweed which I overlooked).

The approach with

%if 0%{?suse_version} >= 1500
%define with_kafka 1
%else
%define with_kafka 0
%endif

works, but I still cannot get

%bcond_with kafka

to work. The work-around I found works for me, but I would really like to understand why %bcond does not work (or other said: how to provide the external parameters obviously required).

Rainer

You got it backwards. “%bcond_with foo” defines option “–with foo” which means default is without (IOW that %with_foo is 0). See also discussion in https://lists.fedoraproject.org/pipermail/devel/2011-December/160347.html

If you want %with_kafka by default you need to use %bcond_without.

Sorry, did not pay enough attention (sometimes it is hard to spot underscores). That’s wrong. %with_kafka is defined only if condition is met, otherwise it is not defined and you get an error. You really should use %{with kafka} (pay attention - it is space, not underscore). Here %{with} is macro which takes one argument and expands to 0 or 1 depending on whether corresponding %with_kafka (notice underscore) is defined. %with_kafka itself is defined by %bcond_with (or %bcond_without) macros. There is also %{without foo} macro for convenience.

Otherwise you must check first whether macro is defined (%{?with_kafka …}, %{defined with_kafka} or similar), but %{with foo} macro already does it for you. It is equivalent to 0%{with_kafka}.

I’ll try with %bcond_without, but it looks hard to understand in the context where no rpmbuild command line params are used.

My approach actually works, because I have the macro always defined, see first part of my message:

%if 0%{?suse_version} >= 1510
%define with_kafka 1
%else
%define with_kafka 0
%endif

To me this looks much cleaner than the “inverse bcond logic” - but if you are more fluent with RPM, that’s probably a mood point. So maybe it is even clearer, if I use this approach, to name the macro like “build_kafka”. So it is clear it’s not related to the with/without RPM logic.

That said, I am still glad for your answer as it helps to understand. I’ll also play a bit more with %bcond_with and _without.

The question that is still not answered is if there is any way to provide rpmbuild parameters (e.g. --with-kafka) on OBS. Is this possible? As of my current understanding it is impossible, so we need to resort to the default values and set them accordingly.

Rainer

You can define macros in project configuration, so you can have multiple projects using the same spec file with different macro values. See Project Configuration | User Guide

Is it what you are after?

Actually no - I am literally after what I have asked. I now know how to build multiple projects from the spec file. However, I would still be interested to know if there is any setting external to the spec file which can be used to provide parameters to rpmbuild.

I admit the question is out of curiosity, but the answer will possible also show a misunderstanding on my part (if there is a way). I think about things like project config or so.

Well, maybe it’s actually the answer :wink: There is nothing listed in the project config settings, so there seems to be now way to specify e.g. --with-kafka rpmbuild parameter. Instead I can use macros as you say.

If that’s correct I think my confusion is cleared up :slight_smile:

Rainer