File xscreensaver.spec of Package xscreensaver

%define name          xscreensaver

%define mainversion   5.43
%define beta_ver      %{nil}

%define modular_conf  1
%define split_getimage   0
%if 0%{?fedora} >= 14
%define split_getimage   1

%define fedora_rel    2

%global use_clang_as_cc 0
%global use_clang_analyze 0
%global use_cppcheck   0
%global use_gcc_strict_sanitize 0
%global use_gcc_trap_on_sanitize 0
%undefine extrarel

%global flagrel %{nil}
%if 0%{?use_cppcheck} >= 1
%global flagrel %{flagrel}.cppcheck
%if 0%{?use_gcc_strict_sanitize} >= 1
%global flagrel %{flagrel}.san

%{!?__git:%define __git git}

%if 0%{?fedora}
%define default_text  %{_sysconfdir}/fedora-release
%define default_text  %{_sysconfdir}/system-release
%define default_URL

%define pam_ver       0.80-7
%define autoconf_ver  2.53

%define update_po     1
%define build_tests   0

%global support_setcap 0
%if 0%{?fedora} >= 31
# TODO write selinux policy for selinux-policy-mls 
# (currently works with selinux-policy-targeted)
#%%global support_setcap 1
# TODO enable xscreensaver-systemd for F-31

%undefine        _changelog_trimtime

Summary:         X screen saver and locker
Name:            %{name}
Version:         %{mainversion}
Release:         100
Epoch:           1
License:         MIT
%if %{modular_conf}
Source10:        update-xscreensaver-hacks
%if 0%{?fedora} >= 12
Source11:        xscreensaver-autostart
Source12:        xscreensaver-autostart.desktop
## Patches
# bug 129335
%global PATCH1_desc \
# sanitize the names of modes in barcode
Patch1:          xscreensaver-5.00b5-sanitize-hacks.patch
## Patches already sent to the upsteam
## Patches which must be discussed with upstream
%global PATCH21_desc \
# Change webcollage not to access to net \
# Also see bug 472061
Patch21:         xscreensaver-5.35-webcollage-default-nonet.patch
%global PATCH51_desc \
# driver/test-passwd tty segfaults
Patch51:         xscreensaver-5.12-test-passwd-segv-tty.patch
%global PATCH52_desc \
# patch to compile driver/test-xdpms
Patch52:         xscreensaver-5.12-tests-miscfix.patch
# reset_strip: kill gcc7 -Wint-in-bool-context
Patch3603:       xscreensaver-5.36-0003-reset_strip-kill-gcc7-Wint-in-bool-context.patch
# init_crystal: kill gcc7 -Wint-in-bool-context
Patch3604:       xscreensaver-5.36-0004-init_crystal-kill-gcc7-Wint-in-bool-context.patch
# misc: kill gcc warn_unused_result warnings
Patch3607:       xscreensaver-5.36-0007-misc-kill-gcc-warn_unused_result-warnings.patch
# open new window for man when using gnome-terminal
Patch4261:       xscreensaver-5.42-0061-open-new-window-for-man-when-using-gnome-terminal.patch
# glhanoi: fix malloc size shortage
Patch4301:       xscreensaver-5.43-0001-glhanoi-fix-malloc-size-shortage.patch
# Debugging patch
# Not apply by default
# XIO: print C backtrace on error
Patch13501:      xscreensaver-5.35-0101-XIO-print-C-backtrace-on-error.patch
Patch12345:      0001-increase-pointer_hysteresis-to-10000.patch
# Patches end
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

