Subject: Re: Adding a program to my custom userland.
To: Brian Rose <lists@brianrose.net>
From: Jeff Rizzo <riz@NetBSD.org>
List: current-users
Date: 08/28/2006 19:35:58
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig6B40D9B639C8F25AD16175D3
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Brian Rose wrote:
>
> I am in the process of building a customized NetBSD system to go onto
> an embedded device. Currently I can build the kernel and userland and
> boot from the kernel. I start by building the kernel (with a ramdisk),
> then userland, and then I finally use crunchgen to select the programs
> I am interested in to populate my system. I take this uber-binary and
> put it into a filesystem, populate some hard links, and stuff it into
> a ramdisk kernel. You can see the process at
>
> http://brianrose.net/columns/TinyNetBSD-3.0.1.html
>
> I'd like to add one of my programs to this, but I need to figure out
> the magical incantation used to build the correct binary for my target
> system. The NetBSD guide indicates that building userland is done with
>
> ./build.sh -U -u -m sparc64 release
>
> My question is how do I add my custom program to this? I am not
> familiar with the ins and outs of the makefile system, so please
> address this as if I were a newbie to NetBSD (but not software
> development in general).
>
> I'm guessing that I can clone one of the simpler programs, like init,
> and just replace init.c with hello.c and then replace all references
> to init with hello. This is rather crude, I admit, but I have not been
> able to find a handy little reference document that shows one how to
> add a program to the standard distribution so that it can be easily
> cross-compiled.
>  =20

I don't think there is a handy little document; I can describe the
process as best I see fit here.  (Please keep in mind, I haven't
actually done this myself, but I'm aware of most of the steps,
especially the ones likely to confuse non-NetBSD folks)

The first step will be to determine where you want to build your program
- were you adding something to NetBSD, you'd likely choose an
appropriate location (/sbin, /bin, /usr/bin, etc) from hier(7) - you may
still choose to do this, but you may also want to add a top-level
category ("local", in my example, for lack of a better name).  Because
it's less work for me  :) , I'll describe how to add a program to /bin -
to add a top-level category, you'll need to edit the top-level Makefile.

To add a program "foo" to /bin, here are the approximate steps:

1.  Create directory "foo" in /usr/src/bin
2.  Assuming your "foo" program uses "foo.c" to build and "foo.1" as
manpage source, create bin/foo/Makefile which looks like this:

# see /usr/share/mk/bsd.README for more info on BSD Makefiles
PROG=3D foo
MAN=3D foo.1
=2Einclude <bsd.prog.mk>

3.  To cause "foo" to be built/installed as part of "/bin", add the
following line to /usr/src/bin/Makefile :

SUBDIR+=3D foo

=2E..make sure to add this ABOVE the ".include <bsd.subdir.mk>

4.  Assuming you wanted "foo" to be part of the "base.tgz" set, you need
to add appropriate lines to /usr/src/distrib/sets/lists/base/mi  ("mi"
in this context means "machine independent" - notice the various files
in that directory.  Most of them have Special Magick in the Makefiles to
only get them used for the appropriate architectures or machines.=20
You'll need to add a line for the binary ("./bin/foo"), the manpage
source ("./usr/share/man/man1/foo.1"), and the catpage
("./usr/share/man/cat1/foo.0") - you may wish to add these to
distrib/sets/lists/man/mi instead.  The second column of this file
format specifies which "syspkg" set they're in - syspkgs are not yet
widely used, but we're trying to move toward them, and you should be
able to just invent a new syspkg name for your new tool.  The third
column specifies which MKXXX variables affect whether the tool is built
- ie, "gdb" means "not built if MKGDB=3Dno".

That's Basically It.  If you need to add new
directories/categories/whatever, you'll need to refer to the various
Makefiles (per-directory, as well as the system files in share/mk) to
learn more about how it's done.  You may also wish to refer to simple
examples, like "bin/sync" for inspiration.=20

Hope this helps!

+j




--------------enig6B40D9B639C8F25AD16175D3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBRPOoErOuUtxCgar5AQO/QQP/Ywk1OAc0x3rtBcPY7pN6+Zyi0PCGmtNU
oBwYq8oSlImhfX+0bc7ArT6ngqzAkQ+typLhwl0FOgHlzx+aFp2Hxt5tUHyTjWDw
TEJ8mzFCgufzBCGvZdhl+VZ4swlXhpr7Hl8mNkNhTxJ+K8YDVsp6NQi7Sn/7QuS0
n7T6a3Zf2Fc=
=9qDk
-----END PGP SIGNATURE-----

--------------enig6B40D9B639C8F25AD16175D3--