# compiler by defauft: gcc, defaut dotests 1, default_bits 64  

# Perl is compiled with xlc and its options are not compatible with gcc
%{!?gcc_compiler: %define gcc_compiler 0}
%{!?default_bits: %define default_bits 64}
%define gcc_compiler 1
%define dotests 1

%define postgres_uid 64200
%define postgres_gid 64200

%global TESTUSER buildusr
%global TESTGROUP staff
%global plpython 1
%global pltcl 1
%global plperl 1
%global ssl 1
%global kerberos 1
%global ldap 1
%global nls 1
%global xml 1
%global pgfts 1

%global test 1
%global tap_tests 0 
%global runselftest  %{dotests}

%define _libdir64 %{_prefix}/lib64

Summary: PostgreSQL client programs
Name: postgresql
%global majorversion 18	
Version:	18.3
%define base_release	1
Release: %{base_release}
# The PostgreSQL license is very similar to other MIT licenses, but the OSI
# recognizes it as an independent license, so we do as well.
License: PostgreSQL
Group: Applications/Databases
URL: https://www.postgresql.org/

Source0:	https://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.gz
Source1:	https://ftp.postgresql.org/pub/source/v%{version}/postgresql-%{version}.tar.gz.md5
# The PDF file is generated by generate-pdf.sh, which see for comments
Source2: %{name}-%{majorversion}-US.pdf
# Get the doc file from:
#   https://www.postgresql.org/files/documentation/pdf/9.6/postgresql-9.6-US.pdf
# and change the name with exact X.Y.Z version as title says
# generate-pdf.sh is not used during RPM build, but included for documentation

# Sources : http://www.oss4aix.org/download/SRPMS/postgresql/postgresql-9.3.5-1.src.rpm
Source3: %{name}-generate-pdf.sh
Source6: %{name}.aix.init
Source7: %{name}-Makefile.regress
Source8: %{name}-pg_config.h
Source9: %{name}-ecpg_config.h
Source10: %{name}-README.rpm-dist
Source11: %{name}-bashprofile
# Results analysis script
Source12: %{name}-%{version}-docs.tar.gz
Source13: %{name}-11.5.resultats.ksh
# Script of passing tests base + Tap + extras ...
#Source14: %{name}-%{version}.run_all_tests.ksh
Source20: %{name}-switch-to-32_bit.sh
Source21: %{name}-switch-to-64_bit.sh

Patch1: postgres-18-gnu.patch
Patch2: postgres-18-gnu-2.patch
Patch3: postgres-18-gnu-3.patch
Patch4: postgres-18-gnu-4.patch
Patch5: postgres-18-gnu-5.patch
Patch6: postgres-18-gnu-6.patch

# To elimiate the error below.
# checking Python include directory... -I/opt/freeware/include/python3.12
# checking how to link an embedded Python application... configure: error: could not find shared library for Python
# You might have to rebuild your Python installation.  Refer to the
# documentation for details.  Use --without-python to disable building

Patch7: postgresql-15.4-shared_library_search.patch

# Hardcode libintl path.
Patch8: postgresql-15.4-libintl.patch

# Two old patches still needed.
Patch9:  postgresql-15.4-1-testcase.patch
Patch10: postgresql-11.5-ForTprof.patch 

%description 
PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, sub-selects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server.  These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
server, or may be on a remote machine which accesses a PostgreSQL
server over a network connection. This package contains the docs
in HTML for the whole package, as well as command-line utilities for
managing PostgreSQL databases on a PostgreSQL server.

If you want to manipulate a PostgreSQL database on a local or remote PostgreSQL
server, you need this package. You also need to install this package
if you're installing the postgresql-server package.

The database is available as 32-bit and 64-bit.

%if %{gcc_compiler} == 1
This version has been compiled with GCC.
%else
This version has been compiled with XLC.
%endif

%package -n %{name}%{majorversion}
Summary: The shared libraries required for any PostgreSQL clients
Group: Applications/Databases

BuildRequires:	bison
BuildRequires:	flex
BuildRequires:	gawk
BuildRequires:	make
BuildRequires:	bzip2 >= 1.0.8
BuildRequires:	perl >= 5.38.2

Requires:       AIX-rpm >= 7.2

%if %plpython
BuildRequires:	python3.12-devel >= 3.12.11
%endif

%if %pltcl
BuildRequires: tcl-devel >= 8.6.13
BuildRequires: tcl-static >= 8.6.13
%endif

BuildRequires:	readline-devel >= 8.2
Requires:	readline >= 8.2
BuildRequires:	zlib-devel >= 1.2.13
Requires:	zlib >= 1.2.13

%if %ssl
#BuildRequires: openssl-devel >= 1.0.1f-1
#Requires: openssl >= 1.0.1f-1
%endif

%if %kerberos
#BuildRequires: krb5-devel >= 1.21.3-1
#Requires: krb5-libs >= 1.21.3-1
%endif

%if %ldap
BuildRequires:	openldap-devel >= 2.5.16
Requires:	openldap >= 2.5.16
%endif

%if %nls
BuildRequires:	gettext >= 0.21
# header file <libintl.h> is required for NLS
BuildRequires:	gettext-devel
Requires:	gettext >= 0.21
%endif

%if %xml
BuildRequires:	libxml2-devel >= 2.14.4
Requires:	libxml2 >= 2.14.4
%endif

# main package requires -libs subpackage
Requires: %{name}%{majorversion}-libs = %{version}-%{release}

Requires:	libxslt >= 1.1.43


%description -n %{name}%{majorversion}
PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, sub-selects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server.  These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
server, or may be on a remote machine which accesses a PostgreSQL
server over a network connection. This package contains the docs
in HTML for the whole package, as well as command-line utilities for
managing PostgreSQL databases on a PostgreSQL server. 

If you want to manipulate a PostgreSQL database on a local or remote PostgreSQL
server, you need this package. You also need to install this package
if you're installing the postgresql-server package.

The database is available as 32-bit and 64-bit.

%if %{gcc_compiler} == 1
This version has been compiled with GCC.
%else
This version has been compiled with XLC.
%endif



%package -n %{name}%{majorversion}-libs
Summary: The shared libraries required for any PostgreSQL clients
Group: Applications/Databases
Provides: libpq.so = %{version}-%{release}
Requires:	gettext >= 0.21
#Requires: krb5-libs >= 1.21.3-1
Requires:	openldap >= 2.5.16
#Requires: openssl >= 1.0.1f-1

Conflicts: %{name}-libs < 15

%description -n %{name}%{majorversion}-libs
The postgresql-libs package provides the essential shared libraries for any 
PostgreSQL client program or interface. You will need to install this package
to use any other PostgreSQL package or any clients that need to connect to a
PostgreSQL server.

The library is available as 32-bit and 64-bit.


%package -n %{name}%{majorversion}-server
Summary: The programs needed to create and run a PostgreSQL server
Group: Applications/Databases
Requires:	openldap >= 2.5.16
Requires:	gettext >= 0.21
Requires:	libxml2 >= 2.14.4
Requires:	zlib >= 1.2.13
Requires: %{name}%{majorversion} = %{version}-%{release}
Requires: %{name}%{majorversion}-libs = %{version}-%{release}
Requires:	libxslt >= 1.1.43

%description -n %{name}%{majorversion}-server
The postgresql-server package includes the programs needed to create
and run a PostgreSQL server, which will in turn allow you to create
and maintain PostgreSQL databases.  PostgreSQL is an advanced
Object-Relational database management system (DBMS) that supports
almost all SQL constructs (including transactions, sub-selects and
user-defined types and functions). You should install
postgresql-server if you want to create and maintain your own
PostgreSQL databases and/or your own PostgreSQL server. You also need
to install the postgresql package.


%package -n %{name}%{majorversion}-docs
Summary: Extra documentation for PostgreSQL
Group: Applications/Databases
Requires: %{name}%{majorversion} = %{version}-%{release}

%description -n %{name}%{majorversion}-docs
The postgresql-docs package includes some additional documentation for
PostgreSQL.  Currently, this includes the main documentation in PDF format
and source files for the PostgreSQL tutorial.


%package -n %{name}%{majorversion}-contrib
Summary: Contributed modules distributed with PostgreSQL
Group: Applications/Databases

Requires:	gettext >= 0.21
Requires:	perl >= 5.38.2
Requires:	python3.12 >= 3.12.11
BuildRequires:	libxslt-devel >= 1.1.43
BuildRequires:	libxml2-devel >= 2.14.4
Requires:	libxslt >= 1.1.43
Requires:	libxml2 >= 2.14.4
Requires:	zlib >= 1.2.13
Requires: %{name}%{majorversion} = %{version}-%{release}
Requires: %{name}%{majorversion}-libs = %{version}-%{release}

