setup.py (Revision 4761, commited at 2013-07-11)

Go to the documentation of this file.
00001 ##
00002 # 
00003 # \brief This is the configuration file that is also used to build the package.
00004 # It uses the standard distutils Python module to provide a platform independent
00005 # build mechanism
00006 # 
00007 
00008 from distutils.core import setup, Extension
00009 import os, sys
00010 import os.path as path
00011 
00012 # ###########################################################################
00013 def getOS():
00014   if os.getenv('OS'):
00015       os_name = os.getenv('OS')
00016       '''Building DIM depends on $OS. If this is wrongly set then building DIM
00017   doesn't work and the installation will fail...
00018       '''        
00019   else:
00020       os_name = os.uname()[0].lower()
00021   return os_name
00022       
00023 # ###########################################################################
00024 
00025 # The operating system (inherited from the environment if it exist). Possible
00026 # variables include 'linux' and 'windows'
00027 OS = getOS()
00028 
00029 
00030 # With which libraries pydim should be linked 
00031 #LIBRARIES = ['dim', 'dl']    
00032 LIBRARIES = ['dim'] 
00033 #
00034 # Use the following variable if you need to pass any special options to the 
00035 # compiler. 
00036 # 
00037 COMPILE_ARGS = []
00038 if OS.lower().find('win') > -1:
00039     # we have some sort of a windows machine
00040     COMPILE_ARGS += ['-DWIN32','-D__DEBUG', '-DDEBUG']
00041     #COMPILE_ARGS += ['-DWIN32']
00042     LIBRARIES.append('ws2_32')
00043     
00044 else:
00045     LIBRARIES.append('dl')
00046 #    COMPILE_ARGS += [ '-Wno-deprecated']
00047 #    COMPILE_ARGS += ['-g', '-O0', '-D__DEBUG', '-DDEBUG', '-fno-inline', '-fno-default-inline']
00048 
00049 
00050 # This can be used to build in debug mode and/or profiling. The internal debug 
00051 # of the DIM wrapper can be turned on using the -DDEBUG. For example: 
00052 #
00053 #
00054 # Additional compile flags can be set using the CFLAGS environment variable or
00055 # by creating a Setup file with the complementary instructions:
00056 #
00057 # http://docs.python.org/install/index.html#tweaking-compiler-linker-flags
00058 #
00059 
00060 # ###########################################################################
00061 # Although we should already have all the build info by this point we can 
00062 # still do a bit of guess work to find the DIM location(s). Building DIM
00063 # usually creates some environment variables that we can search for. 
00064 
00065 # The expected location for the DIM.
00066 dim_dir = None
00067 
00068 # The expected location for the DIM headers is in DIM_HOME/dim. 
00069 dim_include_dirs = []
00070 
00071 # The location where the DIM library (libdim.so on linux or dim.dll on Windows) 
00072 dim_library_dirs = []
00073 
00074 # The following environment variables will be used looking for the Dim installation 
00075 dim_env_vars = ('DIMDIR', 'DIMHOME', 'DIM_HOME')
00076 for dim_var in dim_env_vars:
00077     
00078     if os.getenv(dim_var):
00079       dim_dir = os.getenv(dim_var)
00080       dim_include_dirs = [dim_dir, os.path.join(dim_dir, 'dim')]
00081       dim_library_dirs = [dim_dir, os.path.join(dim_dir, 'bin'),os.path.join(dim_dir, OS)]
00082 
00083 if not dim_include_dirs and not dim_library_dirs:
00084     dim_dir = path.join(os.getcwd(), '..', 'dim')
00085     if path.exists(dim_dir):
00086       dim_include_dirs = [dim_dir, os.path.join(dim_dir, OS)]
00087       dim_library_dirs = [dim_dir, os.path.join(dim_dir, 'dim')]
00088     else:
00089       dim_dir = None
00090 
00091 #Adding the usual library and platform include paths
00092 # Only for linux right now...  
00093 if not dim_include_dirs and os.sys.platform == 'linux2':
00094     dim_include_dirs = [ '/usr/local/include/dim' ]
00095 if not dim_library_dirs and os.sys.platform == 'linxu2':
00096     if os.uname()[4] == 'x86_64':
00097         dim_library_dirs = [ '/usr/local/lib64/' ]
00098     else:
00099         dim_library_dirs = [ '/usr/local/lib' ]
00100 
00101 #INCLUDE_DIRS = [ '/usr/local/include', 
00102 #                      '/usr/include/dim', '/usr/local/include/dim']
00103 
00104 #LIBRARY_DIRS = [ 
00105 #                      '/usr/lib/dim', '/usr/lib64/dim', 
00106 #                      '/usr/local/lib', '/usr/local/lib64',
00107 #                      '/usr/local/lib/dim', '/usr/local/lib64/dim']      
00108 
00109 # ##############################################################################
00110 # The final building parameters
00111 cwd = os.getcwd()
00112 include_dirs = dim_include_dirs# + INCLUDE_DIRS
00113 include_dirs.append(os.path.join(cwd, 'src'))
00114 library_dirs = dim_library_dirs# + LIBRARY_DIRS
00115 compile_args = COMPILE_ARGS
00116 libraries = LIBRARIES
00117 platform = sys.platform
00118 version = open('./VERSION').read().strip()
00119 
00120 ################################################################################
00121 #Printing the final variables and building the package
00122 print 80*'-'
00123 print 'Welcome to the DIM Python interface module (PyDIM) installer.'
00124 print 80*'-'
00125 print 'Using variables:'
00126 print 'DIM dirs: %s' % dim_dir
00127 print 'OS: %s' % OS
00128 print 'Include dirs: %s' %include_dirs
00129 print 'Library dirs: %s' %library_dirs
00130 print 'Compile args: %s' %compile_args
00131 print 80*'-'
00132 
00133 dimmodule = Extension('dimc',
00134                       sources = ['src/dimmodule.cpp', 'src/pydim_utils.cpp'],
00135                       include_dirs = include_dirs,
00136                       libraries = libraries,
00137                       library_dirs = library_dirs,
00138                       extra_compile_args = compile_args
00139                      )
00140 dimmodule_cpp = Extension('dimcpp',
00141                       sources = ['src/dimcppmodule.cpp', 'src/pydim_utils.cpp'],
00142                       include_dirs = include_dirs,
00143                       libraries = libraries,
00144                       library_dirs = library_dirs,
00145                       extra_compile_args = compile_args
00146                       )
00147 setup(name = 'pydim',
00148       version = version,
00149       description = 'Python interface package for DIM C and C++ interfaces.',
00150       long_description = 'The PyDIM package exposes the DIM C and C++ functions and classes in Python.',
00151       license='GPL',
00152       url = 'http://lbdoc.cern.ch/pydim/',
00153       author = 'Niko Neufeld (originally by Radu Stoica)',
00154       author_email = 'niko.neufeld@cern.ch',
00155       py_modules = ['pydim/__init__', 'pydim/debug'],
00156       ext_modules = [dimmodule_cpp, dimmodule],
00157       scripts = [],
00158      )
00159 # And now we should have a happy user :-)
00160 # ##############################################################################
00161 
00162 

Generated on 5 Feb 2014 for PyDIM by  doxygen 1.4.7