--- postgresql94.spec	2016-02-10 11:43:04.544969790 +0100
+++ postgresql94.minimal.spec	2016-02-10 11:50:32.376037452 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package postgresql94
 #
-# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -18,7 +18,7 @@
 
 %define majorversion 9.4
 %define packageversion 94
-%define pgname postgresql%packageversion
+%define pgname postgresql%{packageversion}
 %define libpq libpq5
 %define libecpg libecpg6
 %define libpq_so libpq.so.5
@@ -26,46 +26,24 @@
 %define buildmain 1
 %define buildlibs 0
 %define builddevel 0
-%define pgbasedir %_prefix/lib/%pgname
-%define pgtestdir %pgbasedir/test
-%define pgbindir %pgbasedir/bin
-%define pglibdir %pgbasedir/%_lib
-%define pgincludedir %_includedir/pgsql
-%define pgdatadir %_datadir/%pgname
-%define pgdocdir %_docdir/%pgname
-%define pgextensiondir %pgdatadir/extension
-%define pgmandir %_mandir
-
+%define pgbasedir %{_prefix}/lib/%{pgname}
+%define pgtestdir %{pgbasedir}/test
+%define pgbindir %{pgbasedir}/bin
+%define pglibdir %{pgbasedir}/%{_lib}
+%define pgincludedir %{_includedir}/pgsql
+%define pgdatadir %{_datadir}/%{pgname}
+%define pgdocdir %{_docdir}/%{pgname}
+%define pgextensiondir %{pgdatadir}/extension
+%define pgmandir %{_mandir}
+%define pg_minor_version %(echo %{version} | sed -r 's/^([0-9]+\\.[0-9]+).*/\\1/')
 Name:           postgresql94
-
-%if %buildmain
-BuildRequires:  gettext-devel
-BuildRequires:  ncurses-devel
-BuildRequires:  pam-devel
-BuildRequires:  postgresql-init
-BuildRequires:  python-devel
-BuildRequires:  readline-devel
-BuildRequires:  tcl-devel
-BuildRequires:  timezone
-BuildRequires:  libuuid-devel
-BuildRequires:  zlib-devel
-# 
-%endif
-
-BuildRequires:  fdupes
-BuildRequires:  krb5-devel
-BuildRequires:  libxslt-devel
-BuildRequires:  openldap2-devel
-BuildRequires:  openssl-devel
-BuildRequires:  pkg-config
-BuildRequires:  update-alternatives
+Version:        9.4.5
+Release:        0
 #!BuildIgnore:  %pgname
 Summary:        Basic Clients and Utilities for PostgreSQL
 License:        PostgreSQL
 Group:          Productivity/Databases/Tools
-Version:        9.4.5
-Release:        0
-%define pg_minor_version %(echo %version | sed -r 's/^([0-9]+\\.[0-9]+).*/\\1/')
+Url:            http://www.postgresql.org/
 Source0:        https://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.bz2
 Source1:        baselibs.conf
 Source3:        postgresql-README.SUSE
@@ -76,12 +54,31 @@
 Patch7:         postgresql-testsuite-seclabel-location.patch
 Patch8:         postgresql-testsuite-keep-results-file.patch
 Patch9:         postgresql-var-run-socket.patch
-Url:            http://www.postgresql.org/
-BuildRoot:      %{_tmppath}/%{name}-%{version}-build
-Provides:       postgresql = %version
-Requires:       %libpq >= %majorversion
+BuildRequires:  fdupes
+BuildRequires:  krb5-devel
+BuildRequires:  libxslt-devel
+BuildRequires:  openldap2-devel
+BuildRequires:  openssl-devel
+BuildRequires:  pkg-config
+BuildRequires:  update-alternatives
+Requires:       %{libpq} >= %{majorversion}
 Requires(post): update-alternatives
 Requires(postun): update-alternatives
+Provides:       postgresql = %{version}
+BuildRoot:      %{_tmppath}/%{name}-%{version}-build
+%if %{buildmain}
+BuildRequires:  gettext-devel
+BuildRequires:  libuuid-devel
+BuildRequires:  ncurses-devel
+BuildRequires:  pam-devel
+BuildRequires:  postgresql-init
+BuildRequires:  python-devel
+BuildRequires:  readline-devel
+BuildRequires:  tcl-devel
+BuildRequires:  timezone
+BuildRequires:  zlib-devel
+#
+%endif
 
 %description
 PostgreSQL is an advanced object-relational database management system
