#
# Setup sources
#
%prep
%setup -n %{gs_name}-%{gs_version}

#
# Build commands
#
%build
if [ -z "$GNUSTEP_SYSTEM_ROOT" ]; then
  . %{gs_root}/Library/Makefiles/GNUstep.sh 
fi
if [ "%{gs_configure}" = "YES" ]; then 
  CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{gs_root}
fi
make debug=no
make debug=yes

#
# Install commands (generate file list too)
#
%install
if [ -z "$GNUSTEP_SYSTEM_ROOT" ]; then
  . %{gs_root}/Library/Makefiles/GNUstep.sh 
fi
# build the non debugging file list
mkdir tmp-rpm-build-%{gs_name}
make debug=no \
  INSTALL_ROOT_DIR=`pwd`/tmp-rpm-build-%{gs_name} \
  GNUSTEP_INSTALLATION_DIR=`pwd`/tmp-rpm-build-%{gs_name}/%{gs_install_dir} \
  filelist=yes install
rm -rf tmp-rpm-build-%{gs_name}

# build the debugging file list
make debug=yes \
  INSTALL_ROOT_DIR=$RPM_BUILD_ROOT \
  GNUSTEP_INSTALLATION_DIR=$RPM_BUILD_ROOT%{gs_install_dir} \
  filelist=yes install

# Now filter the debugging file list against the non debugging one
#
# We use `grep':
# `-f file-list' gets the lines to match from file-list
# `-x' gets only matches which match whole lines
# `-v' inverts the matching, so lines which do not match are outputted
#
mv file-list-debug file-list.tmp
for file in `cat file-list`; do
  grep -v -x $file file-list.tmp >> file-list-debug.tmp
  mv file-list-debug.tmp file-list.tmp
done

rm -f file-list-debug.tmp
mv file-list.tmp file-list-debug

#
# Clean commands
#
%clean
rm -rf $RPM_BUILD_ROOT

#
# File list (generated by install)
#
%files -f file-list-debug