+# Declare rpmbuild --with/--without parameters
+%bcond_without servers
+%bcond_without ldiskfs
+%bcond_with zfs
+%bcond_without lustre_tests
+%bcond_without lustre_utils
+%bcond_without lustre_iokit
+%bcond_without lustre_modules
+%bcond_with lnet_dlc
+%bcond_without manpages
+%bcond_without shared
+%bcond_without static
+
+%if %{without servers}
+ # --without servers overrides --with {ldiskfs|zfs}
+ # so undefine the internal variables set by bcond_*
+ %undefine with_ldiskfs
+ %undefine with_zfs
+%endif
+
+%{!?version: %global version @VERSION@}
+%{!?kver: %global kver %(uname -r)}
+%{!?kdir: %global kdir /lib/modules/%{kver}/source}
+%{!?kobjdir: %global kobjdir %(if [ "%{kdir}" = "/lib/modules/%{kver}/source" ]; then echo "/lib/modules/%{kver}/build"; else echo "%{kdir}"; fi)}
+
+# as an alternative to this implementation we could simply "make -C $kdir kernelversion"
+%{!?kversion: %global kversion %(files="include/generated/utsrelease.h include/linux/utsrelease.h include/linux/version.h"; for f in $files; do if test -r %{kobjdir}/$f && grep UTS_RELEASE %{kobjdir}/$f >/dev/null; then sed -ne '/^#define UTS_RELEASE/s/.*"\\(.*\\)"$/\\1/p' %{kobjdir}/$f; break; fi; done)}
+
+# We set this because kernel_module_package has its own method of identifying
+# which kernel to build against, and it is unlikely that its decision will
+# match with Lustre's method of selecting which kernel to build against.
+# By setting this variable, we override kernel_module_package's kernel
+# selection with our selection.
+%{!?kernel_version: %global kernel_version %kversion}
+
+# in order to get kernel symset and/or kernel module dependencies into
+# the RPM, in order to support weak-modules, the internal dependency gen-
+# erator needs to be disabled
+# this is done with (reduce the double % down to a single %):
+#
+# %%global _use_internal_dependency_generator 0
+#
+# on SLES10, /usr/lib/rpm/macros already sets this, so no harm in also
+# defining it here (until Suse changes their mind)
+#
+# on RHEL5, however, we do need to explicitly disable the internal dep-
+# endency generator and allow the external one be used
+# but since RedHat's kABI is only a subset of the total kernel ABI, it
+# doesn't include all of the symbols we (or OFED for that matter) need
+# until RedHat includes all of the symbols we need in their symsets we
+# cannot support weak-modules
+# we did e-mail the maintainer of all of this stuff @redhat but got no
+# response from them
+#%%global _use_internal_dependency_generator 0
+
+# Set the package name prefix
+%if %{undefined lustre_name}
+ %if %{with servers}
+ %global lustre_name lustre
+ %else
+ %global lustre_name lustre-client
+ %endif
+%endif
+
+%if %{undefined kmoddir}
+ %if %{defined kernel_module_package_moddir}
+ %global kmoddir %{kernel_module_package_moddir}
+ %else
+ %if %{defined suse_kernel_module_package}
+ %global kmoddir updates
+ %else
+ %global kmoddir extra
+ %endif
+ %endif
+%endif
+
+%global modules_fs_path /lib/modules/%{kversion}/%{kmoddir}
+
+%if %{_vendor}=="redhat" || %{_vendor}=="fedora"
+ %global requires_kmod_name kmod-%{lustre_name}
+ %global requires_kmod_tests_name kmod-%{lustre_name}-tests
+ %global requires_kmod_version %{version}
+%else #for Suse
+ %global requires_kmod_name %{lustre_name}-kmp
+ %global requires_kmod_tests_name %{lustre_name}-tests-kmp
+ %define krequires %(echo %{kversion} | sed -e 's/\.x86_64$//' -e 's/\.i[3456]86$//' -e 's/-smp$//' -e 's/-bigsmp$//' -e 's/[-.]ppc64$//' -e 's/\.aarch64$//' -e 's/-default$//')
+ %if 0%{?suse_version} >= 1200
+ %global requires_kmod_version %{version}_k%(echo %{krequires} | sed -r 'y/-/_/; s/^(2\.6\.[0-9]+)_/\\1.0_/;')
+ %else
+ %global requires_kmod_version %{version}_%(echo %{krequires} | sed -r 'y/-/_/; s/^(2\.6\.[0-9]+)_/\\1.0_/;')
+ %endif
+%endif