[NLUUG]   Welcome to ftp.nluug.nl
Current directory: /pub/NetBSD/NetBSD-release-10/src/tools/
 
Current bandwidth utilization 1671.07 Mbit/s
Bandwidth utilization bar
Contents of README:
$NetBSD: README,v 1.5.2.1 2024/10/13 14:00:21 martin Exp $

Notes for NetBSD src/tools


Background
==========

Several programs that are part of NetBSD are also built as tools.  Such
programs are typically built twice: once as a tool and once as part of
the release build.  Tools are relevant only when the make(1) variable
USETOOLS=yes, which is the default for most NetBSD builds.

Tools are built on the host platform, using the host compiler,
and will run on the host platform during the cross-build of the
remainder of NetBSD.  They are built near the beginning of a NetBSD
build (e.g. "build.sh tools" or "make tools" from the top level src
directory), and installed in ${TOOLDIR}.

Tools are executed during the main part of the build, when several
TOOL_* variables defined in src/share/mk/bsd.*.mk will refer to the
tools installed in ${TOOLDIR}.


Portability
===========

Programs that are built as tools need to be more portable than other
parts of NetBSD, because they will need to run on the host platform.

Most tools should restrict themselves to C language features that are
defined in C99 (ISO/IEC 9899-1999); they should avoid using C11 language
features, such as <threads.h>, _Alignof, <uchar.h>, _Generic,
static_assert, anonymous structures and unions.

Tools may use library features such as functions, macros, and types,
that are defined in C99 and in POSIX (IEEE Std 1003.1) (XXX year?), and
features that are provided by the compatibility framework
(src/tools/compat) described in a separate section below.

If a tool attempts to use a feature that is not available on the host
platform, then the tools build will fail.  This can be addressed by
changing the tool to avoid that feature, or by adding the feature to the
src/tools/compat framework.  It is usually easy to add new macros or
functions to src/tools/compat, and that is usually better than adding
compatibility definitions to individual tools.


Compatibility framework
=======================

src/tools/compat provides a compatibility framework for use by tools.
It installs the following components, and more:

${TOOLDIR}/lib/libnbcompat.a

    A library containing functions that are needed by some tools.

${TOOLDIR}/include/compat/nbtool_compat.h

    A header file defining macros that are needed by some tools.

${TOOLDIR}/share/compat/defs.mk

    A makefile fragment, to be included by other makefiles,
    to define make variables appropriate for building tools.

    Among other things, this makefile fragment automatically adds
    the libnbcompat.a library to the LDADD and DPADD variables,
    so that tools will be linked with that library, and adds
    -I${NETBSDSRCDIR}/tools/compat and -DHAVE_NBTOOL_CONFIG_H=1 to the
    HOST_CPPFLAGS variable, so that compiled programs can detect when
    they are being built as tools.


Adapting Makefiles for use with tools
=====================================

Makefiles under src/tools/*/Makefile should define the HOSTPROG
variable.  This is typically done by tools/Makefile.hostprog,
which is directly or indirectly included by all Makefiles in
src/tools/*/Makefile.

Makefiles in the non-tools part of the src tree can test whether or not
the HOSTPROG variable is defined, in order tell the difference between
building a tool and building part of a NetBSD release, and they may
alter their behavior accordingly.

For example, the Makefile may conditionally refrain from compiling and
linking certain files, and the Makefile may conditionally pass macros to
the compiler via constructs like this:

    .if defined(HOSTPROG)
    CPPFLAGS+= -DWITH_FEATURE_X=0 # exclude feature X from tools build
    .else
    CPPFLAGS+= -DWITH_FEATURE_X=1 # include feature X in release build
    .endif

Adapting Programs for use with tools
====================================

