Name Date Size #Lines LOC

..23-Jul-2023-

amiga-elf2bb/H08-May-2022-765551

amiga-txlt/H08-May-2022-73

arm-elf2aout/H08-May-2022-1,8791,134

asn1_compile/H08-May-2022-73

autoconf/H08-May-2022-154

awk/H08-May-2022-84

binstall/H08-May-2022-6344

binutils/H08-Feb-2023-245168

cap_mkdb/H08-May-2022-73

cat/H08-May-2022-73

cksum/H08-May-2022-84

compat/H22-Jul-2023-13,19210,195

compile_et/H08-May-2022-73

config/H08-May-2022-94

crunchgen/H08-May-2022-73

ctags/H08-May-2022-73

ctfconvert/H08-May-2022-6250

ctfmerge/H08-May-2022-4229

cvslatest/H08-May-2022-105

date/H08-May-2022-2311

db/H08-May-2022-73

dbsym/H08-May-2022-2516

disklabel/H08-May-2022-116

dtc/H08-May-2022-169

elftoolchain/H08-May-2022-276200

elftosb/H08-May-2022-84

fdisk/H08-May-2022-137

fgen/H08-May-2022-73

file/H08-May-2022-2010

gcc/H28-Jul-2023-1,5061,181

gdb/H09-May-2023-602424

genassym/H08-May-2022-2514

gencat/H08-May-2022-73

gettext/H08-May-2022-137

gmake/H08-May-2022-1910

gmp/H08-May-2022-3516

gpt/H08-May-2022-2516

grep/H08-May-2022-104

groff/H08-May-2022-9563

hexdump/H08-May-2022-73

host-mkdep/H10-Jul-2023-2,8612,320

hp300-mkboot/H08-May-2022-73

hppa-mkboot/H08-May-2022-94

ibmnws-ncdcs/H08-May-2022-73

installboot/H08-May-2022-4127

join/H08-May-2022-73

lex/H08-May-2022-2515

libctf/H08-May-2022-6747

libfdt/H08-May-2022-2513

libprop/H08-May-2022-2514

lint/H08-May-2022-2012

lint1/H08-May-2022-84

lint2/H08-May-2022-84

llvm/H08-May-2022-8459

llvm-clang/H08-May-2022-2114

llvm-clang-tblgen/H08-May-2022-84

llvm-include/H08-May-2022-94

llvm-lib/H08-May-2022-446116

llvm-tblgen/H08-May-2022-84

lorder/H08-May-2022-2817

m4/H08-May-2022-2,6071,842

m68k-elf2aout/H08-May-2022-1,8781,137

macppc-fixcoff/H08-May-2022-94

make/H21-Jul-2023-4,8454,002

makefs/H08-May-2022-105

makekeys/H08-May-2022-73

makestrs/H08-May-2022-73

makewhatis/H08-May-2022-94

mandoc/H08-May-2022-2212

mdsetimage/H08-May-2022-2616

menuc/H08-May-2022-106

mips-elf2ecoff/H08-May-2022-179117

mkcsmapper/H08-May-2022-73

mkdep/H08-May-2022-94

mkesdb/H08-May-2022-73

mklocale/H08-May-2022-73

mknod/H08-May-2022-73

mktemp/H08-May-2022-73

mkubootimage/H08-May-2022-94

mpc/H08-May-2022-156

mpfr/H08-May-2022-145

msgc/H08-May-2022-106

mtree/H08-May-2022-83

mvme68k-wrtvid/H08-May-2022-73

nbperf/H08-May-2022-73

pax/H08-May-2022-73

paxctl/H08-May-2022-105

pcc/H08-May-2022-2014

pigz/H08-May-2022-73

pkg_install/H08-May-2022-9146

powerpc-mkbootimage/H08-May-2022-94

pwd_mkdb/H08-May-2022-73

rpcgen/H08-May-2022-73

sed/H08-May-2022-73

sgivol/H08-May-2022-73

slc/H08-May-2022-73

sortinfo/H08-May-2022-105

sparkcrc/H08-May-2022-73

stat/H08-May-2022-73

strfile/H08-May-2022-73

sunlabel/H08-May-2022-84

texinfo/H08-May-2022-148

tic/H08-May-2022-168

tsort/H08-May-2022-73

uudecode/H08-May-2022-94

veriexecgen/H08-May-2022-116

vgrind/H08-May-2022-1913

xz-bin/H08-May-2022-94

xz-include/H03-Jun-2023-3718

xz-lib/H08-May-2022-83

yacc/H08-May-2022-73

zic/H01-Nov-2022-127

MakefileH A D08-May-20226.8 KiB284213

Makefile.gmakehostH A D08-May-2022830 223

Makefile.gnuhostH A D20-May-20234.6 KiB159103

Makefile.gnuwrapH A D08-May-2022925 3418

Makefile.hostH A D05-Jun-20232 KiB8662

Makefile.nbincludesH A D05-Jun-20231.6 KiB4835

READMEH A D08-May-20225.3 KiB143105

headerlistH A D08-May-20224.3 KiB146144

mkheaderlist.shH A D08-May-2022508 2213

README

