# if you wanna test, add " --define '_run_test 1' " option to rpmbuild command
%define run_test %{?_run_test:1}%{!?_run_test:0}
%define TclTk 8.4
%define pybasever 3.1
%define python_lib %{_libdir}/python%{pybasever}
Summary: An interpreted, interactive, object-oriented programming language.
Summary(ja): オブジェクト指向 Python3 インタプリタ
Name: python3
Version: %{pybasever}.3
Release: 2%{?_dist_release}
License: Modified CNRI Open Source License
Group: Development/Languages
URL: http://www.python.org/download/releases/%{version}
Source0: http://www.python.org/ftp/python/%{version}/Python-%{version}.tar.bz2
Source1: http://docs.python.org/py3k/archives/python-%{version}-docs-html.tar.bz2
Patch0: python-3.1.3-Setup.dist.patch
Patch10: python-3.1.3-locale.patch
Patch100: python-3.1.3-lib64-Makefile.patch
Patch101: python-3.1.3-lib64-setup.patch
Patch102: python-3.1.3-lib64-site.patch
Patch103: python-3.1.3-lib64-install.patch
Patch104: python-3.1.3-lib64-sysconfig.patch
Patch105: python-3.1.3-lib64-getpath.patch
Patch106: python-3.1.3-lib64-test_install.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: gzip tar gcc-c++ pkgconfig sed findutils
BuildRequires: bzip2-devel
BuildRequires: gdbm-devel
BuildRequires: glibc-devel
BuildRequires: ncurses-devel
BuildRequires: openssl-devel
BuildRequires: readline-devel
BuildRequires: sqlite3-devel
BuildRequires: zlib-devel
BuildRequires: libffi-devel
Requires: bzip2
Requires: gdbm
Requires: ncurses
Requires: openssl
Requires: readline
Requires: sqlite3
Requires: zlib
Packager: owa
Vendor: Project Vine
Distribution: Vine Linux

%description
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).

Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface. This package contains most of the standard
Python modules, as well as modules for interfacing to the Tix widget
set for Tk and RPM.

Note that documentation for Python is provided in the python-docs
package.

%package devel
Summary: The libraries and header files needed for Python development.
Group: Development/Libraries

%description devel
The Python programming language's interpreter can be extended with
dynamically loaded extensions and can be embedded in other programs.
This package contains the header files and libraries needed to do
these types of tasks.

Install python-devel if you want to develop Python extensions.  The
python package will also need to be installed.  You'll probably also
want to install the python-docs package, which contains Python
documentation.

%package tkinter
Summary: A graphical user interface for the Python scripting language.
Group: Development/Languages
Requires: %{name} = %{version}
Requires: tcl, tk, tix
Requires: libX11, libxcb, libXau, libXdmcp
BuildRequires: tcl, tk, tix
BuildRequires: libX11-devel, libxcb-devel, libXau-devel, libXdmcp-devel

%description tkinter
The Tkinter (Tk interface) program is an graphical user interface for
the Python scripting language.

You should install the tkinter package if you'd like to use a graphical
user interface for Python programming.

%package tools
Summary: A collection of development tools included with Python.
Group: Development/Tools
Requires: %{name} = %{version}
Requires: %{name}-tkinter = %{version}

%description tools
The Python package includes several development tools that are used
to build python programs.

%package docs
Summary: Documentation for the Python programming language.
Group: Documentation

%description docs
The python-docs package contains documentation on the Python
programming language and interpreter.  The documentation is provided
in ASCII text files and in LaTeX source files.

Install the python-docs package if you'd like to use the documentation
for the Python language.


%prep
%setup -q -n Python-%{version}
%patch0 -p1 -b .Setup
%patch10 -p1 -b .locale

%if %{_lib} == lib64
%patch100 -p1 -b .lib64-Makefile
%patch101 -p1 -b .lib64-setup
%patch102 -p1 -b .lib64-site
%patch103 -p1 -b .lib64-install
%patch104 -p1 -b .lib64-sysconfig
%patch105 -p1 -b .lib64-getpath
%patch106 -p1 -b .test_install
%endif

# fix Tcl/Tk versions
pushd Modules
mv Setup.dist Setup.dist.old
cat Setup.dist.old \
	| sed "s^-ltcl^-ltcl%{TclTk}^" \
	| sed "s^-ltk^-ltk%{TclTk}^" \
	| sed "s^-ltix^-ltix%{TclTk}^" \
	> Setup.dist
rm -f Setup.dist.old
popd


%build
topdir=`pwd`
%configure \
	--enable-shared \
	--enable-ipv6 \
	--enable-profiling \
	--with-wide-unicode \
	--with-system-ffi \
	--with-signal-module \
	;
make %{?_smp_mflags}

## rebuild with new python
export LD_LIBRARY_PATH=$topdir
export PATH="$topdir:$PATH"
ln -s $topdir/python $topdir/python%{pybasever}
#$topdir/python Tools/scripts/pathfix.py -i "/usr/bin/env python%{pybasever}" .
make %{?_smp_mflags}

