separate build host & target (fix win32 asm)
[ardour.git] / libs / pbd / wscript
1 #!/usr/bin/env python
2 from waflib.extras import autowaf as autowaf
3 from waflib import Options
4 from waflib import TaskGen
5 import os
6 import sys
7
8 # Version of this package (even if built as a child)
9 MAJOR = '4'
10 MINOR = '1'
11 MICRO = '0'
12 LIBPBD_VERSION = "%s.%s.%s" % (MAJOR, MINOR, MICRO)
13
14 # Library version (UNIX style major, minor, micro)
15 # major increment <=> incompatible changes
16 # minor increment <=> compatible changes (additions)
17 # micro increment <=> no interface changes
18 LIBPBD_LIB_VERSION = '4.1.0'
19
20 # Variables for 'waf dist'
21 APPNAME = 'libpbd'
22 VERSION = LIBPBD_VERSION
23 I18N_PACKAGE = 'libpbd4'
24
25 # Mandatory variables
26 top = '.'
27 out = 'build'
28
29 path_prefix = 'libs/pbd/'
30
31 libpbd_sources = [
32     'basename.cc',
33     'base_ui.cc',
34     'boost_debug.cc',
35     'cartesian.cc',
36     'command.cc',
37     'configuration_variable.cc',
38     'convert.cc',
39     'controllable.cc',
40     'controllable_descriptor.cc',
41     'crossthread.cc',
42     'cpus.cc',
43     'debug.cc',
44     'enumwriter.cc',
45     'event_loop.cc',
46     'enums.cc',
47     'epa.cc',
48     'error.cc',
49     'ffs.cc',
50     'file_utils.cc',
51     'fpu.cc',
52     'glib_semaphore.cc',
53     'id.cc',
54     'locale_guard.cc',
55     'localtime_r.cc',
56     'malign.cc',
57     'md5.cc',
58     'mountpoint.cc',
59     'openuri.cc',
60     'pathexpand.cc',
61     'pbd.cc',
62     'pool.cc',
63     'property_list.cc',
64     'pthread_utils.cc',
65     'receiver.cc',
66     'resource.cc',
67     'search_path.cc',
68     'semutils.cc',
69     'shortpath.cc',
70     'signals.cc',
71     'stacktrace.cc',
72     'stateful_diff_command.cc',
73     'stateful.cc',
74     'strreplace.cc',
75     'strsplit.cc',
76     'system_exec.cc',
77     'textreceiver.cc',
78     'timer.cc',
79     'timing.cc',
80     'transmitter.cc',
81     'undo.cc',
82     'uuid.cc',
83     'whitespace.cc',
84     'xml++.cc',
85 ]
86
87 def options(opt):
88     autowaf.set_options(opt)
89
90 def configure(conf):
91     conf.load('compiler_cxx')
92     autowaf.configure(conf)
93     autowaf.check_pkg(conf, 'libxml-2.0', uselib_store='XML')
94     autowaf.check_pkg(conf, 'sigc++-2.0', uselib_store='SIGCPP', atleast_version='2.0')
95
96     conf.check(function_name='getmntent', header_name='mntent.h', define_name='HAVE_GETMNTENT',mandatory=False)
97     conf.check(header_name='execinfo.h', define_name='HAVE_EXECINFO',mandatory=False)
98     conf.check(header_name='unistd.h', define_name='HAVE_UNISTD',mandatory=False)
99     conf.check_cc(function_name='posix_memalign', header_name='stdlib.h', cflags='-D_XOPEN_SOURCE=600', define_name='HAVE_POSIX_MEMALIGN', mandatory=False)
100     conf.check(function_name='localtime_r', header_name='time.h', define_name='HAVE_LOCALTIME_R',mandatory=False)
101
102     conf.write_config_header('libpbd-config.h', remove=False)
103
104     # Boost headers
105     autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp')
106     autowaf.check_header(conf, 'cxx', 'boost/weak_ptr.hpp')
107     if Options.options.dist_target == 'mingw':
108         conf.check(compiler='cxx',
109                    lib='ole32',
110                    mandatory=True,
111                    uselib_store='OLE')
112
113 def build(bld):
114
115     # Make signals_generated.h using signals.py
116     bld(rule = 'python ${SRC} ${TGT}', source = 'pbd/signals.py', target = 'pbd/signals_generated.h')
117
118     # Library
119     if bld.is_defined ('INTERNAL_SHARED_LIBS'):
120         obj              = bld.shlib(features = 'cxx cxxshlib', source=libpbd_sources)
121         obj.defines = [ 'LIBPBD_DLL_EXPORTS=1' ]
122     else:
123         obj              = bld.stlib(features = 'cxx cxxstlib', source=libpbd_sources)
124         obj.cxxflags     = [ '-fPIC' ]
125         obj.cflags     = [ '-fPIC' ]
126         obj.defines      = []
127
128     if bld.is_defined('DEBUG_RT_ALLOC'):
129         obj.source += 'debug_rt_alloc.c'
130
131     obj.export_includes = ['.']
132     obj.includes     = ['.']
133     obj.name         = 'libpbd'
134     obj.target       = 'pbd'
135     obj.uselib       = 'GLIBMM SIGCPP XML UUID SNDFILE GIOMM'
136     if sys.platform == 'darwin':
137         TaskGen.task_gen.mappings['.mm'] = TaskGen.task_gen.mappings['.cc']
138         if 'cocoa_open_uri.mm' not in obj.source:
139             obj.source += [ 'cocoa_open_uri.mm' ]
140         obj.uselib += ' OSX'
141     obj.vnum         = LIBPBD_LIB_VERSION
142     obj.install_path = bld.env['LIBDIR']
143     obj.defines     += [ 'PACKAGE="' + I18N_PACKAGE + '"' ]
144
145     if bld.env['build_target'] == 'x86_64':
146         obj.defines += [ 'USE_X86_64_ASM' ]
147     if bld.env['build_target'] == 'mingw':
148         if re.search ('/^x86_64/', str(bld.env['CC'])):
149             obj.defines += [ 'USE_X86_64_ASM' ]
150             obj.defines += ['NO_POSIX_MEMALIGN' ]
151         obj.source += [ 'windows_special_dirs.cc' ]
152         obj.uselib += ' OLE'
153
154     if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
155         # Unit tests
156         testobj              = bld(features = 'cxx cxxprogram')
157         testobj.source       = '''
158                 test/testrunner.cc
159                 test/xpath.cc
160                 test/mutex_test.cc
161                 test/scalar_properties.cc
162                 test/signals_test.cc
163                 test/timer_test.cc
164                 test/convert_test.cc
165                 test/filesystem_test.cc
166                 test/test_common.cc
167         '''.split()
168         testobj.target       = 'run-tests'
169         testobj.includes     = obj.includes + ['test', '../pbd']
170         testobj.uselib       = 'CPPUNIT XML SNDFILE'
171         testobj.use          = 'libpbd'
172         testobj.name         = 'libpbd-tests'
173         testobj.defines      = [ 'PACKAGE="' + I18N_PACKAGE + '"' ]
174         if sys.platform != 'darwin' and bld.env['build_target'] != 'mingw':
175             testobj.linkflags    = ['-lrt']
176             
177 def shutdown():
178     autowaf.shutdown()