%if 0%{?use_clang_analyze} >= 1
BuildRequires:   clang-analyzer
BuildRequires:   clang
%if 0%{?use_clang_as_cc}
BuildRequires:   clang
%if 0%{?use_cppcheck}
BuildRequires:   cppcheck
%if 0%{?use_gcc_strict_sanitize}
BuildRequires:   libasan
BuildRequires:   libubsan
BuildRequires:   git
BuildRequires:   autoconf
BuildRequires:   automake
BuildRequires:   intltool
BuildRequires:   bc
BuildRequires:   desktop-file-utils
BuildRequires:   gawk
BuildRequires:   gettext
BuildRequires:   libtool
BuildRequires:   pam-devel > %{pam_ver}
BuildRequires:   sed
# Use pseudo symlink
# BuildRequires:   xdg-utils
BuildRequires:   xorg-x11-proto-devel
# extrusioni
%if 0%{?fedora} >= 13
BuildRequires:   libgle-devel
BuildRequires:   libX11-devel
BuildRequires:   libXScrnSaver-devel
BuildRequires:   libXext-devel
# From xscreensaver 5.12, write explicitly
BuildRequires:   libXi-devel
BuildRequires:   libXinerama-devel
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
%if 0%{?fedora} <= 30
# libXxf86misc removed from F-31
BuildRequires:   libXxf86misc-devel
BuildRequires:   libXxf86vm-devel
# XScreenSaver 5.31
BuildRequires:   libXft-devel
BuildRequires:   gtk2-devel
# Write explicitly below, especially
# for F-23 gdk_pixbuf package splitting
BuildRequires:   pkgconfig(gdk-pixbuf-2.0)
BuildRequires:   pkgconfig(gdk-pixbuf-xlib-2.0)
BuildRequires:   libjpeg-devel
BuildRequires:   libglade2-devel
%if 0%{?support_setcap} >= 1
BuildRequires:   pkgconfig(libcap)
# For
BuildRequires:    perl-interpreter
BuildRequires:    perl-generators
# For --with-login-manager option
%if 0%{?fedora} >= 14
# Use pseudo symlink, not writing BR: gdm
#BuildRequires:   gdm
Requires:        %{_sysconfdir}/pam.d/system-auth
Requires:        pam > %{pam_ver}
# For xdg-open
Requires:        xdg-utils
%if ! %{split_getimage}
Requires:        xorg-x11-resutils
Requires:        xorg-x11-fonts-ISO8859-1-100dpi
%if 0%{?build_tests} < 1
# Obsoletes but not Provides
Obsoletes:       xscreeensaver-tests < %{epoch}:%{version}-%{release}

%package extras-base
Summary:         A base package for screensavers
%if 0%{?fedora} < 19
Requires:        %{name}-base = %{epoch}:%{version}-%{release}
# For appres, etc
Requires:        xorg-x11-resutils

%package extras
Summary:         An enhanced set of screensavers
%if 0%{?fedora} >= 19
# Does not available on EPEL7
BuildRequires:   desktop-backgrounds-basic
BuildRequires:	   gnome-backgrounds
Requires:        %{name}-base = %{epoch}:%{version}-%{release}
%if %{split_getimage}
Requires:        %{name}-extras-base = %{epoch}:%{version}-%{release}

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

%package gl-extras
Summary:         An enhanced set of screensavers that require OpenGL
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}
Requires:        %{name}-base = %{epoch}:%{version}-%{release}
%if %{split_getimage}
Requires:        %{name}-extras-base = %{epoch}:%{version}-%{release}

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

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

%package tests
Summary:         Test programs related to XScreenSaver
Requires:        %{name}-base = %{epoch}:%{version}-%{release}

%package clang-analyze
Summary:         Clang analyze result log

%package cppcheck
Summary:         cppcheck result log

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 -l fr
Un économiseur d'écran modulaire pour le système X Window.
Plus de 200 modes d'affichages sont inclus dans ce paquet.

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 -l fr base 
Un économiseur d'écran modulaire pour le système X Window.
Ce paquet contient le minimum vital pour éteindre et verouiller
votre écran. Les modes d'affichages graphiques sont inclus
dans les paquets "xscreensaver-extras" et "xscreensaver-gl-extras".

%description extras-base
This package contains common files to make screensaver hacks
work for XScreenSaver.

%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 -l fr extras
Un économiseur d'écran modulaire pour le système X Window.
Ce paquet contient une pléthore d'économiseurs d'écran graphiques
pour votre plaisir des yeux.

%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 -l fr gl-extras
Un économiseur d'écran modulaire pour le système X Window.
Ce paquet contient une pléthore d'économiseurs d'écran basés sur OpenGL (3D)
pour votre plaisir des yeux.

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

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

