contrib/rpm: make build more configurable by using conditionals
authorThomas Haller <thaller@redhat.com>
Tue, 2 Feb 2016 11:57:35 +0000 (12:57 +0100)
committerThomas Haller <thaller@redhat.com>
Tue, 2 Feb 2016 15:09:24 +0000 (16:09 +0100)
Also add a new conditional "debug" to enable more assertions and
more logging, which is disabled by default.

Also add a conditional "test" to disable running the unit tests
(make check) while building the package.

http://rpm.org/wiki/PackagerDocs/ConditionalBuilds

contrib/fedora/rpm/NetworkManager.spec
contrib/fedora/rpm/build.sh
contrib/fedora/rpm/build_clean.sh

index 0d623c8..70bbbc9 100644 (file)
 %global udev_dir %{_prefix}/lib/udev
 %global nmlibdir %{_prefix}/lib/%{name}
 
-%global with_adsl 1
-%global with_bluetooth 1
-%global with_team 1
-%global with_wifi 1
-%global with_wwan 1
-%global with_nmtui 1
-%global regen_docs 1
+%global _hardened_build 1
+
+%global git_sha_version %(test -n '%{git_sha}' && echo '.%{git_sha}')
+
+###############################################################################
+
+%bcond_without adsl
+
+%global default_with_bluetooth 1
+%global default_with_wwan 1
 
 # ModemManager on Fedora < 20 too old for Bluetooth && wwan
 %if (0%{?fedora} && 0%{?fedora} < 20)
-%global with_bluetooth 0
-%global with_wwan 0
+%global default_with_bluetooth 0
+%global default_with_wwan 0
 %endif
 
 # Bluetooth requires the WWAN plugin
-%if 0%{?with_bluetooth}
-%global with_wwan 1
+%if 0%{?default_with_bluetooth}
+%global default_with_wwan 1
+%endif
+
+%if 0%{?default_with_bluetooth}
+%bcond_without bluetooth
+%else
+%bcond_with bluetooth
+%endif
+
+%if 0%{?default_with_wwan}
+%bcond_without wwan
+%else
+%bcond_with wwan
 %endif
 
 %if (0%{?fedora} && 0%{?fedora} <= 19)
-%global with_team 0
+%bcond_with team
+%else
+%bcond_without team
 %endif
 
-%if 0%{?with_bluetooth} || (0%{?with_wwan} && (0%{?rhel} || (0%{?fedora} && 0%{?fedora} > 19)))
+%bcond_without wifi
+
+%bcond_without nmtui
+%bcond_without regen_docs
+%bcond_with    debug
+%bcond_without test
+
+###############################################################################
+
+%if %{with bluetooth} || (%{with wwan} && (0%{?rhel} || (0%{?fedora} && 0%{?fedora} > 19)))
 %global with_modem_manager_1 1
 %else
 %global with_modem_manager_1 0
 %endif
 
-%global _hardened_build 1
-
-%global git_sha_version %(test -n '%{git_sha}' && echo '.%{git_sha}')
+###############################################################################
 
 Name: NetworkManager
 Summary: Network connection manager and user applications
@@ -125,7 +149,7 @@ BuildRequires: nss-devel >= 3.11.7
 BuildRequires: dhclient
 BuildRequires: readline-devel
 BuildRequires: audit-libs-devel
-%if %{regen_docs}
+%if %{with regen_docs}
 BuildRequires: gtk-doc
 %endif
 BuildRequires: libudev-devel
@@ -133,7 +157,7 @@ BuildRequires: libuuid-devel
 BuildRequires: libgudev1-devel >= 143
 BuildRequires: vala-tools
 BuildRequires: iptables
-%if 0%{?with_bluetooth}
+%if %{with bluetooth}
 BuildRequires: bluez-libs-devel
 %endif
 BuildRequires: systemd >= 200-3 systemd-devel
@@ -142,7 +166,7 @@ BuildRequires: libndp-devel >= 1.0
 %if 0%{?with_modem_manager_1}
 BuildRequires: ModemManager-glib-devel >= 1.0
 %endif
