%bcond_with systemd

%define source_date_epoch_from_changelog 1
%define modular_conf  1

%define default_URL   https://vinelinux.org/
%define default_text  %{_sysconfdir}/vine-release

%define pam_ver       1.5.1
%define autoconf_ver  2.71

%define update_po     1

Summary:         X screen saver and locker
Summary(ja):     X ウィンドウシステム・スクリーンセーバ
Name:            xscreensaver
Epoch:           1
Version:         6.01
Release:         1%{?_dist_release}%{?with_systemd:.systemd}
Group:           accessories

License:         BSD
URL:             https://www.jwz.org/xscreensaver/
Source0:         http://www.jwz.org/xscreensaver/xscreensaver-%{version}%{?beta_ver}.tar.gz
%if %{modular_conf}
Source10:        update-xscreensaver-hacks
%endif
Source11:        xscreensaver-autostart
Source12:        xscreensaver-autostart.desktop
# wrapper script for switching user (bug 1878730)
Source13:        xscreensaver-newlogin-wrapper
##
## Patches
##
# bug 129335
Patch1:          xscreensaver-5.45-0001-barcode-glsnake-sanitize-the-names-of-modes.patch
## Patches already sent to the upsteam
## Patches which must be discussed with upstream
# See bug 472061
Patch21:         xscreensaver-5.35-webcollage-default-nonet.patch
# 
# misc: kill gcc warn_unused_result warnings
Patch3607:       xscreensaver-5.36-0007-misc-kill-gcc-warn_unused_result-warnings.patch
# xscreensaver-text use en_US locale for lscpu
Patch5002:      xscreensaver-6.00-0002-xscreensaver-text-use-en_US-locale-for-lscpu.patch
# fontglide.c: pick_font_1 exclude substitution rectagle glyph
Patch5004:      xscreensaver-6.00-0004-fontglide.c-pick_font_1-exclude-substitution-rectagl.patch
# fontglide.c: drain_input: terminate with null explicitly
Patch5007:      xscreensaver-6.00-0007-fontglide.c-drain_input-terminate-with-null-explicit.patch
# main_loop: consistently check init file after some activitity occurred
Patch5101:      xscreensaver-6.01-0001-main_loop-consistently-check-init-file-after-some-ac.patch
# main_loop: check init file saver_mode
Patch5102:      xscreensaver-6.01-0002-main_loop-check-init-file-saver_mode.patch
# window_init: check if asterisk font is available and provide fallback character
Patch5103:      xscreensaver-6.01-0003-window_init-check-if-asterisk-font-is-available-and-.patch
# destroy_window: check ws->xftdraw to avoid nullptr dereference
Patch5104:      xscreensaver-6.01-0004-destroy_window-check-ws-xftdraw-to-avoid-nullptr-der.patch
# Fedora specific
# window_init: search parenthesis first for searching year
Patch10001:     xscreensaver-6.00-0001-screensaver_id-search-parenthesis-first-for-searchin.patch
# dialog.c: window_init: show more version string
Patch10003:     xscreensaver-6.00-0003-dialog.c-window_init-show-more-version-string.patch
# blurb: show 1/100 sec on linux
Patch10005:     xscreensaver-6.00-0005-blurb-show-1-100-sec-on-linux.patch
#
# gcc warning cleanup
# Some cppcheck cleanup
#
# Debugging patch
# Not apply by default
# XIO: print C backtrace on error
Patch13501:      xscreensaver-5.35-0101-XIO-print-C-backtrace-on-error.patch
#
# Patches end

BuildRoot:       %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires:        xscreensaver-base = %{epoch}:%{version}-%{release}
Requires:        xscreensaver-extras = %{epoch}:%{version}-%{release}
Requires:        xscreensaver-gl-extras = %{epoch}:%{version}-%{release}

%package base
Summary:         A minimal installation of xscreensaver
Group:           accessories
BuildRequires:   autoconf
BuildRequires:   bc
BuildRequires:   desktop-file-utils
BuildRequires:   gawk
BuildRequires:   gettext
BuildRequires:   libtool
BuildRequires:   pam-devel >= %{pam_ver}
BuildRequires:   sed
BuildRequires:   xdg-utils
BuildRequires:   xorg-x11-proto-devel
BuildRequires:   mesa-libGL-devel
BuildRequires:   libX11-devel
BuildRequires:   libXScrnSaver-devel
# xscreensaver 6.00
#BuildRequires:   libXcomposite-devel
BuildRequires:   libXext-devel
# From xscreensaver 5.12, write explicitly
BuildRequires:   libXi-devel
BuildRequires:   libXinerama-devel
# Dropped from 6.00
# BuildRequires:   libXmu-devel
# xscreensaver 5.39: check if the following can be removed
BuildRequires:   libXpm-devel
# xscreensaver 5.39
BuildRequires:   libpng-devel
# Write explicitly
BuildRequires:   libXrandr-devel
BuildRequires:   libXt-devel
# libXxf86misc removed from F-31
#BuildRequires:   libXxf86misc-devel
BuildRequires:   libXxf86vm-devel
# XScreenSaver 5.31
BuildRequires:   libXft-devel
BuildRequires:   gtk2-devel
BuildRequires:   pkgconfig(gdk-pixbuf-2.0)
BuildRequires:   pkgconfig(gdk-pixbuf-xlib-2.0)
BuildRequires:   libjpeg-devel
BuildRequires:   libglade2-devel
%if %{with systemd}
BuildRequires:   pkgconfig(libsystemd)
%endif
Requires:        %{_sysconfdir}/pam.d/system-auth
Requires:        pam >= %{pam_ver}
Requires:        xdg-utils
Requires:        xorg-x11-resutils
Requires:        xorg-x11-fonts-ISO8859-1-100dpi

