Commit 50500d0fc94fbdc5a4293e95a049eb1ca50e77ef

Authored by knodlseder
1 parent 68c45e44

Remove double compiling and add special make check rule that links to static library

ChangeLog
1   -2011-10-20 Juergen Knoedlseder <knodlseder@cesr.fr>
  1 +2011-10-23 Juergen Knoedlseder <knodlseder@cesr.fr>
2 2  
3   - * Version 0.3.0 released
  3 + * Version 0.4.0 released
4 4 ========================
5 5  
6 6 Renamed to ctools
7 7 Add configure options for Mac OSX universal builds
8 8 Remove automake dependency tracking
  9 + Improve building of Python bindings
  10 +
  11 +
  12 +2011-10-06 Juergen Knoedlseder <knodlseder@cesr.fr>
  13 +
  14 + * Version 0.3.0 released
  15 + ========================
  16 +
  17 + Renamed to ctools
9 18  
10 19  
11 20 2011-10-03 Juergen Knoedlseder <knodlseder@cesr.fr>
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-04-00
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -October 20, 2011
  5 +October 23, 2011
6 6  
7 7  
8 8 1. Introduction
... ... @@ -21,7 +21,10 @@ universal builds.
21 21  
22 22 3. Python interface
23 23 -------------------
24   -None
  24 +The Python binding building scheme from GammaLib has been adapted.
  25 +This avoids double compilation during 'make' and performs a special
  26 +build during 'make check' that provides a Python module which is
  27 +statically linked to the ctools library.
25 28  
26 29 4. ctobssim - CTA observation simulation
27 30 ----------------------------------------
... ...
pyext/Makefile.am
1   -## Process this file with automake to produce Makefile.in
2   -#
3   -# The actual implemented logic is to use swig if swig is
4   -# available on the system
  1 +#############################################################################
  2 +# Makefile for ctools Python extension module #
  3 +# ------------------------------------------------------------------------- #
  4 +# Copyright (C) 2011 Jurgen Knodlseder #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# This program is free software: you can redistribute it and/or modify #
  8 +# it under the terms of the GNU General Public License as published by #
  9 +# the Free Software Foundation, either version 3 of the License, or #
  10 +# (at your option) any later version. #
  11 +# #
  12 +# This program is distributed in the hope that it will be useful, #
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  15 +# GNU General Public License for more details. #
  16 +# #
  17 +# You should have received a copy of the GNU General Public License #
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>. #
  19 +# #
  20 +# ------------------------------------------------------------------------- #
  21 +# This Makefile will build the Python interface files (*.py) and the Python #
  22 +# wrapper files using SWIG (if available; otherwise we have to make sure #
  23 +# the the files exist already). The Python distutils are used to build and #
  24 +# install the Python modules (see file setup.py.in). #
  25 +# #
  26 +# Process this file with automake to produce Makefile.in. #
  27 +#############################################################################
5 28  
6 29 if WITH_PYTHON
7 30  
... ... @@ -26,16 +49,25 @@ all-local: build
26 49 # of this specific directory. So we build one instance for checking, the other
27 50 # for installation. If we could get the name built by distutils we could avoid
28 51 # this.
  52 +#$(PYTHON) setup.py build --build-platlib build
29 53 build: ctools_wrap.cpp ctools.py
30   - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build --build-platlib build
31   - $(PYTHON_BUILD_PREFIX) $(PYTHON) setup.py build
  54 + $(PYTHON) setup.py build
  55 +
  56 +# If 'make check' is invoked we build the extension modules inplace, so that
  57 +# putting the 'pyext' directory in the PYTHONPATH allows importing the gammalib
  58 +# module. We also catch this special build in the setup script to force static
  59 +# linking with libgamma, which will allow a successful 'make check' on systems
  60 +# (such as Mac OS X) that have fixed shared library paths.
  61 +check-local:
  62 + $(PYTHON) setup.py build_ext --inplace
32 63  
33 64 install-exec-local:
34 65 $(PYTHON) setup.py install --prefix=$(prefix)
35 66  
36 67 clean-local:
37   - rm -rf build
38   -
  68 + rm -rf build _ctools.so
  69 +
  70 +# Rule for building Python wrappers using SWIG.
39 71 if HAVE_SWIG
40 72 ctools_wrap.cpp ctools.py: $(SWIG_INTERFACE)
41 73 $(SWIG) -c++ -python -Wall -I$(prefix)/share/gammalib/swig -I$(GAMMALIB)/share/gammalib/swig -o ctools_wrap.cpp -outdir . $(srcdir)/$(SWIG_INTERFACE)
... ...
pyext/setup.py.in
  1 +#############################################################################
  2 +# Disutils setup file for ctools Python extension module #
  3 +# ------------------------------------------------------------------------- #
  4 +# Copyright (C) 2011 Jurgen Knodlseder #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# This program is free software: you can redistribute it and/or modify #
  8 +# it under the terms of the GNU General Public License as published by #
  9 +# the Free Software Foundation, either version 3 of the License, or #
  10 +# (at your option) any later version. #
  11 +# #
  12 +# This program is distributed in the hope that it will be useful, #
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  15 +# GNU General Public License for more details. #
  16 +# #
  17 +# You should have received a copy of the GNU General Public License #
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>. #
  19 +# #
  20 +#############################################################################
  21 +
