--- /dev/null
+EXECUTE_PROCESS(COMMAND ${PYTHON3_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON3_INSTALL_DIR)
+
+MESSAGE (STATUS "Python3 executable: ${PYTHON3_EXECUTABLE}")
+MESSAGE (STATUS "Python3 installation dir: ${PYTHON3_INSTALL_DIR}")
+MESSAGE (STATUS "Python3 include path: ${PYTHON3_INCLUDE_DIR}")
+
+ADD_CUSTOM_COMMAND (
+ OUTPUT solv_python.c
+ COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} -python -DPYTHON3=1 -I${CMAKE_SOURCE_DIR}/src -o solv_python.c ${CMAKE_SOURCE_DIR}/bindings/solv.i
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS ${CMAKE_SOURCE_DIR}/bindings/solv.i
+)
+
+ADD_DEFINITIONS(-Wno-unused)
+INCLUDE_DIRECTORIES (${PYTHON3_INCLUDE_DIR})
+
+ADD_LIBRARY (bindings_python3 SHARED solv_python.c)
+SET_TARGET_PROPERTIES (bindings_python3 PROPERTIES PREFIX "" OUTPUT_NAME "_solv")
+TARGET_LINK_LIBRARIES (bindings_python3 libsolvext libsolv ${SYSTEM_LIBRARIES})
+
+INSTALL (TARGETS bindings_python3 LIBRARY DESTINATION ${PYTHON3_INSTALL_DIR})
+INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${PYTHON3_INSTALL_DIR})
%bcond_without disable_shared
%bcond_without perl_binding
%bcond_without python_binding
+%bcond_with python3_binding
%bcond_without ruby_binding
%bcond_with zypp
BuildRequires: python-devel
BuildRequires: swig
%endif
+%if %{with python3_binding}
+%global python3_sitearch %(python3 -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True);")
+BuildRequires: python3-devel
+%endif
Summary: A new approach to package dependency solving
License: BSD-3-Clause
%description -n python-solv
Python bindings for sat solver.
+%package -n python3-solv
+Summary: Python3 bindings for the libsolv library
+Group: Development/Languages/Python
+
+%description -n python3-solv
+Python3 bindings for sat solver.
+
%package -n perl-solv
Requires: perl = %{perl_version}
Summary: Perl bindings for the libsolv library
export CXXFLAGS="$CFLAGS"
CMAKE_FLAGS=
+PYTHON_CMAKE_FLAGS=
%if 0%{?fedora_version} || 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600
CMAKE_FLAGS="-DFEDORA=1"
%endif
CMAKE_FLAGS="-DSUSE=1 -DENABLE_APPDATA=1 -DENABLE_COMPS=1"
%endif
-cmake $CMAKE_FLAGS \
+%if %{with python3_binding}
+for pyversion in 3 2 ; do
+test $pyversion == 2 && perl -i -p -e 's/(python)/${1}3/i' CMakeCache.txt
+PYTHON_CMAKE_FLAGS="-DPythonLibs_FIND_VERSION=$pyversion -DPythonLibs_FIND_VERSION_MAJOR=$pyversion"
+%endif
+
+cmake $CMAKE_FLAGS $PYTHON_CMAKE_FLAGS \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DLIB=%{_lib} \
-DCMAKE_VERBOSE_MAKEFILE=TRUE \
%{?with_zypp:-DENABLE_SUSEREPO=1 -DENABLE_HELIXREPO=1} \
-DUSE_VENDORDIRS=1 \
-DCMAKE_SKIP_RPATH=1
+
+%if %{with python3_binding}
+done
+%endif
+
make %{?jobs:-j %jobs}
%install
make DESTDIR=$RPM_BUILD_ROOT install
-%if %{with python_binding}
%if 0%{?suse_version}
+%if %{with python_binding}
pushd $RPM_BUILD_ROOT/%{python_sitearch}
python %py_libdir/py_compile.py *.py
python -O %py_libdir/py_compile.py *.py
popd
%endif
+%if %{with python3_binding}
+%py3_compile $RPM_BUILD_ROOT/%{python3_sitearch}
+%endif
%endif
%if %{with disable_shared}
# we want to leave the .a file untouched
%{python_sitearch}/*
%endif
+%if %{with python3_binding}
+%files -n python3-solv
+%defattr(-,root,root)
+%{python3_sitearch}/*
+%endif
+
%changelog