%package extras
Summary:         An enhanced set of screensavers
Group:           accessories
# BuildRequires:   desktop-backgrounds
BuildRequires:   mate-backgrounds
Requires:        %{name}-base = %{epoch}:%{version}-%{release}

%package gl-base
Summary:         A base package for screensavers that require OpenGL
Group:           accessories
Requires:        %{name}-base = %{epoch}:%{version}-%{release}

%package gl-extras
Summary:         An enhanced set of screensavers that require OpenGL
Group:           accessories
Provides:        xscreensaver-gl = %{epoch}:%{version}-%{release}
Obsoletes:       xscreensaver-gl <= 1:5.00
BuildRequires:   libGL-devel
BuildRequires:   libGLU-devel
%if %{modular_conf}
Requires:        %{name}-gl-base = %{epoch}:%{version}-%{release}
%else
Requires:        %{name}-base = %{epoch}:%{version}-%{release}
%endif

%package extras-gss
Summary:         Desktop files of extras for gnome-screensaver
Group:           accessories
Requires:        %{name}-extras = %{epoch}:%{version}-%{release}
Requires:        mate-screensaver

%package gl-extras-gss
Summary:         Desktop files of gl-extras for gnome-screensaver
Group:           accessories
Requires:        %{name}-gl-extras = %{epoch}:%{version}-%{release}
Requires:        mate-screensaver


%description
A modular screen saver and locker for the X Window System.
More than 200 display modes are included in this package.

This is a metapackage for installing all default packages
related to XScreenSaver.

%description base
A modular screen saver and locker for the X Window System.
This package contains the bare minimum needed to blank and
lock your screen.  The graphical display modes are the
"xscreensaver-extras" and "xscreensaver-gl-extras" packages.

%description extras
A modular screen saver and locker for the X Window System.
This package contains a variety of graphical screen savers for
your mind-numbing, ambition-eroding, time-wasting, hypnotized
viewing pleasure.

%description gl-base
A modular screen saver and locker for the X Window System.
This package contains minimal files to make screensaver hacks
that require OpenGL work for XScreenSaver.

%description gl-extras
A modular screen saver and locker for the X Window System.
This package contains a variety of OpenGL-based (3D) screen
savers for your mind-numbing, ambition-eroding, time-wasting,
hypnotized viewing pleasure.

%description extras-gss
This package contains desktop files of extras screensavers
for gnome-screensaver compatibility.

%description gl-extras-gss
This package contains desktop files of gl-extras screensavers
for gnome-screensaver compatibility.


%debug_package


%prep
%setup -q -n %{name}-%{version}%{?beta_ver}

%patch1 -p1
%patch21 -p1

#patch3607 -p1
%patch10001 -p1
%patch5002 -p1
%patch10003 -p1
%patch5004 -p1
%patch10005 -p1
%patch5007 -p1
%patch5101 -p1
%patch5102 -p1
%patch5103 -p1
%patch5104 -p1

#patch13501 -p1

change_option(){
   set +x
   ADFILE=$1
   if [ ! -f ${ADFILE}.opts ] ; then
      cp -p $ADFILE ${ADFILE}.opts
   fi
   shift

   for ARG in "$@" ; do
      TYPE=`echo $ARG | sed -e 's|=.*$||'`
      VALUE=`echo $ARG | sed -e 's|^.*=||'`

      eval sed -i \
         -e \'s\|\^\\\(\\\*$TYPE\:\[ \\t\]\[ \\t\]\*\\\)\[\^ \\t\]\.\*\$\|\\1$VALUE\|\' \
         $ADFILE
   done
   set -x
}

silence_hack(){
   set +x
   ADFILE=$1
   if [ ! -f ${ADFILE}.hack ] ; then
      cp -p $ADFILE ${ADFILE}.hack
   fi
   shift

   for hack in "$@" ; do
      eval sed -i \
         -e \'\/\^\[ \\t\]\[ \\t\]\*$hack\/s\|\^\|-\|g\' \
         -e \'s\|\^@GL_\.\*@.*\\\(GL\:\[ \\t\]\[ \\t\]\*$hack\\\)\|-\\t\\1\|g\' \
         $ADFILE
   done
   set -x
}

# change some files to UTF-8
for f in \
   hacks/glx/sproingies.man \
   ; do
   iconv -f ISO-8859-1 -t UTF-8 $f > $f.tmp || cp -p $f $f.tmp
   touch -r $f $f.tmp
   mv $f.tmp $f
done

# change some options
change_option driver/XScreenSaver.ad.in \
   captureStderr=False \
   passwdTimeout=0:00:15 \
   grabDesktopImages=False \
   lock=True \
   splash=False \
   ignoreUninstalledPrograms=True \
   textProgram=fortune\ -s \
   textURL=%{default_URL}

# silence the following hacks by default
silence_hack driver/XScreenSaver.ad.in \
   bsod flag \
   peepers \
   headroom \
   %{nil}

