commit 2d8e3fb1d73d8d1bfb7438834fe8bbbe95fd1d71 Author: vaydheesh Date: Mon Jun 3 04:55:29 2019 +0000 1. Bare minimum added python to subdirs added swig vars to configure.ac added m4 macros added: setup.py.in template callable by Makefile diff --git a/Makefile.am b/Makefile.am index 02e7cce..63441d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ACLOCAL_AMFLAGS=-I m4 -SUBDIRS = $(GENERIC_LIBRARY_NAME) +SUBDIRS = $(GENERIC_LIBRARY_NAME) python DIST_SUBDIRS = $(GENERIC_LIBRARY_NAME) pkgconfigdir = $(libdir)/pkgconfig diff --git a/configure.ac b/configure.ac index 3dfc70d..4214c44 100644 --- a/configure.ac +++ b/configure.ac @@ -142,4 +142,12 @@ static_assert(!is_same::value, "size_t == uint64_t"); AM_PATH_PYTHON([2], [], [AC_MSG_WARN([Can't run 'make test' without Python installed.])]) +AC_CONFIG_FILES([ + python/Makefile + python/setup.py + ]) +AX_PKG_SWIG(4.0.0) # check swig version +AX_SWIG_ENABLE_CXX # fill some variable usefull later +AX_SWIG_PYTHON # same + AC_OUTPUT([Makefile lttoolbox.pc lttoolbox/Makefile]) diff --git a/m4/ax_pkg_swig.m4 b/m4/ax_pkg_swig.m4 new file mode 100644 index 0000000..1d467de --- /dev/null +++ b/m4/ax_pkg_swig.m4 @@ -0,0 +1,135 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PKG_SWIG([major.minor.micro], [action-if-found], [action-if-not-found]) +# +# DESCRIPTION +# +# This macro searches for a SWIG installation on your system. If found, +# then SWIG is AC_SUBST'd; if not found, then $SWIG is empty. If SWIG is +# found, then SWIG_LIB is set to the SWIG library path, and AC_SUBST'd. +# +# You can use the optional first argument to check if the version of the +# available SWIG is greater than or equal to the value of the argument. It +# should have the format: N[.N[.N]] (N is a number between 0 and 999. Only +# the first N is mandatory.) If the version argument is given (e.g. +# 1.3.17), AX_PKG_SWIG checks that the swig package is this version number +# or higher. +# +# As usual, action-if-found is executed if SWIG is found, otherwise +# action-if-not-found is executed. +# +# In configure.in, use as: +# +# AX_PKG_SWIG(1.3.17, [], [ AC_MSG_ERROR([SWIG is required to build..]) ]) +# AX_SWIG_ENABLE_CXX +# AX_SWIG_MULTI_MODULE_SUPPORT +# AX_SWIG_PYTHON +# +# LICENSE +# +# Copyright (c) 2008 Sebastian Huber +# Copyright (c) 2008 Alan W. Irwin +# Copyright (c) 2008 Rafael Laboissiere +# Copyright (c) 2008 Andrew Collier +# Copyright (c) 2011 Murray Cumming +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 13 + +AC_DEFUN([AX_PKG_SWIG],[ + # Find path to the "swig" executable. + AC_PATH_PROGS([SWIG],[swig swig3.0 swig2.0]) + if test -z "$SWIG" ; then + m4_ifval([$3],[$3],[:]) + elif test -n "$1" ; then + AC_MSG_CHECKING([SWIG version]) + [swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`] + AC_MSG_RESULT([$swig_version]) + if test -n "$swig_version" ; then + # Calculate the required version number components + [required=$1] + [required_major=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_major" ; then + [required_major=0] + fi + [required=`echo $required | sed 's/[0-9]*[^0-9]//'`] + [required_minor=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_minor" ; then + [required_minor=0] + fi + [required=`echo $required | sed 's/[0-9]*[^0-9]//'`] + [required_patch=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_patch" ; then + [required_patch=0] + fi + # Calculate the available version number components + [available=$swig_version] + [available_major=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_major" ; then + [available_major=0] + fi + [available=`echo $available | sed 's/[0-9]*[^0-9]//'`] + [available_minor=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_minor" ; then + [available_minor=0] + fi + [available=`echo $available | sed 's/[0-9]*[^0-9]//'`] + [available_patch=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_patch" ; then + [available_patch=0] + fi + # Convert the version tuple into a single number for easier comparison. + # Using base 100 should be safe since SWIG internally uses BCD values + # to encode its version number. + required_swig_vernum=`expr $required_major \* 10000 \ + \+ $required_minor \* 100 \+ $required_patch` + available_swig_vernum=`expr $available_major \* 10000 \ + \+ $available_minor \* 100 \+ $available_patch` + + if test $available_swig_vernum -lt $required_swig_vernum; then + AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version.]) + SWIG='' + m4_ifval([$3],[$3],[]) + else + AC_MSG_CHECKING([for SWIG library]) + SWIG_LIB=`$SWIG -swiglib` + AC_MSG_RESULT([$SWIG_LIB]) + m4_ifval([$2],[$2],[]) + fi + else + AC_MSG_WARN([cannot determine SWIG version]) + SWIG='' + m4_ifval([$3],[$3],[]) + fi + fi + AC_SUBST([SWIG_LIB]) +]) diff --git a/m4/ax_swig_python.m4 b/m4/ax_swig_python.m4 new file mode 100644 index 0000000..08b9671 --- /dev/null +++ b/m4/ax_swig_python.m4 @@ -0,0 +1,64 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_swig_python.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_SWIG_PYTHON([use-shadow-classes = {no, yes}]) +# +# DESCRIPTION +# +# Checks for Python and provides the $(AX_SWIG_PYTHON_CPPFLAGS), and +# $(AX_SWIG_PYTHON_OPT) output variables. +# +# $(AX_SWIG_PYTHON_OPT) contains all necessary SWIG options to generate +# code for Python. Shadow classes are enabled unless the value of the +# optional first argument is exactly 'no'. If you need multi module +# support (provided by the AX_SWIG_MULTI_MODULE_SUPPORT macro) use +# $(AX_SWIG_PYTHON_LIBS) to link against the appropriate library. It +# contains the SWIG Python runtime library that is needed by the type +# check system for example. +# +# LICENSE +# +# Copyright (c) 2008 Sebastian Huber +# Copyright (c) 2008 Alan W. Irwin +# Copyright (c) 2008 Rafael Laboissiere +# Copyright (c) 2008 Andrew Collier +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 11 + +AU_ALIAS([SWIG_PYTHON], [AX_SWIG_PYTHON]) +AC_DEFUN([AX_SWIG_PYTHON],[ + AC_REQUIRE([AX_PKG_SWIG]) + AC_REQUIRE([AX_PYTHON_DEVEL]) + test "x$1" != "xno" || swig_shadow=" -noproxy" + AC_SUBST([AX_SWIG_PYTHON_OPT],[-python$swig_shadow]) + AC_SUBST([AX_SWIG_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS]) +]) diff --git a/python/Makefile.am b/python/Makefile.am index db4026b..fe56896 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -1,29 +1,7 @@ -cc_sources = alphabet.cc att_compiler.cc compiler.cc compression.cc entry_token.cc \ - expander.cc fst_processor.cc lt_locale.cc match_exe.cc \ - match_node.cc match_state.cc node.cc pattern_list.cc \ - regexp_compiler.cc sorted_vector.cc state.cc transducer.cc \ - trans_exe.cc xml_parse_util.cc tmx_compiler.cc +SWIG_SOURCES = analysis.i -# SWIG_INTERFACE = analysis.i - -EXTRA_DIST = analysis.i - -pkgdata_DATA = analysis.py - -lib_LTLIBRARIES = libAnalysisPython.la -libAnalysisPython_la_SOURCES = analysis_wrap_python.cpp -libAnalysisPython_la_SOURCES = analysis_wrap_python.cpp -foo_wrap_python.cpp: analysis.i - $(SWIG) -python $(SWIG_ARGS) -o $@ $< - - -BUILT_SOURCES = analysis_wrap.cpp analysis.py -CLEANFILES = $(BUILT_SOURCES) - -library_includedir = $(includedir)/$(GENERIC_LIBRARY_NAME)-$(GENERIC_API_VERSION)/$(GENERIC_LIBRARY_NAME) -library_include_HEADERS = $(h_sources) - -%_wrap.cpp %.py: %.i ../src/libdivvun.la - $(SWIG) -c++ -python -I$(top_srcdir)/src/lib -o $*_wrap.cpp -outdir . $(srcdir)/$*.i - CPPFLAGS="$(CPPFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="-Wl,-rpath,${prefix}/lib $(LDFLAGS)" +all: analysis_wrap.cpp +analysis_wrap.cpp: $(SWIG_SOURCES) + $(SWIG) $(AX_SWIG_PYTHON_OPT) -I$(top_srcdir) -c++ -o $@ $< + (python setup.py build) \ No newline at end of file diff --git a/python/setup.py.in b/python/setup.py.in new file mode 100644 index 0000000..800e87e --- /dev/null +++ b/python/setup.py.in @@ -0,0 +1,45 @@ +#!/usr/bin/python + +""" +Setup for SWIG Python bindings for lttoolbox +""" + +from distutils.core import setup, Extension + + +def getenv_list(var_name): + from os import getenv + var = getenv(var_name) + if var: + return var.split() + else: + return [] + +def get_sources(): + from os import path + sources = ['analysis_wrap.cpp'] + cc = 'alphabet.cc compression.cc fst_processor.cc lt_locale.cc node.cc state.cc trans_exe.cc xml_parse_util.cc' + rel_path = '@top_srcdir@/lttoolbox/' + sources.extend([path.join(rel_path, f) for f in cc.split()]) + return sources + + +analysis_module = Extension( + '_analysis', + sources=get_sources(), + include_dirs=['@top_srcdir@', '/usr/include/libxml2'], + library_dirs=['@top_srcdir@/lttoolbox/.libs', '/usr/include/libxml2'], + extra_compile_args=getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'), + extra_link_args= (getenv_list('LDFLAGS')) + ['-lxml2']) + + +setup(name='python-@PACKAGE@', + version='@PACKAGE_VERSION@', + description='SWIG interface to @PACKAGE_NAME@', + long_description="SWIG interface to @PACKAGE_NAME@ for use in apertium-python", + # TODO: author, maintainer, url + author_email='@PACKAGE_BUGREPORT@', + license='GPL-3.0+', + maintainer_email='@PACKAGE_BUGREPORT@', + py_modules=['analysis'], + ext_modules=[analysis_module]) diff --git a/python/setup2.py b/python/setup2.py new file mode 100644 index 0000000..842a59b --- /dev/null +++ b/python/setup2.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +""" +Setup for SWIG Python bindings for lttoolbox +""" + +from distutils.core import setup, Extension + +# swig -python -c++ -o analysis_wrap.cpp analysis.i + +def getenv_list(var_name): + from os import getenv + var = getenv(var_name) + if var: + return var.split() + else: + return [] + + +def get_sources(): + from os import path + sources = ['analysis_wrap.cpp'] + cc_sources = '\ + att_compiler.cc compiler.cc entry_token.cc expander.cc match_exe.cc \ + match_node.cc match_state.cc pattern_list.cc \ + regexp_compiler.cc sorted_vector.cc transducer.cc tmx_compiler.cc' + + paths = '/home/kawai/Desktop/git_push/lttoolbox/lttoolbox/' + cc = 'alphabet.cc compression.cc fst_processor.cc lt_locale.cc node.cc state.cc trans_exe.cc xml_parse_util.cc' + # for i in cc.split(): + # sources.append(path + i) + # sources.extend(cc_sources.split()) + sources.extend([path.join(paths, f) for f in cc.split()]) + return sources + +analysis_module = Extension( + '_analysis', + # sources=['analysis_wrap.cpp', '/home/kawai/Desktop/git_push/lttoolbox/lttoolbox/fst_processor.cc'], + sources=get_sources(), + include_dirs=['/home/kawai/Desktop/git_push/lttoolbox', '/usr/include/libxml2'], + library_dirs=['/usr/include/libxml2'], + extra_compile_args=getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'), + extra_link_args= (getenv_list('LDFLAGS')) + ['-lxml2']) + + +setup(name='python-@PACKAGE@', + version='@PACKAGE_VERSION@', + description='SWIG interface to @PACKAGE_NAME@', + long_description="SWIG interface to @PACKAGE_NAME@ for use in apertium-python", + # TODO: author, maintainer, url + author_email='@PACKAGE_BUGREPORT@', + license='GPL-3.0+', + maintainer_email='@PACKAGE_BUGREPORT@', + py_modules=['analysis'], + ext_modules=[analysis_module])