%description -n %{name}%{majorversion}-contrib
The postgresql-contrib package contains contributed packages that are
included in the PostgreSQL distribution.


%package -n %{name}%{majorversion}-devel
Summary: PostgreSQL development header files and libraries
Group: Development/Libraries
Requires: %{name}%{majorversion} = %{version}-%{release}
Requires: %{name}%{majorversion}-libs = %{version}-%{release}
Requires:	gettext >= 0.21
Requires:	libxml2 >= 2.14.4
Requires:	libxslt >= 1.1.43

%description -n %{name}%{majorversion}-devel
The postgresql-devel package contains the header files and libraries
needed to compile C or C++ applications which will directly interact
with a PostgreSQL database management server and the ecpg Embedded C
Postgres preprocessor. You need to install this package if you want to
develop applications which will interact with a PostgreSQL server.

If you are compiling a 32-bit program, no special compiler options are
needed.

If you are compiling a 64-bit program, you have to compile and link your
application with "xlc_r -q64" or "gcc -maix64".


%if %plperl
%package -n %{name}%{majorversion}-plperl
Summary: The Perl procedural language for PostgreSQL
Group: Applications/Databases
Requires: %{name}%{majorversion}-server = %{version}-%{release}
#Requires: perl(:MODULE_COMPAT_%(eval "`/opt/freeware/bin/perl -V:version`"; echo $version))
Requires:	perl >= 5.38.2

%description -n %{name}%{majorversion}-plperl
PostgreSQL is an advanced Object-Relational database management
system.  The postgresql-plperl package contains the PL/Perl
procedural language for the backend.
%endif


%if %plpython
%package -n %{name}%{majorversion}-plpython3
Summary: The Python procedural language for PostgreSQL
Group: Applications/Databases
Requires: %{name}%{majorversion}-server = %{version}-%{release}
Requires:	python3.12 >= 3.12.11
Requires:	gettext >= 0.21
Obsoletes: %{name}-plpython  <= 11.9

%description -n %{name}%{majorversion}-plpython3
PostgreSQL is an advanced Object-Relational database management
system.  The postgresql-plpython package contains the PL/Python
procedural language for the backend.
%endif


%if %pltcl
%package -n %{name}%{majorversion}-pltcl
Summary: The Tcl procedural language for PostgreSQL
Group: Applications/Databases
Requires: %{name}%{majorversion}-server = %{version}-%{release}
Requires:	tcl >= 8.6.13

%description -n %{name}%{majorversion}-pltcl
PostgreSQL is an advanced Object-Relational database management
system.  The postgresql-pltcl package contains the PL/Tcl
procedural language for the backend.
%endif


%if %test
%package -n %{name}%{majorversion}-test
Summary: The test suite distributed with PostgreSQL
Group: Applications/Databases
Requires: %{name}%{majorversion}-server = %{version}-%{release}
Requires:	libxml2 >= 2.14.4
Requires:	gettext >= 0.21
Requires:	libxslt >= 1.1.43

%description -n %{name}%{majorversion}-test
PostgreSQL is an advanced Object-Relational database management
system. The postgresql-test package includes the sources and pre-built
binaries of various tests for the PostgreSQL database management
system, including regression tests and benchmarks.
%endif


############################################################################
#                                                                          #
#                                %prep                                     #
#                                                                          #
############################################################################

%prep
export PATH=/opt/freeware/bin:$PATH

echo "dotests=%{dotests}"
echo "tap_tests=%{tap_tests}"
echo "runselftest=%{runselftest}"
echo "gcc_compiler=%{gcc_compiler}"
echo "default_bits=%{default_bits}"
%if %{gcc_compiler} == 1
echo "GCC version=`%{__cc__} --version | head -1`"
%endif

echo "TESTUSER:%{TESTUSER}.%{TESTGROUP}"
# ulimit -m unlimited  is required for test "regex"
#sudo chuser rss=-1 data=-1 stack=-1 %{TESTUSER}

%setup -q -n %{name}-%{version}
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1

cp -p %{SOURCE2} .

# remove .gitignore files to ensure none get into the RPMs
find . -type f -name .gitignore | xargs rm

# Duplicate source for 32 & 64 bits

rm -rf   /tmp/%{name}-%{version}-32bit
cp -pr . /tmp/%{name}-%{version}-32bit
rm -fr *
mv       /tmp/%{name}-%{version}-32bit 32bit
cp -pr 32bit 64bit


############################################################################
#                                                                          #
#                                %build                                    #
#                                                                          #
############################################################################

%build
rpm -qa
cp $0 %{name}-%{version}_script_build.ksh

# This line (use for tracing) sometimes generates the issue: "--trace:  not found" during tests
export MAKE="gmake "

export PATH=/opt/freeware/bin:/opt/freeware/bin:/usr/linux/bin:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin

export AR="/usr/bin/ar -X32_64"

# fail quickly and obviously if user tries to build as root
# %if %runselftest
#     if [ x"`id -u`" = x0 ] ; then
#         echo "postgresql's regression tests fail if run as root."
#         echo "If you really need to build the RPM as root, use"
#         echo "--define='runselftest 0' to skip the regression tests."
#         exit 1
#     fi
# %endif

# we need GNU make before the AIX make

echo "CC: %{gcc_compiler}"

%if %{gcc_compiler} == 1
export CC__="%{__cc__}"
export CXX__="%{__cxx__}"
export FLAG32="-maix32"
export FLAG64="-maix64"

echo "CC Version:"
$CC__ --version

%else

# XLC specific (do NOT compile yet...)
export CC__="/usr/vac/bin/xlc"
export  CC__="/usr/vac/bin/xlc"            # Version: 12.01.0000.0000
#export CC__="/opt/IBM/xlc/13.1.3/bin/xlc"	#  13.01.0003.0004


#export CXX__="/usr/vacpp/bin/xlC"
#export CXX__="/usr/vac/bin/xlc"            # Version: 12.01.0000.0000
#export CXX__="/opt/IBM/xlC/13.1.0/bin/xlC"	#  13.01.0003.0004

export FLAG32="-q32"
export FLAG64="-q64"

echo "CC Version:"
$CC__ -qversion

%endif

export CC32=" ${CC__}  ${FLAG32}"
#export CXX32="${CXX__} ${FLAG32}"
export CC64=" ${CC__}  ${FLAG64}"
#export CXX64="${CXX__} ${FLAG64}"

export GLOBAL_CC_OPTIONS="-O2"

############################### 64-bit BEGIN ##############################
env

cd 64bit

# first build the 64-bit version
export OBJECT_MODE=64
export CC="${CC64}   $GLOBAL_CC_OPTIONS"
#export CXX="${CXX64} $GLOBAL_CC_OPTIONS"

export PERL=/opt/freeware/bin/perl_64
# /opt/freeware/bin/perl_64bit_NoXLC :
# PERLVERSION=`/usr/bin/rpm -qa | grep perl-`
# PERLV=`echo $PERLVERSION | awk -F- '{print $2}'`
# PERLVV=`echo $PERLV | awk -F. '{print $1}'`
# PERLVERSION="perl$PERLVV/$PERLV"
# 
# echo $* | grep ldopts > /dev/null
# if [ $? -eq 0 ]
# then
#         echo "-Wl,-bE:/opt/freeware/lib/$PERLVERSION/ppc-aix-thread-multi-64all/CORE/perl.exp -s -L/opt/freeware/lib64 -L/usr/lib64 -L/opt/freeware/lib -Wl,-brtl -Wl,-bdynamic -L/usr/local/lib -Wl,-b64 -L/opt/freeware/lib/$PERLVERSION/ppc-aix-thread-multi-64all/CORE -lperl -lpthread -lbind -lnsl -ldl -lld -lm -lcrypt -lpthreads -lc"
# else
#         /opt/freeware/bin/perl_64bit "$@"
# fi


export PYTHON=/opt/freeware/bin/python3.12
export LDFLAGS="-L/opt/freeware/lib64 -L/usr/lib64 -L/opt/freeware/lib -L/usr/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"

# unixODBC-devel contains a sqltypes.h which is different from:
#   /src/interfaces/ecpg/include/sqltypes.h
# ==> CCPFLAGS : -I`pwd`/src/include -I`pwd`/src/interfaces/ecpg/include

export CPPFLAGS="-I`pwd`/src/include -I`pwd`/src/interfaces/ecpg/include -I/opt/freeware/include -I/usr/include" ; 
export   CFLAGS="-I`pwd`/src/include -I`pwd`/src/interfaces/ecpg/include -I/opt/freeware/include -I/usr/include" ;

#export XML_CATALOG_FILES=/home/buildusr/rpmbuild/SPECS/docbook/etc/xml/catalog
#export DOCBOOK_XSL=/home/buildusr/rpmbuild/SPECS/docbook/usr/share/xml/docbook/stylesheet/xsl/current

