%global __tar %{_bindir}/tar
%global builddir aix
# Version with/without AIX X11
#%{!?aixX11:%define AIXX11 0}
#%{?aixX11:%define AIXX11 1}

%define AIXX11 1
%{!?dotests:%define DO_TESTS 1}
%{?dotests:%define DO_TESTS 0}

%if %{AIXX11} == 1
%define RELEASE_SUFFIX waixX11
%else
%define RELEASE_SUFFIX wofX11
%endif

%define fontconfig_version 2.8.0
%define freetype_version 2.4.2
%define pixman_version 0.30.0 
%define libpng_version 1.6
%define _libdir64 %{_libdir}64

Summary:	A vector graphics library
Name:		cairo
Version:	1.18.0
Release:	1%{RELEASE_SUFFIX}
URL:		https://cairographics.org
Source:		https://www.cairographics.org/releases/cairo-%{version}.tar.xz
Patch0:         cairo-1.14.6-aix-bigendian.patch
Patch1:         cairo-1.14.6-aix-typeof.patch
Patch2: 	logrotate-aix-missing-asprintf.patch
Patch3: 	logrotate-aix-missing-vasprintf.patch
#Patch4:         cair0-1.14.6-aix.patch
Patch5:		cairo-1.18.0-shared-lib-version-control.patch
License:	LGPL/MPL
Group:		System Environment/Libraries

BuildRequires:	pkgconfig
BuildRequires:	libXrender-devel >= 0.9.8
#BuildRequires: libxcb-devel
BuildRequires:	libpng-devel >= 1.6.37
BuildRequires:	pixman-devel >= 0.42.2
BuildRequires:	freetype2-devel >= 2.12.1
BuildRequires:	fontconfig-devel >= 2.11.95
BuildRequires:	zlib-devel >= 1.2.13
BuildRequires:	glib2-devel >= 2.76.3
BuildRequires:	lzo-devel >= 2.10
#BuildRequires: gettext-devel
%if %{AIXX11} == 1
BuildRequires:	aix-x11-pc
%else
BuildRequires:	libX11-devel
BuildRequires:	libXext-devel

Requires:	libX11
Requires:	libXext
%endif
Requires:	libXrender >= 0.9.8
#Requires: libxcbx
Requires:	libpng >= 1.6.37
Requires:	pixman >= 0.42.2
Requires:	freetype2 >= 2.12.1
Requires:	fontconfig >= 2.11.95
Requires:	zlib >= 1.2.13
Requires:	glib2 >= 2.76.3
Requires:	gettext >= 0.21
Requires:	lzo >= 2.10
%if %{toolchain} == "gcc"
Requires:       libgcc >= 10.3.0
%endif

%description 
Cairo is a vector graphics library designed to provide high-quality
display and print output. Currently supported output targets include
the X Window System, OpenGL (via glitz), in-memory image buffers, and
image files (PDF, PostScript, and SVG).  Cairo is designed to produce
identical output on all output media while taking advantage of display
hardware acceleration when available (e.g. through the X Render
Extension or OpenGL).

The library is available as 32-bit and 64-bit.
%if %{AIXX11} == 1
This package requires AIX X11.
%else
This package requires Bull Freeware X11.
%endif


%package devel
Summary: Cairo developmental libraries and header files
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires:	libXrender-devel >= 0.9.8
Requires:	libpng-devel >= 1.6.37
#Requires: libxcb-devel
Requires:	freetype2-devel >= 2.12.1
Requires:	fontconfig-devel >= 2.11.95
Requires:	zlib-devel >= 1.2.13
Requires:	glib2-devel >= 2.76.3
%if %{AIXX11} == 0
Requires:	libX11-devel
%endif

%description devel
Developmental libraries and header files required for developing or
compiling software which links to the cairo graphics library, which is
an open source vector graphics library.

%prep
echo "AIXX11=%{AIXX11}"
echo "DO_TESTS=%{DO_TESTS}"
%setup -q
#%patch0 -p 1 -b .aix
#%patch1 -p 1 -b .aix
#%patch2
#%patch3
#%patch4 -p0
%patch5 -p0

