%define _prefix /opt/freeware

Summary: 	A C library for parsing command line parameters.
Name: 		popt
Version: 	1.7
Release: 	2
License: 	MIT/X Consortium
Group: 		Development/Libraries
Source: 	popt-%{version}.tar.bz2
Patch0:		popt-1.7-aix.patch
Patch1:		popt-1.7-autotools.patch
BuildRoot: 	%{_tmppath}/%{name}-%{version}-root
BuildRequires:	gettext
Prefix:		%{_prefix}

%define DEFCC cc
%define prefix64 %{_prefix}/64

%description
Popt is a C library for parsing command line parameters. Popt was
heavily influenced by the getopt() and getopt_long() functions, but it
improves on them by allowing more powerful argument expansion. Popt
can parse arbitrary argv[] style arrays and automatically set
variables based on command line arguments. Popt allows command line
arguments to be aliased via configuration files and includes utility
functions for parsing arbitrary strings into argv[] arrays using
shell-like rules.

%prep
%setup -q
%patch0 -p2 -b .aix
%patch1 -p2 -b .autotools

# Create an identical directory called 64 under the build dir.
%setup -D -q -c
mv %{name}-%{version} 64
cd 64
%patch0 -p2 -b .aix
%patch1 -p2 -b .autotools


%build
# Use the default compiler for this platform - gcc otherwise
if [[ -z "$CC" ]]
then
    if test "X`type %{DEFCC} 2>/dev/null`" != 'X'; then
       export CC=%{DEFCC}
    else 
       export CC=gcc
    fi
fi
if [[ "$CC" != "gcc" ]]
then
       export RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed 's:-fsigned-char::'`
fi
export CFLAGS=$RPM_OPT_FLAGS AR=/usr/bin/ar
chmod +x ./configure
./configure --disable-static --prefix=%{_prefix}
make

# The 64-bit build.
cd 64
chmod +x ./configure
export OBJECT_MODE=64
./configure --disable-static --prefix=%{prefix64}
make
cd .libs
ln -sf libpopt.so.0 libpopt64.so.0

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

# Add the 64-bit member to the archive.
/usr/bin/ar -X32_64 -r $RPM_BUILD_ROOT%{_prefix}/lib/libpopt.a 64/.libs/libpopt64.so.0 

# rpm itself depends on the .so file;
# extract it and create the links to match how it was
# in popt 1.5
( cd $RPM_BUILD_ROOT%{_prefix}/lib
  /usr/bin/ar -x libpopt.a libpopt.so.0
  mv libpopt.so.0 libpopt.so.0.0.0
  ln -s libpopt.so.0.0.0 libpopt.so.0
  ln -s libpopt.so.0.0.0 libpopt.so
  cd -
)

( cd $RPM_BUILD_ROOT
 mkdir -p usr/lib usr/include
 cd usr/lib
 ln -sf ../..%{prefix}/lib/* .
 cd ../../usr/include
 ln -sf ../..%{prefix}/include/* .
 cd -
)

# Create a link in the 64-bit libdir.
(
  mkdir -p $RPM_BUILD_ROOT%{prefix64}/lib
  cd $RPM_BUILD_ROOT%{prefix64}/lib
  ln -s ../../lib/*.a .
  cd -
)

%clean 
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-, root, system)
%{_prefix}/lib/libpopt.a
%{prefix64}/lib/libpopt.a
%{_prefix}/lib/libpopt.so*
%{_prefix}/lib/libpopt.la
%{_prefix}/include/popt.h
%{_prefix}/man/man3/popt.3*
/usr/lib/*
/usr/include/*.h
%lang(cs)	%{_prefix}/*/locale/cs/LC_MESSAGES/popt.mo
%lang(da)	%{_prefix}/*/locale/da/LC_MESSAGES/popt.mo
%lang(es)	%{_prefix}/*/locale/es/LC_MESSAGES/popt.mo
%lang(gl)	%{_prefix}/*/locale/gl/LC_MESSAGES/popt.mo
%lang(hu)	%{_prefix}/*/locale/hu/LC_MESSAGES/popt.mo
%lang(is)	%{_prefix}/*/locale/is/LC_MESSAGES/popt.mo
%lang(ko)	%{_prefix}/*/locale/ko/LC_MESSAGES/popt.mo
%lang(no)	%{_prefix}/*/locale/no/LC_MESSAGES/popt.mo
%lang(pt)	%{_prefix}/*/locale/pt/LC_MESSAGES/popt.mo
%lang(ro)	%{_prefix}/*/locale/ro/LC_MESSAGES/popt.mo
%lang(ru)	%{_prefix}/*/locale/ru/LC_MESSAGES/popt.mo
%lang(sk)	%{_prefix}/*/locale/sk/LC_MESSAGES/popt.mo
%lang(sl)	%{_prefix}/*/locale/sl/LC_MESSAGES/popt.mo
%lang(sv)	%{_prefix}/*/locale/sv/LC_MESSAGES/popt.mo
%lang(tr)	%{_prefix}/*/locale/tr/LC_MESSAGES/popt.mo
%lang(uk)	%{_prefix}/*/locale/uk/LC_MESSAGES/popt.mo
%lang(wa)	%{_prefix}/*/locale/wa/LC_MESSAGES/popt.mo
%lang(zh_CN)	%{_prefix}/*/locale/zh_CN.GB2312/LC_MESSAGES/popt.mo

%changelog
* Thu Jul 12 2007 Reza Arbab <arbab@austin.ibm.com> 1.7-2
- Include a 64-bit member in the shared archive.