%if %{run_test}
#%%check
find ./Lib -name '*.py[co]' -print | xargs rm -f
LD_LIBRARY_PATH=$topdir:$topdir/Modules:$topdir/build/lib.linux-%{_host_cpu}-%{pybasever}
PYTHONHOME=$topdir
PYTHONPATH=$topdir/Lib:$topdir/Lib/test:$topdir/Lib/lib-tk:$topdir/Lib/site-packages
PYTHONPATH=$PYTHONPATH:$LD_LIBRARY_PATH
export PYTHONHOME PYTHONPATH LD_LIBRARY_PATH
SKIPLIST="-x test_cmd_line"
./python -tt -E ./Lib/test/regrtest.py -l -w $SKIPLIST 2>&1 | tee make.check1.log
./python -tt -E ./Lib/test/regrtest.py -l -w $SKIPLIST 2>&1 | tee make.check2.log
#-------------------------------##
# Mon Nov 29 2010 ...last tested
# 314 tests OK.
# 4 tests failed:
#  test_cmd_line: "Lib/test/test_cmd_line.py", line 190, in test_large_PYTHONPATH
#  test_httpservers: Lib/test/test_httpservers.py", line 399 in tearDown
#  test_pydoc: Lib/test/test_pydoc.py", line 299, in test_badimport
#  test_warnings: Lib/test/test_warnings.py", line 707, in test_issue_8766
# 22 tests skipped:
# 2 skips unexpected on linux2:
#-------------------------------##
%endif


%install
rm -fr $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT BINDIR=%{_bindir} install

## Clean up the testsuite - we don't need compiled files for it
find $RPM_BUILD_ROOT%{python_lib}/test \
    -name "*.pyc" -o -name "*.pyo" | xargs rm -f

chmod 755 $RPM_BUILD_ROOT%{_libdir}/libpython*.so.*
chmod 755 $RPM_BUILD_ROOT%{python_lib}/lib-dynload/*.so
find $RPM_BUILD_ROOT%{python_lib} -perm -o=x -name '*.py' | xargs chmod -x
mv $RPM_BUILD_ROOT%{_bindir}/2to3 $RPM_BUILD_ROOT%{_bindir}/2to3.1


## html document
tar xvzf %SOURCE1
if [ -d Doc/html ] ; then
	rm -r Doc/html
fi
mv python-%{version}-docs-html Doc/html


%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%clean
rm -fr $RPM_BUILD_ROOT

%files
%defattr(-, root, root)
%doc LICENSE README
%{_bindir}/%{name}
%{_bindir}/%{name}-config
%{_bindir}/python%{pybasever}
%{_bindir}/python%{pybasever}-config
%{_libdir}/libpython%{pybasever}.so*
%{_libdir}/pkgconfig/python-%{pybasever}.pc
%{_libdir}/pkgconfig/python3.pc
%{_mandir}/man1/*
%dir %{python_lib}
%dir %{python_lib}/site-packages
%{python_lib}/LICENSE.txt
%{python_lib}/*.py*
%{python_lib}/*.doc
%{python_lib}/ctypes
%{python_lib}/curses
%{python_lib}/distutils
%{python_lib}/dbm
%{python_lib}/email
%{python_lib}/encodings
%{python_lib}/html
%{python_lib}/http
%{python_lib}/importlib
%{python_lib}/json
%{python_lib}/logging
%{python_lib}/multiprocessing
%{python_lib}/plat-linux2
%{python_lib}/pydoc_data
%{python_lib}/sqlite3
%{python_lib}/urllib
%{python_lib}/wsgiref
%{python_lib}/wsgiref.egg-info
%{python_lib}/xml
%{python_lib}/xmlrpc
%{python_lib}/lib-dynload
%exclude %{python_lib}/lib-dynload/_tkinter.so

%files devel
%defattr(-,root,root)
%{_includedir}/python%{pybasever}
%{python_lib}/config
%{python_lib}/test

%files tools
%defattr(-,root,root)
%{_bindir}/2to3.1
%{_bindir}/idle3
%{_bindir}/pydoc3
%{python_lib}/idlelib
%{python_lib}/lib2to3
%{python_lib}/site-packages

%files tkinter
%defattr(-,root,root)
%{python_lib}/tkinter
%{python_lib}/lib-dynload/_tkinter.so

%files docs
%defattr(-,root,root)
%doc Misc/ACKS Misc/HISTORY Misc/NEWS Misc/README
%doc Misc/cheatsheet Misc/Porting
%doc Doc/html


%changelog
* Fri Jan 14 2011 Shu KONNO <owa@bg.wakwak.com> 3.1.3-2
- rebuilt with openssl-1.0.0c

* Mon Nov 29 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.3-1
- updated python to 3.1.3
- added python-3.1.3-locale.patch
- dropt python-3.1.2-lib64.patch
- added python-3.1.3-lib64-*.patchs
  python-3.1.3-lib64-Makefile.patch
  python-3.1.3-lib64-setup.patch
  python-3.1.3-lib64-site.patch
  python-3.1.3-lib64-install.patch
  python-3.1.3-lib64-sysconfig.patch
  python-3.1.3-lib64-getpath.patch
  python-3.1.3-lib64-test_install.patch
- added run_test macro to run unit test
- added BR: libffi

* Sun Sep 26 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.2-4
- rebuilt with rpm-4.8.1 for pkg-config

* Sun Jun 20 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.2-3
- spec in utf-8

* Sun Jun 20 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.2-2
- added missings in BuildRequires, Requires

* Fri Jun 18 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.2-1
- initial build for VineSeed

