From 0d1c7585332c58bde922f257b952283aabca1e9d Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Fri, 22 Sep 2023 10:26:21 +0200
Subject: use official Oracle Instant Client RPM

---
 php-5.6.3-oci8conf.patch | 35 ++++++++++++++++++-----------------
 php.spec                 | 30 +++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/php-5.6.3-oci8conf.patch b/php-5.6.3-oci8conf.patch
index f2d8f99..0f923f7 100644
--- a/php-5.6.3-oci8conf.patch
+++ b/php-5.6.3-oci8conf.patch
@@ -10,28 +10,29 @@ diff -up php5.3-201104170830/ext/ldap/php_ldap.h.remi-oci8 php5.3-201104170830/e
  
  extern zend_module_entry ldap_module_entry;
  #define ldap_module_ptr &ldap_module_entry
-diff -up php5.3-201104170830/ext/oci8/config.m4.remi-oci8 php5.3-201104170830/ext/oci8/config.m4
---- php5.3-201104170830/ext/oci8/config.m4.remi-oci8	2011-03-30 00:35:22.000000000 +0200
-+++ php5.3-201104170830/ext/oci8/config.m4	2011-04-17 11:55:25.628871315 +0200
-@@ -376,6 +376,7 @@ if test "$PHP_OCI8" != "no"; then
- 
-     dnl Header directory for Instant Client SDK RPM install
-     OCISDKRPMINC=`echo "$PHP_OCI8_INSTANT_CLIENT" | $PHP_OCI8_SED -e 's!^/usr/lib/oracle/\(.*\)/client\('${PHP_OCI8_IC_LIBDIR_SUFFIX}'\)*/lib[/]*$!/usr/include/oracle/\1/client\2!'`
-+    OCISDKRPMINC=`echo "$PHP_OCI8_INSTANT_CLIENT" | $PHP_OCI8_SED -e 's!^/usr/\(lib64\|lib\)/oracle/\(.*\)/\(client64\|client\)/lib[/]*$!/usr/include/oracle/\2/\3!'`
- 
-     dnl Header directory for Instant Client SDK zip file install
-     OCISDKZIPINC=$PHP_OCI8_INSTANT_CLIENT/sdk/include
-diff -up php5.3-201104170830/ext/pdo_oci/config.m4.remi-oci8 php5.3-201104170830/ext/pdo_oci/config.m4
---- php5.3-201104170830/ext/pdo_oci/config.m4.remi-oci8	2011-04-02 04:35:24.000000000 +0200
-+++ php5.3-201104170830/ext/pdo_oci/config.m4	2011-04-17 12:02:42.837194120 +0200
-@@ -104,8 +104,10 @@ You need to tell me where to find your O
+diff -up ./ext/pdo_oci/config.m4.remi-oci8 ./ext/pdo_oci/config.m4
+--- ./ext/pdo_oci/config.m4.remi-oci8	2019-10-22 18:59:47.000000000 +0200
++++ ./ext/pdo_oci/config.m4	2023-09-22 09:49:00.888471382 +0200
+@@ -104,7 +104,10 @@ You need to tell me where to find your O
+       fi
+     fi
+     AC_MSG_CHECKING([for oci.h])
+-    if test -f $PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/oci.h ; then
++    if test -f $PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_MAJ_VER/$PDO_OCI_CLIENT_DIR/oci.h ; then
++      PHP_ADD_INCLUDE($PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_MAJ_VER/$PDO_OCI_CLIENT_DIR)
++      AC_MSG_RESULT($PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_MAJ_VER/$PDO_OCI_CLIENT_DIR)
++    elif test -f $PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/oci.h ; then
+       PHP_ADD_INCLUDE($PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR)
+       AC_MSG_RESULT($PDO_OCI_IC_PREFIX/include/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR)
+     elif test -f $PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/include/oci.h ; then
+@@ -119,8 +122,10 @@ You need to tell me where to find your O
      else
        AC_MSG_ERROR([I'm too dumb to figure out where the include dir is in your Instant Client install])
      fi
 -    if test -f "$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME" ; then
 -    PDO_OCI_LIB_DIR="$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib"
-+    if test -f "$PDO_OCI_IC_PREFIX/lib64/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME" ; then
-+      PDO_OCI_LIB_DIR="$PDO_OCI_IC_PREFIX/lib64/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib"
++    if test -f "$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_MAJ_VER/$PDO_OCI_CLIENT_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME" ; then
++      PDO_OCI_LIB_DIR="$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_MAJ_VER/$PDO_OCI_CLIENT_DIR/lib"
 +    elif test -f "$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME" ; then
 +      PDO_OCI_LIB_DIR="$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/$PDO_OCI_CLIENT_DIR/lib"
      elif test -f "$PDO_OCI_IC_PREFIX/$PDO_OCI_CLIENT_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME" ; then
diff --git a/php.spec b/php.spec
index 6850d79..26920ea 100644
--- a/php.spec
+++ b/php.spec
@@ -55,8 +55,15 @@
 
 %global mysql_sock %(mysql_config --socket  2>/dev/null || echo /var/lib/mysql/mysql.sock)
 
-%global oraclever 21.10
+%ifarch aarch64
+%global oraclever 19.19
+%global oraclelib 19.1
+%global oracledir 19.19
+%else
+%global oraclever 21.11
 %global oraclelib 21.1
+%global oracledir 21
+%endif
 
 # Build for LiteSpeed Web Server (LSAPI)
 %global with_lsws     1
@@ -648,15 +655,20 @@ Summary:        A module for PHP applications that use OCI8 databases
 Group:          Development/Languages
 # All files licensed under PHP version 3.01
 License:        PHP
+%ifarch aarch64
+BuildRequires:  oracle-instantclient%{oraclever}-devel
+# Should requires libclntsh.so.19.1()(aarch-64), but it's not provided by Oracle RPM.
+Requires:       libclntsh.so.%{oraclelib}
+AutoReq:        0
+%else
 BuildRequires:  oracle-instantclient-devel >= %{oraclever}
+%endif
 Requires:       %{?scl_prefix}php-pdo%{?_isa} = %{version}-%{release}
 Provides:       %{?scl_prefix}php_database
 Provides:       %{?scl_prefix}php-pdo_oci, %{?scl_prefix}php-pdo_oci%{?_isa}
 Obsoletes:      %{?scl_prefix}php-pecl-oci8 <  %{oci8ver}
 Conflicts:      %{?scl_prefix}php-pecl-oci8 >= %{oci8ver}
 Provides:       %{?scl_prefix}php-pecl(oci8) = %{oci8ver}, %{?scl_prefix}php-pecl(oci8)%{?_isa} = %{oci8ver}
-# Should requires libclntsh.so.12.1, but it's not provided by Oracle RPM.
-AutoReq:        0
 
 %description oci8
 The %{?scl_prefix}php-oci8 packages provides the OCI8 extension version %{oci8ver}
@@ -666,13 +678,9 @@ The extension is linked with Oracle client libraries %{oraclever}
 (Oracle Instant Client).  For details, see Oracle's note
 "Oracle Client / Server Interoperability Support" (ID 207303.1).
 
-You must install libclntsh.so.%{oraclelib} to use this package, provided
-in the database installation, or in the free Oracle Instant Client
-available from Oracle.
-
-Notice:
-- %{?scl_prefix}php-oci8 provides oci8 and pdo_oci extensions from php sources.
-- %{?scl_prefix}php-pecl-oci8 only provides oci8 extension.
+You must install libclntsh.so.%{oraclelib} to use this package,
+provided by Oracle Instant Client RPM available from Oracle on:
+https://www.oracle.com/database/technologies/instant-client/downloads.html
 
 Documentation is at http://php.net/oci8 and http://php.net/pdo_oci
 %endif
@@ -1290,7 +1298,7 @@ build --libdir=%{_libdir}/php \
       --with-mysqli=shared,mysqlnd \
       --with-mysql-sock=%{mysql_sock} \
 %if %{with_oci8}
-      --with-oci8=shared,instantclient,%{_root_libdir}/oracle/%{oraclever}/client64/lib,%{oraclever} \
+         --with-oci8=shared,instantclient,%{_root_prefix}/lib/oracle/%{oracledir}/client64/lib,%{oraclever} \
       --with-pdo-oci=shared,instantclient,%{_root_prefix},%{oraclever} \
 %endif
 %if %{with_interbase}
-- 
cgit