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