# Duplicate source for 32 & 64 bits
rm -rf /tmp/%{name}-%{version}-32bit
mkdir  /tmp/%{name}-%{version}-32bit
mv *   /tmp/%{name}-%{version}-32bit
mkdir 32bit
mv     /tmp/%{name}-%{version}-32bit/* 32bit
rm -rf /tmp/%{name}-%{version}-32bit
mkdir 64bit
cp -rp 32bit/* 64bit/

%build
export PATH=/usr/bin:/opt/freeware/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:.
export LIBPATH=
export CONFIG_SHELL=/usr/bin/ksh
export CONFIG_ENV_ARGS=/usr/bin/ksh
export RM="/usr/bin/rm -f"
#export AR="/usr/bin/ar -X32_64"
export NM="/usr/bin/nm -X32_64"
export CC="%{__cc__}"
export CXX="%{__cxx__}"

# first build the 64-bit version
cd 64bit
export CFLAGS="-maix64 -O2 -D_NO_PROTO -I/usr/lpp/X11/include/X11/extensions -Wno-error=implicit-function-declaration"
export CXXFLAGS="-maix64 -O2 -D_NO_PROTO -I/usr/lpp/X11/include/X11/extensions -Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib: -lXrender"
export OBJECT_MODE=64
meson setup %{builddir} \
  --buildtype=plain \
  --prefix=%{_prefix} \
  --libdir=%{_libdir64} \
  -Dfreetype=enabled \
  -Dfontconfig=enabled \
  -Dglib=enabled \
  -Dgtk_doc=false \
  -Dspectre=disabled \
  -Dsymbol-lookup=disabled \
  -Dtee=disabled \
  -Dtests=disabled \
  -Dxcb=disabled \
  -Dxlib=enabled \
  -Dpng=enabled \
  -Dzlib=enabled

meson compile -C %{builddir} -j8 --verbose

if [ "%{DO_TESTS}" == 1 ]
then
    ( meson test -C aix || true )
fi
cd ..


# now build the 32-bit version
cd 32bit
export OBJECT_MODE=32
export CFLAGS="-O2 -D_LARGE_FILES -D_NO_PROTO -I/usr/lpp/X11/include/X11/extensions -Wno-error=implicit-function-declaration"
export CXXFLAGS="-O2 -D_LARGE_FILES -D_NO_PROTO -I/usr/lpp/X11/include/X11/extensions -Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib: -lXrender -Wl,-bmaxdata:0x80000000"

meson setup %{builddir} \
  --buildtype=plain \
  --prefix=%{_prefix} \
  --libdir=%{_libdir} \
  -Dfreetype=enabled \
  -Dfontconfig=enabled \
  -Dglib=enabled \
  -Dgtk_doc=false \
  -Dspectre=disabled \
  -Dsymbol-lookup=disabled \
  -Dtee=disabled \
  -Dtests=disabled \
  -Dxcb=disabled \
  -Dxlib=enabled \
  -Dpng=enabled \
  -Dzlib=enabled

meson compile -C %{builddir} -j8 --verbose

if [ "%{DO_TESTS}" == 1 ]
then
    ( meson test -C aix || true )
fi

%define LINKS lib/libcairo*.a
%define LINKS_DEVEL include/cairo lib/libcairo*.la

%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
export RM="/usr/bin/rm -f"
# setup environment for 32-bit and 64-bit builds
export AR="/usr/bin/ar -X32_64"
export NM="/usr/bin/nm -X32_64"
export DESTDIR=${RPM_BUILD_ROOT}

# install 64-bit version
export OBJECT_MODE=64
cd 64bit
meson install -C %{builddir} --no-rebuild
cd ..

# Extract the 64 bit object from the lib
LIBS="libcairo
libcairo-gobject
libcairo-script-interpreter"
cd ${RPM_BUILD_ROOT}%{_libdir64}
for LIB in $LIBS; do
    /usr/bin/ar -X64 xv ${LIB}.a ${LIB}.so.2
done
cd -

# install 32-bit version
export OBJECT_MODE=32
cd 32bit
meson install -C %{builddir} --no-rebuild
cd ..

# add the 64-bit shared objects to the shared library containing already the
# 32-bit shared objects and extract the 32 bit shared object
cd ${RPM_BUILD_ROOT}%{_libdir}
for LIB in $LIBS; do
    /usr/bin/ar -q -X64 ${LIB}.a ${RPM_BUILD_ROOT}%{_libdir64}/${LIB}.so.2
    /usr/bin/ar -X32 xv ${LIB}.a ${LIB}.so.2
done
cd ${RPM_BUILD_ROOT}%{_libdir}


%files
%defattr(-,root,system,-)
%doc 32bit/AUTHORS 32bit/BIBLIOGRAPHY 32bit/BUGS 32bit/COPYING 32bit/COPYING-LGPL-2.1 32bit/COPYING-MPL-1.1 32bit/NEWS 32bit/README
%{_libdir}/libcairo*.a
%{_libdir64}/*.a


%files devel
%defattr(-,root,system,-)
%{_libdir}/pkgconfig/cairo*.pc
%{_includedir}/cairo/cairo*.h
#%{_datadir}/gtk-doc/html/cairo/*


%changelog
* Tue Jan 09 2023 Reshma V Kumar <reskumar@in.ibm.com> - 1.18.0-1 
- Update to version 1.18.0

* Wed Sep 7 2016 Ravi Hirekurabar<rhirekur@in.ibm.com> - 1.14.6-1
- Update to version 1.14.6

* Mon Oct 07 2013 Gerard Visiedo <gerard.visiedo@bull.net> - 1.12.2-3
- Rebuild due to libX11 issue

* Fri Mar 29 2013 Gerard Visiedo <gerard.visiedo@bull.net> - 1.12.2-2
- Rebuild to libXrender.a issue

* Thu Jun 21 2012 Gerard Visiedo <gerard.visiedo@bull.net> - 1.12.2-1
- Update to version 1.12.2

* Thu Feb 02 2012 Gerard Visiedo <gerard.visiedo@bull.net> - 1.8.8-4
- Initial port on Aix6.1

* Fri Oct 14 2011 Gerard Visiedo <gerard.visiedo@bull.net> - 1.8.8-3
- rebuild for compatibility with new libiconv.a 1.13.1-2

* Thu Sep 08 2011 Gerard Visiedo <gerard.visiedo@bull.net> 1.8.8-2
- Add 64-bit libraries

* Tue Nov 30 2010 Jean Noel Cordenenr <jean-noel.cordenner@bull.net> 1.8.8-1
- updated to version 1.8.8

*  Fri Nov 17 2006  BULL
 - Release  1
 - New version  version: 1.2.4
 - gnome 2.16.1

*  Mon Sep 18 2006  BULL
 - Release  5
 - support 64 bits

*  Wed Jul 26 2006  BULL
 - Release  1
 - New version  version: 1.0.2

*  Mon Feb 13 2006  BULL
 - Release 4
 - Prototype gtk 64 bit - build with type CARD32 = unsigned int
*  Fri Dec 23 2005  BULL
 - Release 3
 - Prototype gtk 64 bit
*  Tue Nov 15 2005  BULL
 - Release  2

*  Fri Nov 04 2005  BULL
 - Release  1
 - New version  version: 1.0.0

