|
1 import Utils |
|
2 import os |
|
3 from Utils import ModuleAttributeBase |
|
4 |
|
5 class ModuleBuild(ModuleAttributeBase): |
|
6 def __init__(self): |
|
7 ModuleAttributeBase.__init__(self) |
|
8 @classmethod |
|
9 def create(cls, name): |
|
10 for subclass in ModuleBuild.__subclasses__(): |
|
11 if subclass.name() == name: |
|
12 return subclass() |
|
13 return None |
|
14 def build(self, logger, srcdir, blddir, installdir): |
|
15 raise NotImplemented() |
|
16 def clean(self, logger, srcdir, blddir): |
|
17 raise NotImplemented() |
|
18 |
|
19 class NoneModuleBuild(ModuleBuild): |
|
20 def __init__(self): |
|
21 ModuleBuild.__init__(self) |
|
22 @classmethod |
|
23 def name(cls): |
|
24 return 'none' |
|
25 def build(self, logger, srcdir, blddir, installdir): |
|
26 pass |
|
27 def clean(self, logger, srcdir, blddir): |
|
28 pass |
|
29 |
|
30 class Cmake(ModuleBuild): |
|
31 def __init__(self): |
|
32 ModuleBuild.__init__(self) |
|
33 self.add_attribute('CC', '', 'C compiler to use') |
|
34 self.add_attribute('CXX', '', 'C++ compiler to use') |
|
35 self.add_attribute('CFLAGS', '', 'Flags to use for C compiler') |
|
36 self.add_attribute('CXXFLAGS', '', 'Flags to use for C++ compiler') |
|
37 self.add_attribute('LDFLAGS', '', 'Flags to use for Linker') |
|
38 @classmethod |
|
39 def name(cls): |
|
40 return 'cmake' |
|
41 def build(self, logger, srcdir, blddir, installdir): |
|
42 variables = [] |
|
43 if self.attribute('CC').value != '': |
|
44 variables.append('-DCMAKE_C_COMPILER=' + self.attribute('CC').value) |
|
45 if self.attribute('CFLAGS').value != '': |
|
46 variables.append('-DCMAKE_CFLAGS=' + self.attribute('CFLAGS').value) |
|
47 if self.attribute('CXX').value != '': |
|
48 variables.append('-DCMAKE_CXX_COMPILER=' + self.attribute('CXX').value) |
|
49 if self.attribute('CXXFLAGS').value != '': |
|
50 variables.append('-DCMAKE_CXXFLAGS=' + self.attribute('CXXFLAGS').value) |
|
51 if self.attribute('LDFLAGS').value != '': |
|
52 variables.append('-DCMAKE_EXE_LINKER_FLAGS=' + self.attribute('LDFLAGS').value) |
|
53 Utils.run_command(['cmake', srcdir, '-DCMAKE_INSTALL_PREFIX=' + installdir] + variables, |
|
54 logger, |
|
55 directory=blddir) |
|
56 Utils.run_command(['make'], logger, directory = blddir) |
|
57 Utils.run_command(['make', 'doc'], logger, directory = blddir) |
|
58 Utils.run_command(['make', 'install'], logger, directory = blddir) |
|
59 def clean(self, logger, srcdir, blddir): |
|
60 pass |
|
61 |
|
62 |
|
63 class Autotools(ModuleBuild): |
|
64 def __init__(self): |
|
65 ModuleBuild.__init__(self) |
|
66 self.add_attribute('CC', '', 'C compiler to use') |
|
67 self.add_attribute('CXX', '', 'C++ compiler to use') |
|
68 self.add_attribute('CFLAGS', '', 'Flags to use for C compiler') |
|
69 self.add_attribute('CXXFLAGS', '', 'Flags to use for C++ compiler') |
|
70 self.add_attribute('LDFLAGS', '', 'Flags to use for Linker') |
|
71 self.add_attribute('blddir', 'srcdir', |
|
72 'Does this module support building in blddir != srcdir ? ' |
|
73 'Defaults to blddir == srcdir. ') |
|
74 self.add_attribute('maintainer', 'no', 'Maintainer mode ?') |
|
75 @classmethod |
|
76 def name(cls): |
|
77 return 'autotools' |
|
78 def build(self, logger, srcdir, blddir, installdir): |
|
79 if self.attribute('maintainer').value != 'no': |
|
80 Utils.run_command(['autoreconf', '--install'], logger, |
|
81 directory = srcdir) |
|
82 if self.attribute('blddir').value == 'srcdir': |
|
83 blddir = srcdir |
|
84 Utils.run_command([os.path.join(srcdir, 'configure'), |
|
85 '--prefix=' + installdir, |
|
86 'CC=' + self.attribute('CC').value, |
|
87 'CXX=' + self.attribute('CXX').value, |
|
88 'CFLAGS=' + self.attribute('CFLAGS').value, |
|
89 'CXXFLAGS=' + self.attribute('CXXFLAGS').value, |
|
90 'LDFLAGS=' + self.attribute('LDFLAGS').value], |
|
91 logger, |
|
92 directory = blddir) |
|
93 Utils.run_command(['make'], logger, directory = blddir) |
|
94 Utils.run_command(['make', 'install'], logger, directory = blddir) |
|
95 |
|
96 def clean(self, logger, srcdir, blddir): |
|
97 if self.attribute('blddir').value == 'srcdir': |
|
98 blddir = srcdir |
|
99 if not os.path.isfile(os.path.join(blddir,'Makefile')): |
|
100 return |
|
101 if self.attribute('maintainer').value != 'no': |
|
102 Utils.run_command(['make', '-k', 'maintainerclean'], logger, directory = blddir) |
|
103 else: |
|
104 Utils.run_command(['make', '-k', 'distclean'], logger, directory = blddir) |
|
105 try: |
|
106 os.remove(os.path.join(blddir, 'config.cache')) |
|
107 except OSError: |
|
108 pass |
|
109 |
|
110 |