From 50500d0fc94fbdc5a4293e95a049eb1ca50e77ef Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Mon, 24 Oct 2011 03:56:12 +0000 Subject: [PATCH] Remove double compiling and add special make check rule that links to static library --- ChangeLog | 13 +++++++++++-- NEWS | 7 +++++-- pyext/Makefile.am | 48 ++++++++++++++++++++++++++++++++++++++++-------- pyext/setup.py.in | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- 4 files changed, 124 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 583d033..6602432 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,20 @@ -2011-10-20 Juergen Knoedlseder +2011-10-23 Juergen Knoedlseder - * Version 0.3.0 released + * Version 0.4.0 released ======================== Renamed to ctools Add configure options for Mac OSX universal builds Remove automake dependency tracking + Improve building of Python bindings + + +2011-10-06 Juergen Knoedlseder + + * Version 0.3.0 released + ======================== + + Renamed to ctools 2011-10-03 Juergen Knoedlseder diff --git a/NEWS b/NEWS index 0559ddc..35086fa 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-04-00 Author(s) : Juergen Knoedlseder -October 20, 2011 +October 23, 2011 1. Introduction @@ -21,7 +21,10 @@ universal builds. 3. Python interface ------------------- -None +The Python binding building scheme from GammaLib has been adapted. +This avoids double compilation during 'make' and performs a special +build during 'make check' that provides a Python module which is +statically linked to the ctools library. 4. ctobssim - CTA observation simulation ---------------------------------------- diff --git a/pyext/Makefile.am b/pyext/Makefile.am index 79b034a..12384a2 100755 --- a/pyext/Makefile.am +++ b/pyext/Makefile.am @@ -1,7 +1,30 @@ -## Process this file with automake to produce Makefile.in -# -# The actual implemented logic is to use swig if swig is -# available on the system +############################################################################# +# Makefile for ctools Python extension module # +# ------------------------------------------------------------------------- # +# Copyright (C) 2011 Jurgen Knodlseder # +# ------------------------------------------------------------------------- # +# # +# 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 3 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 . # +# # +# ------------------------------------------------------------------------- # +# This Makefile will build the Python interface files (*.py) and the Python # +# wrapper files using SWIG (if available; otherwise we have to make sure # +# the the files exist already). The Python distutils are used to build and # +# install the Python modules (see file setup.py.in). # +# # +# Process this file with automake to produce Makefile.in. # +############################################################################# if WITH_PYTHON @@ -26,16 +49,25 @@ all-local: build # of this specific directory. So we build one instance for checking, the other # for installation. If we could get the name built by distutils we could avoid # this. +#$(PYTHON) setup.py build --build-platlib build build: ctools_wrap.cpp ctools.py - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build --build-platlib build - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build + $(PYTHON) setup.py build + +# If 'make check' is invoked we build the extension modules inplace, so that +# putting the 'pyext' directory in the PYTHONPATH allows importing the gammalib +# module. We also catch this special build in the setup script to force static +# linking with libgamma, which will allow a successful 'make check' on systems +# (such as Mac OS X) that have fixed shared library paths. +check-local: + $(PYTHON) setup.py build_ext --inplace install-exec-local: $(PYTHON) setup.py install --prefix=$(prefix) clean-local: - rm -rf build - + rm -rf build _ctools.so + +# Rule for building Python wrappers using SWIG. if HAVE_SWIG ctools_wrap.cpp ctools.py: $(SWIG_INTERFACE) $(SWIG) -c++ -python -Wall -I$(prefix)/share/gammalib/swig -I$(GAMMALIB)/share/gammalib/swig -o ctools_wrap.cpp -outdir . $(srcdir)/$(SWIG_INTERFACE) diff --git a/pyext/setup.py.in b/pyext/setup.py.in index 988e92c..b2a36a2 100644 --- a/pyext/setup.py.in +++ b/pyext/setup.py.in @@ -1,60 +1,67 @@ +############################################################################# +# Disutils setup file for ctools Python extension module # +# ------------------------------------------------------------------------- # +# Copyright (C) 2011 Jurgen Knodlseder # +# ------------------------------------------------------------------------- # +# # +# 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 3 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 . # +# # +############################################################################# + from distutils.core import setup, Extension from distutils import sysconfig import glob import os import sys -# Removes list of bad prefixes from list -#def remove_prefixes(optlist, bad_prefixes): -# for bad_prefix in bad_prefixes: -# for i, flag in enumerate(optlist): -# if flag.startswith(bad_prefix): -# optlist.pop(i) -# break -# return optlist - -# Adjust compile options for darwin -#if sys.platform.lower().startswith("darwin"): -# -# # Remove some time consuming options -# cvars = sysconfig.get_config_vars() -# cflags = cvars.get('OPT') -# if cflags: -# cflags = remove_prefixes(cflags.split(), -# ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG']) -# cvars['OPT'] = str.join(' ', cflags) -# cvars['CFLAGS'] = cvars['BASECFLAGS'] + ' ' + cvars['OPT'] -# -# # Remove -arch flags. This prevents building a fat library -# cvars['ARCHFLAGS'] = '' -# -# # Signal darwin compiler adjustments -# print 'Adjust default distutils compiler options for darwin.' - -# Remove any existing symbolic link to libctools.a -# This will prevent any exception in creating the symbolic link due to -# an already existing link. -try: - os.remove('../src/.libs/libctools_python.a') - print 'Removed ../src/.libs/libctools_python.a' -except: - pass +# Detect execution mode +is_unit_test = False +if (len(sys.argv) >= 3): + if (sys.argv[2] == '--inplace'): + print "This build is for unit testing." + is_unit_test = True -# Create a symbolic link. This allows us to enforce static linking instead of -# dynamic linking. We prefer here static linking to avoid any problems with -# finding the gammalib shared library during checking. -try: - os.symlink('libctools.a', '../src/.libs/libctools_python.a') - print 'Created ../src/.libs/libctools_python.a' - libcta='ctools_python' -except: - libcta='ctatool' +# Set ctools library name. If we're about to make the test build then +# create a symbolic link to the static library to enforce static linking. +# This is required on some system (such as Mac OS X) to avoid problems +# with finding the shared library during unit testing. +libcta='ctools' +if is_unit_test: + + # Remove any existing symbolic link to libctools.a. This will + # prevent any exception in creating the symbolic link due to + # an already existing link. + try: + os.remove('../src/.libs/libctools_python.a') + print 'Removed ../src/.libs/libctools_python.a' + except: + pass + + # Now create a symbolic link and set the library name to this + # symbolic link + try: + os.symlink('libctools.a', '../src/.libs/libctools_python.a') + print 'Created ../src/.libs/libctools_python.a' + libcta='ctools_python' + except: + print 'WARNING: Failed to create symbolic link to static library. Link dynamically.' # Set default include directories and data files -include_dirs = ['@prefix@/include/gammalib'] -data_files = glob.glob('@top_srcdir@/pyext/*.i') -library_dirs = ['../src/.libs'] -libraries = [libcta,'gamma'] +include_dirs = ['@prefix@/include/gammalib'] +install_files = glob.glob('@top_srcdir@/pyext/*.i') +library_dirs = ['../src/.libs'] +libraries = [libcta,'gamma'] # Append prefix library directory if it exists and set default runtime # library directories @@ -96,11 +103,17 @@ for extra_include_dir in extra_include_dirs: if len(dir) > 0: include_dirs.append(dir) +# Set data files to install. Do not install data files in unit testing mode. +if is_unit_test: + data_files=[] +else: + data_files=[('@prefix@/share/ctools/swig', install_files)] + # Setup setup(name='@PACKAGE_NAME@', version='@PACKAGE_VERSION@', - description='ctools Python binding', - author='Jurgen Knodlseder', + description='ctools Python bindings', + author='Juergen Knoedlseder', author_email='@PACKAGE_BUGREPORT@', url='http://gammalib.sourceforge.net/', py_modules=['ctools'], @@ -109,4 +122,8 @@ setup(name='@PACKAGE_NAME@', library_dirs=library_dirs, libraries=libraries, runtime_library_dirs=runtime_library_dirs)], - ) + data_files=data_files, + license="GNU GPL v3", + long_description="CTA science analysis tools", + platforms=["Linux", "Solaris", "Mac OS-X", "Unix", "BSD"], + ) -- libgit2 0.21.4