blob: 23cdf0ac933444a419707800e3c26e850b330212 [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 Pesavento910232f2023-09-08 14:20:02 -04003Copyright (c) 2014-2023, 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 Pesavento910232f2023-09-08 14:20:02 -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 Pesavento910232f2023-09-08 14:20:02 -040037 target=f'{top}/bin/{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:
Davide Pesavento910232f2023-09-08 14:20:02 -040062 srcObjects = f'tools-{name}-objects'
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',
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040066 headers=subdir.find_node(f'{name}-pch.hpp'),
Davide Pesaventoa9b09b62022-06-04 14:07:25 -040067 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 Pesavento910232f2023-09-08 14:20:02 -040072 target=f'{top}/bin/{name}',
Davide Pesavento56a741f2018-02-10 16:30:59 -050073 source=[mainFile],
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040074 use=f'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 Pesavento910232f2023-09-08 14:20:02 -040087 target=f'{top}/bin/{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/*'))