When a tool is being built, the C compiler should automatically be
invoked with -DHAVE_NBTOOL_CONFIG_H=1.  This is done as a result of
settings in ${TOOLDIR}/share/compat/defs.mk, which should be included
from src/tools/Makefile.host, which should be included directly or
indirectly from src/tools/*/Makefile.

A C source file can test whether the HAVE_NBTOOL_CONFIG_H macro is
defined, in order to tell whether or not it is being compiled as part of
a tool.

In order to obtain the definitions provided by the tools compatibility
framework, almost every C source file that is built as part of a tool
should have lines like these as the first non-comment lines:

    #if HAVE_NBTOOL_CONFIG_H
    #include "nbtool_config.h"
    #endif

To omit features from the tools version of a program, the program
may test the HAVE_NBTOOL_CONFIG_H macro, like this:

    #if HAVE_NBTOOL_CONFIG_H
       ... code to be used when built as a tool
    #else
       ... code to be used when built as part of a release
    #endif

It is often preferable to use macros whose names refer to the features
that should be included or omitted.  See the section on "Adapting
Makefiles for use with tools" for an example in which the Makefile
passes -DWITH_FEATURE_X=0 or -DWITH_FEATURE_X=1 to the compiler
according to whether or not the program is being built as a tool.  Then
the program can use code like this:

    #if WITH_FEATURE_X 
       ... code to be used when FEATURE X is desired,
       ... e.g. when being built as part of a release.
    #else
       ... code to be used when FEATURE X is not desired,
       ... e.g. when being built as a tool.
    #endif

Icon  Name                               Last modified      Size  
[DIR] Parent Directory - [DIR] CVS/ 30-Oct-2024 04:07 - [DIR] amiga-elf2bb/ 17-Dec-2022 21:36 - [DIR] amiga-txlt/ 17-Dec-2022 21:36 - [DIR] arm-elf2aout/ 17-Dec-2022 21:36 - [DIR] asn1_compile/ 17-Dec-2022 21:36 - [DIR] autoconf/ 17-Dec-2022 21:36 - [DIR] awk/ 17-Dec-2022 21:36 - [DIR] binstall/ 17-Dec-2022 21:36 - [DIR] binutils/ 30-Oct-2024 04:07 - [DIR] cap_mkdb/ 17-Dec-2022 21:36 - [DIR] cat/ 17-Dec-2022 21:36 - [DIR] cksum/ 17-Dec-2022 21:36 - [DIR] compat/ 30-Oct-2024 04:07 - [DIR] compile_et/ 17-Dec-2022 21:36 - [DIR] config/ 17-Dec-2022 21:36 - [DIR] crunchgen/ 17-Dec-2022 21:36 - [DIR] ctags/ 17-Dec-2022 21:36 - [DIR] ctfconvert/ 17-Dec-2022 21:36 - [DIR] ctfmerge/ 17-Dec-2022 21:36 - [DIR] cvslatest/ 17-Dec-2022 21:36 - [DIR] date/ 17-Dec-2022 21:36 - [DIR] db/ 17-Dec-2022 21:36 - [DIR] dbsym/ 17-Dec-2022 21:36 - [DIR] disklabel/ 17-Dec-2022 21:36 - [DIR] dtc/ 17-Dec-2022 21:36 - [DIR] elftoolchain/ 17-Dec-2022 21:36 - [DIR] elftosb/ 17-Dec-2022 21:36 - [DIR] fdisk/ 17-Dec-2022 21:36 - [DIR] fgen/ 17-Dec-2022 21:36 - [DIR] file/ 17-Dec-2022 21:36 - [DIR] gcc/ 11-Oct-2023 05:11 - [DIR] gdb/ 15-Jan-2024 04:12 - [DIR] genassym/ 17-Dec-2022 21:36 - [DIR] gencat/ 17-Dec-2022 21:36 - [DIR] gettext/ 17-Dec-2022 21:36 - [DIR] gmake/ 17-Dec-2022 21:36 - [DIR] gmp/ 05-Oct-2024 05:22 - [DIR] gpt/ 17-Dec-2022 21:36 - [DIR] grep/ 17-Dec-2022 21:36 - [DIR] groff/ 17-Dec-2022 21:36 - [DIR] hexdump/ 17-Dec-2022 21:36 - [DIR] host-mkdep/ 04-Nov-2023 04:35 - [DIR] hp300-mkboot/ 17-Dec-2022 21:36 - [DIR] hppa-mkboot/ 17-Dec-2022 21:36 - [DIR] ibmnws-ncdcs/ 17-Dec-2022 21:36 - [DIR] installboot/ 30-Oct-2024 04:07 - [DIR] join/ 17-Dec-2022 21:36 - [DIR] lex/ 17-Dec-2022 21:36 - [DIR] libctf/ 17-Dec-2022 21:36 - [DIR] libfdt/ 17-Dec-2022 21:36 - [DIR] libprop/ 17-Dec-2022 21:36 - [DIR] lint/ 17-Dec-2022 21:36 - [DIR] lint1/ 17-Dec-2022 21:36 - [DIR] lint2/ 17-Dec-2022 21:36 - [DIR] llvm-clang-tblgen/ 17-Dec-2022 21:36 - [DIR] llvm-clang/ 17-Dec-2022 21:36 - [DIR] llvm-include/ 17-Dec-2022 21:36 - [DIR] llvm-lib/ 30-Oct-2024 04:07 - [DIR] llvm-tblgen/ 17-Dec-2022 21:36 - [DIR] llvm/ 17-Dec-2022 21:36 - [DIR] lorder/ 17-Dec-2022 21:36 - [DIR] m4/ 17-Dec-2022 21:36 - [DIR] m68k-elf2aout/ 17-Dec-2022 21:36 - [DIR] macppc-fixcoff/ 17-Dec-2022 21:36 - [DIR] macppc_installboot/ 06-Jul-2024 05:23 - [DIR] make/ 17-Dec-2022 21:36 - [DIR] makefs/ 17-Dec-2022 21:36 - [DIR] makekeys/ 17-Dec-2022 21:36 - [DIR] makestrs/ 17-Dec-2022 21:36 - [DIR] makewhatis/ 17-Dec-2022 21:36 - [DIR] mandoc/ 17-Dec-2022 21:36 - [DIR] mdsetimage/ 17-Dec-2022 21:36 - [DIR] menuc/ 17-Dec-2022 21:36 - [DIR] mips-elf2ecoff/ 30-Oct-2024 04:07 - [DIR] mkcsmapper/ 17-Dec-2022 21:36 - [DIR] mkdep/ 17-Dec-2022 21:36 - [DIR] mkesdb/ 17-Dec-2022 21:36 - [DIR] mkhybrid/ 06-Jul-2024 05:23 - [DIR] mklocale/ 17-Dec-2022 21:36 - [DIR] mknod/ 17-Dec-2022 21:36 - [DIR] mktemp/ 17-Dec-2022 21:36 - [DIR] mkubootimage/ 17-Dec-2022 21:36 - [DIR] mpc/ 17-Dec-2022 21:36 - [DIR] mpfr/ 17-Dec-2022 21:36 - [DIR] msgc/ 17-Dec-2022 21:36 - [DIR] mtree/ 17-Dec-2022 21:36 - [DIR] mvme68k-wrtvid/ 17-Dec-2022 21:36 - [DIR] nbperf/ 17-Dec-2022 21:36 - [DIR] pax/ 17-Dec-2022 21:36 - [DIR] paxctl/ 17-Dec-2022 21:36 - [DIR] pcc/ 17-Dec-2022 21:36 - [DIR] pigz/ 17-Dec-2022 21:36 - [DIR] pkg_install/ 17-Dec-2022 21:36 - [DIR] powerpc-mkbootimage/ 17-Dec-2022 21:36 - [DIR] pwd_mkdb/ 17-Dec-2022 21:36 - [DIR] rpcgen/ 17-Dec-2022 21:36 - [DIR] sed/ 17-Dec-2022 21:36 - [DIR] sgivol/ 17-Dec-2022 21:36 - [DIR] slc/ 17-Dec-2022 21:36 - [DIR] sortinfo/ 17-Dec-2022 21:36 - [DIR] sparkcrc/ 17-Dec-2022 21:36 - [DIR] stat/ 17-Dec-2022 21:36 - [DIR] strfile/ 17-Dec-2022 21:36 - [DIR] sunlabel/ 17-Dec-2022 21:36 - [DIR] texinfo/ 17-Dec-2022 21:36 - [DIR] tic/ 17-Dec-2022 21:36 - [DIR] tsort/ 17-Dec-2022 21:36 - [DIR] uudecode/ 17-Dec-2022 21:36 - [DIR] veriexecgen/ 17-Dec-2022 21:36 - [DIR] vgrind/ 17-Dec-2022 21:36 - [DIR] xz-bin/ 17-Dec-2022 21:36 - [DIR] xz-include/ 17-Dec-2022 21:36 - [DIR] xz-lib/ 17-Dec-2022 21:36 - [DIR] yacc/ 17-Dec-2022 21:36 - [DIR] zic/ 17-Dec-2022 21:36 - [TXT] Makefile 06-Jul-2024 05:23 6.9K [TXT] Makefile.gmakehost 21-Jan-2012 00:01 830 [TXT] Makefile.gnuhost 29-May-2023 05:11 4.6K [TXT] Makefile.gnuwrap 14-Mar-2003 06:22 925 [TXT] Makefile.host 04-May-2018 16:50 2.0K [TXT] Makefile.nbincludes 24-Jun-2024 05:07 2.2K [TXT] README 14-Oct-2024 05:07 5.3K [   ] headerlist 01-Apr-2018 06:35 4.3K [   ] mkheaderlist.sh 23-Feb-2016 12:43 508

NLUUG - Open Systems. Open Standards
Become a member and get discounts on conferences and more, see the NLUUG website!