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

Name: 		xcursor
Version: 	1.1.7
Release: 	1
Group: 		X11/Libraries
Summary: 	X Cursor library
License: 	MIT
BuildRoot: 	%{_tmppath}/%{name}-%{version}-root
Obsoletes:      xcursor-static
Source:         http:///%{name}-%{version}.tar.bz2
Patch0:         libXcursor-1.1.7-autotools.patch


# 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
X Cursor library.

%package devel
Summary:        X Cursor library headers
Group:          X11/Development/Libraries
Requires:       %{name} = %{version}
#Requires:      xrender-devel
Obsoletes:      xcursor-static

%description devel
X Cursor library headers.

%prep
%setup -q

if test x$PATCH = x ; then
  PATCH=patch ;
fi

$PATCH -p1 -u < %{_sourcedir}/libXcursor-1.1.7-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 64 
cd 64
bunzip2 -dc %{_sourcedir}/%{name}-%{version}.tar.bz2 |tar xf - 
cd %{name}-%{version}
$PATCH -p1 -u < %{_sourcedir}/libXcursor-1.1.7-autotools.patch


%endif

%build

export OBJECT_MODE=32

#ksh autogen.sh --prefix=%{_prefix}
./configure --prefix=%{_prefix}

gmake

%if %{BUILD64} == 1
# Now build again as 64bit
###########################
cd 64/%{name}-%{version}
export OBJECT_MODE=64

#ksh autogen.sh --prefix=%{_prefix}
./configure --prefix=%{_prefix}

gmake

# Go back to 32-bit library and add our 64bit shared object
#  into same archive
cd ../..

/usr/bin/ar -q src/.libs/libXcursor.a 64/%{name}-%{version}/src/.libs/libXcursor.so.1

%endif #BUILD64

%install

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

gmake DESTDIR=%{buildroot} install
cp ./src/.libs/libXcursor.exp %{buildroot}%{_prefix}/lib

# Make the 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 %{buildroot}%{_prefix}/64/lib
 cd %{buildroot}%{_prefix}/64/lib
 ln -sf ../../../..%{_prefix}/lib/* .
)
%endif

%post

if [ `/usr/bin/uname -v` -ne 5 ]; then
##
## Repair link back to X11 path if pointing to freeware path
##
    if [ -f /usr/lib/libXcursor.a ]; then
        DEST_PATH=`/usr/bin/ls -l  /usr/lib/libXcursor.a | /usr/bin/tr -s " " | /usr/bin/cut -d" " -f11`
        if [ $? -ne 0 ]; then
            ##
            ## Don't know what went wrong
            ##
            exit 1
        fi

        if [ -n "${DEST_PATH}" -a "${DEST_PATH}" == '../../opt/freeware/lib/libXcursor.a' ]; then
            /usr/bin/mv -f /usr/lib/libXcursor.a /tmp

            /usr/bin/ln -fs /usr/lpp/X11/lib/R7/libXcursor.a /usr/lib
            if [ $? -ne 0 ]; then
                ##
                ## Restore whatever was there in /usr/lib
                ##
                /usr/bin/mv -f /tmp/libXcursor.a /usr/lib
                exit 1
            fi
	    ##
	    ## Remove backup
	    ##
	    /usr/bin/rm -f /tmp/libXcursor.a
        fi
    else
	/usr/bin/ln -fs /usr/lpp/X11/lib/R7/libXcursor.a /usr/lib
	if [ $? -ne 0 ]; then
	    exit 1
	fi
    fi
fi

exit 0

%postun

if [ `/usr/bin/uname -v` -ne 5 ]; then
##
## Repair link back to X11 path
##
    /usr/bin/ln -fs /usr/lpp/X11/lib/R7/libXcursor.a /usr/lib
    if [ $? -ne 0 ]; then
	exit 1
    fi
fi

exit 0

%files
%defattr (-,root,system)
%doc ChangeLog

%dir %{_libdir}
%{_libdir}/lib*.a

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

%files devel
%defattr(-,root,system)
%attr(755,root,root) 
%{_libdir}/libXcursor.la
%{_libdir}/lib*.exp

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

%dir %{_includedir}/X11
%{_includedir}/X11/*

%dir %{_libdir}/pkgconfig
%{_libdir}/pkgconfig/*

%{_libdir}/../man/man3/Xcursor.3*

/usr/lib/lib*.la

%changelog
*  Thu Feb 28 2008  IBM
 - Updated to release 1.1.7

*  Wed Oct 17 2007  IBM
 - Release 4 - Changed spec to build RPM and to build 32 as well 64 bit lib files.
 - Added script code for repairing links in /usr/lib /if OS is AIX 6.

*  Thu Jan 19 2006  BULL
 - Release  3
 - Library contain both 32 and 64 bit members
*  Tue Nov 15 2005  BULL
 - Release  2

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