# record time, version
eval sed -i.ver \
   -e \'s\|version \[45\]\.\[0-9a-z\]\[0-9a-z\]\*\|version %{version}-`echo \
      %{release} | sed -e '/IGNORE THIS/s|\.[a-z][a-z0-9].*$||'`\|\' \
      driver/XScreenSaver.ad.in

eval sed -i.date \
   -e \'s\|\[0-9\].\*-.\*-20\[0-9\]\[0-9\]\|`LANG=C LC_ALL=C date -u +'%%d-%%b-%%Y'`\|g\' \
   driver/XScreenSaver.ad.in

eval sed -i.ver \
   -e \'s\|\(\[0-9\].\*-.\*-20\[0-9\]\[0-9\]\)\|\(`LANG=C LC_ALL=C \
      date -u +'%%d-%%b-%%Y'`\)\|g\' \
   -e \'s\|\\\([56]\\\.\[0-9\]\[0-9\]\\\)[a-z]\[0-9\]\[0-9\]\*\|\\\1\|\' \
   -e \'s\|[56]\\\.\[0-9\]\[0-9\]\|%{version}-`echo %{release} | \
      sed -e '/IGNORE THIS/s|\.[a-zA-Z][a-zA-Z0-9].*$||'`\|\' \
   -e \'s\|\\\(XSCREENSAVER_RELEASED\\\)\.\*\|\\\1 ${SOURCE_DATE_EPOCH}\|\' \
   utils/version.h

# move man entry to 6x.
for f in `find hacks -name Makefile.in` ; do
   sed -i.mansuf \
      -e '/^mansuffix/s|6|6x|'\
      $f
done

# search first 6x entry, next 1 entry for man pages
sed -i.manentry -e 's@man %%s@man 6x %%s 2>/dev/null || man 1 %%s @' \
   driver/XScreenSaver.ad.in

# suppress rpmlint booing.
# suppress about pam config (although this is 
# not the fault of xscreensaver.pam ......).
#sed -i.rpmlint -n -e '1,5p' driver/xscreensaver.pam 

if [ -x %{_datadir}/libtool/config.guess ]; then
  # use system-wide copy
   cp -p %{_datadir}/libtool/config.{sub,guess} .
fi

# fix for desktop-file-utils 0.14+
sed -i.icon -e 's|xscreensaver\.xpm|xscreensaver|' \
   driver/screensaver-properties.desktop.in

# test-fade: give more time between fading
sed -i.delay -e 's| delay = 2| delay = 3|' driver/test-fade.c

# test-grab: testing time too long, setting time 15 min -> 20 sec
sed -i.delay -e 's|60 \* 15|20|' driver/test-grab.c

# Well, clang misinterpretates how gcc / autoconf uses -Wunknown-warning-option ....
sed -i 's|-Wunknown-warning-option|-Wfoo-bar-baz|' ax_pthread.m4

aclocal
autoconf
autoheader


%build
archdir=`sh ./config.guess`
[ -d $archdir ] || mkdir $archdir
cd $archdir

# Create temporary path and symlink
rm -rf ./TMPBINDIR

# Make it sure that perl interpreter is recognized
# as /usr/bin/perl, not /bin/perl so as not to make
# /bin/perl added as rpm dependency
export PATH=/usr/bin:$PATH

mkdir TMPBINDIR
pushd TMPBINDIR/
export PATH=$(pwd):$PATH

# xdg-open
ln -sf /bin/true xdg-open
popd

# Set optflags first
%set_build_flags

export CFLAGS="$CFLAGS -Wno-long-long"
export CFLAGS="$CFLAGS -Wno-variadic-macros"

CONFIG_OPTS="--prefix=%{_prefix} --with-pam --without-shadow --without-kerberos"
CONFIG_OPTS="$CONFIG_OPTS --without-setuid-hacks"
CONFIG_OPTS="$CONFIG_OPTS --with-text-file=%{default_text}"
CONFIG_OPTS="$CONFIG_OPTS --with-x-app-defaults=%{_datadir}/X11/app-defaults"
CONFIG_OPTS="$CONFIG_OPTS --disable-root-passwd"
CONFIG_OPTS="$CONFIG_OPTS --with-browser=xdg-open"

# From xscreensaver 5.12, login-manager option is on by default
# For now, let's enable it on F-14 and above
pushd TMPBINDIR
# ln -sf /bin/true gdmflexiserver
install -cpm 0755 %{SOURCE13} .
CONFIG_OPTS="$CONFIG_OPTS --with-login-manager=xscreensaver-newlogin-wrapper"
popd

# Enable account type pam validation on F-18+,
# debian bug 656766
CONFIG_OPTS="$CONFIG_OPTS --enable-pam-check-account-type"

# xscreensaver 5.30
CONFIG_OPTS="$CONFIG_OPTS --with-record-animation"

%if %{with systemd}
CONFIG_OPTS="$CONFIG_OPTS --with-systemd"
%endif

# This is flaky:
# CONFIG_OPTS="$CONFIG_OPTS --with-login-manager"

unlink configure || :
ln -s ../configure .
%configure $CONFIG_OPTS || { cat config.log ; sleep 10 ; exit 1; }
rm -f configure

# Remove embedded build path
sed -i driver/XScreenSaver.ad -e "s|$(pwd)/TMPBINDIR/||"

