[NLUUG]   Welcome to ftp.nluug.nl
Current directory: /pub/os/NetBSD/NetBSD-release-9/src/tools/
 
Current bandwidth utilization 1593.31 Mbit/s
Bandwidth utilization bar
Contents of README:
$NetBSD: README,v 1.4.18.1 2024/10/13 14:01:31 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 C89 (ISO 9899-1989); they should avoid using C99 language
features.  There are a few tools, such as compilers, where it is not
practical for the C89 restriction to be maintained.  There are also a
few features, such as the long long data type, that are used by many
tools despite not being defined in C89.

Tools may use library features such as functions, macros, and
types, that are defined in C89 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.  This is
usually not an onerous burden, because many C99 library features, and
NetBSD-specific features, are already provided by src/tools/compat, or
can be added when the need for them becomes apparent.

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/ 20-Nov-2024 04:04 - [DIR] amiga-elf2bb/ 14-Feb-2024 19:51 - [DIR] amiga-txlt/ 14-Feb-2024 19:51 - [DIR] arm-elf2aout/ 14-Feb-2024 19:51 - [DIR] asn1_compile/ 14-Feb-2024 19:51 - [DIR] autoconf/ 14-Feb-2024 19:51 - [DIR] awk/ 14-Feb-2024 19:51 - [DIR] binstall/ 14-Feb-2024 19:51 - [DIR] binutils/ 20-Nov-2024 04:04 - [DIR] cap_mkdb/ 14-Feb-2024 19:51 - [DIR] cat/ 14-Feb-2024 19:51 - [DIR] cksum/ 14-Feb-2024 19:51 - [DIR] compat/ 20-Nov-2024 04:04 - [DIR] compile_et/ 14-Feb-2024 19:51 - [DIR] config/ 14-Feb-2024 19:51 - [DIR] crunchgen/ 14-Feb-2024 19:51 - [DIR] ctags/ 14-Feb-2024 19:51 - [DIR] ctfconvert/ 14-Feb-2024 19:51 - [DIR] ctfmerge/ 14-Feb-2024 19:51 - [DIR] cvslatest/ 14-Feb-2024 19:51 - [DIR] db/ 14-Feb-2024 19:51 - [DIR] dbsym/ 14-Feb-2024 19:51 - [DIR] disklabel/ 14-Feb-2024 19:51 - [DIR] dtc/ 14-Feb-2024 19:51 - [DIR] elftosb/ 14-Feb-2024 19:51 - [DIR] fdisk/ 14-Feb-2024 19:51 - [DIR] fgen/ 14-Feb-2024 19:51 - [DIR] file/ 14-Feb-2024 19:51 - [DIR] gcc/ 14-Feb-2024 19:51 - [DIR] gdb/ 14-Feb-2024 19:51 - [DIR] genassym/ 14-Feb-2024 19:51 - [DIR] gencat/ 14-Feb-2024 19:51 - [DIR] gettext/ 14-Feb-2024 19:51 - [DIR] gmake/ 14-Feb-2024 19:51 - [DIR] gmp/ 14-Feb-2024 19:51 - [DIR] gpt/ 14-Feb-2024 19:51 - [DIR] grep/ 14-Feb-2024 19:51 - [DIR] groff/ 14-Feb-2024 19:51 - [DIR] hexdump/ 14-Feb-2024 19:51 - [DIR] host-mkdep/ 14-Feb-2024 19:51 - [DIR] hp300-mkboot/ 14-Feb-2024 19:51 - [DIR] hppa-mkboot/ 14-Feb-2024 19:51 - [DIR] ibmnws-ncdcs/ 14-Feb-2024 19:51 - [DIR] installboot/ 20-Nov-2024 04:04 - [DIR] join/ 14-Feb-2024 19:51 - [DIR] lex/ 14-Feb-2024 19:51 - [DIR] libctf/ 14-Feb-2024 19:51 - [DIR] libdwarf/ 14-Feb-2024 19:51 - [DIR] libelf/ 14-Feb-2024 19:51 - [DIR] libfdt/ 14-Feb-2024 19:51 - [DIR] libprop/ 14-Feb-2024 19:51 - [DIR] lint/ 14-Feb-2024 19:51 - [DIR] lint1/ 14-Feb-2024 19:51 - [DIR] lint2/ 14-Feb-2024 19:51 - [DIR] llvm-clang-tblgen/ 14-Feb-2024 19:51 - [DIR] llvm-clang/ 14-Feb-2024 19:51 - [DIR] llvm-include/ 14-Feb-2024 19:51 - [DIR] llvm-lib/ 20-Nov-2024 04:04 - [DIR] llvm-lld/ 14-Feb-2024 19:51 - [DIR] llvm-mcld/ 14-Feb-2024 19:51 - [DIR] llvm-tblgen/ 14-Feb-2024 19:51 - [DIR] llvm/ 14-Feb-2024 19:51 - [DIR] lorder/ 14-Feb-2024 19:51 - [DIR] m4/ 14-Feb-2024 19:51 - [DIR] m68k-elf2aout/ 14-Feb-2024 19:51 - [DIR] macppc-fixcoff/ 14-Feb-2024 19:51 - [DIR] make/ 14-Feb-2024 19:51 - [DIR] makefs/ 14-Feb-2024 19:51 - [DIR] makekeys/ 14-Feb-2024 19:51 - [DIR] makestrs/ 14-Feb-2024 19:51 - [DIR] makewhatis/ 14-Feb-2024 19:51 - [DIR] mandoc/ 14-Feb-2024 19:51 - [DIR] mdsetimage/ 14-Feb-2024 19:51 - [DIR] menuc/ 14-Feb-2024 19:51 - [DIR] mips-elf2ecoff/ 20-Nov-2024 04:04 - [DIR] mkcsmapper/ 14-Feb-2024 19:51 - [DIR] mkdep/ 14-Feb-2024 19:51 - [DIR] mkesdb/ 14-Feb-2024 19:51 - [DIR] mklocale/ 14-Feb-2024 19:51 - [DIR] mknod/ 14-Feb-2024 19:51 - [DIR] mktemp/ 14-Feb-2024 19:51 - [DIR] mkubootimage/ 14-Feb-2024 19:51 - [DIR] mpc/ 14-Feb-2024 19:51 - [DIR] mpfr/ 14-Feb-2024 19:51 - [DIR] msgc/ 14-Feb-2024 19:51 - [DIR] mtree/ 14-Feb-2024 19:51 - [DIR] nbperf/ 14-Feb-2024 19:51 - [DIR] pax/ 14-Feb-2024 19:51 - [DIR] paxctl/ 14-Feb-2024 19:51 - [DIR] pcc/ 14-Feb-2024 19:51 - [DIR] pigz/ 14-Feb-2024 19:51 - [DIR] pkg_install/ 20-Nov-2024 04:04 - [DIR] powerpc-mkbootimage/ 14-Feb-2024 19:51 - [DIR] pwd_mkdb/ 14-Feb-2024 19:51 - [DIR] rpcgen/ 14-Feb-2024 19:51 - [DIR] sed/ 14-Feb-2024 19:51 - [DIR] sgivol/ 14-Feb-2024 19:51 - [DIR] slc/ 14-Feb-2024 19:51 - [DIR] sortinfo/ 14-Feb-2024 19:51 - [DIR] sparkcrc/ 14-Feb-2024 19:51 - [DIR] stat/ 14-Feb-2024 19:51 - [DIR] strfile/ 14-Feb-2024 19:51 - [DIR] sunlabel/ 14-Feb-2024 19:51 - [DIR] texinfo/ 14-Feb-2024 19:51 - [DIR] tic/ 14-Feb-2024 19:51 - [DIR] tsort/ 14-Feb-2024 19:51 - [DIR] uudecode/ 14-Feb-2024 19:51 - [DIR] veriexecgen/ 14-Feb-2024 19:51 - [DIR] vgrind/ 14-Feb-2024 19:51 - [DIR] xz-bin/ 14-Feb-2024 19:51 - [DIR] xz-include/ 14-Feb-2024 19:51 - [DIR] xz-lib/ 14-Feb-2024 19:51 - [DIR] yacc/ 14-Feb-2024 19:51 - [DIR] zic/ 14-Feb-2024 19:51 - [TXT] Makefile 07-May-2019 12:22 6.5K [TXT] Makefile.gmakehost 21-Jan-2012 00:01 830 [TXT] Makefile.gnuhost 22-Oct-2018 15:19 4.5K [TXT] Makefile.gnuwrap 14-Mar-2003 06:22 925 [TXT] Makefile.host 04-May-2018 16:50 2.0K [TXT] Makefile.nbincludes 14-Sep-2016 02:41 1.9K [TXT] README 14-Oct-2024 05:04 5.7K [   ] 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!