%define _prefix /opt/freeware
%define _defaultdocdir %{_prefix}/doc

Summary: 	A library of functions for manipulating PNG image format files.
Name: 		libpng
Version: 	1.2.8
Release: 	6
Epoch:		2
License: 	OSI certified
Group: 		System Environment/Libraries
Source: 	ftp://swrinde.nde.swri.edu/pub/png/src/libpng-%{version}.tar.bz2

Patch0:		libpng-1.2.8-aix.patch
Patch1:		libpng-1.2.8-autotools.patch

Buildroot: 	%{_tmppath}/%{name}-%{version}-root
URL: 		http://www.libpng.org/pub/png/

# Use --define 'no64 1' on the command line to disable 64bit build
%{!?no64:%define BUILD64 1}
%{?no64:%define BUILD64 0}
%define prefix64 %{_prefix}/64


%description
The libpng package contains a library of functions for creating and
manipulating PNG (Portable Network Graphics) image format files.  PNG
is a bit-mapped graphics format similar to the GIF format.  PNG was
created to replace the GIF format, since GIF uses a patented data
compression algorithm.

Libpng should be installed if you need to manipulate PNG format image
files.

%package devel
Summary: 	Development tools for programs to manipulate PNG image format files.
Group: 		Development/Libraries
Requires: 	libpng = %{version}, zlib-devel

%description devel
The libpng-devel package contains the header files and static
libraries necessary for developing programs using the PNG (Portable
Network Graphics) library.

If you want to develop programs which will manipulate PNG image format
files, you should install libpng-devel.  You'll also need to install
the libpng package.

%prep
%setup -q

if test x$PATCH = x ; then
  PATCH=patch ;
fi
$PATCH -p2 -s < %{_sourcedir}/libpng-1.2.8-aix.patch
$PATCH -p2 -s < %{_sourcedir}/libpng-1.2.8-autotools.patch

%if %{BUILD64} == 1
# Prep 64-bit build in 64bit subdirectory
##########################################
# Test whether we can run a 64bit command so we don't waste our time
/usr/bin/locale64 >/dev/null 2>&1
mkdir 64bit
cd 64bit
bzip2 -dc %{SOURCE0} |tar -xf -
cd %{name}-%{version}
$PATCH -p2 -s < %{_sourcedir}/libpng-1.2.8-aix.patch
$PATCH -p2 -s < %{_sourcedir}/libpng-1.2.8-autotools.patch
%endif

# The 'install-sh' script created by the patch is not executable
chmod +x install-sh

%build
export OBJECT_MODE=32
chmod +x ./configure
chmod +x ./install-sh
CFLAGS="-I%{_includedir}" ./configure --prefix=%{_prefix}
gmake


%if %{BUILD64} == 1
# Now build again as 64bit
###########################
cd 64bit/%{name}-%{version}
export OBJECT_MODE=64
chmod +x ./configure 
chmod +x ./install-sh
export LDFLAGS="-q64"
CFLAGS="-I%{_includedir}" ./configure --prefix=%{_prefix}
gmake

# Go back to 32-bit library and add our 64bit shared object
#  into same archive
cd ../..
pwd 
/usr/bin/ar -q .libs/libpng.a ./64bit/%{name}-%{version}/.libs/libpng.so.3
/usr/bin/ar -q .libs/libpng12.a ./64bit/%{name}-%{version}/.libs/libpng12.so.0

%endif #BUILD64


%install
if test "%{buildroot}" != "/"; then
	rm -rf %{buildroot}
fi
mkdir -p %{buildroot}
gmake DESTDIR=%{buildroot} install

# make links
cd %{buildroot}
for dir in bin lib include
do
        mkdir -p usr/$dir
        cd usr/$dir
        ln -sf ../..%{_prefix}/$dir/* .
        cd -
done

%if %{BUILD64} == 1
#Add links for 64-bit library members
(
 mkdir -p $RPM_BUILD_ROOT/%{prefix64}/lib
 cd $RPM_BUILD_ROOT/%{prefix64}/lib
 ln -s ../../lib/*.a .
)
%endif

%files
%defattr(-,root,system)
%doc *.txt example.c README TODO CHANGES
%{_bindir}/*-config
%{_libdir}/libpng*.a
#%{_prefix}/64/lib/libpng*.a
%{_mandir}/man5/*


/usr/lib/
/usr/bin/
%if %{BUILD64} == 1
%attr(755,bin,bin) %dir /%{prefix64}
%attr(755,bin,bin) %dir /%{prefix64}/lib
/%{prefix64}/lib/lib*.a
%endif

%files devel
%defattr(-,root,system)
%{_includedir}/*
%{_libdir}/libpng*.la
%{_mandir}/man3/*
%{_libdir}/pkgconfig/*.pc

/usr/include/
%changelog
*  Wed Nov 15 2006  BULL
 - Release  5
 - gnome 2.16.1

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

*  Fri Jan 06 2006  BULL
 - Release  3
 - added compatmember= shr.o

*  Fri Dec 23 2005  BULL
 - Release 2 
 - Prototype gtk 64 bit 

*  Tue Nov 15 2005  BULL
 - Release  1
 - New version  version: 1.2.8

