From 88a2df4292f26c4a17de4a856b0579c4ce0de7dd Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Fri, 10 Aug 2012 23:58:41 -0400 Subject: autogenerate setup.py --- configure.ac | 54 ++++++++++++++++++------------------ m4/cython.m4 | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ python/setup.py | 49 --------------------------------- python/setup.py.in | 52 +++++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+), 75 deletions(-) create mode 100644 m4/cython.m4 delete mode 100644 python/setup.py create mode 100644 python/setup.py.in diff --git a/configure.ac b/configure.ac index eb2f4aaa..10cd8fd9 100644 --- a/configure.ac +++ b/configure.ac @@ -13,6 +13,9 @@ AC_LANG_CPLUSPLUS BOOST_REQUIRE([1.44]) BOOST_PROGRAM_OPTIONS BOOST_TEST +AM_PATH_PYTHON +# TODO detect Cython, generate python/Makefile that calls "python setup.py build" + AC_ARG_ENABLE(mpi, [ --enable-mpi Build MPI binaries, assumes mpi.h is present ], [ mpi=yes @@ -79,13 +82,6 @@ AC_CHECK_HEADER(google/dense_hash_map, AC_PROG_INSTALL -AM_CONDITIONAL([RAND_LM], false) -AC_ARG_WITH(randlm, - [AC_HELP_STRING([--with-randlm=PATH], [(optional) path to RandLM toolkit])], - [with_randlm=$withval], - [with_randlm=no] - ) - AM_CONDITIONAL([GLC], false) AC_ARG_WITH(glc, [AC_HELP_STRING([--with-glc=PATH], [(optional) path to Global Lexical Coherence package (Context CRF)])], @@ -94,24 +90,6 @@ AC_ARG_WITH(glc, ) FF_GLC="" -if test "x$with_randlm" != 'xno' -then - SAVE_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -I${with_randlm}/include" - - AC_CHECK_HEADER(RandLM.h, - [AC_DEFINE([HAVE_RANDLM], [], [flag for RandLM])], - [AC_MSG_ERROR([Cannot find RandLM!])]) - - - LIB_RANDLM="-lrandlm" - LDFLAGS="$LDFLAGS -L${with_randlm}/lib" - LIBS="$LIBS $LIB_RANDLM" - FMTLIBS="$FMTLIBS librandlm.a" - AM_CONDITIONAL([RAND_LM], true) -fi - - if test "x$with_glc" != 'xno' then SAVE_CPPFLAGS="$CPPFLAGS" @@ -132,4 +110,28 @@ fi CPPFLAGS="-DPIC -fPIC $CPPFLAGS -DHAVE_CONFIG_H" -AC_OUTPUT(Makefile rst_parser/Makefile utils/Makefile mteval/Makefile extools/Makefile decoder/Makefile phrasinator/Makefile training/Makefile training/liblbfgs/Makefile dpmert/Makefile pro-train/Makefile rampion/Makefile minrisk/Makefile klm/util/Makefile klm/lm/Makefile mira/Makefile dtrain/Makefile gi/pyp-topics/src/Makefile gi/clda/src/Makefile gi/pf/Makefile gi/markov_al/Makefile) +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([utils/Makefile]) +AC_CONFIG_FILES([mteval/Makefile]) +AC_CONFIG_FILES([extools/Makefile]) +AC_CONFIG_FILES([decoder/Makefile]) +AC_CONFIG_FILES([phrasinator/Makefile]) +AC_CONFIG_FILES([training/Makefile]) +AC_CONFIG_FILES([training/liblbfgs/Makefile]) +AC_CONFIG_FILES([dpmert/Makefile]) +AC_CONFIG_FILES([pro-train/Makefile]) +AC_CONFIG_FILES([rampion/Makefile]) +AC_CONFIG_FILES([minrisk/Makefile]) +AC_CONFIG_FILES([klm/util/Makefile]) +AC_CONFIG_FILES([klm/lm/Makefile]) +AC_CONFIG_FILES([mira/Makefile]) +AC_CONFIG_FILES([dtrain/Makefile]) +AC_CONFIG_FILES([gi/pyp-topics/src/Makefile]) +AC_CONFIG_FILES([gi/clda/src/Makefile]) +AC_CONFIG_FILES([gi/pf/Makefile]) +AC_CONFIG_FILES([gi/markov_al/Makefile]) + +AC_CONFIG_FILES([python/setup.py],[chmod +x python/setup.py]) + +AC_OUTPUT + diff --git a/m4/cython.m4 b/m4/cython.m4 new file mode 100644 index 00000000..2d98eee7 --- /dev/null +++ b/m4/cython.m4 @@ -0,0 +1,81 @@ +dnl Taken from the python bindings to the Enlightenment foundation libraries, +dnl and was part of a GPL package. I have included this file to fix the build. +dnl +dnl +dnl AM_CHECK_CYTHON([VERSION [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]]) +dnl Check if a Cython version is installed +dnl Defines CYTHON_VERSION and CYTHON_FOUND +AC_DEFUN([AM_CHECK_CYTHON], +[ +AC_REQUIRE([AM_PATH_PYTHON]) +ifelse([$1], [], [_msg=""], [_msg=" >= $1"]) +AC_MSG_CHECKING(for Cython$_msg) +AC_CACHE_VAL(py_cv_cython, [ + +prog="import Cython.Compiler.Version; print Cython.Compiler.Version.version" +CYTHON_VERSION=`$PYTHON -c "$prog" 2>&AC_FD_CC` + +py_cv_cython=no +if test "x$CYTHON_VERSION" != "x"; then + py_cv_cython=yes +fi + +if test "x$py_cv_cython" = "xyes"; then + ifelse([$1], [], [:], + AS_VERSION_COMPARE([$CYTHON_VERSION], [$1], [py_cv_cython=no])) +fi +]) + +AC_MSG_RESULT([$py_cv_cython]) + +if test "x$py_cv_cython" = "xyes"; then + CYTHON_FOUND=yes + ifelse([$2], [], [:], [$2]) +else + CYTHON_FOUND=no + ifelse([$3], [], [AC_MSG_ERROR([Could not find usable Cython$_msg])], [$3]) +fi +]) + +dnl AM_CHECK_CYTHON_PRECOMPILED(FILE-LIST [, ACTION-IF-ALL [, ACTION-IF-NOT-ALL]]) +dnl given a list of files ending in .pyx (FILE-LIST), check if their .c +dnl counterpart exists and is not older than the source. +dnl ACTION-IF-ALL is called only if no files failed the check and thus +dnl all pre-generated files are usable. +dnl ACTION-IF-NOT-ALL is called if some or all failed. If not provided, +dnl an error will be issued. +AC_DEFUN([AM_CHECK_CYTHON_PRECOMPILED], +[ +_to_check_list="$1" +_failed_list="" +_exists_list="" + +for inf in $_to_check_list; do + outf=`echo "$inf" | sed -e 's/^\(.*\)[.]pyx$/\1.c/'` + if test "$outf" = "$inf"; then + AC_MSG_WARN([File to check must end in .pyx, but got: $inf -- Skip]) + continue + fi + + AC_MSG_CHECKING([for pre-generated $outf for $inf]) + if ! test -f "$outf"; then + _res=no + _failed_list="${_failed_list} $outf" + elif ! test "$outf" -nt "$inf"; then + _res="no (older)" + _failed_list="${_failed_list} $outf" + else + _res=yes + _exists_list="${_exists_list} $outf" + fi + AC_MSG_RESULT($_res) +done + +if test -z "$_failed_list" -a -n "$_exists_list"; then + ifelse([$2], [], [:], [$2]) +else + ifelse([$3], [], + [AC_MSG_ERROR([Missing pre-generated files: $_failed_list])], + [$3]) +fi +]) diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 54510024..00000000 --- a/python/setup.py +++ /dev/null @@ -1,49 +0,0 @@ -from distutils.core import setup -from distutils.extension import Extension -import sys -import re - -def fail(msg): - sys.stderr.write(msg) - sys.exit(1) - -INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] -LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] - -try: - with open('../config.status') as config: - config = config.read() - subs = dict(re.findall('s,@(\w+)@,\|#_!!_#\|(.*),g', config)) # sed - if not subs: - subs = dict(re.findall('S\["(\w+)"\]="(.*)"', config)) # awk - if not subs: - fail('Cannot parse config.status\n' - 'Please report this bug to the developers') - LIBS = re.findall('-l([^\s]+)', subs['LIBS']) - CPPFLAGS = re.findall('-[^R][^\s]+', subs['CPPFLAGS']) - LDFLAGS = re.findall('-[^\s]+', subs['LDFLAGS']) - LDFLAGS = [opt.replace('-R', '-Wl,-rpath,') for opt in LDFLAGS] -except IOError: - fail('Did you run ./configure? Cannot find config.status') -except KeyError as e: - fail('Cannot find option {0} in config.status'.format(e)) - -ext_modules = [ - Extension(name='cdec._cdec', - sources=['src/_cdec.cpp'], - include_dirs=INC, - library_dirs=LIB, - libraries=LIBS + ['z', 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], - extra_compile_args=CPPFLAGS, - extra_link_args=LDFLAGS), - Extension(name='cdec.sa._sa', - sources=['src/sa/_sa.c', 'src/sa/strmap.cc']) -] - -setup( - name='cdec', - ext_modules=ext_modules, - requires=['configobj'], - packages=['cdec', 'cdec.sa'], - package_dir={'': 'pkg'} -) diff --git a/python/setup.py.in b/python/setup.py.in new file mode 100644 index 00000000..77c10b07 --- /dev/null +++ b/python/setup.py.in @@ -0,0 +1,52 @@ +from distutils.core import setup +from distutils.extension import Extension +import sys +import re + +def fail(msg): + sys.stderr.write(msg) + sys.exit(1) + +INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] +LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] + +# set automatically by configure +raw_config_libs = '@LIBS@' + +try: + with open('../config.status') as config: + config = config.read() + subs = dict(re.findall('s,@(\w+)@,\|#_!!_#\|(.*),g', config)) # sed + if not subs: + subs = dict(re.findall('S\["(\w+)"\]="(.*)"', config)) # awk + if not subs: + fail('Cannot parse config.status\n' + 'Please report this bug to the developers') + LIBS = re.findall('-l([^\s]+)', subs['LIBS']) + CPPFLAGS = re.findall('-[^R][^\s]+', subs['CPPFLAGS']) + LDFLAGS = re.findall('-[^\s]+', subs['LDFLAGS']) + LDFLAGS = [opt.replace('-R', '-Wl,-rpath,') for opt in LDFLAGS] +except IOError: + fail('Did you run ./configure? Cannot find config.status') +except KeyError as e: + fail('Cannot find option {0} in config.status'.format(e)) + +ext_modules = [ + Extension(name='cdec._cdec', + sources=['src/_cdec.cpp'], + include_dirs=INC, + library_dirs=LIB, + libraries=LIBS + ['z', 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], + extra_compile_args=CPPFLAGS, + extra_link_args=LDFLAGS), + Extension(name='cdec.sa._sa', + sources=['src/sa/_sa.c', 'src/sa/strmap.cc']) +] + +setup( + name='cdec', + ext_modules=ext_modules, + requires=['configobj'], + packages=['cdec', 'cdec.sa'], + package_dir={'': 'pkg'} +) -- cgit v1.2.3