@@ -95,25 +92,24 @@
 HTML documentation for PostgreSQL can be found in the postgresql-docs
 package.
 
-%if %buildlibs
-
-%package -n %libpq
+%if %{buildlibs}
+%package -n %{libpq}
 Summary:        Shared Libraries Required for PostgreSQL Clients
 Group:          Productivity/Databases/Clients
-Provides:       postgresql-libs:%_libdir/libpq.so.5
-Obsoletes:      postgresql-libs < %version
+Provides:       postgresql-libs:%{_libdir}/libpq.so.5
+Obsoletes:      postgresql-libs < %{version}
 # bug437293
-%if "%_lib" == "lib64"
-Conflicts:      %libpq-32bit < %version
+%if "%{_lib}" == "lib64"
+Conflicts:      %{libpq}-32bit < %{version}
 %endif
 %ifarch ia64
-Conflicts:      %libpq-x86 < %version
+Conflicts:      %{libpq}-x86 < %{version}
 %endif
 %ifarch ppc64
 Obsoletes:      postgresql-libs-64bit
 %endif
 
-%description -n %libpq
+%description -n %{libpq}
 
 PostgreSQL is an advanced object-relational database management system
 that supports an extended subset of the SQL standard, including
@@ -123,13 +119,12 @@
 This package provides the client library that most PostgreSQL client
 program or language bindings are using.
 
-%package -n %libecpg
-
+%package -n %{libecpg}
 Summary:        Shared Libraries Required for PostgreSQL Clients
 Group:          Productivity/Databases/Clients
-Provides:       postgresql-libs:%_libdir/libecpg.so.6
+Provides:       postgresql-libs:%{_libdir}/libecpg.so.6
 
-%description -n %libecpg
+%description -n %{libecpg}
 PostgreSQL is an advanced object-relational database management system
 that supports an extended subset of the SQL standard, including
 transactions, foreign keys, subqueries, triggers, user-defined types
@@ -139,20 +134,20 @@
 preprocessor for PostgreSQL.
 %endif
 
-%if %builddevel
-%package -n %pgname-devel
+%if %{builddevel}
+%package -n %{pgname}-devel
 Summary:        PostgreSQL development header files and libraries
 Group:          Development/Libraries/C and C++
-Provides:       postgresql-devel = %version
-Requires:       %libecpg >= %majorversion
-Requires:       %libpq >= %majorversion
+Requires:       %{libecpg} >= %{majorversion}
+Requires:       %{libpq} >= %{majorversion}
 Requires(post): update-alternatives
 Requires(postun): update-alternatives
+Conflicts:      postgresql-devel-exclusive < %{majorversion}
+Provides:       postgresql-devel = %{version}
 # Installation of postgresql??-devel is exclusive
-Provides:       postgresql-devel-exclusive = %majorversion
-Conflicts:      postgresql-devel-exclusive < %majorversion
+Provides:       postgresql-devel-exclusive = %{majorversion}
 
-%description -n %pgname-devel
+%description -n %{pgname}-devel
 PostgreSQL is an advanced object-relational database management system
 that supports an extended subset of the SQL standard, including
 transactions, foreign keys, subqueries, triggers, and user-defined
@@ -166,20 +161,19 @@
 
 %endif
 
-%if %buildmain
-
+%if %{buildmain}
 %package server
 Summary:        The Programs Needed to Create and Run a PostgreSQL Server
 Group:          Productivity/Databases/Servers
-PreReq:         /sbin/chkconfig
-PreReq:         postgresql = %version
-PreReq:         postgresql-init >= %majorversion
 Requires:       glibc-locale
-Provides:       postgresql-server = %version
-Requires(preun): postgresql-init >= %majorversion
-Requires(postun): postgresql-init >= %majorversion
+PreReq:         /sbin/chkconfig
+PreReq:         postgresql = %{version}
+PreReq:         postgresql-init >= %{majorversion}
 Requires(post): update-alternatives
+Requires(postun): postgresql-init >= %{majorversion}
 Requires(postun): update-alternatives
