source: trunk/distutils/setupext.py@ 2490

Last change on this file since 2490 was 2490, checked in by Malte Marquarding, 13 years ago

transitional directory for build files as a distutils based python package. The contents will move to the top dir and scons will be removed.

File size: 4.6 KB
Line 
1import os, sys, platform
2from distutils.command import build_ext
3
4def 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
11ARCHLIBDIR = get_libdir()
12
13class 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
35 def initialize_options(self):
36 """
37 Overload to enable custom settings to be picked up
38 """
39 build_ext.build_ext.initialize_options(self)
40 # attribute corresponding to directory prefix
41 # command line option
42 self.libraries = ['casa_casa']
43 self.boostlib = 'boost_python'
44 self.extra_root = None
45 self.casacore_root = '/usr/local'
46 self.boost_root = '/usr'
47 self.cfitsio_root = '/usr'
48 self.cfitsiolib = 'cfitsio'
49 self.wcs_root = '/usr/local'
50 self.wcslib = 'wcs'
51 self.rpfits_root = '/usr/local'
52 self.rpfitslib = 'rpfits'
53
54 def finalize_options(self):
55 """
56 Overloaded build_ext implementation to append custom library
57 include file and library linking options
58 """
59 build_ext.build_ext.finalize_options(self)
60
61 if self.extra_root:
62 ldir = os.path.join(self.extra_root, ARCHLIBDIR)
63 if ldir not in self.library_dirs:
64 self.library_dirs += [ldir]
65 idir = os.path.join(self.extra_root, 'include')
66 if idir not in self.include_dirs:
67 self.include_dirs += [idir]
68
69 cclibdir = os.path.join(self.casacore_root, ARCHLIBDIR)
70 boostlibdir = os.path.join(self.boost_root, ARCHLIBDIR)
71 cfitsiolibdir = os.path.join(self.cfitsio_root, ARCHLIBDIR)
72 wcslibdir = os.path.join(self.wcs_root, ARCHLIBDIR)
73 rpfitslibdir = os.path.join(self.rpfits_root, ARCHLIBDIR)
74
75 ccincdir = os.path.join(self.casacore_root, 'include', 'casacore')
76 boostincdir = os.path.join(self.boost_root, 'include')
77 cfitsioincdir = os.path.join(self.cfitsio_root, 'include')
78 cfitsioincdir2 = os.path.join(self.cfitsio_root, 'include', 'cfitsio')
79 # cfitsio can have different path
80 if os.path.exists(cfitsioincdir2):
81 cfitsioincdir = cfitsioincdir2
82 wcsincdir = os.path.join(self.wcs_root, 'include')
83 rpfitsincdir = os.path.join(self.rpfits_root, 'include')
84
85 if cclibdir not in self.library_dirs:
86 self.library_dirs += [cclibdir]
87
88 if ccincdir not in self.include_dirs:
89 self.include_dirs += [ccincdir]
90 if boostincdir not in self.include_dirs:
91 self.include_dirs += [boostincdir]
92 if cfitsioincdir not in self.include_dirs:
93 self.include_dirs += [cfitsioincdir]
94 if wcsincdir not in self.include_dirs:
95 self.include_dirs += [wcsincdir]
96 if rpfitsincdir not in self.include_dirs:
97 self.include_dirs += [rpfitsincdir]
98
99 def add_static(lib, libdir):
100 if lib.endswith(".a"):
101 self.extensions[0].extra_objects.extend([lib])
102 else:
103 if libdir not in self.library_dirs:
104 self.library_dirs += [libdir]
105 self.libraries += [lib]
106
107 add_static(self.boostlib, boostlibdir)
108 add_static(self.wcslib, wcslibdir)
109 add_static(self.cfitsiolib, cfitsiolibdir)
110 # always static anyway
111 self.libraries += [self.rpfitslib]
112
113 sysdir = '/usr/include'
114 if sysdir in self.include_dirs:
115 self.include_dirs.remove(sysdir)
116 sysdir = os.path.join('/usr', ARCHLIBDIR)
117 for d in self.library_dirs:
118 if d.startswith(sysdir):
119 sysdir = d
120 self.library_dirs.remove(sysdir)
121 break
122
123
124 def run(self):
125 build_ext.build_ext.run(self)
Note: See TracBrowser for help on using the repository browser.