-%if 0%{?with_nmtui}
+%if %{with nmtui}
 BuildRequires: newt-devel
 %endif
 BuildRequires: /usr/bin/dbus-launch
@@ -160,7 +184,7 @@ Ethernet, Bridge, Bond, VLAN, Team, InfiniBand, Wi-Fi, mobile broadband
 services.
 
 
-%if 0%{?with_adsl}
+%if %{with adsl}
 %package adsl
 Summary: ADSL device plugin for NetworkManager
 Group: System Environment/Base
@@ -173,7 +197,7 @@ This package contains NetworkManager support for ADSL devices.
 %endif
 
 
-%if 0%{?with_bluetooth}
+%if %{with bluetooth}
 %package bluetooth
 Summary: Bluetooth device plugin for NetworkManager
 Group: System Environment/Base
@@ -188,7 +212,7 @@ This package contains NetworkManager support for Bluetooth devices.
 %endif
 
 
-%if 0%{?with_team}
+%if 0%{with team}
 %package team
 Summary: Team device plugin for NetworkManager
 Group: System Environment/Base
@@ -203,7 +227,7 @@ This package contains NetworkManager support for team devices.
 %endif
 
 
-%if 0%{?with_wifi}
+%if %{with wifi}
 %package wifi
 Summary: Wifi plugin for NetworkManager
 Group: System Environment/Base
@@ -216,7 +240,7 @@ This package contains NetworkManager support for Wifi and OLPC devices.
 %endif
 
 
-%if 0%{?with_wwan}
+%if %{with wwan}
 %package wwan
 Summary: Mobile broadband device plugin for NetworkManager
 Group: System Environment/Base
@@ -323,7 +347,7 @@ by nm-connection-editor and nm-applet in a non-graphical environment.
 
 %build
 
-%if %{regen_docs}
+%if %{with regen_docs}
 # back up pristine docs and use them instead of generated ones, which make
 # multilib unhappy due to different timestamps in the generated content
 cp -R docs ORIG-docs
@@ -337,6 +361,10 @@ intltoolize --automake --copy --force
        --with-dhcpcd=no \
        --with-crypto=nss \
        --enable-more-warnings=error \
+%if %{with debug}
+       --with-more-logging \
+       --with-more-asserts=10000 \
+%endif
        --enable-ppp=yes \
        --with-libaudit=yes-disabled-by-default \
 %if 0%{?with_modem_manager_1}
@@ -344,7 +372,7 @@ intltoolize --automake --copy --force
 %else
        --with-modem-manager-1=no \
 %endif
-%if 0%{?with_wifi}
+%if %{with wifi}
        --enable-wifi=yes \
 %if 0%{?fedora}
        --with-wext=yes \
@@ -355,12 +383,12 @@ intltoolize --automake --copy --force
        --enable-wifi=no \
 %endif
        --enable-vala=yes \
-%if 0%{?regen_docs}
+%if %{with regen_docs}
        --enable-gtk-doc \
 %else
        --disable-gtk-doc \
 %endif
-%if 0%{?with_team}
+%if %{with team}
        --enable-teamdctl=yes \
 %else
        --enable-teamdctl=no \