%description tests
This package contains some test programs to debug XScreenSaver.

%description clang-analyze
This package contains Clang analyze result of XScreenSaver.

%description cppcheck
This package contains cppcheck result of XScreenSaver.

%setup -q -n %{name}-%{mainversion}%{?beta_ver}

cat > .gitignore <<EOF

# Firstly clean this
rm -f driver/XScreenSaver_ad.h

# chmod
find . -name \*.c -exec chmod ugo-x {} \;

%__git init
%__git config ""
%__git config "XScreenSaver owners"
%__git add .
%__git commit -m "base" -q

%patch1 -p1
  %__git commit -m "%PATCH1_desc" -a
%patch21 -p1
  %__git commit -m "%PATCH21_desc" -a

%patch51 -p1
  %__git commit -m "%PATCH51_desc" -a
%patch52 -p1
  %__git commit -m "%PATCH52_desc" -a

%__cat %PATCH3603 | %__git am
%__cat %PATCH3604 | %__git am
#%%__cat %PATCH3607 | %__git am
%__cat %PATCH4261 | %__git am
%__cat %PATCH4301 | %__git am

#%%__cat %PATCH13501 | %%__git am

%__cat %PATCH12345 | %__git am

   set +x
   if [ ! -f ${ADFILE}.opts ] ; then
      cp -p $ADFILE ${ADFILE}.opts

   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\|\' \
   set -x

   set +x
   if [ ! -f ${ADFILE}.hack ] ; then
      cp -p $ADFILE ${ADFILE}.hack

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

%global PATCH_desc \
# change some files to UTF-8
for f in \
   driver/ \
   hacks/glx/ \
   ; 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
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# Change some options \
# For grabDesktopImages, lock, see bug 126809
change_option driver/ \
   captureStderr=False \
   passwdTimeout=0:00:15 \
   grabDesktopImages=False \
   lock=True \
   splash=False \
   ignoreUninstalledPrograms=True \
   textProgram=fortune\ -s \
%if 0%{?fedora} >= 12
%__git commit -m "%PATCH_desc" -a

# peepers: 5.39: too scary (mtasaka)
%global PATCH_desc \
# Disable the following hacks by default \
# (disable, not remove)
silence_hack driver/ \
   bsod flag \
   peepers \
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# Record time, EVR
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].*$||'`\|\' \

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

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\|\\\(5.\[0-9\]\[0-9\]\\\)[a-z]\[0-9\]\[0-9\]\*\|\\\1\|\' \
   -e \'s\|5.\[0-9\]\[0-9\]\|%{version}-`echo %{release} | \
      sed -e '/IGNORE THIS/s|\.[a-zA-Z][a-zA-Z0-9].*$||'`\|\' \
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# Move man entry to 6x (bug 197741)
for f in `find hacks -name` ; do
   sed -i.mansuf \
      -e '/^mansuffix/s|6|6x|'\
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# 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 @' \
%__git commit -m "%PATCH_desc" -a

# Suppress rpmlint warnings.
# suppress about pam config (although this is 
# not the fault of xscreensaver.pam ......).
# From xscreensaver-5.15-10, no longer do this
%if 0
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} .

%global PATCH_desc \
# Fix for desktop-file-utils 0.14+
%if 0%{?fedora} >= 9
sed -i.icon -e 's|xscreensaver\.xpm|xscreensaver|' \
%__git commit -m "%PATCH_desc" -a || echo "Nothing changed"

%global PATCH_desc \
# Disable (don't build) some tests \
# apm: doesn't compile \
# mlstring: causes OOM - need check again
sed -i.test \
   -e 's|test-apm[ \t][ \t]*t|t|' \
%if 0
   -e 's|test-mlstring[ \t][ \t]*t|t|' \
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# test-fade: give more time between fading
sed -i.delay -e 's| delay = 1| delay = 3|' driver/test-fade.c
%__git commit -m "%PATCH_desc" -a

%global PATCH_desc \
# test-grab: testing time too long, setting time 15 min -> 20 sec
sed -i.delay -e 's|60 \* 15|20|' driver/test-grab.c
%__git commit -m "%PATCH_desc" -a



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

