blob: b8c2358ce8e0aa71eb63de0a3f9a4f27b5246784 [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyevfff47d62014-05-11 19:24:46 -07003from waflib import Utils
4
Davide Pesavento25d4f1c2020-04-29 23:31:04 -04005top = '../'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08006
7def build(bld):
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05008 # Single object tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -04009 # tools/foo.cpp is a self-contained tool with a main() function
10 # and is built as build/bin/foo. These tools cannot be unit-tested.
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050011 for tool in bld.path.ant_glob('*.cpp'):
12 name = tool.change_ext('').path_from(bld.path.get_bld())
Davide Pesavento19442812018-11-23 14:00:04 -050013 bld.program(name='tool-%s' % name,
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040014 target=top + 'bin/%s' % name,
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050015 source=[tool],
16 use='ndn-cxx')
Yingdi Yu8d7468f2014-02-21 14:49:45 -080017
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050018 # Sub-directory tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040019 # tools/foo/**/*.cpp are compiled and linked into build/bin/foo.
20 # tools/foo/main.cpp must exist and must contain the main() function.
21 # All other objects are collected into 'tool-foo-objects' and can be unit-tested.
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050022 for subdir in bld.path.ant_glob('*', dir=True, src=False):
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040023 name = subdir.path_from(bld.path)
24 subWscript = subdir.find_node('wscript')
25 if subWscript:
26 # if the subdir has a wscript, delegate to it
27 bld.recurse(name)
28 continue
29
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050030 mainFile = subdir.find_node('main.cpp')
31 if mainFile is None:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040032 # not a C++ tool, skip the subdir
33 continue
Alexander Afanasyev28d0d942015-01-04 14:52:19 -080034
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050035 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
36 srcObjects = ''
37 if srcFiles:
Davide Pesavento19442812018-11-23 14:00:04 -050038 srcObjects = 'tool-%s-objects' % name
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050039 bld.objects(target=srcObjects,
40 source=srcFiles,
Davide Pesavento7e780642018-11-24 15:51:34 -050041 use='ndn-cxx')
Davide Pesavento19442812018-11-23 14:00:04 -050042 bld.program(name='tool-%s' % name,
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040043 target=top + 'bin/%s' % name,
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050044 source=[mainFile],
Davide Pesavento7e780642018-11-24 15:51:34 -050045 use='ndn-cxx ' + srcObjects)
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050046
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050047 # Tool wrappers
48 wrapperFiles = bld.path.ant_glob('wrapper/*.sh')
Davide Pesavento19442812018-11-23 14:00:04 -050049 bld(name='tool-wrappers',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050050 features='subst',
51 source=wrapperFiles,
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040052 target=[top + 'bin/%s' % node.change_ext('', '.sh').path_from(bld.path.find_dir('wrapper').get_bld())
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050053 for node in wrapperFiles],
54 install_path='${BINDIR}',
55 chmod=Utils.O755)