1#!/usr/bin/env python
2from waflib.extras import autowaf as autowaf
3from waflib import Options
4from waflib import TaskGen
5import os
6import sys
7
8# Version of this package (even if built as a child)
9MAJOR = '4'
10MINOR = '1'
11MICRO = '0'
12LIBPBD_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
18LIBPBD_LIB_VERSION = '4.1.0'
19LIBPBD_MAJOR_VERSION = '4'
20
21# Variables for 'waf dist'
22APPNAME = 'libpbd'
23VERSION = LIBPBD_VERSION
24I18N_PACKAGE = 'libpbd4'
25
26# Mandatory variables
27top = '.'
28out = 'build'
29
30path_prefix = 'libs/pbd/'
31
32libpbd_sources = [
33    'basename.cc',
34    'base_ui.cc',
35    'boost_debug.cc',
36    'cartesian.cc',
37    'command.cc',
38    'configuration_variable.cc',
39    'convert.cc',
40    'controllable.cc',
41    'crossthread.cc',
42    'cpus.cc',
43    'debug.cc',
44    'demangle.cc',
45    'enumwriter.cc',
46    'event_loop.cc',
47    'enums.cc',
48    'epa.cc',
49    'error.cc',
50    'ffs.cc',
51    'file_archive.cc',
52    'file_utils.cc',
53    'fpu.cc',
54    'id.cc',
55    'locale_guard.cc',
56    'localtime_r.cc',
57    'malign.cc',
58    'md5.cc',
59    'microseconds.cc',
60    'mountpoint.cc',
61    'openuri.cc',
62    'pathexpand.cc',
63    'pbd.cc',
64    'pool.cc',
65    'property_list.cc',
66    'pthread_utils.cc',
67    'reallocpool.cc',
68    'receiver.cc',
69    'resource.cc',
70    'search_path.cc',
71    'semutils.cc',
72    'shortpath.cc',
73    'signals.cc',
74    'spinlock.cc',
75    'stacktrace.cc',
76    'stateful_diff_command.cc',
77    'stateful.cc',
78    'string_convert.cc',
79    'strreplace.cc',
80    'strsplit.cc',
81    'system_exec.cc',
82    'textreceiver.cc',
83    'timer.cc',
84    'timing.cc',
85    'tlsf.cc',
86    'transmitter.cc',
87    'undo.cc',
88    'uuid.cc',
89    'whitespace.cc',
90    'xml++.cc',
91]
92
93def options(opt):
94    opt.load('compiler_cxx')
95    autowaf.set_options(opt)
96    opt.add_option('--ppc', action='store_true', default=False, dest='ppc',
97                   help='Compile with -arch ppc (OS X ONLY)')
98    opt.add_option('--dist-target', type='string', default='auto', dest='dist_target',
99                    help='Specify the target for cross-compiling [auto,none,x86,i386,i686,x86_64,tiger,leopard,mingw,msvc]')
100    opt.add_option('--internal-shared-libs', action='store_true', default=True, dest='internal_shared_libs',
101                   help='Build internal libs as shared libraries')
102
103def configure(conf):
104    conf.load('compiler_cxx')
105    autowaf.configure(conf)
106    autowaf.check_pkg(conf, 'libxml-2.0', uselib_store='XML')
107    autowaf.check_pkg(conf, 'sigc++-2.0', uselib_store='SIGCPP', atleast_version='2.0')
108    autowaf.check_pkg(conf, 'libcurl', uselib_store='CURL', atleast_version='7.0.0', mandatory=True)
109    autowaf.check_pkg(conf, 'libarchive', uselib_store='ARCHIVE', atleast_version='3.0.0', mandatory=True)
110    autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.32.0', mandatory=True)
111    autowaf.check_pkg(conf, 'giomm-2.4', uselib_store='GIOMM', atleast_version='2.2', mandatory=True)
112
113    conf.check(header_name='execinfo.h', define_name='HAVE_EXECINFO',mandatory=False)
114    conf.check(header_name='unistd.h', define_name='HAVE_UNISTD',mandatory=False)
115    if not Options.options.ppc:
116        conf.check_cc(
117                msg="Checking for function 'posix_memalign' in stdlib.h",
118                fragment = "#define _XOPEN_SOURCE 600\n #include <stdlib.h>\n int main(void) { return posix_memalign (0, 64, 1); }\n",
119                define_name='HAVE_POSIX_MEMALIGN', execute = False, mandatory=False)
120    conf.check_cc(
121            msg="Checking for function 'getmntent' in mntent.h",
122            fragment = "#include <mntent.h>\n int main(void) { return (int)getmntent(0); }\n",
123            define_name='HAVE_GETMNTENT', execute = False, mandatory=False)
124    conf.check_cc(
125            msg="Checking for function 'localtime_r' in time.h",
126            fragment = "#include <time.h>\n int main(void) { return localtime_r(NULL, NULL); }\n",
127            define_name='HAVE_LOCALTIME_R', execute = False, mandatory=False)
128
129    # Boost headers
130    autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp')
131    autowaf.check_header(conf, 'cxx', 'boost/weak_ptr.hpp')
132    if Options.options.dist_target == 'mingw':
133        conf.check(compiler='cxx',
134                   lib='ole32',
135                   mandatory=True,
136                   uselib_store='OLE')
137
138    if Options.options.internal_shared_libs:
139        conf.define('INTERNAL_SHARED_LIBS', 1)
140
141    conf.write_config_header('libpbd-config.h', remove=False)
142
143def build(bld):
144    if not autowaf.is_child():  # Building standalone, install dev stuff
145        # C++ Headers
146        includedir = '${INCLUDEDIR}/pbd-%s/pbd' % LIBPBD_MAJOR_VERSION
147        bld.install_files(includedir, bld.path.ant_glob('pbd/*.h'))
148        bld.install_files(includedir, 'build/pbd/signals_generated.h')
149
150        # Pkgconfig file
151        autowaf.build_pc(bld, 'libpbd', LIBPBD_VERSION, LIBPBD_MAJOR_VERSION, [],
152                         {'LIBPBD_VERSION' : LIBPBD_VERSION,
153                          'LIBPBD_MAJOR_VERSION' : LIBPBD_MAJOR_VERSION})
154
155    # Make signals_generated.h using signals.py
156    bld(rule = sys.executable + ' ${SRC} ${TGT}', source = 'pbd/signals.py', target = 'pbd/signals_generated.h', name="pbdsignals", features='use', ext_out=['.h'])
157
158    # Library
159    if bld.is_defined ('INTERNAL_SHARED_LIBS'):
160        obj              = bld.shlib(features = 'cxx cxxshlib', source=libpbd_sources)
161        obj.defines = [ 'LIBPBD_DLL_EXPORTS=1' ]
162    else:
163        obj              = bld.stlib(features = 'cxx cxxstlib', source=libpbd_sources)
164        obj.cxxflags     = [ bld.env['compiler_flags_dict']['pic'] ]
165        obj.cflags       = [ bld.env['compiler_flags_dict']['pic'] ]
166        obj.defines      = []
167
168    if bld.is_defined('DEBUG_RT_ALLOC'):
169        obj.source += 'debug_rt_alloc.c'
170
171    obj.export_includes = ['.']
172    obj.includes     = ['.']
173    obj.name         = 'libpbd'
174    obj.target       = 'pbd'
175    obj.use          = 'pbdsignals'
176    obj.uselib       = 'GLIBMM SIGCPP XML UUID SNDFILE GIOMM ARCHIVE CURL XML'
177    if sys.platform == 'darwin':
178        TaskGen.task_gen.mappings['.mm'] = TaskGen.task_gen.mappings['.cc']
179        if 'cocoa_open_uri.mm' not in obj.source:
180            obj.source += [ 'cocoa_open_uri.mm' ]
181        obj.uselib += ' OSX'
182    obj.vnum         = LIBPBD_LIB_VERSION
183    obj.install_path = bld.env['LIBDIR']
184    obj.defines     += [ 'PACKAGE="' + I18N_PACKAGE + '"' ]
185
186    if sys.platform.startswith('netbsd'):
187        obj.linkflags = '-lexecinfo'
188
189    if bld.env['build_target'] == 'x86_64':
190        obj.defines += [ 'USE_X86_64_ASM' ]
191    if bld.env['build_target'] == 'mingw':
192        obj.defines += [ 'NO_POSIX_MEMALIGN' ]
193        obj.source += [ 'windows_special_dirs.cc' ]
194        obj.source += [ 'windows_timer_utils.cc' ]
195        obj.source += [ 'windows_mmcss.cc' ]
196        obj.uselib += ' OLE'
197
198    if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
199        # Unit tests
200        testobj              = bld(features = 'cxx cxxprogram')
201        testobj.source       = '''
202                test/testrunner.cc
203                test/xpath.cc
204                test/mutex_test.cc
205                test/scalar_properties.cc
206                test/signals_test.cc
207                test/string_convert_test.cc
208                test/convert_test.cc
209                test/filesystem_test.cc
210                test/natsort_test.cc
211                test/rcu_test.cc
212                test/reallocpool_test.cc
213                test/xml_test.cc
214                test/test_common.cc
215        '''.split()
216        if bld.env['build_target'] == 'mingw':
217            testobj.source += [ 'test/windows_timer_utils_test.cc' ]
218        testobj.target       = 'run-tests'
219        testobj.includes     = obj.includes + ['test', '../pbd']
220        testobj.uselib       = 'GLIBMM SIGCPP XML UUID SNDFILE GIOMM ARCHIVE CURL XML OSX CPPUNIT'
221        testobj.use          = 'libpbd'
222        testobj.name         = 'libpbd-tests'
223        testobj.defines      = [ 'PACKAGE="' + I18N_PACKAGE + '"' ]
224        if sys.platform != 'darwin' and bld.env['build_target'] != 'mingw':
225            testobj.lib      = ['rt', 'dl']
226