@@ -425,7 +453,7 @@ rm -f %{buildroot}%{_libdir}/*.la
 rm -f %{buildroot}%{_libdir}/pppd/%{ppp_version}/*.la
 rm -f %{buildroot}%{_libdir}/NetworkManager/*.la
 
-%if %{regen_docs}
+%if %{with regen_docs}
 # install the pristine docs
 cp ORIG-docs/libnm-glib/html/* %{buildroot}%{_datadir}/gtk-doc/html/libnm-glib/
 cp ORIG-docs/libnm-util/html/* %{buildroot}%{_datadir}/gtk-doc/html/libnm-util/
@@ -433,7 +461,9 @@ cp ORIG-docs/libnm-util/html/* %{buildroot}%{_datadir}/gtk-doc/html/libnm-util/
 
 
 %check
+%if %{with test}
 make check
+%endif
 
 
 %post
@@ -490,7 +520,7 @@ fi
 %{_libexecdir}/nm-iface-helper
 %dir %{_libdir}/NetworkManager
 %{_libdir}/NetworkManager/libnm-settings-plugin*.so
-%if 0%{?with_nmtui}
+%if %{with nmtui}
 %exclude %{_mandir}/man1/nmtui*
 %endif
 %dir %{_sysconfdir}/%{name}
@@ -518,29 +548,29 @@ fi
 %doc NEWS AUTHORS README CONTRIBUTING TODO
 %license COPYING
 
-%if 0%{?with_adsl}
+%if %{with adsl}
 %files adsl
 %{_libdir}/%{name}/libnm-device-plugin-adsl.so
 %else
 %exclude %{_libdir}/%{name}/libnm-device-plugin-adsl.so
 %endif
 
-%if 0%{?with_bluetooth}
+%if %{with bluetooth}
 %files bluetooth
 %{_libdir}/%{name}/libnm-device-plugin-bluetooth.so
 %endif
 
-%if 0%{?with_team}
+%if %{with team}
 %files team
 %{_libdir}/%{name}/libnm-device-plugin-team.so
 %endif
 
-%if 0%{?with_wifi}
+%if %{with wifi}
 %files wifi
 %{_libdir}/%{name}/libnm-device-plugin-wifi.so
 %endif
 
-%if 0%{?with_wwan}
+%if %{with wwan}
 %files wwan
 %{_libdir}/%{name}/libnm-device-plugin-wwan.so
 %{_libdir}/%{name}/libnm-wwan.so
@@ -608,7 +638,7 @@ fi
 %dir %{nmlibdir}/conf.d
 %{nmlibdir}/conf.d/00-server.conf
 
-%if 0%{?with_nmtui}
+%if %{with nmtui}
 %files tui
 %{_bindir}/nmtui
 %{_bindir}/nmtui-edit
index 8e6539d..c2f5136 100755 (executable)
@@ -125,7 +125,7 @@ case "$BUILDTYPE" in
                ;;
 esac
 
-rpmbuild --define "_topdir $TEMP" $RPM_BUILD_OPTION "$TEMPSPEC" || die "ERROR: rpmbuild FAILED"
+rpmbuild --define "_topdir $TEMP" $RPM_BUILD_OPTION "$TEMPSPEC" $NM_RPMBUILD_ARGS || die "ERROR: rpmbuild FAILED"
 
 ln -snf "$TEMPBASE" ./latest
 TEMP_LATEST="$(readlink -f .)"/latest
index f369427..5a3f05e 100755 (executable)
@@ -32,8 +32,15 @@ IGNORE_DIRTY=0
 GIT_CLEAN=0
 QUICK=0
 NO_BUILD=0
+WITH_LIST=()
 
+_next_with=
 for A; do
+    if [ -n "$_next_with" ]; then
+        WITH_LIST=("${WITH_LIST[@]}" "$_next_with" "$A")
+        _next_with=
+        continue
+    fi
     case "$A" in
         -h|--help|-\?|help)
             usage
@@ -55,6 +62,12 @@ for A; do
             NO_BUILD=1
             IGNORE_DIRTY=1
             ;;
+        -w|--with)
+            _next_with=--with
+            ;;
+        -W|--without)
+            _next_with=--without
+            ;;
         *)
             usage
             die "Unexpected argument \"$A\""
@@ -62,6 +75,8 @@ for A; do
     esac
 done
 
+test -n "$_next_with" && die "Missing argument to $_next_with"
+
 if [[ $GIT_CLEAN == 1 ]]; then
     git clean -fdx :/
 fi
@@ -96,6 +111,7 @@ if [[ $NO_BUILD != 1 ]]; then
 fi
 
 export BUILDTYPE
+export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
 
 "$SCRIPTDIR"/build.sh