Bug 112663 - Macros for easy conditional build (like --with selinux, --without selinux etc)
Macros for easy conditional build (like --with selinux, --without selinux etc)
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: rpm (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Paul Nasrat
Mike McLean
: FutureFeature
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-12-26 14:51 EST by Arkadiusz Miskiewicz
Modified: 2007-11-30 17:10 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-11-28 18:54:53 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Arkadiusz Miskiewicz 2003-12-26 14:51:32 EST
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 18:54:53 EST
I'm pretty sure this is merged in rawhide already (rpm 4.4.2)

Note You need to log in before you can comment on or make changes to this bug.