+Requires(preun): postgresql-init >= %{majorversion}
+Provides:       postgresql-server = %{version}
 
 %description server
 PostgreSQL is an advanced object-relational database management system
@@ -194,7 +188,7 @@
 %package test
 Summary:        The test suite for PostgreSQL
 Group:          Productivity/Databases/Servers
-Requires:       postgresql-server = %version
+Requires:       postgresql-server = %{version}
 
 %description test
 This package contains the sources and pre-built binaries of various
@@ -204,7 +198,7 @@
 %package docs
 Summary:        HTML Documentation for PostgreSQL
 Group:          Productivity/Databases/Tools
-Provides:       postgresql-docs = %version
+Provides:       postgresql-docs = %{version}
 %if 0%{?suse_version} >= 1120
 BuildArch:      noarch
 %endif
@@ -216,7 +210,7 @@
 types and functions.
 
 This package contains the HTML documentation for PostgreSQL. The start
-page is: file:///usr/share/doc/packages/%name/html/index.html .
+page is: file://%{_docdir}/%{name}/html/index.html .
 Manual pages for the PostgreSQL SQL statements can be found in the
 postgresql package.
 
@@ -224,9 +218,9 @@
 Summary:        Contributed Extensions and Additions to PostgreSQL
 Group:          Productivity/Databases/Tools
 #FIXME
-PreReq:         %pgname-server = %version
-Provides:       postgresql-contrib = %version
+PreReq:         %{pgname}-server = %{version}
 Requires(post): update-alternatives
+Provides:       postgresql-contrib = %{version}
 
 %description contrib
 PostgreSQL is an advanced object-relational database management system
@@ -239,15 +233,15 @@
 officially part of the PostgreSQL core.
 
 Documentation for the modules contained in this package can be found in
-/usr/share/doc/packages/postgresql/contrib.
+%{_docdir}/postgresql/contrib.
 
 %package plperl
 Summary:        The PL/Tcl, PL/Perl, and  PL/Python procedural languages for PostgreSQL
 Group:          Productivity/Databases/Servers
-Requires:       perl = %perl_version
-Provides:       postgresql-plperl = %version
 #FIXME
-Requires:       %pgname-server = %version
+Requires:       %{pgname}-server = %{version}
+Requires:       perl = %{perl_version}
+Provides:       postgresql-plperl = %{version}
 
 %description plperl
 This package contains the the PL/Tcl, PL/Perl, and PL/Python procedural
@@ -259,10 +253,10 @@
 %package plpython
 Summary:        The PL/Python Procedural Languages for PostgreSQL
 Group:          Productivity/Databases/Servers
-Provides:       postgresql-plpython = %version
 #FIXME
-Requires:       %pgname-server = %version
+Requires:       %{pgname}-server = %{version}
 Requires:       python
+Provides:       postgresql-plpython = %{version}
 
 %description plpython
 PostgreSQL is an advanced object-relational database management system
@@ -280,10 +274,10 @@
 %package pltcl
 Summary:        PL/Tcl Procedural Language for PostgreSQL
 Group:          Productivity/Databases/Tools
-Provides:       postgresql-pltcl = %version
 #FIXME
-Requires:       %pgname-server = %version
+Requires:       %{pgname}-server = %{version}
 Requires:       tcl
+Provides:       postgresql-pltcl = %{version}
 
 %description pltcl
 PostgreSQL is an advanced object-relational database management system
@@ -291,7 +285,7 @@
 transactions, foreign keys, subqueries, triggers, and user-defined
 types and functions.
 
-This package contains the PL/Tcl procedural language for PostgreSQL. 
+This package contains the PL/Tcl procedural language for PostgreSQL.
 With thie module one can use Tcl to write stored procedures, functions,
 and triggers.
 
@@ -301,7 +295,7 @@
 %endif
 
 %prep
-%setup -q -n postgresql-%version
+%setup -q -n postgresql-%{version}
 # Keep the timestamp of configure, because patching it would otherwise
 # confuse PostgreSQL's build system
 touch -r configure tmp
@@ -317,22 +311,22 @@
 find -name .gitignore -delete
 
 %build