export PATH=$(pwd):$PATH

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

# Doesn't work well when generating debuginfo...
# export CFLAGS="$(echo $CFLAGS | sed -e 's|-g |-g3 -ggdb |')"

%if 0%{?fedora} >= 24
export CFLAGS="$CFLAGS -Wno-long-long"
export CFLAGS="$CFLAGS -Wno-variadic-macros"

%if 0%{?use_clang_as_cc}
export CC=clang
export CFLAGS="$(echo $CFLAGS | sed -e 's|-fstack-protector-strong|-fstack-protector|')"
export CFLAGS="$(echo $CFLAGS | sed -e 's|-specs=[^ \t][^ \t]*||')"
export CFLAGS="$CFLAGS -Wno-gnu-statement-expression"
export LDFLAGS="$(echo $LDFLAGS %__global_ldflags | sed -e 's|-specs=[^ \t][^ \t]*||g')"

%if 0%{?use_gcc_strict_sanitize}
export CC="gcc -fsanitize=address -fsanitize=undefined"
%if 0%{?fedora} >= 24
export LDFLAGS="%__global_ldflags -pthread"
%if 0%{?use_gcc_trap_on_sanitize}
export CC="$CC -fsanitize-undefined-trap-on-error"
# Currently -fPIE binary cannot work with ASAN on kernel 4.12
export CFLAGS="$(echo $CFLAGS | sed -e 's|-specs=[^ \t][^ \t]*||')"
export LDFLAGS="$(echo $LDFLAGS %__global_ldflags | sed -e 's|-specs=[^ \t][^ \t]*||g')"

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
%if 0%{?fedora} >= 14
ln -sf /bin/true gdmflexiserver
CONFIG_OPTS="$CONFIG_OPTS --without-login-manager"
# Enable extrusion on F-13 and above
%if 0%{?fedora} <= 12
CONFIG_OPTS="$CONFIG_OPTS --without-gle"
# Enable account type pam validation on F-18+,
# debian bug 656766
%if 0%{?fedora} >= 18
CONFIG_OPTS="$CONFIG_OPTS --enable-pam-check-account-type"
# xscreensaver 5.30
CONFIG_OPTS="$CONFIG_OPTS --with-record-animation"

%if 0%{?fedora} >= 30
CONFIG_OPTS="$CONFIG_OPTS --with-setcap-hacks"

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

%if 0%{?use_clang_analyze} >= 1
%global _configure scan-build --use-analyzer %_bindir/clang ./configure

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

