Bug 112663

Summary: Macros for easy conditional build (like --with selinux, --without selinux etc)
Product: [Fedora] Fedora Reporter: Arkadiusz Miskiewicz <arekm>
Component: rpmAssignee: Paul Nasrat <nobody+pnasrat>
Status: CLOSED RAWHIDE QA Contact: Mike McLean <mikem>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: herrold, lav, tmraz
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-11-28 23:54:53 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Arkadiusz Miskiewicz 2003-12-26 19:51:32 UTC
Usage example:
rpmbuild -bb pam.spec --with selinux --without noideawhat --with 
something_else

Each bcond should be declared at beginning of the spec files with ie:
%bcond_with selinux (defaults to off - bcond allows to turn it on via 
--with selinux) or %bcond_without selinux (defaults to on).

Then you can use
%if %{with selinux)
doit
%endif
or
%{?with_selinux:doit}
or
%if %{with selinux} && %{without something}
doit
%else
%donotit
%endif

Note that with_selinux is always defined properly and doesn't depend 
on what is by default (%bcond_with vs %bcond_without).

rpmpopt file:
rpm     alias --with            --define "_with_!#:+       --with-!#:
+" \
        --POPTdesc=$"enable configure <option> for build" \
        --POPTargs=$"<option>"
rpm     alias --without         --define "_without_!#:+    
--without-!#:+" \
        --POPTdesc=$"disable configure <option> for build" \
        --POPTargs=$"<option>"

rpmb    alias --with            --define "_with_!#:+       --with-!#:
+" \
        --POPTdesc=$"enable configure <option> for build" \
        --POPTargs=$"<option>"
rpmb    alias --without         --define "_without_!#:+    
--without-!#:+" \
        --POPTdesc=$"disable configure <option> for build" \
        --POPTargs=$"<option>"

rpmbuild alias --with           --define "_with_!#:+     --with-!#:+" 
\
        --POPTdesc=$"enable configure <option> for build" \
        --POPTargs=$"<option>"
rpmbuild alias --without        --define "_without_!#:+  --without-!
#:+" \
        --POPTdesc=$"disable configure <option> for build" \
        --POPTargs=$"<option>"

macros file:

%with()         %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without()      %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}

# Handle conditional builds. %bcond_with is for case when feature is
# default off and needs to be activated with --with ... command line
# switch. %bcond_without is for the dual case.
#
# %bcond_with foo defines symbol with_foo if --with foo was specified 
on
# command line.
# %bcond_without foo defines symbol with_foo if --without foo was 
*not*
# specified on command line.
#
# For example:
#
# %bcond_with extra_fonts
# %bcond_without static
# %if %{with extra_fonts}
# ...
# %endif
# %ifdef %{with static}
# ...
# %endif
# %{?with_static: ... }
# %{!?with_static: ... }
# %{?with_extra_fonts: ... }
# %{!?with_extra_fonts: ... }
#
# The bottom line: never use without_foo, _with_foo nor _without_foo, 
only
# with_foo. This way changing default set of bconds for given spec is 
just
# a matter of changing single line in it and syntax is more readable.
%bcond_with()           %{expand:%%{?_with_%{1}:%%global with_%{1} 1}
}
%bcond_without()        %{expand:%%{!?_without_%{1}:%%global with_%
{1} 1}}
# 
---------------------------------------------------------------------
---

This supports comes from PLD/Linux (www.pld-linux.org) rpm.

Comment 1 Paul Nasrat 2005-11-28 23:54:53 UTC
I'm pretty sure this is merged in rawhide already (rpm 4.4.2)