-PACKAGE_TARNAME=%name %configure \
-        --bindir=%pgbindir \
-        --libdir=%pglibdir \
-        --includedir=%pgincludedir \
-        --datadir=%pgdatadir \
-        --docdir=%pgdocdir \
-        --mandir=%pgmandir \
+PACKAGE_TARNAME=%{name} %configure \
+        --bindir=%{pgbindir} \
+        --libdir=%{pglibdir} \
+        --includedir=%{pgincludedir} \
+        --datadir=%{pgdatadir} \
+        --docdir=%{pgdocdir} \
+        --mandir=%{pgmandir} \
 	--disable-rpath \
 	--enable-nls \
 	--enable-thread-safety \
 	--enable-integer-datetimes \
-%if %buildmain
+%if %{buildmain}
         --with-python \
         --with-perl \
         --with-tcl \
-        --with-tclconfig=%_libdir \
+        --with-tclconfig=%{_libdir} \
 	--with-pam \
         --with-uuid=e2fs \
 	--with-libxml \
@@ -346,26 +340,25 @@
 	--with-gssapi \
 	--with-krb5 \
 %endif
-	--with-system-tzdata=/usr/share/zoneinfo
-%if !%buildmain
+	--with-system-tzdata=%{_datadir}/zoneinfo
+%if !%{buildmain}
 make -C src/backend %{?_smp_mflags} libpq-recursive
-%if %builddevel
+%if %{builddevel}
 make -C src/port %{?_smp_mflags} libpgport.a
 make -C src/common %{?_smp_mflags} libpgcommon.a
 make -C src/interfaces/ecpg/preproc %{?_smp_mflags}
 make -C src/bin/pg_config %{?_smp_mflags} pg_config
 %endif
-%if %buildlibs || %builddevel
+%if %{buildlibs} || %{builddevel}
 make -C src/interfaces %{?_smp_mflags}
 %endif
 %else
 # {{{ build the test package
 make -C src/test/regress all
 # }}}
-make %{?_smp_mflags} PACKAGE_TARNAME=%name world
+make %{?_smp_mflags} PACKAGE_TARNAME=%{name} world
 %ifnarch %arm
 %if 0%{?suse_version} > 910
-
 %check
 #
 # Run the regression tests.
@@ -383,30 +376,30 @@
 %endif
 
 %install
-%if %buildmain
-make DESTDIR=%buildroot PACKAGE_TARNAME=%name install install-docs
+%if %{buildmain}
+make DESTDIR=%{buildroot} PACKAGE_TARNAME=%{name} install install-docs
 # {{{ the test package
-mkdir -p %buildroot%pgtestdir/regress
-install -sm 0755 contrib/spi/{refint.so,autoinc.so} %buildroot%pgtestdir/regress
-install -sm 0755 src/test/regress/{pg_regress,regress.so,dummy_seclabel.so} %buildroot%pgtestdir/regress
+mkdir -p %{buildroot}%{pgtestdir}/regress
+install -sm 0755 contrib/spi/{refint.so,autoinc.so} %{buildroot}%{pgtestdir}/regress
+install -sm 0755 src/test/regress/{pg_regress,regress.so,dummy_seclabel.so} %{buildroot}%{pgtestdir}/regress
 for i in  src/test/regress/{data,expected,input,output,sql}; do
-	cp -r $i %buildroot%pgtestdir/regress/
+	cp -r $i %{buildroot}%{pgtestdir}/regress/
 done
-install -m 0644 src/test/regress/{serial,parallel}_schedule %buildroot%pgtestdir/regress
+install -m 0644 src/test/regress/{serial,parallel}_schedule %{buildroot}%{pgtestdir}/regress
 # }}}
 %endif
-%if %builddevel && !%buildmain
+%if %{builddevel} && !%{buildmain}
 SUBINSTALL=install
-install -d %buildroot%pgmandir/man1
-install -m644 doc/src/sgml/man1/{ecpg,pg_config}.1 %buildroot%pgmandir/man1
+install -d %{buildroot}%{pgmandir}/man1
+install -m644 doc/src/sgml/man1/{ecpg,pg_config}.1 %{buildroot}%{pgmandir}/man1
 %else
 SUBINSTALL=uninstall
-rm -f %buildroot%pgmandir/*/ecpg*
-rm -f %buildroot%pgmandir/*/pg_config*
+rm -f %{buildroot}%{pgmandir}/*/ecpg*
+rm -f %{buildroot}%{pgmandir}/*/pg_config*
 %endif
 # Install them for postgresql-libs and uninstall them for postgresql
