-CONFIGURE_ARGS=""
-%if %{build_lustre_tests}
-CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-tests --enable-liblustre-tests"
-%else
-CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-tests --disable-liblustre-tests"
-%endif
-%configure %{?configure_args:%configure_args} $CONFIGURE_ARGS
-make -j $RPM_BUILD_NCPUS -s
+
+CONFIGURE_ARGS="%{?configure_args}"
+if [ -n "$CONFIGURE_ARGS" ]; then
+ # make sure %%kdir and %%kobjdir are not in the configure arguments
+ CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux=[^ ][^ ]* \?//')
+ CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux-obj=[^ ][^ ]* \?//')
+ # remove --with-kmp-moddir from configure arguments,
+ # it will be set --with-kmp-moddir=%%kmoddir
+ CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-kmp-moddir=[^ ][^ ]* \?//')
+fi
+
+# we need to eval "configure" because $CONFIGURE_ARGS could have a quoted
+# string in it which we don't want word splitted by the shell
+# also remove (build|host|target) options because they will be specified
+# inside $CONFIGURE_ARGS
+# kmod tools/scripts require %{name} directory with kernel modules
+%define eval_configure %(echo '%configure' | sed -e 's#\./configure#eval ./configure#' -e 's/--\\(build\\|host\\|target\\)=[^ ][^ ]* //g')
+
+%eval_configure $CONFIGURE_ARGS \
+ %{?with_lustre_tests:--enable-tests}%{!?with_lustre_tests:--disable-tests} \
+ %{?with_lustre_utils:--enable-utils}%{!?with_lustre_utils:--disable-utils} \
+ %{?with_lustre_modules:--enable-modules}%{!?with_lustre_modules:--disable-modules} \
+ %{!?with_shared:--disable-shared} \
+ %{!?with_static:--disable-static} \
+ %{!?with_lustre_iokit:--disable-iokit} \
+ %{!?with_ldiskfs:--disable-ldiskfs} \
+ %{!?with_servers:--disable-server} \
+ %{!?with_zfs:--without-zfs} \
+ %{!?with_lnet_dlc:--disable-dlc} \
+ %{!?with_snmp:--disable-snmp} \
+ %{!?with_manpages:--disable-manpages} \
+ %{!?with_systemd:--with-systemdsystemunitdir=no} \
+ %{?with_systemd:--with-systemdsystemunitdir=%{_unitdir}} \
+ --with-linux=%{kdir} \
+ --with-linux-obj=%{kobjdir} \
+ --with-kmp-moddir=%{kmoddir}/%{name}
+
+make %{?_smp_mflags} -s %{?make_args}