%if %{update_po}
#( cd po ; make generate_potfiles_in update-po )
# ???
( cd po ; make generate_potfiles_in ; cp -p .. ; export srcdir=.. ; make update-po ; rm -f ../POTFILES_in )
( cp -p ../po/*.po po/)
( ( cd ../po ; git add *.po ; git commit -m "po regenerated" ) || true )

%if 0%{?use_clang_analyze} >= 1
%global __make scan-build  --use-analyzer %_bindir/clang -v -v -v -o clang-analyze make
mkdir clang-analyze

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

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

# Again
%__make %{?_smp_mflags} -k

%if %{modular_conf}
# Make modular (bug 200881)
rm -rf $CONFD
mkdir $CONFD

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

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

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


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

%if 0%{?use_cppcheck} >= 1
cd ..
CPPCHECK_FLAGS="$CPPCHECK_FLAGS -I. -Iutils -Idriver -Ihacks -I$archdir -I$archdir/hacks/"
# find stddef.h
GCC_HEADER_PATH=$(echo '#include <stddef.h>' | gcc -E - | sed -n -e 's|^.*"\(.*\)stddef\.h".*$|\1|p' | head -n 1)
CPPCHECK_FLAGS="$CPPCHECK_FLAGS $(pkg-config --cflags gtk+-2.0 | sed -e 's|-pthread||')"

cppcheck $CPPCHECK_FLAGS . 2>&1 | tee cppcheck-result.log
cppcheck $CPPCHECK_FLAGS --check-config . 2>&1 | tee cppcheck-path-inclusion-check.log

cd $archdir

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

# Kill OnlyShowIn=GNOME; on F-11+ (bug 483495)
desktop-file-install --vendor "" --delete-original    \
   --dir $RPM_BUILD_ROOT%{_datadir}/applications         \
%if 0%{?fedora} < 11
   --add-only-show-in GNOME                              \
   --add-category    DesktopSettings                     \
%if 0
   --add-category X-Red-Hat-Base                         \
   --remove-category Appearance                          \
   --remove-category AdvancedSettings                    \
   --remove-category Application                         \

# 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.

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

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

%if 0%{?support_setcap} >= 1
sed -i $dd/gl-extras.files \
	-e '\@sonar$@s|^|%%attr(0755,root,root) %%caps(cap_net_raw=p)|' \

# Move xscreensaver-gettext-foo, xscreensaver-text to extras-base
# (bug 668427)
%if %{split_getimage}
echo "%%defattr(-,root,root,-)" >> $dd/extras-base.files
for target in \
   /xscreensaver-getimage \
   grep -v $target $dd/base.files > $dd/
   grep $target $dd/base.files >> $dd/extras-base.files
   mv $dd/base.files{.new,}

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

sed -i -e '/xscreensaver-gl-helper/d' $dd/gl-extras.files
for dir in `find . -name \*xscreensaver-gl-helper\*` ; do
   echo "${dir#.}" >> $dd/gl-base.files
sed -i -e 's|^\(%{_mandir}.*\)$|\1*|' $dd/gl-base.files

%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/* \
cp -p xscreensaver/hacks.conf.d/xscreensaver.conf \

for adfile in xscreensaver/* ; do
   filen=`basename $adfile`
   echo "%%config(noreplace) %{_sysconfdir}/xscreensaver/$filen" >> $dd/base.files
echo -n "%%verify(not size md5 mtime) " >> $dd/base.files
echo "%{_sysconfdir}/xscreensaver/" >> \
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

ln -sf ../../../..%{_sysconfdir}/xscreensaver/ \


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

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

%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

# tests
%if %{build_tests}
echo "%%defattr(-,root,root,-)" > $dd/tests.files
cd driver
for tests in `find . -name test-\* -perm -0700` ; do
   install -cpm 0755 $tests ${RPM_BUILD_ROOT}%{_libexecdir}/xscreensaver
   echo "%{_libexecdir}/xscreensaver/$tests" >> $dd/tests.files
cd ..

%if 0%{?use_clang_analyze} >= 1
pushd ..
rm -rf clang-analyze
mkdir -p clang-analyze/html
cp -a $archdir/clang-analyze/*/* clang-analyze/html

# 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+
%if 0%{?fedora} >= 12
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 \
%if 0%{?fedora} >= 27
   --add-only-show-in=X-NODEFAULT \
   --add-only-show-in=GNOME \
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 gnome-screensaver
# bug 204944, 208560
   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
   if [ ! -x $RPM_BUILD_ROOT/$COMMAND ] ; then
      echo "WARNING:"
      echo "$COMMAND could not be found under $RPM_BUILD_ROOT"
      #exit 1
# 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"

   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

echo "%%dir $SAVERDIR" >> base.files

for list in *extras.files ; do

   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
      desktop=xscreensaver-`basename $file`

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

# 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
exec webcollage.original \\
	-directory %{_datadir}/backgrounds/images \\
chmod 0755 webcollage
echo "%%{_libexecdir}/%%{name}/webcollage.original" >> \

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

%post base
%if %{modular_conf}

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

exit 0


%files -f base.files base

%if %{build_tests}
%files -f tests.files tests

%if %{split_getimage}
%files -f extras-base.files extras-base

%files -f extras.files extras

%if %{modular_conf}
%files -f gl-base.files gl-base

%files -f gl-extras.files gl-extras

%files -f gnome-extras.files extras-gss

%files -f gnome-gl-extras.files gl-extras-gss

%if 0%{?use_clang_analyze} >= 1
%files clang-analyze
%doc clang-analyze/html

%if 0%{?use_cppcheck} >= 1
%files cppcheck
%doc cppcheck-*.log