1 22 from distutils.core import setup, Extension
2 23 from distutils import sysconfig
3 24 import glob
4 25 import os
5 26 import sys
6 27  
7   -# Removes list of bad prefixes from list
8   -#def remove_prefixes(optlist, bad_prefixes):
9   -# for bad_prefix in bad_prefixes:
10   -# for i, flag in enumerate(optlist):
11   -# if flag.startswith(bad_prefix):
12   -# optlist.pop(i)
13   -# break
14   -# return optlist
15   -
16   -# Adjust compile options for darwin
17   -#if sys.platform.lower().startswith("darwin"):
18   -#
19   -# # Remove some time consuming options
20   -# cvars = sysconfig.get_config_vars()
21   -# cflags = cvars.get('OPT')
22   -# if cflags:
23   -# cflags = remove_prefixes(cflags.split(),
24   -# ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG'])
25   -# cvars['OPT'] = str.join(' ', cflags)
26   -# cvars['CFLAGS'] = cvars['BASECFLAGS'] + ' ' + cvars['OPT']
27   -#
28   -# # Remove -arch flags. This prevents building a fat library
29   -# cvars['ARCHFLAGS'] = ''
30   -#
31   -# # Signal darwin compiler adjustments
32   -# print 'Adjust default distutils compiler options for darwin.'
33   -
34   -# Remove any existing symbolic link to libctools.a
35   -# This will prevent any exception in creating the symbolic link due to
36   -# an already existing link.
37   -try:
38   - os.remove('../src/.libs/libctools_python.a')
39   - print 'Removed ../src/.libs/libctools_python.a'
40   -except:
41   - pass
  28 +# Detect execution mode
  29 +is_unit_test = False
  30 +if (len(sys.argv) >= 3):
  31 + if (sys.argv[2] == '--inplace'):
  32 + print "This build is for unit testing."
  33 + is_unit_test = True
42 34  
43   -# Create a symbolic link. This allows us to enforce static linking instead of
44   -# dynamic linking. We prefer here static linking to avoid any problems with
45   -# finding the gammalib shared library during checking.
46   -try:
47   - os.symlink('libctools.a', '../src/.libs/libctools_python.a')
48   - print 'Created ../src/.libs/libctools_python.a'
49   - libcta='ctools_python'
50   -except:
51   - libcta='ctatool'
  35 +# Set ctools library name. If we're about to make the test build then
  36 +# create a symbolic link to the static library to enforce static linking.
  37 +# This is required on some system (such as Mac OS X) to avoid problems
  38 +# with finding the shared library during unit testing.
  39 +libcta='ctools'
  40 +if is_unit_test:
  41 +
  42 + # Remove any existing symbolic link to libctools.a. This will
  43 + # prevent any exception in creating the symbolic link due to
  44 + # an already existing link.
  45 + try:
  46 + os.remove('../src/.libs/libctools_python.a')
  47 + print 'Removed ../src/.libs/libctools_python.a'
  48 + except:
  49 + pass
  50 +
  51 + # Now create a symbolic link and set the library name to this
  52 + # symbolic link
  53 + try:
  54 + os.symlink('libctools.a', '../src/.libs/libctools_python.a')
  55 + print 'Created ../src/.libs/libctools_python.a'
  56 + libcta='ctools_python'
  57 + except:
  58 + print 'WARNING: Failed to create symbolic link to static library. Link dynamically.'
52 59  
53 60 # Set default include directories and data files
54   -include_dirs = ['@prefix@/include/gammalib']
55   -data_files = glob.glob('@top_srcdir@/pyext/*.i')
56   -library_dirs = ['../src/.libs']
57   -libraries = [libcta,'gamma']
  61 +include_dirs = ['@prefix@/include/gammalib']
  62 +install_files = glob.glob('@top_srcdir@/pyext/*.i')
  63 +library_dirs = ['../src/.libs']
  64 +libraries = [libcta,'gamma']
58 65  
59 66 # Append prefix library directory if it exists and set default runtime
60 67 # library directories
... ... @@ -96,11 +103,17 @@ for extra_include_dir in extra_include_dirs:
96 103 if len(dir) > 0:
97 104 include_dirs.append(dir)
98 105  
  106 +# Set data files to install. Do not install data files in unit testing mode.
  107 +if is_unit_test:
  108 + data_files=[]
  109 +else:
  110 + data_files=[('@prefix@/share/ctools/swig', install_files)]
  111 +
99 112 # Setup
100 113 setup(name='@PACKAGE_NAME@',
101 114 version='@PACKAGE_VERSION@',
102   - description='ctools Python binding',
103   - author='Jurgen Knodlseder',
  115 + description='ctools Python bindings',
  116 + author='Juergen Knoedlseder',
104 117 author_email='@PACKAGE_BUGREPORT@',
105 118 url='http://gammalib.sourceforge.net/',
106 119 py_modules=['ctools'],
... ... @@ -109,4 +122,8 @@ setup(name=&#39;@PACKAGE_NAME@&#39;,
109 122 library_dirs=library_dirs,
110 123 libraries=libraries,
111 124 runtime_library_dirs=runtime_library_dirs)],
112   - )
  125 + data_files=data_files,
  126 + license="GNU GPL v3",
  127 + long_description="CTA science analysis tools",
  128 + platforms=["Linux", "Solaris", "Mac OS-X", "Unix", "BSD"],
  129 + )
... ...