-make -C src DESTDIR=%buildroot $SUBINSTALL-local
-make -C src/pl/plpgsql/src DESTDIR=%buildroot $SUBINSTALL-headers
+make -C src DESTDIR=%{buildroot} $SUBINSTALL-local
+make -C src/pl/plpgsql/src DESTDIR=%{buildroot} $SUBINSTALL-headers
 for dir in \
         config \
         src/bin/pg_config \
@@ -417,73 +410,73 @@
         src/common \
         src/test/regress
 do
-        make -C $dir DESTDIR=%buildroot $SUBINSTALL
+        make -C $dir DESTDIR=%{buildroot} $SUBINSTALL
 done
 
-%if %builddevel
+%if %{builddevel}
 # The client libraries go to libdir
-mkdir -p %buildroot/%_libdir
-ls %buildroot%pglibdir/lib* |
+mkdir -p %{buildroot}/%{_libdir}
+ls %{buildroot}%{pglibdir}/lib* |
    grep -v walreceiver |
-   xargs mv -t %buildroot/%_libdir
-mv %buildroot%pglibdir/pkgconfig %buildroot%_libdir
-sed -i 's, -L%pglibdir,,' %buildroot%_libdir/pkgconfig/*.pc
+   xargs mv -t %{buildroot}/%{_libdir}
+mv %{buildroot}%{pglibdir}/pkgconfig %{buildroot}%{_libdir}
+sed -i 's, -L%{pglibdir},,' %{buildroot}%{_libdir}/pkgconfig/*.pc
 %endif
 # Don't ship static libraries,
 # libpgport.a and libpgcommon.a are needed, though.
-rm -f $(ls %buildroot/%_libdir/*.a | grep -F -v -e libpgport.a -e libpgcommon.a)
-%if %buildmain
+rm -f $(ls %{buildroot}/%{_libdir}/*.a | grep -F -v -e libpgport.a -e libpgcommon.a)
+%if %{buildmain}
 #
 # Install and collect the contrib stuff
 #
 touch flag; sleep 1 # otherwise we have installed files that are not newer than flag
-make DESTDIR=%buildroot -C contrib install
-find %buildroot -type f -cnewer flag -printf "/%%P\n" |
-     grep -v -e %_docdir -e %pgbindir > contrib.files
+make DESTDIR=%{buildroot} -C contrib install
+find %{buildroot} -type f -cnewer flag -printf "/%%P\n" |
+     grep -v -e %{_docdir} -e %{pgbindir} > contrib.files
 rm flag
-install -d -m 750 %buildroot/var/lib/pgsql
-install -d -m755 %buildroot%pgdocdir
+install -d -m 750 %{buildroot}%{_localstatedir}/lib/pgsql
+install -d -m755 %{buildroot}%{pgdocdir}
 cp doc/KNOWN_BUGS doc/MISSING_FEATURES COPYRIGHT \
-   README HISTORY doc/bug.template %buildroot%pgdocdir
-cp -a %SOURCE3 %buildroot%pgdocdir/README.SUSE
+   README HISTORY doc/bug.template %{buildroot}%{pgdocdir}
+cp -a %{SOURCE3} %{buildroot}%{pgdocdir}/README.SUSE
 %endif
 # Use versioned names for the man pages:
-for f in %buildroot%pgmandir/man*/*; do
-        mv $f ${f}pg%packageversion
+for f in %{buildroot}%{pgmandir}/man*/*; do
+        mv $f ${f}pg%{packageversion}
 done
 
-%if %builddevel
+%if %{builddevel}
 # Make sure we can also link agaist newer versions
-pushd %buildroot%_libdir
+pushd %{buildroot}%{_libdir}
 for f in *.so; do
     ln -sf $f.? $f
 done
 popd
-%if %buildlibs
+%if %{buildlibs}
 %find_lang libpq5-%{pg_minor_version} libpq.lang
 %find_lang ecpglib6-%{pg_minor_version} libecpg.lang
 %else
-rm %buildroot/usr/share/locale/*/*/libpq5*
-rm %buildroot/usr/share/locale/*/*/ecpglib6*
-rm %buildroot%_libdir/lib*.so.*
-rm %buildroot%pgdatadir/pg_service.conf.sample
+rm %{buildroot}%{_datadir}/locale/*/*/libpq5*
+rm %{buildroot}%{_datadir}/locale/*/*/ecpglib6*
+rm %{buildroot}%{_libdir}/lib*.so.*
+rm %{buildroot}%{pgdatadir}/pg_service.conf.sample
 %endif
 %endif
 cat > alternatives <<"EOF"
 shopt -s nullglob
