Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / setup.py
1 from setuptools import setup, Extension
2 import distutils.command.build_ext
3 from distutils.dep_util import newer
4
5 import os
6 import sys
7
8 def replace_suffix(path, new_suffix):
9   return os.path.splitext(path)[0]+new_suffix
10
11 class build_ext(distutils.command.build_ext.build_ext):
12   description="also compile qt moc files"
13
14   def __init__(self, *args, **kwargs):
15     if sys.platform == 'linux2':
16       self.moc_binary = 'moc'
17       self.rcc_binary = 'rcc'
18
19       if os.path.exists('/usr/bin/moc-qt4'):
20         self.moc_binary = '/usr/bin/moc-qt4'
21       if os.path.exists('/usr/bin/rcc-qt4'):  
22         self.rcc_binary = '/usr/bin/rcc-qt4'
23
24     distutils.command.build_ext.build_ext.__init__(self, *args, **kwargs)
25
26   def swig_sources(self, sources, extensions=None):
27     if self.extensions is None:
28       return
29   
30     # filter out sources
31     qrc_sources = []
32     moc_sources = []
33     other_sources = []
34     for src in sources:
35       base,ext= os.path.splitext(src)
36       if ext == '.qrc':
37         qrc_sources.append(src)
38       elif ext in ('.hpp', '.hxx', '.h'):
39         moc_sources.append(src)
40       else:
41         other_sources.append(src)
42
43     build_sources = other_sources
44     # create qresource
45     build_sources.extend(self.compile_qrcs(qrc_sources))
46     # create moc files 
47     build_sources.extend(self.compile_mocs(moc_sources))
48     return build_sources 
49
50   def compile_qrcs(self, qrc_files):
51     targets = []
52     for qrc in qrc_files:
53       if os.path.exists(qrc):
54         source = qrc
55         name = os.path.splitext(os.path.split(qrc)[1])[0]
56         target = "qrc_"+name+".cpp"
57         if newer(source, target) or self.force:
58           self.compile_qrc(name, source, target)
59         targets.append(target)
60     return targets
61
62   def compile_qrc(self, name, source, target):
63     """compile qt resource file"""
64     os.system("%s -name %s -o %s %s" %(self.rcc_binary, name, target, source))
65
66   def compile_mocs(self, moc_headers):
67     targets = []
68    
69     for moc_hpp in moc_headers:
70       if os.path.exists(moc_hpp):
71         source = moc_hpp
72         target = "moc_"+replace_suffix(os.path.split(moc_hpp)[1],'.cpp')
73         if newer(source, target) or self.force:
74           self.compile_moc(source, target)
75         targets.append(target)
76     return targets
77   
78   def compile_moc(self, source, target):
79     os.system("%s -o%s %s" %(self.moc_binary, target, source))
80
81 boost_py = ["py/conserved_path.cpp",
82            "py/glsequence.cpp",
83            "py/module.cpp",
84            "py/mussa.cpp",
85            "py/MussaWindow.cpp",
86            "py/nway_paths.cpp",
87            "py/sequence.cpp",]
88
89 core_alg = ["alg/annotation_colors.cpp",
90             "alg/color.cpp",
91             "alg/conserved_path.cpp",
92             "alg/flp.cpp",
93             "alg/flp_seqcomp.cpp",
94             "alg/glseqbrowser.cpp",
95             "alg/glsequence.cpp",
96             "alg/mussa.cpp",
97             "alg/nway_entropy.cpp",
98             "alg/nway_other.cpp",
99             "alg/nway_paths.cpp",
100             #"alg/nway_refine",
101             #"alg/parse_options.cpp",
102             "alg/sequence.cpp",]
103
104 moc_headers = ['qui/ImageSaveDialog.hpp',
105                'qui/ImageScaler.hpp',
106                'qui/IntAction.hpp',
107                'qui/MussaAlignedWindow.hpp',
108                'qui/MussaWindow.hpp',
109                'qui/ThresholdWidget.hpp',
110                'qui/ZoomWidget.hpp',
111                'qui/motif_editor/MotifDetail.hpp',
112                'qui/motif_editor/MotifEditor.hpp',
113                'qui/mussa_setup_dialog/IsFileValidator.hpp',
114                'qui/mussa_setup_dialog/MussaSetupDialog.hpp',
115                'qui/mussa_setup_dialog/MussaSetupWidget.hpp',
116                'qui/mussa_setup_dialog/SequenceSetupFrame.hpp',
117                'qui/mussa_setup_dialog/SequenceSetupWidget.hpp',
118                'qui/mussa_setup_dialog/SetupInfo.hpp',
119                'qui/seqbrowser/ScrollableSequenceBrowser.hpp',
120                'qui/seqbrowser/SequenceBrowser.hpp',
121                'qui/seqbrowser/SequenceBrowserSidebar.hpp',
122                'qui/seqbrowser/SequenceBrowserWidget.hpp',
123                'qui/seqbrowser/SequenceDescription.hpp',]
124
125 qui_sources = ['qui/ImageSaveDialog.cpp',
126                'qui/ImageScaler.cpp',
127                'qui/IntAction.cpp',        
128                'qui/MussaAlignedWindow.cpp',
129                'qui/MussaWindow.cpp',
130                'qui/ThresholdWidget.cpp',
131                'qui/ZoomWidget.cpp',
132                'qui/motif_editor/MotifDetail.cpp',
133                'qui/motif_editor/MotifEditor.cpp',
134                'qui/mussa_setup_dialog/IsFileValidator.cpp',
135                'qui/mussa_setup_dialog/MussaSetupDialog.cpp',
136                'qui/mussa_setup_dialog/MussaSetupWidget.cpp',
137                'qui/mussa_setup_dialog/SequenceSetupFrame.cpp',
138                'qui/mussa_setup_dialog/SequenceSetupWidget.cpp',
139                'qui/mussa_setup_dialog/SetupInfo.cpp',
140                'qui/seqbrowser/ScrollableSequenceBrowser.cpp',
141                'qui/seqbrowser/SequenceBrowser.cpp',
142                'qui/seqbrowser/SequenceBrowserSidebar.cpp',
143                'qui/seqbrowser/SequenceBrowserWidget.cpp',
144                'qui/seqbrowser/SequenceDescription.cpp',
145               ]
146
147 qrc_sources = ['icons.qrc']
148
149 sources = boost_py+core_alg+moc_headers+qui_sources+qrc_sources
150
151
152 extra_link_args = []
153 libraries = ['boost_python', 
154              'boost_filesystem']
155 include_dirs = ['.']
156
157 if sys.platform == 'darwin':
158   import py2app
159   qtroot = '/usr/local/qt/4.1.2'
160   qtincludes.os.path.join(qtroot, 'include')
161   extra_link_args.extend([
162     '-F%s/lib' % (qtroot),
163     '-framework', 'QtCore',
164     '-framework', 'QtGui',
165     '-framework', 'QtOpenGL',
166     '-framework', 'OpenGL',
167                       ])
168 else:
169   qtroot = '/usr'
170   qtinclude = os.path.join(qtroot, 'include', 'qt4')
171   libraries += ['QtCore']
172   libraries += ['QtGui']
173   libraries += ['QtOpenGL']
174  
175  
176
177 for qtdir in ['','QtCore','QtGui','QtOpenGL']:
178   include_dirs.append(os.path.join(qtinclude, qtdir))
179
180 mussa_ext = Extension("_mussa", 
181                       sources,
182                       include_dirs=include_dirs,
183                       library_dirs=[
184                         #'/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/',
185                         '/usr/local/qt/4.1.2/lib',
186                       ],
187                       libraries=libraries,
188                       extra_link_args = extra_link_args
189             )
190 setup(app=['mussa.py'],
191       name='mussa',
192       version='0.0',
193       ext_modules=[mussa_ext],
194       cmdclass={'build_ext': build_ext})
195
196