%if %{update_po}
#( cd po ; make generate_potfiles_in update-po )
# ???
pushd po
  make generate_potfiles_in
  cp -p POTFILES.in ..
  # Workaround for ui file
  sed -i ../POTFILES.in POTFILES.in POTFILES \
     -e '\@xscreensaver\.ui@s|^\([ \t]*\)\(.*\)$|\1[type: gettext/glade]\2|'
  make xscreensaver.pot srcdir=..
  ( export srcdir=.. ; make update-po )
  rm -f ../POTFILES_in
popd

( cp -p ../po/*.po po/)
( ( cd ../po ; git add *.po ; git commit -m "po regenerated" ) || true )
%endif

# Update po
#cp -p %{SOURCE100} po/

# Workaround for 5.39
mkdir -p hacks/images || true
if [ ! -f hacks/images/Makefile ] ; then
   cat > hacks/images/Makefile <<EOF
default:
install:
EOF
fi
# Workaround end

# From 5.45: temporary workaround for installation issue
# From 6.00: temporary workaround for installation issue
cp -p ../driver/xscreensaver.ui driver/
cp -a ../hacks/fonts hacks

%if 0%{?use_clang_analyze} < 1
# Workaround for ppc64 build failure
make -C ../hacks/images -j1
for dir in \
  utils driver ../hacks/images hacks/images hacks hacks/glx po
do
  %__make %{?_smp_mflags} -k \
    -C $dir \
	GMSGFMT="msgfmt --statistics"
done
%endif

# Again
%__make %{?_smp_mflags} -k

%if %{modular_conf}
# Make XScreenSavar.ad modular (bug 200881)
CONFD=xscreensaver
rm -rf $CONFD
mkdir $CONFD

# Preserve the original adfile
cp -p driver/XScreenSaver.ad $CONFD

# First split XScreenSaver.ad into 3 parts
cat driver/XScreenSaver.ad | \
   sed -n -e '1,/\*programs/p' > $CONFD/XScreenSaver.ad.header
cat driver/XScreenSaver.ad | sed -e '1,/\*programs/d' | \
   sed -n -e '1,/\\n$/p' > $CONFD/XScreenSaver.ad.hacks
cat driver/XScreenSaver.ad | sed -e '1,/\\n$/d' > $CONFD/XScreenSaver.ad.tail

# Seperate XScreenSaver.ad.hacks into each hacks
cd $CONFD
mkdir hacks.conf.d ; cp -p XScreenSaver.ad.hacks hacks.conf.d/xscreensaver.conf
cd ..

%endif

# test
# for now, build tests anyway (even if they are not to be installed)
make tests -C driver


%install
archdir=`sh ./config.guess`
cd $archdir

rm -rf ${RPM_BUILD_ROOT}

# We have to make sure these directories exist,
# or nothing will be installed into them.
#
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/pam.d

make install_prefix=$RPM_BUILD_ROOT INSTALL="install -c -p" install

desktop-file-install --vendor "" --delete-original       \
   --dir $RPM_BUILD_ROOT%{_datadir}/applications         \
   --add-category    DesktopSettings                     \
   --remove-category Appearance                          \
   --remove-category AdvancedSettings                    \
   --remove-category Application                         \
   $RPM_BUILD_ROOT%{_datadir}/applications/*.desktop

# This function prints a list of things that get installed.
# It does this by parsing the output of a dummy run of "make install".
list_files() {
   echo "%%defattr(-,root,root,-)"
   make -s install_prefix=${RPM_BUILD_ROOT} INSTALL=true "$@"  \
      | sed -n -e 's@.* \(/[^ ]*\)$@\1@p'                      \
      | sed    -e "s@^${RPM_BUILD_ROOT}@@"                     \
               -e "s@/[a-z][a-z]*/\.\./@/@"                    \
      | sed    -e 's@\(.*/man/.*\)@%%doc \1\*@'                      \
               -e 's@\(.*/pam\.d/\)@%%config(noreplace) \1@'    \
      | sort  \
      | uniq
}

# Generate three lists of files for the three packages.
#
dd=%{_builddir}/%{name}-%{version}%{?beta_ver}