# For more information in building trace :  --enable-debug --enable-dtrace
./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir64} \
    --mandir=%{_mandir} \
    --without-icu \
%if %plperl
    --with-perl \
%endif
%if %pltcl
    --with-tcl \
    --with-tclconfig=%{_prefix}/lib64 \
%endif
%if %plpython
    --with-python \
%endif
%if %ldap
    --with-ldap \
%endif
%if %ssl
    --with-openssl \
%endif
%if %xml
    --with-libxml \
    --with-libxslt \
%endif
%if %nls
    --enable-nls \
%endif
%if %pgfts
    --enable-thread-safety \
%endif
%if %tap_tests
    --enable-tap-tests \
%endif
    --sysconfdir=/etc/sysconfig/%{name}

# Ad per documentation build without man and html page since it needs docbook v4.5
# Refere here https://www.postgresql.org/docs/current/install-make.html
$MAKE %{?_smp_mflags} world-bin

# Have to hack makefile to put correct path into tutorial scripts
sed "s|C=\`pwd\`;|C=%{_libdir}/%{name}/tutorial;|" < src/tutorial/Makefile > src/tutorial/GNUmakefile
$MAKE %{?_smp_mflags} -C src/tutorial NO_PGXS=1 all
rm -f src/tutorial/GNUmakefile

