%define _prefix /opt/freeware
%define _defaultdocdir %{_prefix}/doc
%define pkgconfig_version 0.19
%define glib2_version 2.8.1

Summary: 	Library for parsing IDL (Interface Definition Language)
Name: 		libIDL
Version: 	0.8.6
Release: 	3
Source: 	ftp://ftp.gnome.org/pub/GNOME/pre-gnome2/sources/libIDL/%{name}-%{version}.tar.bz2

Patch0:		libIDL-0.8.6-aix.patch
Patch1:		libIDL-0.8.6-autotools.patch

Group: 		System Environment/Libraries
License: 	LGPL
BuildRoot: 	%{_tmppath}/%{name}-%{version}-root
BuildRequires: pkg-config >= %{pkgconfig_version}
BuildRequires: glib2-devel >= %{glib2_version}
BuildRequires: flex

# 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
libIDL is a library for parsing IDL (Interface Definition Language). 
It can be used for both COM-style and CORBA-style IDL.

%package devel
Summary: 	Development libraries and header files for libIDL
Group: 		Development/Libraries
Requires: 	libIDL = %{version}
Requires: 	pkg-config >= %{pkgconfig_version}
Requires: 	glib2-devel >= %{glib2_version}
Prereq: 	/sbin/install-info

%description devel
libIDL is a library for parsing IDL (Interface Definition Language). 
It can be used for both COM-style and CORBA-style IDL.

This package contains the header files and libraries needed to write 
or compile programs that use libIDL.

%prep
%setup -q

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

%if %{BUILD64} == 1
# Prep 64-bit build in 64bit subdirectory
mkdir 64bit
cd 64bit
bzip2 -dc %{SOURCE0} | tar -xf -
cd libIDL-0.8.6
$PATCH -p2 -s < %{_sourcedir}/libIDL-0.8.6-aix.patch
$PATCH -p2 -s < %{_sourcedir}/libIDL-0.8.6-autotools.patch
%endif

%build
# now build the 32-bit version
export OBJECT_MODE=32
export CC="xlc_r -q32"
PATH=%{_bindir}:$PATH ./configure --prefix=%{_prefix}
make

# now build the 64-bit version
%if %{BUILD64} == 1
cd 64bit/libIDL-0.8.6
export OBJECT_MODE=64
export CC="xlc_r -q64"
PATH=%{_bindir}:$PATH ./configure --prefix=%{_prefix}
make

# Go back to 32-bit library and add our 64bit shared object
# into same archive
cd ../..
pwd
/usr/bin/ar -X32_64 -q ./.libs/libIDL-2.a ./64bit/libIDL-0.8.6/.libs/libIDL-2.so.0
%endif #BUILD64


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

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

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


%files
%defattr(-,root,system)
%{_libdir}/lib*.a
/usr/lib/lib*.a
#/opt/freeware/lib/libIDL-2.a
%doc AUTHORS COPYING README NEWS

%files devel
%defattr(-,root,system)
%{_includedir}/*
/usr/include/*
%{_libdir}/lib*.la
%{_libdir}/pkgconfig/*
%{_bindir}/*
/usr/bin/libIDL-config-2
%{_infodir}/libIDL2.info


%changelog
*  Fri Jan 6 2006  BULL
 - Release  2
 - libIDL-2.a with both members 32 and 64 bits
*  Tue Nov 15 2005  BULL
 - Release  1
 - New version  version: 0.8.6

*  Wed Aug 10 2005  BULL
 - Release  3

*  Mon May 30 2005  BULL
 - Release  2
 - .o removed from lib
*  Wed May 25 2005  BULL
 - Release  1
 - New version  version: 0.8.5

*  Tue Nov 23 2004  BULL
 - Release  1
 - New version  version: 0.8.4