-for FILE in %pgbindir/*; do
+for FILE in %{pgbindir}/*; do
         NAME=$(basename $FILE)
-        DIR=%_bindir
+        DIR=%{_bindir}
         SLAVES="$SLAVES --slave $DIR/$NAME $NAME $FILE"
 done
 if test -n "$SLAVES"; then
 	update-alternatives --quiet --install \
-        /usr/lib/postgresql postgresql %pgbasedir %packageversion \
+        %{_prefix}/lib/postgresql postgresql %{pgbasedir} %{packageversion} \
         $SLAVES
 fi
 EOF
-mkdir -p %buildroot{%_bindir,%_mandir/man1}
-mkdir -p %buildroot/etc/alternatives
+mkdir -p %{buildroot}{%{_bindir},%{_mandir}/man1}
+mkdir -p %{buildroot}%{_sysconfdir}/alternatives
 genlists ()
 {
     # usage: genlists packagename basenames
@@ -491,29 +484,29 @@
     shift
     for f in $@
     do
-        BIN=%_bindir/$f
-        ALTBIN=/etc/alternatives/$f
-        PGBIN=%pgbindir/$f
-        MAN=%pgmandir/man1/$f.1*
+        BIN=%{_bindir}/$f
+        ALTBIN=%{_sysconfdir}/alternatives/$f
+        PGBIN=%{pgbindir}/$f
+        MAN=%{pgmandir}/man1/$f.1*
 
-        touch %buildroot$ALTBIN
-        ln -s $ALTBIN %buildroot$BIN
+        touch %{buildroot}$ALTBIN
+        ln -s $ALTBIN %{buildroot}$BIN
 
         echo "$PGBIN" >> $PKG.files
         echo "$BIN" >> $PKG.files
         echo "%ghost $ALTBIN" >> $PKG.files
-        test -e %buildroot$MAN &&
+        test -e %{buildroot}$MAN &&
             echo "%doc $MAN" >> $PKG.files
-        %find_lang $f-%pg_minor_version $PKG.files ||:
+        %find_lang $f-%{pg_minor_version} $PKG.files ||:
     done
 }
-%if %buildmain
+%if %{buildmain}
 genlists main \
         createdb clusterdb createlang createuser dropdb droplang \
         dropuser pg_dump pg_dumpall pg_restore psql vacuumdb \
         reindexdb pg_basebackup pg_receivexlog pg_isready pg_recvlogical
-%find_lang plpgsql-%pg_minor_version main.files
-%find_lang pgscripts-%pg_minor_version main.files
+%find_lang plpgsql-%{pg_minor_version} main.files
+%find_lang pgscripts-%{pg_minor_version} main.files
 
 genlists server \
         initdb pg_ctl pg_controldata pg_resetxlog postgres postmaster
@@ -525,19 +518,18 @@
     %find_lang $pl-%{pg_minor_version} $pl.lang
 done
 %endif
-ln -s /etc/alternatives/postgresql %buildroot/usr/lib/postgresql
-touch %buildroot/etc/alternatives/postgresql
-%if %builddevel
+ln -s %{_sysconfdir}/alternatives/postgresql %{buildroot}%{_prefix}/lib/postgresql
+touch %{buildroot}%{_sysconfdir}/alternatives/postgresql
+%if %{builddevel}
 genlists devel \
         pg_config ecpg
 %endif
-%fdupes %buildroot
-
-%if %buildmain
+%fdupes %{buildroot}
 
+%if %{buildmain}
 %postun
 if test "$1" == 0; then
-    update-alternatives --remove postgresql %pgbasedir
+    update-alternatives --remove postgresql %{pgbasedir}
 fi
 
 %post -p /bin/bash -f alternatives
@@ -547,10 +539,10 @@
 %preun server
 # Stop only when we are uninstalling the currently running version
 PID=$(pidof -s postgres) || :
-if test -n "$PID" -a -x /etc/init.d/postgresql; then
+if test -n "$PID" -a -x %{_initddir}/postgresql; then
     BIN=$(readlink /proc/$PID/exe)
     DIR=$(dirname ${BIN% *})
-    if test "$DIR" = "%pgbindir"; then
+    if test "$DIR" = "%{pgbindir}"; then
         %stop_on_removal postgresql
     fi
 fi
@@ -559,10 +551,10 @@
 # Restart only when we are updating the currently running version
 # or from the old packaging scheme
 PID=$(pidof -s postgres) || :
-if test -n "$PID" -a -x /etc/init.d/postgresql; then
+if test -n "$PID" -a -x %{_initddir}/postgresql; then
     BIN=$(readlink /proc/$PID/exe)
     DIR=$(dirname ${BIN% *})
-    if test "$DIR" = "%pgbindir" -o "$DIR" = "%_bindir"; then
+    if test "$DIR" = "%{pgbindir}" -o "$DIR" = "%{_bindir}"; then
         %restart_on_update postgresql
     fi
 fi
@@ -573,129 +565,126 @@
 
 %endif
 
-%if %builddevel
+%if %{builddevel}
+%post -n %{pgname}-devel -f alternatives
 
-%post -n %pgname-devel -f alternatives
-
-%postun -n %pgname-devel -f alternatives
+%postun -n %{pgname}-devel -f alternatives
 %endif
 
-%if %buildlibs
-%post -n %libpq -p /sbin/ldconfig
+%if %{buildlibs}
+%post -n %{libpq} -p /sbin/ldconfig
 
-%postun -n %libpq -p /sbin/ldconfig
+%postun -n %{libpq} -p /sbin/ldconfig
 
-%post -n %libecpg -p /sbin/ldconfig
+%post -n %{libecpg} -p /sbin/ldconfig
 
-%postun -n %libecpg -p /sbin/ldconfig
+%postun -n %{libecpg} -p /sbin/ldconfig
 %endif
 
-%if %buildmain
-
+%if %{buildmain}
 %files -f main.files
 %defattr(-,root,root)
-%dir %pgbindir
-%doc %pgmandir/man7/*
-%docdir %pgdocdir
-%dir %pgdocdir
-%pgdocdir/[[:upper:]]*
-%pgdocdir/bug.template
-%dir %pglibdir
-/usr/lib/postgresql
-%ghost /etc/alternatives/postgresql
+%dir %{pgbindir}
+%doc %{pgmandir}/man7/*
+%docdir %{pgdocdir}
+%dir %{pgdocdir}
+%{pgdocdir}/[[:upper:]]*
+%{pgdocdir}/bug.template
+%dir %{pglibdir}
+%{_prefix}/lib/postgresql
+%ghost %{_sysconfdir}/alternatives/postgresql
 
 %files test
 %defattr(-,root,root,-)
-%pgtestdir
+%{pgtestdir}
 
 %files docs
 %defattr(-,root,root)
-%doc %pgmandir/man3/*
-%docdir %pgdocdir
-%dir %pgdocdir
-%pgdocdir/html
+%doc %{pgmandir}/man3/*
+%docdir %{pgdocdir}
+%dir %{pgdocdir}
+%{pgdocdir}/html
 
 %files contrib -f contrib.files
 %defattr(-,root,root)
-%docdir %pgdocdir
-%dir %pgdocdir
-%pgdocdir/extension
-%dir %pgdatadir
-/usr/lib/postgresql
-%ghost /etc/alternatives/postgresql
+%docdir %{pgdocdir}
+%dir %{pgdocdir}
+%{pgdocdir}/extension
+%dir %{pgdatadir}
+%{_prefix}/lib/postgresql
+%ghost %{_sysconfdir}/alternatives/postgresql
 
 %files server -f server.files
 %defattr(-,root,root)
-%dir %pgbasedir
-%dir %pgextensiondir
-%dir %pglibdir
-%pglibdir/plpgsql.so
-%pglibdir/dict_snowball.so
-%pgdatadir/tsearch_data
-%exclude %pgdatadir/tsearch_data/*.rules
-%dir %pgdatadir
-/usr/lib/postgresql
-%ghost /etc/alternatives/postgresql
-%pgdatadir/timezone*
-%pgdatadir/*.*
-%if %buildlibs
-%exclude %pgdatadir/pg_service.conf.sample
-%endif
-%exclude %pgdatadir/*.pltcl
-%pglibdir/*_and_*.so
-%pglibdir/euc2004_sjis2004.so
-%pglibdir/libpqwalreceiver.so
-%pgextensiondir/plpgsql*
-%attr(750,postgres,postgres) %dir /var/lib/pgsql
+%dir %{pgbasedir}
+%dir %{pgextensiondir}
+%dir %{pglibdir}
+%{pglibdir}/plpgsql.so
+%{pglibdir}/dict_snowball.so
+%{pgdatadir}/tsearch_data
+%exclude %{pgdatadir}/tsearch_data/*.rules
+%dir %{pgdatadir}
+%{_prefix}/lib/postgresql
+%ghost %{_sysconfdir}/alternatives/postgresql
+%{pgdatadir}/timezone*
+%{pgdatadir}/*.*
+%if %{buildlibs}
+%exclude %{pgdatadir}/pg_service.conf.sample
+%endif
+%exclude %{pgdatadir}/*.pltcl
+%{pglibdir}/*_and_*.so
+%{pglibdir}/euc2004_sjis2004.so
+%{pglibdir}/libpqwalreceiver.so
+%{pgextensiondir}/plpgsql*
+%attr(750,postgres,postgres) %dir %{_localstatedir}/lib/pgsql
 
 %files pltcl -f pltcl.lang
 %defattr(-,root,root)
-%pgextensiondir/pltcl*
-%pglibdir/pltcl.so
-%pgdatadir/*.pltcl
-%pgbindir/pltcl*
+%{pgextensiondir}/pltcl*
+%{pglibdir}/pltcl.so
+%{pgdatadir}/*.pltcl
+%{pgbindir}/pltcl*
 
 %files plperl -f plperl.lang
 %defattr(-,root,root)
-%pgextensiondir/plperl*
-%pglibdir/plperl.so
+%{pgextensiondir}/plperl*
+%{pglibdir}/plperl.so
 
 %files plpython -f plpython.lang
 %defattr(-,root,root)
-%pgextensiondir/plpython*
-%pglibdir/plpython*.so
+%{pgextensiondir}/plpython*
+%{pglibdir}/plpython*.so
 
 %endif
-%if %buildlibs
 
-%files -n %libpq -f libpq.lang
+%if %{buildlibs}
+%files -n %{libpq} -f libpq.lang
 %defattr(-,root,root)
-%dir %pgbasedir
-%dir %pgdatadir
-%_libdir/libpq.so.*
-%pgdatadir/pg_service.conf.sample
+%dir %{pgbasedir}
+%dir %{pgdatadir}
+%{_libdir}/libpq.so.*
+%{pgdatadir}/pg_service.conf.sample
 
-%files -n %libecpg -f libecpg.lang
+%files -n %{libecpg} -f libecpg.lang
 %defattr(-,root,root)
-%_libdir/libecpg*.so.*
-%_libdir/libpgtypes.so.*
+%{_libdir}/libecpg*.so.*
+%{_libdir}/libpgtypes.so.*
 
 %endif
 
-%if %builddevel
-
-%files -n %pgname-devel -f devel.files
+%if %{builddevel}
+%files -n %{pgname}-devel -f devel.files
 %defattr(-,root,root)
-%dir %pgbasedir
-%dir %pgbindir
-%dir %pglibdir
-%_libdir/pkgconfig/*
-%_libdir/lib*.a
-%_libdir/lib*.so
-%pglibdir/pgxs
-%pgincludedir
-/usr/lib/postgresql
-%ghost /etc/alternatives/postgresql
+%dir %{pgbasedir}
+%dir %{pgbindir}
+%dir %{pglibdir}
+%{_libdir}/pkgconfig/*
+%{_libdir}/lib*.a
+%{_libdir}/lib*.so
+%{pglibdir}/pgxs
+%{pgincludedir}
+%{_prefix}/lib/postgresql
+%ghost %{_sysconfdir}/alternatives/postgresql
 
 %endif
 
