NetBSD/tools
aymeric a3838ae30d add our libc's regex implementation to libnbcompat.
This way, nbsed picks it up and it unbreaks the build of xf86-video-intel-old's
man page under Linux and probably other future changes which rightfully expect
the (net)bsd behaviour.

Full release tested on ArchLinux and NetBSD 7.0_STABLE
2016-03-06 10:19:01 +00:00
..
amiga-elf2bb Remove the borked definition of ELF64_Shalf from some more places. 2014-01-03 16:50:54 +00:00
amiga-txlt
asn1_compile
autoconf Revert previous change to tools/Makefile.gnuhost. When getenv("M4") 2013-08-07 17:50:55 +00:00
awk
binstall no man pages for tools build. 2013-03-16 22:32:50 +00:00
binutils use EXTERNAL_BINUTILS_SUBDIR 2016-01-26 17:47:35 +00:00
cap_mkdb Build getcap.c only once. 2012-06-04 18:53:02 +00:00
cat
cksum
compat add our libc's regex implementation to libnbcompat. 2016-03-06 10:19:01 +00:00
compile_et
config
crunchgen
ctags
ctfconvert switch to the new libelf and libdwarf 2014-03-09 17:12:03 +00:00
ctfmerge use HOST_CFLAGS for -pthread 2016-01-27 21:18:28 +00:00
cvslatest Tool version 2016-01-24 20:14:17 +00:00
db
dbsym silent when we don't have -ldl 2016-02-01 14:18:16 +00:00
disklabel Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine 2013-05-03 16:05:11 +00:00
elftosb Add elftosb tools to evbarm userland and toolchain. 2012-11-15 19:49:11 +00:00
fdisk Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8) 2012-06-05 13:41:23 +00:00
fgen
file force set ac_cv_mkdir_path to our install -d program. 2012-04-15 08:37:32 +00:00
gcc Add missing closing ) and line continuation for mknative 2016-02-15 13:25:12 +00:00
gdb use EXTERNAL_GDB_SUBDIR 2016-01-26 17:48:31 +00:00
genassym Make most things under src/tools use the TOOLDIR version of compat/defs.mk, 2012-12-02 12:48:32 +00:00
gencat
gettext Prevent the tools/gettext build from trying to run emacs. 2013-03-06 14:34:01 +00:00
gmake switch to the new gmake 2014-08-18 06:58:51 +00:00
gmp Save a couple of dollars now that make is fixed. 2016-01-09 01:13:42 +00:00
gpt now gpt works under macosx. 2014-09-30 18:00:28 +00:00
grep
groff grr another copy of the path I missed; factor out to a variable. 2016-01-14 01:13:26 +00:00
hexdump
host-mkdep Like the non-host mkdep don't print ./foo.h as a dependency, but simplify 2015-05-12 00:04:34 +00:00
hp300-mkboot
hppa-mkboot Rename NetBSD/hp700 to NetBSD/hppa. 2014-02-24 07:23:38 +00:00
ibmnws-ncdcs
installboot
join
lex
libctf libelf has moved. 2015-12-27 21:37:50 +00:00
libdwarf switch to the new libdwarf 2014-03-09 17:10:38 +00:00
libelf switch to the new libelf 2014-03-09 17:10:12 +00:00
lint
lint1
lint2
llvm misc/48722: Use explicit HOST_SH in case the user insists on removing 2015-03-05 10:22:25 +00:00
llvm-clang
llvm-clang-tblgen Update LLVM/Clang snapshot to r141658. This primarily fixes a regression 2011-10-11 13:53:56 +00:00
llvm-include Fix version string returned by clang --version. 2012-06-17 07:40:25 +00:00
llvm-lib Update build system glue for LLVM 3.6RC1. Notable changes: 2015-01-29 20:41:33 +00:00
llvm-lld Update LLVM/Clang snapshot to r189662. This includes many improvements 2013-09-02 14:34:55 +00:00
llvm-mcld Add infrastructure for building MCLinker. 2013-02-27 21:25:05 +00:00
llvm-tblgen Update LLVM/Clang snapshot to r141658. This primarily fixes a regression 2011-10-11 13:53:56 +00:00
lorder Make most things under src/tools use the TOOLDIR version of compat/defs.mk, 2012-12-02 12:48:32 +00:00
m4
m68k-elf2aout Remove the borked definition of ELF64_Shalf from some more places. 2014-01-03 16:50:54 +00:00
macppc-fixcoff
make
makefs
makekeys Support building the xorg X11 libraries under MKCOMPAT. 2015-06-24 22:20:24 +00:00
makestrs Support building the xorg X11 libraries under MKCOMPAT. 2015-06-24 22:20:24 +00:00
makewhatis
mandoc clean Makefile.local 2016-01-27 21:24:59 +00:00
mdsetimage kill error message 2016-02-01 14:17:21 +00:00
menuc
mips-elf2ecoff Remove the borked definition of ELF64_Shalf from some more places. 2014-01-03 16:50:54 +00:00
mkcsmapper
mkdep
mkesdb
mklocale
mknod
mktemp
mkubootimage
mpc update to MPC 1.0.1. 2013-11-28 12:08:56 +00:00
mpfr force set ac_cv_mkdir_path to our install -d program. 2012-04-15 08:37:32 +00:00
msgc
mtree Don't create a crippled mtree with no hashes. We have hash support in 2013-02-06 01:01:48 +00:00
nbperf Hook up nbperf into the normal tool build. 2011-11-01 21:16:28 +00:00
pax
paxctl
pcc
pigz
pkg_install
powerpc-mkbootimage
pwd_mkdb
rpcgen
sed
sgivol
slc
sortinfo Add sortinfo 2015-12-18 18:56:33 +00:00
sparkcrc
stat
strfile
sunlabel
texinfo Invoke tools/binstall/mkmanifest for Cygwin via ${HOST_SH}. 2013-06-14 16:10:02 +00:00
tic Handle auto-generating hash.c 2011-11-02 17:49:20 +00:00
tsort
uudecode
veriexecgen
vgrind use host rules for files. 2014-07-15 16:04:35 +00:00
yacc
zic
headerlist Sort using mkheaderlist.sh:1.3 2016-02-23 11:43:57 +00:00
Makefile move cvslatest last 2016-01-24 22:49:08 +00:00
Makefile.gmakehost Merge the two Makefiles that were mostly copies of each others. 2012-01-20 23:01:05 +00:00
Makefile.gnuhost look in gpl3 for stuff too (autoconf) 2016-01-16 18:38:53 +00:00
Makefile.gnuwrap
Makefile.host Invoke tools/binstall/mkmanifest for Cygwin via ${HOST_SH}. 2013-06-14 16:10:02 +00:00
Makefile.nbincludes Add endian_machdep.h files for sh3 machines to _ARCH_INCS as 2015-01-24 16:21:33 +00:00
mkheaderlist.sh Sort the output 2016-02-23 11:43:04 +00:00
README Update documentation about tools being restricted to C89 (or not). 2015-01-03 13:20:11 +00:00

$NetBSD: README,v 1.4 2015/01/03 13:20:11 apb 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/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