1$NetBSD: README,v 1.5 2022/02/03 20:32:38 rillig Exp $
2
3Notes for NetBSD src/tools
4
5
6Background
7==========
8
9Several programs that are part of NetBSD are also built as tools.  Such
10programs are typically built twice: once as a tool and once as part of
11the release build.  Tools are relevant only when the make(1) variable
12USETOOLS=yes, which is the default for most NetBSD builds.
13
14Tools are built on the host platform, using the host compiler,
15and will run on the host platform during the cross-build of the
16remainder of NetBSD.  They are built near the beginning of a NetBSD
17build (e.g. "build.sh tools" or "make tools" from the top level src
18directory), and installed in ${TOOLDIR}.
19
20Tools are executed during the main part of the build, when several
21TOOL_* variables defined in src/share/mk/bsd.*.mk will refer to the
22tools installed in ${TOOLDIR}.
23
24
25Portability
26===========
27
28Programs that are built as tools need to be more portable than other
29parts of NetBSD, because they will need to run on the host platform.
30
31Most tools should restrict themselves to C language features that are
32defined in C99 (ISO/IEC 9899-1999); they should avoid using C11 language
33features, such as <threads.h>, _Alignof, <uchar.h>, _Generic,
34static_assert, anonymous structures and unions.
35
36Tools may use library features such as functions, macros, and types,
37that are defined in C99 and in POSIX (IEEE Std 1003.1) (XXX year?), and
38features that are provided by the compatibility framework
39(src/tools/compat) described in a separate section below.
40
41If a tool attempts to use a feature that is not available on the host
42platform, then the tools build will fail.  This can be addressed by
43changing the tool to avoid that feature, or by adding the feature to the
44src/tools/compat framework.  It is usually easy to add new macros or
45functions to src/tools/compat, and that is usually better than adding
46compatibility definitions to individual tools.
47
48
49Compatibility framework
50=======================
51
52src/tools/compat provides a compatibility framework for use by tools.
53It installs the following components, and more:
54
55${TOOLDIR}/lib/libnbcompat.a
56
57    A library containing functions that are needed by some tools.
58
59${TOOLDIR}/include/nbtool_compat.h
60
61    A header file defining macros that are needed by some tools.
62
63${TOOLDIR}/share/compat/defs.mk
64
65    A makefile fragment, to be included by other makefiles,
66    to define make variables appropriate for building tools.
67
68    Among other things, this makefile fragment automatically adds
69    the libnbcompat.a library to the LDADD and DPADD variables,
70    so that tools will be linked with that library, and adds
71    -I${NETBSDSRCDIR}/tools/compat and -DHAVE_NBTOOL_CONFIG_H=1 to the
72    HOST_CPPFLAGS variable, so that compiled programs can detect when
73    they are being built as tools.
74
75
76Adapting Makefiles for use with tools
77=====================================
78
79Makefiles under src/tools/*/Makefile should define the HOSTPROG
80variable.  This is typically done by tools/Makefile.hostprog,
81which is directly or indirectly included by all Makefiles in
82src/tools/*/Makefile.
83
84Makefiles in the non-tools part of the src tree can test whether or not
85the HOSTPROG variable is defined, in order tell the difference between
86building a tool and building part of a NetBSD release, and they may
87alter their behavior accordingly.
88
89For example, the Makefile may conditionally refrain from compiling and
90linking certain files, and the Makefile may conditionally pass macros to
91the compiler via constructs like this:
92
93    .if defined(HOSTPROG)
94    CPPFLAGS+= -DWITH_FEATURE_X=0 # exclude feature X from tools build
95    .else
96    CPPFLAGS+= -DWITH_FEATURE_X=1 # include feature X in release build
97    .endif
98
99Adapting Programs for use with tools
100====================================
101
102When a tool is being built, the C compiler should automatically be
103invoked with -DHAVE_NBTOOL_CONFIG_H=1.  This is done as a result of
104settings in ${TOOLDIR}/share/compat/defs.mk, which should be included
105from src/tools/Makefile.host, which should be included directly or
106indirectly from src/tools/*/Makefile.
107
108A C source file can test whether the HAVE_NBTOOL_CONFIG_H macro is
109defined, in order to tell whether or not it is being compiled as part of
110a tool.
111
112In order to obtain the definitions provided by the tools compatibility
113framework, almost every C source file that is built as part of a tool
114should have lines like these as the first non-comment lines:
115
116    #if HAVE_NBTOOL_CONFIG_H
117    #include "nbtool_config.h"
118    #endif
119
120To omit features from the tools version of a program, the program
121may test the HAVE_NBTOOL_CONFIG_H macro, like this:
122
123    #if HAVE_NBTOOL_CONFIG_H
124       ... code to be used when built as a tool
125    #else
126       ... code to be used when built as part of a release
127    #endif
128
129It is often preferable to use macros whose names refer to the features
130that should be included or omitted.  See the section on "Adapting
131Makefiles for use with tools" for an example in which the Makefile
132passes -DWITH_FEATURE_X=0 or -DWITH_FEATURE_X=1 to the compiler
133according to whether or not the program is being built as a tool.  Then
134the program can use code like this:
135
136    #if WITH_FEATURE_X
137       ... code to be used when FEATURE X is desired,
138       ... e.g. when being built as part of a release.
139    #else
140       ... code to be used when FEATURE X is not desired,
141       ... e.g. when being built as a tool.
142    #endif
143