[2490] | 1 | import os, sys, platform
|
---|
| 2 | from distutils.command import build_ext
|
---|
| 3 |
|
---|
| 4 | def get_libdir():
|
---|
| 5 | if not platform.architecture()[0].startswith("64"):
|
---|
| 6 | return "lib"
|
---|
| 7 | dist = platform.dist()[0].lower()
|
---|
| 8 | distdict = dict(suse='lib64', redhat='lib64')
|
---|
| 9 | return distdict.get(dist, 'lib')
|
---|
| 10 |
|
---|
| 11 | ARCHLIBDIR = get_libdir()
|
---|
| 12 |
|
---|
[2494] | 13 |
|
---|
| 14 | def get_numpy():
|
---|
| 15 | if sys.platform != "darwin":
|
---|
| 16 | return
|
---|
| 17 | import numpy
|
---|
| 18 | return os.path.join(numpy.__path__[0], "core", "include")
|
---|
| 19 |
|
---|
[2490] | 20 | class casacorebuild_ext(build_ext.build_ext):
|
---|
| 21 | """
|
---|
| 22 | """
|
---|
| 23 | user_options = build_ext.build_ext.user_options + \
|
---|
| 24 | [('casacore-root=', None,
|
---|
| 25 | 'Prefix for casacore installation location'),
|
---|
| 26 | ('pyrap=', None, 'Prefix for pyrap installation location'),
|
---|
| 27 | ('boost-root=', None,
|
---|
| 28 | 'Prefix for boost_python installation location'),
|
---|
| 29 | ('boostlib=', None, 'Name of the boost_python library'),
|
---|
| 30 | ('cfitsio-root=', None,
|
---|
| 31 | 'Prefix for cfitsio installation location'),
|
---|
| 32 | ('cfitsiolib=', None, 'Name of the cfitsio library'),
|
---|
| 33 | ('wcs-root=', None, 'Prefix for wcslib installation location'),
|
---|
| 34 | ('wcslib=', None, 'Name of the wcs library'),
|
---|
| 35 | ('rpfits-root=', None, 'Prefix for rpfits installation location'),
|
---|
| 36 | ('rpfitslib=', None, 'Name of the rpfits library'),
|
---|
| 37 | ('extra-root=', None,
|
---|
| 38 | 'Extra root directory where muiltple packages could be found,'
|
---|
| 39 | ' e.g. $HOME, to add $HOME/lib etc to the build.'),
|
---|
| 40 | ]
|
---|
| 41 |
|
---|
[2492] | 42 |
|
---|
[2490] | 43 | def initialize_options(self):
|
---|
| 44 | """
|
---|
| 45 | Overload to enable custom settings to be picked up
|
---|
| 46 | """
|
---|
| 47 | build_ext.build_ext.initialize_options(self)
|
---|
| 48 | # attribute corresponding to directory prefix
|
---|
| 49 | # command line option
|
---|
| 50 | self.libraries = ['casa_casa']
|
---|
| 51 | self.boostlib = 'boost_python'
|
---|
| 52 | self.extra_root = None
|
---|
| 53 | self.casacore_root = '/usr/local'
|
---|
| 54 | self.boost_root = '/usr'
|
---|
| 55 | self.cfitsio_root = '/usr'
|
---|
| 56 | self.cfitsiolib = 'cfitsio'
|
---|
| 57 | self.wcs_root = '/usr/local'
|
---|
| 58 | self.wcslib = 'wcs'
|
---|
| 59 | self.rpfits_root = '/usr/local'
|
---|
| 60 | self.rpfitslib = 'rpfits'
|
---|
| 61 |
|
---|
| 62 | def finalize_options(self):
|
---|
| 63 | """
|
---|
| 64 | Overloaded build_ext implementation to append custom library
|
---|
| 65 | include file and library linking options
|
---|
| 66 | """
|
---|
| 67 | build_ext.build_ext.finalize_options(self)
|
---|
| 68 |
|
---|
| 69 | if self.extra_root:
|
---|
| 70 | ldir = os.path.join(self.extra_root, ARCHLIBDIR)
|
---|
| 71 | if ldir not in self.library_dirs:
|
---|
| 72 | self.library_dirs += [ldir]
|
---|
| 73 | idir = os.path.join(self.extra_root, 'include')
|
---|
| 74 | if idir not in self.include_dirs:
|
---|
| 75 | self.include_dirs += [idir]
|
---|
| 76 |
|
---|
| 77 | cclibdir = os.path.join(self.casacore_root, ARCHLIBDIR)
|
---|
| 78 | boostlibdir = os.path.join(self.boost_root, ARCHLIBDIR)
|
---|
| 79 | cfitsiolibdir = os.path.join(self.cfitsio_root, ARCHLIBDIR)
|
---|
| 80 | wcslibdir = os.path.join(self.wcs_root, ARCHLIBDIR)
|
---|
| 81 | rpfitslibdir = os.path.join(self.rpfits_root, ARCHLIBDIR)
|
---|
| 82 |
|
---|
| 83 | ccincdir = os.path.join(self.casacore_root, 'include', 'casacore')
|
---|
| 84 | boostincdir = os.path.join(self.boost_root, 'include')
|
---|
| 85 | cfitsioincdir = os.path.join(self.cfitsio_root, 'include')
|
---|
| 86 | cfitsioincdir2 = os.path.join(self.cfitsio_root, 'include', 'cfitsio')
|
---|
| 87 | # cfitsio can have different path
|
---|
| 88 | if os.path.exists(cfitsioincdir2):
|
---|
| 89 | cfitsioincdir = cfitsioincdir2
|
---|
| 90 | wcsincdir = os.path.join(self.wcs_root, 'include')
|
---|
| 91 | rpfitsincdir = os.path.join(self.rpfits_root, 'include')
|
---|
| 92 |
|
---|
| 93 | if cclibdir not in self.library_dirs:
|
---|
| 94 | self.library_dirs += [cclibdir]
|
---|
| 95 |
|
---|
[2494] | 96 | numpyinc = get_numpy()
|
---|
| 97 | if numpyinc:
|
---|
| 98 | self.include_dirs += [numpyinc]
|
---|
| 99 |
|
---|
[2490] | 100 | if ccincdir not in self.include_dirs:
|
---|
| 101 | self.include_dirs += [ccincdir]
|
---|
| 102 | if boostincdir not in self.include_dirs:
|
---|
| 103 | self.include_dirs += [boostincdir]
|
---|
| 104 | if cfitsioincdir not in self.include_dirs:
|
---|
| 105 | self.include_dirs += [cfitsioincdir]
|
---|
| 106 | if wcsincdir not in self.include_dirs:
|
---|
| 107 | self.include_dirs += [wcsincdir]
|
---|
| 108 | if rpfitsincdir not in self.include_dirs:
|
---|
| 109 | self.include_dirs += [rpfitsincdir]
|
---|
| 110 |
|
---|
| 111 | def add_static(lib, libdir):
|
---|
| 112 | if lib.endswith(".a"):
|
---|
| 113 | self.extensions[0].extra_objects.extend([lib])
|
---|
| 114 | else:
|
---|
| 115 | if libdir not in self.library_dirs:
|
---|
| 116 | self.library_dirs += [libdir]
|
---|
| 117 | self.libraries += [lib]
|
---|
| 118 |
|
---|
| 119 | add_static(self.boostlib, boostlibdir)
|
---|
| 120 | add_static(self.wcslib, wcslibdir)
|
---|
| 121 | add_static(self.cfitsiolib, cfitsiolibdir)
|
---|
| 122 | # always static anyway
|
---|
| 123 | self.libraries += [self.rpfitslib]
|
---|
| 124 |
|
---|
| 125 | sysdir = '/usr/include'
|
---|
| 126 | if sysdir in self.include_dirs:
|
---|
| 127 | self.include_dirs.remove(sysdir)
|
---|
| 128 | sysdir = os.path.join('/usr', ARCHLIBDIR)
|
---|
| 129 | for d in self.library_dirs:
|
---|
| 130 | if d.startswith(sysdir):
|
---|
| 131 | sysdir = d
|
---|
| 132 | self.library_dirs.remove(sysdir)
|
---|
| 133 | break
|
---|
| 134 |
|
---|
| 135 |
|
---|
[2492] | 136 | def build_extensions(self):
|
---|
[2493] | 137 | def remove_args(args):
|
---|
| 138 | out = []
|
---|
| 139 | delargs = ["-Wstrict-prototypes", "-Wshorten-64-to-32",
|
---|
| 140 | "-fwrapv", ]
|
---|
| 141 | for arg in args:
|
---|
| 142 | if arg not in delargs and arg not in out:
|
---|
| 143 | out.append(arg)
|
---|
| 144 | return out
|
---|
[2492] | 145 |
|
---|
[2493] | 146 | self.compiler.compiler = remove_args(self.compiler.compiler)
|
---|
| 147 | self.compiler.compiler_so = remove_args(self.compiler.compiler_so)
|
---|
| 148 | self.compiler.compiler_cxx = remove_args(self.compiler.compiler_cxx)
|
---|
| 149 |
|
---|
[2492] | 150 | build_ext.build_ext.build_extensions(self)
|
---|