# In case rpm -bi --short-circuit is tried multiple times:
rm -f $dd/*.files

(  cd hacks     ; list_files install ) >  $dd/extras.files
(  cd hacks/fonts     ; list_files install ) >>  $dd/extras.files
(  cd hacks/glx ; list_files install ) >  $dd/gl-extras.files
(  cd driver    ; list_files install ) >  $dd/base.files

# Own directory
echo "%%dir %{_datadir}/fonts/xscreensaver" >> $dd/extras.files

# Move %%{_bindir}/xscreensaver-gl-helper to gl-base
# (bug 336331).
%if %{modular_conf}
echo "%%defattr(-,root,root,-)" >> $dd/gl-base.files

grep xscreensaver-gl-visual $dd/gl-extras.files >> $dd/gl-base.files
sed -i -e '/xscreensaver-gl-helper/d' $dd/gl-extras.files
sed -i -e 's|^\(%{_mandir}.*\)$|\1*|' $dd/gl-base.files
%endif

%if %{modular_conf}
# Install update script
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
install -cpm 755 %{SOURCE10} $RPM_BUILD_ROOT%{_sbindir}
echo "%{_sbindir}/update-xscreensaver-hacks" >> $dd/base.files

# Make hack conf modular
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xscreensaver
mkdir -p $RPM_BUILD_ROOT%{_datadir}/xscreensaver/hacks.conf.d
cp -p xscreensaver/XScreenSaver.ad* \
   $RPM_BUILD_ROOT%{_sysconfdir}/xscreensaver
cp -p xscreensaver/hacks.conf.d/xscreensaver.conf \
   $RPM_BUILD_ROOT%{_datadir}/xscreensaver/hacks.conf.d/

for adfile in xscreensaver/XScreenSaver.ad.* ; do
   filen=`basename $adfile`
   echo "%%config(noreplace) %{_sysconfdir}/xscreensaver/$filen" >> $dd/base.files
done
echo -n "%%verify(not size md5 mtime) " >> $dd/base.files
echo "%{_sysconfdir}/xscreensaver/XScreenSaver.ad" >> \
   $dd/base.files
echo "%{_datadir}/xscreensaver/hacks.conf.d/xscreensaver.conf" \
   >> $dd/base.files

# Check symlink
rm -f $RPM_BUILD_ROOT%{_datadir}/X11/app-defaults/XScreenSaver

pushd $RPM_BUILD_ROOT%{_datadir}/X11/app-defaults
pushd ../../../..
if [ ! $(pwd) == $RPM_BUILD_ROOT ] ; then
   echo "Possibly symlink broken"
   exit 1
fi
popd
popd

ln -sf ../../../..%{_sysconfdir}/xscreensaver/XScreenSaver.ad \
   $RPM_BUILD_ROOT%{_datadir}/X11/app-defaults/XScreenSaver

%endif

# Add documents
pushd $dd &> /dev/null
for f in README* ; do
   echo "%%doc $f" >> $dd/base.files
done
popd

# Add directory
pushd $RPM_BUILD_ROOT
for dir in `find . -type d | grep xscreensaver` ; do
   echo "%%dir ${dir#.}" >> $dd/base.files
done
popd

%find_lang %{name}
cat %{name}.lang | uniq >> $dd/base.files

# Suppress rpmlint warnings
# sanitize path in script file
for f in ${RPM_BUILD_ROOT}%{_bindir}/xscreensaver-getimage-* \
   ${RPM_BUILD_ROOT}%{_libexecdir}/xscreensaver/vidwhacker \
   ${RPM_BUILD_ROOT}%{_bindir}/xscreensaver-text ; do
   if [ -f $f ] ; then
      sed -i -e 's|%{_prefix}//bin|%{_bindir}|g' $f
   fi
done

# Install desktop application autostart stuff
# Add OnlyShowIn=GNOME (bug 517391)
# Leave autostart stuff installed (at least useful for LXDE),
# but not show them by default for all DE
# (bug 1266521) for F-27+
mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/xdg/autostart
install -cpm 0755 %{SOURCE11} ${RPM_BUILD_ROOT}%{_libexecdir}/
desktop-file-install \
   --vendor "" \
   --dir ${RPM_BUILD_ROOT}%{_sysconfdir}/xdg/autostart \
   --add-only-show-in=X-NODEFAULT \
   %{SOURCE12}
chmod 0644 ${RPM_BUILD_ROOT}%{_sysconfdir}/xdg/autostart/xscreensaver*.desktop

echo "%{_libexecdir}/xscreensaver-autostart" >> $dd/base.files
echo '%{_sysconfdir}/xdg/autostart/xscreensaver*.desktop' >> $dd/base.files

# create desktop entry for mate-screensaver
create_desktop(){
   COMMAND=`cat $1 | sed -n -e 's|^<screen.*name=\"\([^ ][^ ]*\)\".*$|\1|p'`
# COMMAND must be full path (see bug 531151)
# Check if the command actually exists
   COMMAND=%{_libexecdir}/xscreensaver/$COMMAND
   if [ ! -x $RPM_BUILD_ROOT/$COMMAND ] ; then
      echo
      echo "WARNING:"
      echo "$COMMAND could not be found under $RPM_BUILD_ROOT"
      #exit 1
   fi
# NAME entry fix (bug 953558)
   NAME=`cat $1 | sed -n -e 's|^<screen.*_label=\"\([^\"][^\"]*\)\".*>.*$|\1|p'`
   ARG=`cat $1 | sed -n -e 's|^.*<command arg=\"\([^ ][^ ]*\)\".*$|\1|p'`
   ARG=$(echo "$ARG" | while read line ; do echo -n "$line " ; done)
   COMMENT="`cat $1 | sed -e '1,/_description/d' | \
     sed -e '/_description/q' | sed -e '/_description/d'`"
   COMMENT=$(echo "$COMMENT" | while read line ; do echo -n "$line " ; done)

# webcollage treatment
## changed to create wrapper script
%if 0
   if [ "x$COMMAND" = "xwebcollage" ] ; then
      ARG="$ARG -directory %{_datadir}/backgrounds/images"
   fi
%endif

   if [ "x$NAME" = "x" ] ; then NAME=$COMMAND ; fi

   rm -f $2
   echo "[Desktop Entry]" >> $2
#   echo "Encoding=UTF-8" >> $2
   echo "Name=$NAME" >> $2
   echo "Comment=$COMMENT" >> $2
   echo "TryExec=$COMMAND" >> $2
   echo "Exec=$COMMAND $ARG" >> $2
   echo "StartupNotify=false" >> $2
   echo "Type=Application" >> $2
   echo "Categories=GNOME;Screensaver;" >> $2
# Add OnlyShowIn (bug 953558)
   echo "OnlyShowIn=GNOME;MATE;" >> $2
}

cd $dd

SAVERDIR=%{_datadir}/applications/screensavers
mkdir -p ${RPM_BUILD_ROOT}${SAVERDIR}
echo "%%dir $SAVERDIR" >> base.files

for list in *extras.files ; do

   glist=gnome-$list
   rm -f $glist

   echo "%%defattr(-,root,root,-)" > $glist
##  move the owner of $SAVERDIR to -base
##   echo "%%dir $SAVERDIR" >> $glist

   set +x
   for xml in `cat $list | grep xml$` ; do
      file=${RPM_BUILD_ROOT}${xml}
      desktop=xscreensaver-`basename $file`
      desktop=${desktop%.xml}.desktop

      echo + create_desktop $file  ${RPM_BUILD_ROOT}${SAVERDIR}/$desktop
      create_desktop $file  ${RPM_BUILD_ROOT}${SAVERDIR}/$desktop
      echo ${SAVERDIR}/$desktop >> $glist
   done
   set -x
done

# Create wrapper script for webcollage to use nonet option
# by default, and rename the original webcollage
# (see bug 472061)
pushd ${RPM_BUILD_ROOT}%{_libexecdir}/%{name}
mv -f webcollage webcollage.original

cat > webcollage <<EOF
#!/bin/sh
PATH=%{_libexecdir}/%{name}:\$PATH
exec webcollage.original \\
	-directory %{_datadir}/backgrounds/images \\
	"\$@"
EOF
chmod 0755 webcollage
echo "%%{_libexecdir}/%%{name}/webcollage.original" >> \
	$dd/extras.files

# install wrapper-script for switching user
install -cpm 0755 %{SOURCE13} ${RPM_BUILD_ROOT}%{_libexecdir}/%{name}
echo "%{_libexecdir}/%{name}/xscreensaver-newlogin-wrapper" >> $dd/base.files


# Make sure all files are readable by all, and writable only by owner.
#
chmod -R a+r,u+w,og-w ${RPM_BUILD_ROOT}


%clean
rm -rf ${RPM_BUILD_ROOT}


%if %{modular_conf}
%post base
%{_sbindir}/update-xscreensaver-hacks
%endif

# In the case that pam setting is edited locally by sysadmin:
if ! grep -q '^account' %{_sysconfdir}/pam.d/xscreensaver
then
    echo "Warning: %{_sysconfdir}/pam.d/xscreensaver saved as %{_sysconfdir}/pam.d/xscreensaver.rpmsave"
    cp -p %{_sysconfdir}/pam.d/xscreensaver{,.rpmsave}
    PAMFILE=%{_sysconfdir}/pam.d/xscreensaver
    echo >> $PAMFILE
    echo "# Account validation" >> $PAMFILE
    echo "account include system-auth" >> $PAMFILE
fi

exit 0


%files
%defattr(-,root,root,-)

%files -f base.files base
%defattr(-,root,root,-)

%files -f extras.files extras
%defattr(-,root,root,-)

%if %{modular_conf}
%files -f gl-base.files gl-base
%defattr(-,root,root,-)
%endif

%files -f gl-extras.files gl-extras
%defattr(-,root,root,-)

%files -f gnome-extras.files extras-gss
%defattr(-,root,root,-)

%files -f gnome-gl-extras.files gl-extras-gss
%defattr(-,root,root,-)


%changelog
* Sat Jul 31 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 6.01-1
- new upstream release.
- dropped all patches.
- imported patches from rawhide.

* Sun Aug 26 2018 Toshiaki Ara <ara_t@384.jp> 5.37-1
- update to 5.37
- apply patches of fodora

* Sun Jan 12 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 5.26-1
- new upstream release

* Sat Oct 20 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> 5.20-1
- new upstream release

* Wed Feb 15 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> 5.15-1
- new upstream release

* Sun Oct 31 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 5.12-1
- new upstream release

* Sun Jul 25 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 5.11-1
- new upstream release
- drop Patch3, Patch21, Patch22

* Wed May 21 2008 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 5.05-1
- new upstream release
- remove unneeded patches

* Sat Sep  9 2006 Ryoichi INAGAKI <daisuke@linux.or.jp> 4.18-0vl3
- rebuilt for Vine Linux 4.0
- changed Group to User Interface/X

* Mon Mar 21 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 4.18-0vl2
- add Patch3 to use htmlview by default
- add Patch5 to use blank screen by default instead of random screensaver
- move desktopfile to %{_datadir}/applications/

* Thu Nov 11 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 4.18-0vl1
- new upstream release

* Wed Dec 17 2003 Daisuke SUZUKI <daisuke@linux.or.jp> 4.14-0vl1
- new upstream release

* Mon Dec 30 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.06-4vl2
- update ja.po
- copy xscreensaver.xpm to /usr/share/pixmaps directory

* Sat Dec 28 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.06-4vl1
- merged with rawhide release
- build on gnome2.1.5/gtk2.2
  * Fri Nov 29 2002 Tim Powers <timp@redhat.com> 1:4.06-4
  - call autoconf instead of autoconf-2.53
  * Mon Nov 11 2002 Bill Nottingham <notting@redhat.com> 4.06-3
  - put glade tweaks back in
  - switch pam package to not specify directories, to work on multilib
    arches
  * Fri Nov  8 2002 Nalin Dahyabhai <nalin@redhat.com> 4.06-1
  - add a BuildPrereq on bc, which configure requires
  - replace use of fortune with an innocuous-and-editable stand-in script in
    %{stand_in_path}
  - define FORTUNE_PROGRAM at compile-time to force apps to use what's specified
    even if it doesn't happen to be installed at compile-time
  * Sun Sep  2 2002 Bill Nottingham <notting@redhat.com> 4.05-6
  - fix typo (#73246)
  * Wed Aug 28 2002 Bill Nottingham <notting@redhat.com> 4.05-5
  - revert to non-gtk unlock dialog
  - fix translations
  * Mon Aug 12 2002 Bill Nottingham <notting@redhat.com> 4.05-4
  - twiddle titlebar (#67844)
  - fix extraneous text (#70975)
  - tweak desktop entry (#69502)
  * Fri Aug 9 2002 Yu Shao <yshao@redhat.com> 4.05-3
  - use GTK_IM_MODULE=gtk-im-context-simple in lock widget
  - to avoid CJK IM weirdness (#70655, #68216)
  - xscreensaver-rh-imcjk.patch
  * Wed Jul 17 2002 Elliot Lee <sopwith@redhat.com> 4.05-2
  - Add fortune-mod to buildprereq to make beehive happy
  - Fix find_lang usage - install translations properly by specifying datadir
  * Tue Jun 11 2002 Bill Nottingham <notting@redhat.com> 4.05-1
  - update to 4.05
  - use gtk2 lock widget (<jacob@ximian.com>)
  - some Red Hat-ifications
  - fix critical (#63916)
  * Mon Jun 10 2002 Bill Nottingham <notting@redhat.com> 4.04-2
  - remove no longer needed xloadimage dependency
  * Mon Jun  3 2002 Bill Nottingham <notting@redhat.com> 4.04-1
  - update to 4.04, gtk2 property dialog is now mainline
  * Thu May 16 2002 Bill Nottingham <notting@redhat.com> 4.03-1
  - update to 4.03
  - use gtk2 properties dialog

* Mon Nov 25 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 4.01-2vl5
- rebuilt with new toolchain

* Sun Mar 31 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.01-2vl4
- provides screensaver capplet entry for control-center

* Wed Mar 27 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.01-2vl2
- change Requires fortune-mod ( not file-depend )

* Tue Mar 26 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.01-2vl1
- merged with rawhide release

* Thu Mar 14 2002 Bill Nottingham <notting@redhat.com> 4.01-2
- don't show screensavers that aren't available

* Sun Feb 24 2002 Bill Nottingham <notting@redhat.com>
- update to 4.01

* Mon Feb 11 2002 Bill Nottingham <notting@redhat.com>
- update to 4.00

* Wed Jan 09 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Thu Aug 23 2001 Bill Nottingham <notting@redhat.com>
- fix segfault on ia64 (#52336)

* Thu Aug  9 2001 Bill Nottingham <notting@redhat.com>
- never mind, back to 3.33 (wheeee)
- hack window-id back in for the time being
- disable memlimit so GL works

* Mon Jul 23 2001 Bill Nottingham <notting@redhat.com>
- oops, back to 3.32 for now
- remove optflags override (oops)
- add pam-devel buildprereq

* Mon Jul 16 2001 Bill Nottingham <notting@redhat.com>
- update to 3.33, fix broken last build
- fix build weirdness on some package sets (#48905)
- don't document non-existent options for forest (#49139)

* Sun Jun 24 2001 Elliot Lee <sopwith@redhat.com>
- Bump release + rebuild.

* Tue May 22 2001 Havoc Pennington <hp@redhat.com>
- putting in tree for David 

* Tue May 22 2001 David Sainty <dsainty@redhat.com>
- added DPMS options to command line help

* Sun Apr 22 2001 Bill Nottingham <notting@redhat.com>
- update to 3.32
- add patch to specify DPMS settings on the command line

* Wed Apr 11 2001 Bill Nottingham <notting@redhat.com>
- update to 3.31

* Wed Apr  4 2001 Bill Nottingham <notting@redhat.com>
- fix extrusion exclusion (#34742)

* Tue Apr  3 2001 Bill Nottingham <notting@redhat.com>
- disable GL screensavers by default (bleah)

* Mon Feb 19 2001 Bill Nottingham <notting@redhat.com>
- update to 3.29 (#27437)

* Tue Jan 23 2001 Bill Nottingham <notting@redhat.com>
- update to 3.27

* Fri Dec 01 2000 Bill Nottingham <notting@redhat.com>
- rebuild because of broken fileutils

* Fri Nov 10 2000 Bill Nottingham <notting@redhat.com>
- 3.26

* Fri Aug 11 2000 Jonathan Blandford <jrb@redhat.com>
- Up Epoch and release

* Wed Jul 26 2000 Bill Nottingham <notting@redhat.com>
- hey, vidmode works again

* Fri Jul 21 2000 Bill Nottingham <notting@redhat.com>
- update to 3.25

* Thu Jul 13 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Sat Jun 17 2000 Bill Nottingham <notting@redhat.com>
- xscreensaver.kss is not a %%config file.

* Sun Jun 11 2000 Bill Nottingham <notting@redhat.com>
- tweak kss module (#11872)

* Thu Jun  1 2000 Nalin Dahyabhai <nalin@redhat.com>
- modify PAM configuration to use system-auth

* Thu May 18 2000 Preston Brown <pbrown@redhat.com>
- added Red Hat screensaver (waving flag has logo now).

* Fri May  5 2000 Bill Nottingham <notting@redhat.com>
- tweaks for ia64

* Mon Apr 10 2000 Bill Nottingham <notting@redhat.com>
- turn off xf86vidmode ext, so that binaries built against XFree86 4.0
  work on 3.x servers

* Wed Apr  5 2000 Bill Nottingham <notting@redhat.com>
- turn off gnome support for now

* Mon Apr  3 2000 Bill Nottingham <notting@redhat.com>
- update to 3.24

* Wed Feb 09 2000 Preston Brown <pbrown@redhat.com>
- wmconfig entry gone.

* Mon Jan 31 2000 Bill Nottingham <notting@redhat.com>
- update to 3.23

* Fri Jan 14 2000 Bill Nottingham <notting@redhat.com>
- rebuild to fix GL depdencies

* Tue Dec 14 1999 Bill Nottingham <notting@redhat.com>
- everyone in GL
- single package again

* Fri Dec 10 1999 Bill Nottingham <notting@redhat.com>
- update to 3.22
- turn off xf86vmode on alpha

* Tue Dec  7 1999 Bill Nottingham <notting@redhat.com>
- mmm... hardware accelerated GL on i386. :) :)

* Mon Nov 22 1999 Bill Nottingham <notting@redhat.com>
- 3.21
- use shm on alpha, let's see what breaks

* Tue Nov 16 1999 Bill Nottingham <notting@redhat.com>
- update to 3.20

* Wed Nov  3 1999 Bill Nottingham <notting@redhat.com>
- update to 3.19

* Thu Oct 14 1999 Bill Nottingham <notting@redhat.com>
- update to 3.18

* Sat Sep 25 1999 Bill Nottingham <notting@redhat.com>
- add a '-oneshot' single time lock option.

* Mon Sep 20 1999 Bill Nottingham <notting@redhat.com>
- take webcollage out of random list (for people who pay for bandwidth)

* Fri Sep 10 1999 Bill Nottingham <notting@redhat.com>
- patch webcollage to use xloadimage
- in the random list, run petri with -size 2 to save memory
- extend RPM silliness to man pages, too.

* Mon Jul 19 1999 Bill Nottingham <notting@redhat.com>
- update to 3.17
- add a little RPM silliness to package GL stuff if it's built

* Thu Jun 24 1999 Bill Nottingham <notting@redhat.com>
- update to 3.16

* Mon May 10 1999 Bill Nottingham <notting@redhat.com>
- update to 3.12

* Tue May  4 1999 Bill Nottingham <notting@redhat.com>
- remove security problem introduced earlier

* Wed Apr 28 1999 Bill Nottingham <notting@redhat.com>
- update to 3.10

* Thu Apr 15 1999 Bill Nottingham <notting@redhat.com>
- kill setuid the Right Way(tm)

* Mon Apr 12 1999 Bill Nottingham <notting@redhat.com>
- fix xflame on alpha

* Mon Apr 12 1999 Preston Brown <pbrown@redhat.com>
- upgrade to 3.09, fixes vmware interaction problems.

* Mon Apr  5 1999 Bill Nottingham <notting@redhat.com>
- remove setuid bit. Really. I mean it.

* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com> 
- auto rebuild in the new build environment (release 3)

* Fri Mar 19 1999 Bill Nottingham <notting@redhat.com>
- kill setuid, since pam works OK

* Tue Mar 16 1999 Bill Nottingham <notting@redhat.com>
- update to 3.08

* Wed Feb 24 1999 Bill Nottingham <notting@redhat.com>
- wmconfig returns, and no one is safe...

* Tue Feb 23 1999 Bill Nottingham <notting@redhat.com>
- remove bsod from random list because it's confusing people???? *sigh*

* Tue Jan 12 1999 Cristian Gafton <gafton@redhat.com>
- call libtoolize to get it to compile cleanely on the arm

* Tue Jan  5 1999 Bill Nottingham <notting@redhat.com>
- update to 3.07

* Mon Nov 23 1998 Bill Nottingham <notting@redhat.com>
- update to 3.06

* Tue Nov 17 1998 Bill Nottingham <notting@redhat.com>
- update to 3.04

* Thu Nov 12 1998 Bill Nottingham <notting@redhat.com>
- update to 3.02
- PAMify

* Tue Oct 13 1998 Cristian Gafton <gafton@redhat.com>
- take out Noseguy module b/c of possible TMv
- install modules in /usr/X11R6/lib/xscreensaver
- don't compile support for xshm on the alpha
- properly buildrooted
- updated to version 2.34

* Fri Aug  7 1998 Bill Nottingham <notting@redhat.com>
- update to 2.27

* Wed Jun 10 1998 Prospector System <bugs@redhat.com>
- translations modified for de

* Mon Jun 08 1998 Erik Troan <ewt@redhat.com>
- added fix for argv0 buffer overflow

* Fri Apr 24 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Sat Apr 11 1998 Donnie Barnes <djb@redhat.com>
- updated from 2.10 to 2.16
- added buildroot

* Sat Oct 25 1997 Marc Ewing <marc@redhat.com>
- wmconfig

* Thu Oct 23 1997 Marc Ewing <marc@redhat.com>
- new version, configure

* Fri Aug 22 1997 Erik Troan <ewt@redhat.com>
- built against glibc