%if %runselftest
    HERE=$PWD
    mkdir -p src/bin/scripts/tmp_check/log/
    find src/bin/scripts/tmp_check| xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/test                 | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plperl            | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plpgsql           | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plpython          | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/tcl               | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/interfaces/ecpg/test | xargs chown %{TESTUSER}.%{TESTGROUP}
    find contrib/*                | xargs chown %{TESTUSER}.%{TESTGROUP}
#    find src/bin/pg_upgrade      | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/bin                  | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/backend/             | xargs chown %{TESTUSER}.%{TESTGROUP}
    [ -d tmp_install ] && find tmp_install | xargs chown %{TESTUSER}.%{TESTGROUP}
    chown %{TESTUSER}.%{TESTGROUP} .

    export EXTRA_TESTS_LIST="numeric_big"
#     Failing Extra Tests (to be studied) :
#	hs_standby_allowed
#	hs_standby_check
#	hs_standby_disallowed
#	hs_standby_functions"
#     Non-existing Extra Tests src/test/regress/expected/hs_primary_*.out files for:
#	hs_primary_extremes
#	hs_primary_setup
#
#	RUNNING=`ps -edf | grep postgres | awk '{ if($1=="pgstbf") print $2}'`
# Needs a NOT empt list !
#	kill -9 $RUNNING
#
#	ps -edf | awk '{print $1}' | grep postgres > /dev/null
#	if [ $? -eq 1 ]
#	then
#		echo "Other PostgreSQL process postgres is running ! Stop !"
#	fi
#	ps -edf | awk '{print $1}' | grep pgstbf > /dev/null
#	if [ $? -eq 1 ]
#	then
#		echo "Other PostgreSQL process pgstbf is running ! Stop !"
#	fi
#
#   Do not use ! "su - ..." since environment variables, like: OBJECT_MODE, CC, etc. will not be passed
#   ulimit -m unlimited is required for "regex" test in 64bit and is done in %prep phase

    ulimit -m unlimited
    (set -x;cd $HERE || exit 1; \
	$MAKE -k MAX_CONNECTIONS=5 check-world EXTRA_TESTS=$EXTRA_TESTS_LIST 2>&1 || true; exit 0)
    
    
%endif


############################### 64-bit END ##############################

############################### 32-bit BEGIN ##############################

cd ../32bit

# now build the 32-bit version
export OBJECT_MODE=32
export CC="${CC32}   $GLOBAL_CC_OPTIONS -D_LARGE_FILES"
#export CXX="${CXX32} $GLOBAL_CC_OPTIONS"

export PERL=/opt/freeware/bin/perl_32
export PYTHON=%{_libexecdir}/python3.12_32

%if %{gcc_compiler} == 1
	export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib"
%else
	export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000"
%endif
export LDFLAGS="$LDFLAGS -Wl,-bmaxdata:0x80000000"
# PROBLEME avec Perl ! qui donne des options XLC, dans le cas 32bits
#	configure:7874: checking for flags to link embedded Perl
#	configure:7891: result:  -s -Wl,-bmaxdata:0x80000000 -L/opt/freeware/lib -L/usr/lib -b32 -bmaxdata:0x80000000  -L/opt/freeware/lib/perl5/5.24.0/ppc-aix-thread-multi/CORE -lperl -l pthread -lbind -lnsl -ldl -lld -lm -lcrypt -lpthreads -lc
#	gcc: error: unrecognized command line option '-b32'
#	gcc: error: unrecognized command line option '-bmaxdata:0x80000000'
#
# C'est le fichier : /opt/freeware/lib/perl5/5.24.0/ppc-aix-thread-multi/Config_heavy.pl
# Il faut le patcher en remplacant le bazar XLC par du bazar GCC

export CPPFLAGS="-I`pwd`/src/include -I`pwd`/src/interfaces/ecpg/include -I/opt/freeware/include -I/usr/include" ;
export   CFLAGS="-I`pwd`/src/include -I`pwd`/src/interfaces/ecpg/include -I/opt/freeware/include -I/usr/include" ;

# For more information in building trace :  --enable-debug --enable-dtrace
./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --mandir=%{_mandir} \
    --without-icu \
%if %plperl
    --with-perl \
%endif
%if %pltcl
    --with-tcl \
    --with-tclconfig=%{_prefix}/lib \
%endif
%if %plpython
    --with-python \
%endif
%if %ldap
    --with-ldap \
%endif
%if %ssl
    --with-openssl \
%endif
%if %xml
    --with-libxml \
    --with-libxslt \
%endif
%if %nls
    --enable-nls \
%endif
%if %pgfts
    --enable-thread-safety \
%endif
%if %tap_tests
    --enable-tap-tests \
%endif
    --sysconfdir=/etc/sysconfig/%{name}

$MAKE %{?_smp_mflags} world-bin

# Have to hack makefile to put correct path into tutorial scripts
sed "s|C=\`pwd\`;|C=%{_libdir}/%{name}/tutorial;|" < src/tutorial/Makefile > src/tutorial/GNUmakefile
$MAKE %{?_smp_mflags} -C src/tutorial NO_PGXS=1 all
rm -f src/tutorial/GNUmakefile

%if %runselftest
    HERE=$PWD
    mkdir -p src/bin/scripts/tmp_check/log/
    find src/bin/scripts/tmp_check| xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/test                 | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plperl            | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plpgsql           | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/plpython          | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/pl/tcl               | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/interfaces/ecpg/test | xargs chown %{TESTUSER}.%{TESTGROUP}
    find contrib/*                | xargs chown %{TESTUSER}.%{TESTGROUP}
#   find src/bin/pg_upgrade       | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/bin                  | xargs chown %{TESTUSER}.%{TESTGROUP}
    find src/backend/             | xargs chown %{TESTUSER}.%{TESTGROUP}
    [ -d tmp_install ] && find tmp_install | xargs chown %{TESTUSER}.%{TESTGROUP}
    chown %{TESTUSER}.%{TESTGROUP} .

    export EXTRA_TESTS_LIST="numeric_big"
#     Failing Extra Tests (to be studied) :
#	hs_standby_allowed
#	hs_standby_check
#	hs_standby_disallowed
#	hs_standby_functions"
#     Non-existing Extra Tests src/test/regress/expected/hs_primary_*.out files for:
#	hs_primary_extremes
#	hs_primary_setup

    (set -x; cd $HERE || exit 1; $MAKE -k MAX_CONNECTIONS=5 check-world EXTRA_TESTS=$EXTRA_TESTS_LIST 2>&1 || true; exit 0)
    
    
%endif


############################### 32-bit END ##############################


############################################################################
#                                                                          #
#                                %install                                  #
#                                                                          #
############################################################################

%install

if [ "%{default_bits}" == 32 ]; then
    DEFAULT_BITS=32;
else
    DEFAULT_BITS=64;
fi

export PATH=/opt/freeware/bin:/opt/freeware/bin:/usr/linux/bin:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin
export AR=/usr/bin/ar

cp $0 %{name}-%{version}_script_install.ksh

[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

export MAKE="gmake --trace"

# Extract the document tar ball
/opt/freeware/bin/tar -xzf %{SOURCE12} 
mkdir -p ${RPM_BUILD_ROOT}/%{_mandir}
mkdir -p ${RPM_BUILD_ROOT}/%{_docdir}/%{name}
cp -R ./postgresql-%{version}/doc/src/sgml/man1 ${RPM_BUILD_ROOT}/%{_mandir}
cp -R ./postgresql-%{version}/doc/src/sgml/man3 ${RPM_BUILD_ROOT}/%{_mandir}
cp -R ./postgresql-%{version}/doc/src/sgml/man7 ${RPM_BUILD_ROOT}/%{_mandir}
cp -R  ./postgresql-%{version}/doc/src/sgml/html ${RPM_BUILD_ROOT}/%{_docdir}/%{name}

cd 64bit
export OBJECT_MODE=64
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"

$MAKE DESTDIR=${RPM_BUILD_ROOT} install-world-bin

cp src/backend/postgres.imp ${RPM_BUILD_ROOT}%{_libdir}64/postgresql/

cd src/test/modules
$MAKE DESTDIR=${RPM_BUILD_ROOT} install
cd -
cd contrib
$MAKE DESTDIR=${RPM_BUILD_ROOT} install
cd -

(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in * ; do
    mv -f ${f} ${f}_64
  done
)

# multilib header hack; note pg_config.h is installed in two places!
mv ${RPM_BUILD_ROOT}%{_includedir}/pg_config.h ${RPM_BUILD_ROOT}%{_includedir}/pg_config-ppc64.h
mv ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config.h ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config-ppc64.h

mv ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config.h ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config-ppc64.h

cd ../32bit
export OBJECT_MODE=32
export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000"

$MAKE DESTDIR=${RPM_BUILD_ROOT} install

cp src/backend/postgres.imp ${RPM_BUILD_ROOT}%{_libdir}/postgresql/

cd src/test/modules
$MAKE DESTDIR=${RPM_BUILD_ROOT} install
cd -
cd contrib
$MAKE DESTDIR=${RPM_BUILD_ROOT} install
cd -

(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in `ls -1 | grep -v _64` ; do
    mv -f ${f} ${f}_32
  done
  ln -fs postgres_64 postmaster_64
  ln -fs postgres_32 postmaster_32
)

/usr/bin/strip -X32_64 ${RPM_BUILD_ROOT}%{_bindir}/* || :

# make the 64-bit version the default version
(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for file in `ls -1 | grep -v _64` ; do
    f=`basename ${file} _32`
    ln -s ${f}_${DEFAULT_BITS} ${f}
  done

  cp %{SOURCE20} .
  cp %{SOURCE21} .
  chmod 0755 %{name}-switch-to-*.sh
)

# dynamic library :
# 1/ extract *.so from lib64
# 2/ merge *.so (lib64) to lib32
# 3/ Create a link from lib64 to lib32


# add the 64-bit shared objects to the shared libraries containing already the
# 32-bit shared objects

(
  cd ${RPM_BUILD_ROOT}%{_libdir64}
  for f in ecpg ecpg_compat pgtypes pq ; do
      /usr/bin/ar -X64 -x lib${f}.a
      rm -f lib${f}.a
      ln -s ../lib/lib${f}.a lib${f}.a
      /usr/bin/ar -X64 -q ${RPM_BUILD_ROOT}%{_libdir}/lib${f}.a ${RPM_BUILD_ROOT}%{_libdir64}/lib${f}.so*
      # Strip -e .so files that appear in .a files
      strip -X64 -e ${RPM_BUILD_ROOT}%{_libdir64}/lib${f}.so*
  done
  
# extraction /lib  of *.so
  cd ${RPM_BUILD_ROOT}%{_libdir}
  for f in ecpg ecpg_compat pgtypes pq ; do
    /usr/bin/ar -X32 -x lib${f}.a
    # Strip -e .so files that appear in .a files
    strip -X32 -e ${RPM_BUILD_ROOT}%{_libdir}/lib${f}.so*
  done

)

# multilib header hack; note pg_config.h is installed in two places!
mv ${RPM_BUILD_ROOT}%{_includedir}/pg_config.h ${RPM_BUILD_ROOT}%{_includedir}/pg_config-ppc32.h
mv ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config.h ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config-ppc32.h
cp %{SOURCE8} ${RPM_BUILD_ROOT}%{_includedir}/pg_config.h
chmod 644 ${RPM_BUILD_ROOT}%{_includedir}/pg_config.h
cp %{SOURCE8} ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config.h
chmod 644 ${RPM_BUILD_ROOT}%{_includedir}/%{name}/server/pg_config.h

mv ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config.h ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config-ppc32.h
cp %{SOURCE9} ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config.h
chmod 644 ${RPM_BUILD_ROOT}%{_includedir}/ecpg_config.h

mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/%{name}/tutorial
chmod 0755 ${RPM_BUILD_ROOT}%{_libdir}/%{name}/tutorial
cp src/tutorial/* ${RPM_BUILD_ROOT}%{_libdir}/%{name}/tutorial/

# prep the initscript, including insertion of some values it needs
mkdir -p ${RPM_BUILD_ROOT}/etc/rc.d/init.d
sed -e 's|^PGVERSION=.*$|PGVERSION=%{version}|' \
	-e 's|^PGDOCDIR=.*$|PGDOCDIR=%{_docdir}/%{name}-%{version}|' \
	< %{SOURCE6} > %{name}.init
cp %{name}.init ${RPM_BUILD_ROOT}/etc/rc.d/init.d/%{name}
chmod 0755 ${RPM_BUILD_ROOT}/etc/rc.d/init.d/%{name}

# PGDATA needs removal of group and world permissions due to pg_pwd hole.
mkdir -p ${RPM_BUILD_ROOT}/var/lib/%{name}/data
chmod 0700 ${RPM_BUILD_ROOT}/var/lib/%{name}/data

# backups of data go here...
mkdir -p ${RPM_BUILD_ROOT}/var/lib/%{name}/backups
chmod 0700 ${RPM_BUILD_ROOT}/var/lib/%{name}/backups

# postgres' .bash_profile
cp %{SOURCE11} ${RPM_BUILD_ROOT}/var/lib/%{name}/.bash_profile
chmod 0644 %{SOURCE11} ${RPM_BUILD_ROOT}/var/lib/%{name}/.bash_profile

# Create the multiple postmaster startup directory
mkdir -p ${RPM_BUILD_ROOT}/etc/sysconfig/%{name}
chmod 0700 ${RPM_BUILD_ROOT}/etc/sysconfig/%{name}

mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/%{name}/pgxs/src/backend/port/aix
mkdir -p ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/pgxs/src/backend/port/aix
cp src/backend/port/aix/mkldexport.sh \
    ${RPM_BUILD_ROOT}%{_libdir}/%{name}/pgxs/src/backend/port/aix
cp src/backend/port/aix/mkldexport.sh \
    ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/pgxs/src/backend/port/aix
chmod 0755 ${RPM_BUILD_ROOT}%{_libdir}/%{name}/pgxs/src/backend/port/aix/mkldexport.sh
chmod 0755 ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/pgxs/src/backend/port/aix/mkldexport.sh

%if %test
cd ../64bit
(
    # tests. There are many files included here that are unnecessary,
    # but include them anyway for completeness.  We replace the original
    # Makefiles, however.
    mkdir -p ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/test
    cp -p -r src/test/regress ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/test
    cd ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/test/regress
    strip -X64 *.so
    rm -f GNUmakefile Makefile *.o
    cp %{SOURCE7} ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/test/regress/Makefile
    chmod 0644 ${RPM_BUILD_ROOT}%{_libdir64}/%{name}/test/regress/Makefile
)
cd ../32bit
(
    # tests. There are many files included here that are unnecessary,
    # but include them anyway for completeness.  We replace the original
    # Makefiles, however.
    mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/%{name}/test
    cp -p -r src/test/regress ${RPM_BUILD_ROOT}%{_libdir}/%{name}/test
    cd ${RPM_BUILD_ROOT}%{_libdir}/%{name}/test/regress
    strip -X32 *.so
    rm -f GNUmakefile Makefile *.o
    cp %{SOURCE7} ${RPM_BUILD_ROOT}%{_libdir}/%{name}/test/regress/Makefile
    chmod 0644 ${RPM_BUILD_ROOT}%{_libdir}/%{name}/test/regress/Makefile
)

(
  # librairy : libregress.a
  f=regress
  cd ${RPM_BUILD_ROOT}%{_libdir64}/postgresql/test/regress
  #/usr/bin/ar  -X64 -x lib${f}.a
  #rm -f lib${f}.a
  #ln -s ../../../../lib/postgresql/test/regress/lib${f}.a lib${f}.a
  /usr/bin/ar -X64 -q ${RPM_BUILD_ROOT}%{_libdir}/postgresql/test/regress/lib${f}.a ${RPM_BUILD_ROOT}%{_libdir64}/postgresql/test/regress/${f}.so*
  /usr/bin/ar -X32_64 -q ${RPM_BUILD_ROOT}%{_libdir}/postgresql/test/regress/lib${f}.a ${RPM_BUILD_ROOT}%{_libdir}/postgresql/test/regress/${f}.so*
#  rm -f  ${f}.so*
  cd ${RPM_BUILD_ROOT}%{_libdir}/postgresql/test/regress
#  rm -f  ${f}.so*
####  /usr/bin/ar  -X64 -x lib${f}.a
)
%endif

# Fix some more documentation
# gzip doc/internals.ps
cp %{SOURCE10} README.rpm-dist

# %find_lang does not find *any* message catalogs, thus use my own version
my_find_lang()
{
  /usr/bin/find ${RPM_BUILD_ROOT} -name $1.mo | \
      /usr/bin/sed "s|${RPM_BUILD_ROOT}||g" > $1.lang
}


my_find_lang ecpg-%{majorversion}
cat ecpg-%{majorversion}.lang > devel.lst
my_find_lang ecpglib6-%{majorversion}
cat ecpglib6-%{majorversion}.lang > libs.lst
my_find_lang initdb-%{majorversion}
cat initdb-%{majorversion}.lang > server.lst
my_find_lang libpq5-%{majorversion}
cat libpq5-%{majorversion}.lang >> libs.lst
my_find_lang pg_basebackup-%{majorversion}
cat pg_basebackup-%{majorversion}.lang >>server.lst
my_find_lang pg_controldata-%{majorversion}
cat pg_controldata-%{majorversion}.lang >> server.lst
my_find_lang pg_ctl-%{majorversion}
cat pg_ctl-%{majorversion}.lang >> server.lst
my_find_lang pg_config-%{majorversion}
cat pg_config-%{majorversion}.lang > main.lst
my_find_lang pg_dump-%{majorversion}
cat pg_dump-%{majorversion}.lang >> main.lst
my_find_lang pg_resetwal-%{majorversion}
cat pg_resetwal-%{majorversion}.lang >> server.lst
my_find_lang pgscripts-%{majorversion}
cat pgscripts-%{majorversion}.lang >> main.lst
%if %plperl
my_find_lang plperl-%{majorversion}
cat plperl-%{majorversion}.lang > plperl.lst
%endif
my_find_lang plpgsql-%{majorversion}
cat plpgsql-%{majorversion}.lang >> server.lst
%if %plpython
my_find_lang plpython-%{majorversion}
cat plpython-%{majorversion}.lang > plpython.lst
%endif
%if %pltcl
my_find_lang pltcl-%{majorversion}
cat pltcl-%{majorversion}.lang > pltcl.lst
%endif
my_find_lang postgres-%{majorversion}
cat postgres-%{majorversion}.lang >> server.lst
my_find_lang psql-%{majorversion}
cat psql-%{majorversion}.lang >> main.lst
my_find_lang pg_amcheck-%{majorversion}
cat pg_amcheck-%{majorversion}.lang >> contrib.lst
my_find_lang pg_archivecleanup-%{majorversion}
cat pg_archivecleanup-%{majorversion}.lang >> contrib.lst
my_find_lang pg_test_timing-%{majorversion}
cat pg_test_timing-%{majorversion}.lang>> contrib.lst
my_find_lang pg_test_fsync-%{majorversion}
cat pg_test_fsync-%{majorversion}.lang>> contrib.lst
my_find_lang pg_waldump-%{majorversion}
cat pg_waldump-%{majorversion}.lang>> contrib.lst
my_find_lang pg_rewind-%{majorversion}
cat pg_rewind-%{majorversion}.lang >> server.lst
my_find_lang pg_checksums-%{majorversion}
cat pg_checksums-%{majorversion}.lang >> server.lst
my_find_lang pg_verifybackup-%{majorversion}
cat pg_verifybackup-%{majorversion}.lang >> server.lst
my_find_lang pg_upgrade-%{majorversion}
cat pg_upgrade-%{majorversion}.lang >> main.lst


%pre -n %{name}%{majorversion}-server
# add the "postgres" group only if it does not yet exist
result=`/usr/sbin/lsgroup postgres | /usr/bin/awk '{ print $1 }' 2>/dev/null`
if [[ "${result}" != "postgres" ]] ; then
    /usr/bin/mkgroup -A id=%{postgres_gid} postgres 2> /dev/null || :
fi
# add the "postgres" user only if it does not yet exist
result=`/usr/sbin/lsuser postgres| /usr/bin/awk '{ print $1 }' 2>/dev/null`
if [[ "${result}" != "postgres" ]] ; then
    /usr/bin/mkuser id=%{postgres_uid} pgrp='postgres' gecos='PostgreSQL Server' \
        home='/var/lib/%{name}' \
        login='true' rlogin='true' postgres 2> /dev/null || :
fi


%preun -n %{name}%{majorversion}-server
if [ $1 = 0 ] ; then
    /etc/rc.d/init.d/%{name} stop >/dev/null 2>&1
# remove "postgres" user and group
/usr/sbin/rmuser -p postgres || :
/usr/sbin/rmgroup postgres || :
fi


%postun -n %{name}%{majorversion}-server
if [ $1 -ge 1 ] ; then
    /etc/rc.d/init.d/%{name} condrestart >/dev/null 2>&1 || :
fi


# FILES section.

%files -n %{name}%{majorversion} -f 32bit/main.lst
%defattr(-,root,system)
%doc 32bit/doc/KNOWN_BUGS 32bit/doc/MISSING_FEATURES 32bit/doc/TODO
%doc 32bit/COPYRIGHT 32bit/README.md 32bit/HISTORY
%doc 32bit/README.rpm-dist
%{_bindir}/clusterdb*
%{_bindir}/createdb*
%{_bindir}/createuser*
%{_bindir}/dropdb*
%{_bindir}/dropuser*
%{_bindir}/pg_config*
%{_bindir}/pg_dump*
# %{_bindir}/pg_dumpall*
%{_bindir}/pg_isready*
%{_bindir}/pg_restore*
%{_bindir}/pg_upgrade*
%{_bindir}/psql*
%{_bindir}/reindexdb*
%{_bindir}/vacuumdb*
%{_bindir}/%{name}-switch-to-*.sh

#%dir %{_libdir}/%{name}
#%dir %{_libdir64}/%{name}

%{_mandir}/man1/clusterdb.*
%{_mandir}/man1/createdb.*
%{_mandir}/man1/createuser.*
%{_mandir}/man1/dropdb.*
%{_mandir}/man1/dropuser.*
%{_mandir}/man1/pg_dump.*
%{_mandir}/man1/pg_dumpall.*
%{_mandir}/man1/pg_isready.*
%{_mandir}/man1/pg_restore.*
%{_mandir}/man1/pg_upgrade.*
%{_mandir}/man1/psql.*
%{_mandir}/man1/reindexdb.*
%{_mandir}/man1/vacuumdb.*
%{_mandir}/man7/*

# Dynamic library
#%{_libdir}/libecpg.a
#%{_libdir}/libecpg.so*
#%{_libdir64}/libecpg.so*
#%{_libdir}/libecpg_compat.a
#%{_libdir}/libecpg_compat.so*
#%{_libdir64}/libecpg_compat.so*
#%{_libdir}/libpgtypes.a
#%{_libdir}/libpgtypes.so*
#%{_libdir64}/libpgtypes.so*
#%{_libdir}/libpq.a
#%{_libdir}/libpq.so*
#%{_libdir64}/libpq.so*
# Statics library
#%{_libdir}/libpgcommon.a
#%{_libdir64}/libpgcommon.a
#%{_libdir}/libpgport.a
#%{_libdir64}/libpgport.a
#%{_libdir}/libpgfeutils.a
#%{_libdir64}/libpgfeutils.a


# link from lib64 to lib for dynamics lybrary
#%{_libdir64}/libpq.a
#%{_libdir64}/libecpg.a
#%{_libdir64}/libecpg_compat.a
#%{_libdir64}/libpgtypes.a


%files -n %{name}%{majorversion}-docs
%defattr(-,root,system)
%doc 32bit/*-US.pdf
%doc 32bit/doc/html
%{_libdir}/%{name}/tutorial/


%files -n %{name}%{majorversion}-contrib -f 32bit/contrib.lst
%defattr(-,root,system)
%doc 32bit/contrib/spi/*.example
%{_bindir}/oid2name*
%{_bindir}/pg_amcheck*
%{_bindir}/pg_archivecleanup*
%{_bindir}/pg_test_fsync*
%{_bindir}/pg_test_timing*
%{_bindir}/pg_waldump*

%{_bindir}/pg_walsummary
%{_bindir}/pg_combinebackup

%{_bindir}/pgbench*
%{_bindir}/vacuumlo*

%{_datadir}/%{name}/extension/amcheck*
%{_datadir}/%{name}/extension/autoinc*
%{_datadir}/%{name}/extension/bloom*
%{_datadir}/%{name}/extension/btree_gin*
%{_datadir}/%{name}/extension/btree_gist*
%{_datadir}/%{name}/extension/citext*
%{_datadir}/%{name}/extension/cube*
%{_datadir}/%{name}/extension/dblink*
%{_datadir}/%{name}/extension/dict_int*
%{_datadir}/%{name}/extension/dict_xsyn*
%{_datadir}/%{name}/extension/earthdistance*
%{_datadir}/%{name}/extension/file_fdw*
%{_datadir}/%{name}/extension/fuzzystrmatch*
%{_datadir}/%{name}/extension/hstore*
%{_datadir}/%{name}/extension/insert_username*
%{_datadir}/%{name}/extension/intagg*
%{_datadir}/%{name}/extension/intarray*
%{_datadir}/%{name}/extension/isn*
%{_datadir}/%{name}/extension/lo*
%{_datadir}/%{name}//extension/pg_logicalinspect*
%{_datadir}/%{name}/extension/ltree*
%{_datadir}/%{name}/extension/moddatetime*
%{_datadir}/%{name}/extension/pageinspect*
%{_datadir}/%{name}/extension/pg_buffercache*
%{_datadir}/%{name}/extension/pg_freespacemap*
%{_datadir}/%{name}/extension/pg_prewarm*
%{_datadir}/%{name}/extension/pg_stat_statements*
%{_datadir}/%{name}/extension/pg_surgery*
%{_datadir}/%{name}/extension/pg_trgm*
%{_datadir}/%{name}/extension/pg_visibility*
%{_datadir}/%{name}/extension/pg_walinspect*
%{_datadir}/%{name}/extension/pgcrypto*
%{_datadir}/%{name}/extension/pgrowlocks*
%{_datadir}/%{name}/extension/pgstattuple*
%{_datadir}/%{name}/extension/postgres_fdw*
%{_datadir}/%{name}/extension/refint*
%{_datadir}/%{name}/extension/seg*
%{_datadir}/%{name}/extension/tablefunc*
%{_datadir}/%{name}/extension/tcn*
%{_datadir}/%{name}/extension/tsm_system_rows*
%{_datadir}/%{name}/extension/tsm_system_time*
%{_datadir}/%{name}/extension/unaccent*
%{_libdir}/%{name}/_int.so
%{_libdir64}/%{name}/_int.so
%{_libdir}/%{name}/amcheck.so
%{_libdir64}/%{name}/amcheck.so
%{_libdir}/%{name}/auth_delay.so
%{_libdir64}/%{name}/auth_delay.so
%{_libdir}/%{name}/auto_explain.so
%{_libdir64}/%{name}/auto_explain.so
%{_libdir}/%{name}/autoinc.so
%{_libdir64}/%{name}/autoinc.so
%{_libdir}/%{name}/bloom.so
%{_libdir64}/%{name}/bloom.so
%{_libdir}/%{name}/btree_gin.so
%{_libdir64}/%{name}/btree_gin.so
%{_libdir}/%{name}/btree_gist.so
%{_libdir64}/%{name}/btree_gist.so
%{_libdir}/%{name}/citext.so
%{_libdir64}/%{name}/citext.so
%{_libdir}/%{name}/cube.so
%{_libdir64}/%{name}/cube.so

%{_libdir64}/%{name}/dblink.so
%{_libdir}/%{name}/dict_int.so
%{_libdir64}/%{name}/dict_int.so
%{_libdir}/%{name}/dict_xsyn.so
%{_libdir64}/%{name}/dict_xsyn.so
%{_libdir}/%{name}/earthdistance.so
%{_libdir64}/%{name}/earthdistance.so
%{_libdir}/%{name}/file_fdw.so
%{_libdir64}/%{name}/file_fdw.so
%{_libdir}/%{name}/fuzzystrmatch.so
%{_libdir64}/%{name}/fuzzystrmatch.so
%{_libdir}/%{name}/hstore.so
%{_libdir64}/%{name}/hstore.so
%if %plperl
%{_libdir}/%{name}/hstore_plperl.so
%{_libdir64}/%{name}/hstore_plperl.so
%{_libdir}/%{name}/jsonb_plperl.so
%{_libdir64}/%{name}/jsonb_plperl.so
%endif
%if %plpython
%{_libdir}/%{name}/hstore_plpython3.so
%{_libdir64}/%{name}/hstore_plpython3.so
%{_libdir}/%{name}/ltree_plpython3.so
%{_libdir64}/%{name}/ltree_plpython3.so
%{_libdir}/%{name}/jsonb_plpython3.so
%{_libdir64}/%{name}/jsonb_plpython3.so
%endif
%{_libdir}/%{name}/insert_username.so
%{_libdir64}/%{name}/insert_username.so
%{_libdir}/%{name}/isn.so
%{_libdir64}/%{name}/isn.so
%{_libdir}/%{name}/lo.so
%{_libdir64}/%{name}/lo.so
%{_libdir}/%{name}/ltree.so
%{_libdir64}/%{name}/ltree.so

%{_libdir}/%{name}/pg_logicalinspect.so
%{_libdir64}/%{name}/pg_logicalinspect.so

%{_libdir}/%{name}/pg_overexplain.so
%{_libdir64}/%{name}/pg_overexplain.so

%{_libdir}/%{name}/moddatetime.so
%{_libdir64}/%{name}/moddatetime.so

%{_libdir}/%{name}/pageinspect.so
%{_libdir64}/%{name}/pageinspect.so

%{_libdir}/%{name}/passwordcheck.so
%{_libdir64}/%{name}/passwordcheck.so

%{_libdir}/%{name}/pg_buffercache.so
%{_libdir64}/%{name}/pg_buffercache.so
%{_libdir}/%{name}/pg_freespacemap.so
%{_libdir64}/%{name}/pg_freespacemap.so
%{_libdir}/%{name}/pg_stat_statements.so
%{_libdir64}/%{name}/pg_stat_statements.so
%{_libdir}/%{name}/pg_surgery.so
%{_libdir64}/%{name}/pg_surgery.so
%{_libdir}/%{name}/pg_trgm.so
%{_libdir64}/%{name}/pg_trgm.so
%{_libdir}/%{name}/pg_visibility.so
%{_libdir64}/%{name}/pg_visibility.so
%{_libdir}/%{name}/pg_walinspect.so
%{_libdir64}/%{name}/pg_walinspect.so
%{_libdir}/%{name}/pgcrypto.so
%{_libdir64}/%{name}/pgcrypto.so
%{_libdir}/%{name}/pgrowlocks.so
%{_libdir64}/%{name}/pgrowlocks.so
%{_libdir}/%{name}/pgstattuple.so
%{_libdir64}/%{name}/pgstattuple.so
%{_libdir}/%{name}/postgres_fdw.so
%{_libdir64}/%{name}/postgres_fdw.so
%{_libdir}/%{name}/refint.so
%{_libdir64}/%{name}/refint.so
%{_libdir}/%{name}/seg.so
%{_libdir64}/%{name}/seg.so
%{_libdir}/%{name}/tablefunc.so
%{_libdir64}/%{name}/tablefunc.so
%{_libdir}/%{name}/tcn.so
%{_libdir64}/%{name}/tcn.so
%{_libdir}/%{name}/test_decoding.so
%{_libdir64}/%{name}/test_decoding.so
%{_libdir}/%{name}/tsm_system_rows.so
%{_libdir64}/%{name}/tsm_system_rows.so
%{_libdir}/%{name}/tsm_system_time.so
%{_libdir64}/%{name}/tsm_system_time.so
%{_libdir}/%{name}/unaccent.so
%{_libdir64}/%{name}/unaccent.so
%{_libdir}/%{name}/basebackup_to_shell.so
%{_libdir64}/%{name}/basebackup_to_shell.so
%{_libdir}/%{name}/basic_archive.so
%{_libdir64}/%{name}/basic_archive.so
%{_mandir}/man1/oid2name.*
%{_mandir}/man1/pg_archivecleanup.*
%{_mandir}/man1/pg_recvlogical.*
%{_mandir}/man1/pg_test_fsync.*
%{_mandir}/man1/pg_test_timing.*
%{_mandir}/man1/pg_waldump.*
%{_mandir}/man1/pgbench.*
%{_mandir}/man1/pg_amcheck.*
%{_mandir}/man1/vacuumlo.*
%{_mandir}/man3/dblink*

%if %ssl
%{_datadir}/%{name}/extension/sslinfo*
%{_libdir}/%{name}/sslinfo.so
%{_libdir64}/%{name}/sslinfo.so
%endif

%if %xml
%{_datadir}/%{name}/extension/xml2*
%{_libdir}/%{name}/pgxml.so
%{_libdir64}/%{name}/pgxml.so
%endif

%files -n %{name}%{majorversion}-libs -f 32bit/libs.lst
%defattr(-,root,system)
%doc 32bit/COPYRIGHT

%dir %{_libdir}/%{name}
%dir %{_libdir64}/%{name}

# Dynamic library
%{_libdir}/libecpg.a
%{_libdir}/libecpg.so*
%{_libdir64}/libecpg.so*
%{_libdir}/libecpg_compat.a
%{_libdir}/libecpg_compat.so*
%{_libdir64}/libecpg_compat.so*
%{_libdir}/libpgtypes.a
%{_libdir}/libpgtypes.so*
%{_libdir64}/libpgtypes.so*
%{_libdir}/libpq.a
%{_libdir}/libpq.so*
%{_libdir64}/libpq.so*
# Statics library
%{_libdir}/libpgcommon.a
%{_libdir64}/libpgcommon.a
%{_libdir}/libpgcommon_shlib.a
%{_libdir64}/libpgcommon_shlib.a
%{_libdir}/libpgport.a
%{_libdir64}/libpgport.a
%{_libdir}/libpgport_shlib.a
%{_libdir64}/libpgport_shlib.a
%{_libdir}/libpgfeutils.a
%{_libdir64}/libpgfeutils.a
# link from lib64 to lib for dynamics lybrary
%{_libdir64}/libpq.a
%{_libdir64}/libecpg.a
%{_libdir64}/libecpg_compat.a
%{_libdir64}/libpgtypes.a

%files -n %{name}%{majorversion}-server -f 32bit/server.lst
%defattr(-,root,system)
/etc/rc.d/init.d/postgresql
%attr (755,root,system) %dir /etc/sysconfig/%{name}
%{_bindir}/initdb*
%{_bindir}/pg_basebackup*
%{_bindir}/pg_checksums*
%{_bindir}/pg_controldata*
%{_bindir}/pg_ctl*
%{_bindir}/pg_receivewal*
%{_bindir}/pg_recvlogical*
%{_bindir}/pg_resetwal*
%{_bindir}/pg_rewind*
%{_bindir}/pg_verifybackup*
%{_bindir}/postgres*
%{_bindir}/postmaster*

%{_bindir}/pg_createsubscriber

%{_libdir}/%{name}/dict_snowball.so
%{_libdir64}/%{name}/dict_snowball.so
%{_libdir}/%{name}/plpgsql.so
%{_libdir64}/%{name}/plpgsql.so
%{_libdir}/%{name}/libpqwalreceiver.so
%{_libdir64}/%{name}/libpqwalreceiver.so
%{_libdir}/%{name}/pg_prewarm.so
%{_libdir64}/%{name}/pg_prewarm.so
%{_libdir}/%{name}/*_and_*.so
%{_libdir64}/%{name}/*_and_*.so
%{_libdir}/%{name}/euc2004_sjis2004.so
%{_libdir64}/%{name}/euc2004_sjis2004.so


%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*.sample
%dir %{_datadir}/%{name}/extension
%{_datadir}/%{name}/extension/plpgsql*
%{_datadir}/%{name}/information_schema.sql
%{_datadir}/%{name}/postgres.bki
%{_datadir}/%{name}/snowball_create.sql
%{_datadir}/%{name}/sql_features.txt
%{_datadir}/%{name}/system_views.sql
%{_datadir}/%{name}/system_constraints.sql
%{_datadir}/%{name}/system_functions.sql
%{_datadir}/%{name}/timezone/
%{_datadir}/%{name}/timezonesets/
%{_datadir}/%{name}/tsearch_data/

# %attr(700,postgres,postgres) %dir /var/lib/%{name}
# %attr(700,postgres,postgres) %dir /var/lib/%{name}/data
# %attr(700,postgres,postgres) %dir /var/lib/%{name}/backups
# %attr(644,postgres,postgres) %config(noreplace) /var/lib/%{name}/.bash_profile

%{_mandir}/man1/initdb.*
%{_mandir}/man1/pg_basebackup.*
%{_mandir}/man1/pg_controldata.*
%{_mandir}/man1/pg_ctl.*
%{_mandir}/man1/pg_receivewal.*
%{_mandir}/man1/pg_resetwal.*
%{_mandir}/man1/pg_rewind.*
%{_mandir}/man1/postgres.*
%{_mandir}/man1/pg_checksums.*
%{_mandir}/man1/pg_verifybackup.*
%{_mandir}/man1/postgres.*

%{_mandir}/man1/pg_walsummary.*
%{_mandir}/man1/pg_combinebackup.*
%{_mandir}/man1/pg_createsubscriber.*

# %{_tmpfilesdir}/postgresql.conf
# %{_unitdir}/postgresql.service
# %{_unitdir}/postgresql@.service
%attr(700,postgres,postgres) %dir /var/lib/%{name}
%attr(644,postgres,postgres) %config(noreplace) /var/lib/%{name}/.bash_profile
%attr(700,postgres,postgres) %dir /var/lib/%{name}/backups
%attr(700,postgres,postgres) %dir /var/lib/%{name}/data

%files -n %{name}%{majorversion}-devel -f 32bit/devel.lst
%defattr(-,root,system)
%{_bindir}/ecpg*
%{_bindir}/pg_config*

%{_includedir}/*

## %{_libdir}/libecpg.so

## %{_libdir64}/libecpg.so
## %{_libdir}/libecpg_compat.so
## %{_libdir64}/libecpg_compat.so
## %{_libdir}/libpgtypes.so
## %{_libdir64}/libpgtypes.so
## %{_libdir}/libpq.so
## %{_libdir64}/libpq.so
%{_libdir}/%{name}/pgxs/
%{_libdir64}/%{name}/pgxs/
%{_libdir}/pkgconfig/*.pc
%{_libdir64}/pkgconfig/*.pc
%{_libdir}/%{name}/postgres.imp
%{_libdir64}/%{name}/postgres.imp

%{_mandir}/man1/ecpg.*
%{_mandir}/man1/pg_config.*
%{_mandir}/man3/SPI_*



%if %plperl
%files -n %{name}%{majorversion}-plperl -f 32bit/plperl.lst
%defattr(-,root,system)
%{_datadir}/%{name}/extension/plperl*
%{_libdir}/%{name}/plperl.so
%{_libdir64}/%{name}/plperl.so
%{_libdir}/%{name}/bool_plperl.so
%{_libdir64}/%{name}/bool_plperl.so
%endif


%if %pltcl
%files -n %{name}%{majorversion}-pltcl -f  32bit/pltcl.lst
%defattr(-,root,system)
%{_datadir}/%{name}/extension/pltcl*
%{_libdir}/%{name}/pltcl.so
%{_libdir64}/%{name}/pltcl.so
%endif

%if %plpython
%files -n %{name}%{majorversion}-plpython3 -f 32bit/plpython.lst
%defattr(-,root,system)
%{_datadir}/%{name}/extension/plpython3*
%{_datadir}/%{name}/extension/plpython3u*
%{_libdir}/%{name}/plpython3.so
%{_libdir64}/%{name}/plpython3.so
%endif


%if %test
%files -n %{name}%{majorversion}-test
%defattr(-,postgres,postgres)
%attr(-,postgres,postgres) %dir %{_libdir}/%{name}/test
%attr(-,postgres,postgres) %dir %{_libdir64}/%{name}/test
%attr(-,postgres,postgres) %{_libdir}/%{name}/test/*
%attr(-,postgres,postgres) %{_libdir64}/%{name}/test/*
%exclude  %{_libdir64}/%{name}/test/regress/tmp_check/
%exclude  %{_libdir}/%{name}/test/regress/tmp_check/
%endif

%changelog
* Tue Mar 03 2026 Aditya Kamath <Aditya.Kamath1@ibm.com> - 18.3
- Update CVE-2026-2003, CVE-2026-2004, CVE-2026-2006, CVE-2026-2005

* Thu Oct 23 2025 Aditya Kamath <Aditya.Kamath1@ibm.com> - 18.0
- Update to postgres 18.
- No more admin pack. https://www.postgresql.org/docs/16/adminpack.html

* Tue Jun 17 2025 Reshma V Kumar <reskumar@in.ibm.com> -15.13-1
- Update to 15.13 to fix CVE-2025-1094,CVE-2025-4207
- Build with openssl 3

* Fri Jan 10 2025 Reshma V Kumar <reskumar@in.ibm.com> - 15.10-1 
- Update to version 15.10 to fix CVE-2024-10976,CVE-2024-10978,CVE-2024-10977,CVE-2024-10979

* Tue Oct 08 2024 Parth Patel <parth.patel7@ibm.com> - 15.8-1 
- Update to version 15.8 to fix CVE-2024-7348

* Wed May 22 2024 Parth Patel <parth.patel7@ibm.com> - 15.6-1 
- Update to version 15.6 to fix CVE-2024-0985

* Thu Feb 29 2024 Reshma V Kumar <reskumar@in.ibm.com> - 15.5-1 
- Update to version 15.5 to fix CVE-2023-5869,CVE-2023-5868,CVE-2023-5870

* Thu Nov 23 2023 Reshma V Kumar <reskumar@in.ibm.com> - 15.4-1
- Update to version 15.4

* Mon Jul 17 2023 Aditya Kamath <Aditya.Kamath1@ibm.com> - 11.20-1
- Update to fix CVE-E-2023-2454

* Fri May 26 2023 Reshma V Kumar <reskumar@in.ibm.com> - 11.19-1
- Update to fix CVE-2022-41862

* Wed Apr 26 2023 Reshma V Kumar <reskumar@in.ibm.com> - 11.18-2
- Rebuild with python3.9

* Thu Jan 12 2023 Reshma V Kumar <reskumar@in.ibm.com> - 11.18-1
- Update to fix CVE-2022-2625, CVE-2022-1552
- Build with openldap 2.5.12

* Thu Dec 16 2021 Reshma V Kumar <reskumar@in.ibm.com> - 11.14-1
- Update to fix CVE-2021-23214 	

* Mon Jul 19 2021 Reshma V Kumar <reskumar@in.ibm.com> - 11.12-1
- Update to fix CVE-2021-32027,CVE-2021-32028

* Fri Jun 04 2021 Reshma V Kumar <reskumar@in.ibm.com> - 11.11-1
- Update to fix CVE-2021-20229
- Build with tcl-8.6.11

* Fri Jan 15 2021 Reshma V Kumar <reskumar@in.ibm.com> - 11.10-1
- Update to fix CVE-2020-25694,CVE-2020-25695,CVE-2020-25696
- Build with python3

* Wed Nov 18 2020 Reshma V Kumar <reskumar@in.ibm.com> - 11.9-1
- Update to fix CVE-2020-14349,CVE-2020-14350

* Tue Jul 14 2020 Reshma V Kumar <reskumar@in.ibm.com> - 11.7-2
- Rebuild with perl 5.30.2

* Fri May 29 2020 Reshma V Kumar <reskumar@in.ibm.com> - 11.7-1
- Update to fix CVE-2020-1720

* Wed Aug 21 2019 Reshma V Kumar <reskumar@in.ibm.com> - 11.5-1
- Update to latest version

* Tue Jun 11 2019 Reshma V Kumar <reskumar@in.ibm.com> - 10.8-1
- Update to fix CVE-2019-10130,CVE-2019-10127, CVE-2019-10129, CVE-2019-10128
- Build with 0001-Add-shared_memory_type-GUC.patch

* Tue Jan 08 2019 Reshma V Kumar <reskumar@in.ibm.com> - 10.6-1
- Update to fix CVE-2018-16850

* Thu Sep 27 2018 Reshma V Kumar <reskumar@in.ibm.com> - 10.5-1
- Update to fix security vulnerability

* Thu Jun 07 2018 Reshma V Kumar <reskumar@in.ibm.com> - 10.4-1
- Update to fix security vulnerability

* Tue Mar 01 2018 Tony Reix <tony.reix@atos.net> - 10.3-1
- Update to version 10.3 .

* Tue Feb 27 2018 Tony Reix <tony.reix@atos.net> - 10.2-3
- Fix perf issue with XLC: See patch: ForTprof.patch
- Fix issue for tprof: See patch: NoKill.patch

* Mon Feb 12 2018 Tony Reix <tony.reix@atos.net> - 10.2-2
- Manage GCC for 32bit & Perl by: postgresql.....perl_32bit_NoXLC.ksh

* Fri Feb 09 2018 Tony Reix <tony.reix@atos.net> - 10.2-1
- Update to version 10.2 .

* Thu Feb 08 2018 Tony Reix <tony.reix@atos.net> - 10.1-3
- Compile with GCC.

* Wed Nov 08 2017 Pascal Oliva <pascal.oliva@atos.net> - 10.1-2
- Updated to version 10.1 .

* Tue Jun 27 2017 Tony Reix <tony.reix@bull.net> - 10beta1-1
- Updated to version 10beta1 .

* Fri Mar 17 2017 Tony Reix <tony.reix@bull.net> - 9.6.2-1
- Updated to version 9.6.2 .

* Tue Mar 07 2017 Jean Girardet <jean.girardet@atos.net> - 9.6.1-2
- Add  --enable-tap-tests to configire.

* Tue Jan 31 2017 Tony Reix <tony.reix@bull.net> - 9.6.1-1
- Updated to version 9.6.1 .

* Mon Jan 30 2017 Tony Reix <tony.reix@bull.net> - 9.6.0-7
- Add more tests

* Thu Jan 26 2017 Tony Reix <tony.reix@bull.net> - 9.6.0-6
- Use xlc 13.0.3 . Remove xlC which is unused

* Tue Jan 25 2017 Tony Reix <tony.reix@bull.net> - 9.6.0-5
- Add aix 7.2

* Tue Jan 24 2017 Tony Reix <tony.reix@bull.net> - 9.6.0-4
- Add strip -e
- /opt/freeware/bin/perl_64bit_NoXLC mess. Just adding comments for now.

* Mon Nov 14 2016 Jean Girardet <jean.girardet@atos.net> - 9.6.0-3
- Add postgresql/test/regress/libregress.a

* Wed Oct 26 2016 Jean Girardet <jean.girardet@atos.net> - 9.6.0-2
- Updated to version 9.6.0

* Wed Oct 26 2016 Tony Reix <tony.reix@bull.net> - 9.6.0-1
- Updated to version 9.6.0

* Thu Jul 24 2014 Michael Perzl <michael@perzl.org> - 9.3.5-1
- updated to version 9.3.5

* Mon Mar 24 2014 Michael Perzl <michael@perzl.org> - 9.3.4-1
- updated to version 9.3.4

* Mon Feb 24 2014 Michael Perzl <michael@perzl.org> - 9.3.3-1
- updated to version 9.3.3

* Mon Feb 24 2014 Michael Perzl <michael@perzl.org> - 9.3.2-1
- updated to version 9.3.2

* Mon Feb 24 2014 Michael Perzl <michael@perzl.org> - 9.3.1-1
- updated to version 9.3.1

* Mon Feb 24 2014 Michael Perzl <michael@perzl.org> - 9.3.0-1
- updated to version 9.3.0

* Mon Feb 17 2014 Michael Perzl <michael@perzl.org> - 9.2.6-2
- changed build process to individual AIX versions
- fixed the rc.d/init.d init script

* Fri Dec 06 2013 Michael Perzl <michael@perzl.org> - 9.2.6-1
- updated to version 9.2.6

* Mon Oct 14 2013 Michael Perzl <michael@perzl.org> - 9.2.5-1
- updated to version 9.2.5

* Thu Apr 04 2013 Michael Perzl <michael@perzl.org> - 9.2.4-1
- updated to version 9.2.4

* Thu Feb 07 2013 Michael Perzl <michael@perzl.org> - 9.2.3-1
- updated to version 9.2.3

* Wed Dec 12 2012 Michael Perzl <michael@perzl.org> - 9.2.2-1
- updated to version 9.2.2

* Fri Dec 07 2012 Michael Perzl <michael@perzl.org> - 9.2.1-2
- added missing 64-bit shared objects to archive libraries
- added symlinks to easily switch between the 32-bit and 64-bit version

* Tue Sep 25 2012 Michael Perzl <michael@perzl.org> - 9.2.1-1
- updated to version 9.2.1

* Tue Sep 25 2012 Michael Perzl <michael@perzl.org> - 9.2.0-1
- updated to version 9.2.0

* Mon Aug 27 2012 Michael Perzl <michael@perzl.org> - 9.1.5-1
- updated to version 9.1.5

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.1.4-1
- updated to version 9.1.4

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.1.3-1
- updated to version 9.1.3

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.1.2-1
- updated to version 9.1.2

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.1.1-1
- updated to version 9.1.1

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.1.0-1
- updated to version 9.1.0

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.0.8-1
- updated to version 9.0.8

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.0.7-1
- updated to version 9.0.7

* Thu Jun 28 2012 Michael Perzl <michael@perzl.org> - 9.0.6-1
- updated to version 9.0.6

* Fri Apr 20 2012 Michael Perzl <michael@perzl.org> - 9.0.5-1
- updated to version 9.0.5

* Wed Aug 25 2011 Michael Perzl <michael@perzl.org> - 9.0.4-1
- updated to version 9.0.4

* Wed Aug 25 2011 Michael Perzl <michael@perzl.org> - 9.0.3-1
- updated to version 9.0.3

* Wed Mar 16 2011 Michael Perzl <michael@perzl.org> - 8.4.7-1
- first version for AIX V5.1 and higher
