diff --git a/.gitignore b/.gitignore index 387ba0c247fd10f1bb388a7887c98ed527f48d0a..12b8627023974ba044a7e94305edf944822fe296 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ MANIFEST test/ParaViewTrace*.pvs dist *~ +Makefile +siteconf.py diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..98cc4606f93c586d6c39ba2981c7b573cfbc5054 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,5 @@ +all: + ${PYTHON_EXE} setup.py build + +install: + ${PYTHON_EXE} setup.py install diff --git a/configure b/configure new file mode 100755 index 0000000000000000000000000000000000000000..88c9647f6e6b1690d1b4efb701f0f36bd0f88bd8 --- /dev/null +++ b/configure @@ -0,0 +1,83 @@ +#! /usr/bin/env python + + + + + +def var_to_option(caps_name): + return "--" + caps_name.lower().replace("_", "-") + + + + +def var_kind(caps_name): + last_underscore = caps_name.rfind("_") + return caps_name[last_underscore+1:] + + + + +if __name__ == "__main__": + from optparse import OptionParser + + execfile("configvars.py") + + description = "generate a siteconf.py file for this software package" + parser = OptionParser(description=description) + parser.add_option( + "--python-exe", dest="python_exe", default="python", + help="Which Python interpreter to use", metavar="PATH") + + for var, default, help in vars: + option = var_to_option + + if default: + help += " (default: %s)" % default + parser.add_option( + var_to_option(var), dest=var.lower(), default=default, + metavar=var_kind(var), help=help) + + parser.add_option("--prefix", default=None, + help="Ignored") + parser.add_option("--enable-shared", help="Ignored", action="store_false") + parser.add_option("--disable-static", help="Ignored", action="store_false") + + options, args = parser.parse_args() + + substitutions = { + "PYTHON_EXE": options.python_exe + } + + for var, default, help in vars: + substitutions[var] = getattr(options, var.lower()) + + import re + var_re = re.compile(r"\$\{([A-Za-z_0-9]+)\}") + string_var_re = re.compile(r"\$str\{([A-Za-z_0-9]+)\}") + for fname in subst_files: + lines = open(fname+".in", "r").readlines() + new_lines = [] + for l in lines: + made_change = True + while made_change: + made_change = False + match = var_re.search(l) + if match: + varname = match.group(1) + l = l[:match.start()] + substitutions[varname] + l[match.end():] + made_change = True + + match = string_var_re.search(l) + if match: + varname = match.group(1) + subst = substitutions[varname] + if subst is None: + subst = "" + else: + subst = '"%s"' % subst + + l = l[:match.start()] + subst + l[match.end():] + made_change = True + new_lines.append(l) + + file(fname, "w").write("".join(new_lines)) diff --git a/configvars.py b/configvars.py new file mode 100644 index 0000000000000000000000000000000000000000..0a2a0f0782684ea2142bfe711603cbc40a1827ae --- /dev/null +++ b/configvars.py @@ -0,0 +1,12 @@ +vars = [ + ("BOOST_INC_DIR", None, + "The include directory for all of Boost C++"), + ("BOOST_LIB_DIR", None, + "The library directory for all of Boost C++"), + ("BOOST_PYTHON_LIBNAME", "boost_python-gcc41-mt", + "The name of the Boost Python library binary (without lib and .so)"), + ("CXXFLAGS", None, + "Any extra C++ compiler options to include"), + ] + +subst_files = ["Makefile", "siteconf.py"] diff --git a/setup.py b/setup.py index 92246124df795eca7a557407487ef7903b7c6069..debfc38278671dd330f9c2976a8264924236f39b 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,27 @@ #!/usr/bin/env python -import os +import sys + +try: + execfile("siteconf.py") +except IOError: + print "*** Please run configure first." + sys.exit(1) + from distutils.core import setup,Extension -home = os.getenv("HOME") -boost_path = "%s/pool/include/boost-1_34" % home -include_dirs = [boost_path, "src"] -library_dirs = ["%s/pool/lib" % home] -libraries = ["boost_python-gcc41-mt"] +def non_matching_config(): + print "*** The version of your configuration template does not match" + print "*** the version of the setup script. Please re-run configure." + sys.exit(1) + +try: + MESHPY_CONF_TEMPLATE_VERSION +except NameError: + non_matching_config() + +if MESHPY_CONF_TEMPLATE_VERSION != 1: + non_matching_config() triangle_macros = [ ( "EXTERNAL_TEST", 1 ), @@ -20,7 +34,9 @@ tetgen_macros = [ ( "SELF_CHECK", 1 ) , ] - +INCLUDE_DIRS = BOOST_INCLUDE_DIRS +LIBRARY_DIRS = BOOST_LIBRARY_DIRS +LIBRARIES = BPL_LIBRARIES execfile("meshpy/__init__.py") setup(name="MeshPy", @@ -35,17 +51,17 @@ setup(name="MeshPy", Extension( "meshpy._triangle", ["src/wrap_triangle.cpp","src/triangle.c"], - include_dirs = include_dirs, - library_dirs = library_dirs, - libraries = libraries, + include_dirs=INCLUDE_DIRS, + library_dirs=LIBRARY_DIRS, + libraries=LIBRARIES, define_macros=triangle_macros ), Extension( "meshpy._tetgen", ["src/tetgen.cpp", "src/predicates.cpp", "src/wrap_tetgen.cpp"], - include_dirs = include_dirs, - library_dirs = library_dirs, - libraries = libraries, + include_dirs=INCLUDE_DIRS, + library_dirs=LIBRARY_DIRS, + libraries=LIBRARIES, define_macros=tetgen_macros ), ] diff --git a/siteconf.py.in b/siteconf.py.in new file mode 100644 index 0000000000000000000000000000000000000000..907f049950d4adf08b003ee185a5e08372283b9f --- /dev/null +++ b/siteconf.py.in @@ -0,0 +1,20 @@ +# -------------------------------------------------------------------- +# Specify your configuration below. +# See documentation for hints. +# -------------------------------------------------------------------- + +MESHPY_CONF_TEMPLATE_VERSION = 1 + +# -------------------------------------------------------------------- +# Path options +# -------------------------------------------------------------------- + +BOOST_INCLUDE_DIRS = [$str{BOOST_INC_DIR}] +BOOST_LIBRARY_DIRS = [$str{BOOST_LIB_DIR}] +BPL_LIBRARIES = [$str{BOOST_PYTHON_LIBNAME}] + +# -------------------------------------------------------------------- +# Compiler flags +# -------------------------------------------------------------------- +EXTRA_COMPILE_ARGS = [$str{CXXFLAGS}] +