blob: f3ee6a8b44b172b0d4bc1cc0c2d0b094e5c42b4f [file] [log] [blame]
Alexander Afanasyev262203b2015-01-26 16:39:59 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Davide Pesavento0064c1d2018-03-03 18:43:53 -05002"""
Davide Pesaventoa9b09b62022-06-04 14:07:25 -04003Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesavento0064c1d2018-03-03 18:43:53 -05004 Arizona Board of Regents,
5 Colorado State University,
6 University Pierre & Marie Curie, Sorbonne University,
7 Washington University in St. Louis,
8 Beijing Institute of Technology,
9 The University of Memphis.
Alexander Afanasyev262203b2015-01-26 16:39:59 -080010
Davide Pesavento0064c1d2018-03-03 18:43:53 -050011This file is part of NFD (Named Data Networking Forwarding Daemon).
12See AUTHORS.md for complete list of NFD authors and contributors.
13
14NFD is free software: you can redistribute it and/or modify it under the terms
15of the GNU General Public License as published by the Free Software Foundation,
16either version 3 of the License, or (at your option) any later version.
17
18NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20PURPOSE. See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along with
23NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24"""
Alexander Afanasyev262203b2015-01-26 16:39:59 -080025
Davide Pesavento0064c1d2018-03-03 18:43:53 -050026from waflib import Context, Utils
27
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040028top = '../'
Davide Pesavento56a741f2018-02-10 16:30:59 -050029
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040030def build(bld):
Davide Pesavento56a741f2018-02-10 16:30:59 -050031 # Single object tools:
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040032 # tools/foo.cpp is a self-contained tool with a main() function
33 # and is built as build/bin/foo. These tools cannot be unit-tested.
Davide Pesavento0064c1d2018-03-03 18:43:53 -050034 for tool in bld.path.ant_glob('*.cpp'):
35 name = tool.change_ext('').path_from(bld.path.get_bld())
36 bld.program(name=name,
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040037 target=top + 'bin/%s' % name,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050038 source=[tool],
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040039 use='core-objects')
Alexander Afanasyev262203b2015-01-26 16:39:59 -080040
Davide Pesavento56a741f2018-02-10 16:30:59 -050041 # Sub-directory tools:
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040042 # tools/foo/**/*.cpp are compiled and linked into build/bin/foo.
43 # tools/foo/main.cpp must exist and must contain the main() function.
Junxiao Shi38f4ce92016-08-04 10:01:52 +000044 # All other objects are collected into 'tools-objects' and can be unit-tested.
45 testableObjects = []
Davide Pesavento0064c1d2018-03-03 18:43:53 -050046 for subdir in bld.path.ant_glob('*', dir=True, src=False):
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040047 name = subdir.path_from(bld.path)
48 subWscript = subdir.find_node('wscript')
49 if subWscript:
50 # if the subdir has a wscript, delegate to it
51 bld.recurse(name)
52 continue
53
Davide Pesavento0064c1d2018-03-03 18:43:53 -050054 mainFile = subdir.find_node('main.cpp')
Junxiao Shi38f4ce92016-08-04 10:01:52 +000055 if mainFile is None:
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040056 # not a C++ tool, skip the subdir
57 continue
Davide Pesavento0064c1d2018-03-03 18:43:53 -050058
Davide Pesavento0064c1d2018-03-03 18:43:53 -050059 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
60 srcObjects = ''
Davide Pesavento56a741f2018-02-10 16:30:59 -050061 if srcFiles:
Junxiao Shi38f4ce92016-08-04 10:01:52 +000062 srcObjects = 'tools-%s-objects' % name
Davide Pesavento56a741f2018-02-10 16:30:59 -050063 bld.objects(target=srcObjects,
64 source=srcFiles,
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040065 features='pch',
66 headers=subdir.find_node(name + '-pch.hpp'),
67 use='core-objects LIBRESOLV',
Davide Pesavento0064c1d2018-03-03 18:43:53 -050068 includes=name)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000069 testableObjects.append(srcObjects)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000070
Davide Pesavento0064c1d2018-03-03 18:43:53 -050071 bld.program(name=name,
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040072 target=top + 'bin/%s' % name,
Davide Pesavento56a741f2018-02-10 16:30:59 -050073 source=[mainFile],
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040074 use='core-objects ' + srcObjects,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050075 includes=name)
Davide Pesavento56a741f2018-02-10 16:30:59 -050076
Davide Pesavento0064c1d2018-03-03 18:43:53 -050077 bld.objects(target='tools-objects',
78 source=[],
79 export_includes='.',
80 use=testableObjects)
Alexander Afanasyev262203b2015-01-26 16:39:59 -080081
Davide Pesavento0064c1d2018-03-03 18:43:53 -050082 # Scripts
83 for script in bld.path.ant_glob(['*.sh', '*.py']):
84 name = script.change_ext('').path_from(bld.path.get_bld())
85 bld(features='subst',
86 name=name,
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040087 target=top + 'bin/%s' % name,
Davide Pesavento0064c1d2018-03-03 18:43:53 -050088 source=[script],
89 install_path='${BINDIR}',
90 chmod=Utils.O755,
91 VERSION=Context.g_module.VERSION)
Alexander Afanasyev262203b2015-01-26 16:39:59 -080092
Davide Pesavento56a741f2018-02-10 16:30:59 -050093 bld.install_files('${DATAROOTDIR}/ndn',
Alexander Afanasyev262203b2015-01-26 16:39:59 -080094 bld.path.ant_glob('nfd-status-http-server-files/*'))