Solved Getting source for base applications and libraries

The fetch program isn't a port exactly (or I would be asking this question in the forum on ports, or actually I would already know the answer), so I hope this is the right place to ask:

Is there a way to download (and then compile) the fetch program and its underlying library without downloading and building the whole release?

EDIT: I changed the title of the thread to make it more accessible to searches by newbies like me.
 
Last edited:
Copy /usr/src/usr.bin/fetch and /usr/src/lib/libfetch to somewhere. They will build fine out of the source tree (at least on FreeBSD).

I believe you can checkout individual directories with SVN.
 
To expand on tobik's reply, for the benefit of any lurkers who might be newbies like me, this is how to download, modify, and install the source for a base application or library, if you're running FreeBSD 10.0 or 10.1. (But see tobik's useful observations in the next comment of this thread.)

Step one: Bring up your Internet connection, if it's not up already. (Many will use dhclient for this.)

Step two: Install subversion if you have not done so already. (If you don't know whether you have, do it again; it won't hurt.)
pkg install subversion
Step three: Choose the most appropriate subversion mirror site. A list is here. Where you see svn-mirror below, insert the name of the subversion mirror site you've chosen. Be sure to precede the name of the site with svn://, as the examples below show.

Step four: Pick the name of a directory where you want the source files to go. The directory must not already exist, but its parent must. For example, if you want the source files to go to directory /alpha/beta/gamma, directory /alpha/beta must already exist, but directory /alpha/beta/gamma must not exist. Where you see gamma below, insert the name of the (so far) nonexistent directory to hold the source code.

Step five: Download the source. The form of the command depends on whether you're working with an application or a library, and if it's an application, where the object code normally sits; to find that out for application fetch, for example, do this:
which fetch
In this case, you'll see:
Code:
/usr/bin
Our examples below use dmesg, which is in directory /sbin; pkg, which is in directory /usr/sbin; ls, which is in directory /bin; and fetch, which is in directory /usr/bin. So to download the source, pick one of these commands:
svn checkout svn://svn-mirror/base/stable/10/lib/libfetch gamma # for any library
svn checkout svn://svn-mirror/base/stable/10/sbin/dmesg gamma # for apps in /sbin
svn checkout svn://svn-mirror/base/stable/10/usr.sbin/pkg gamma # for apps in /usr/sbin
svn checkout svn://svn-mirror/base/stable/10/bin/ls gamma # for apps in /bin
svn checkout svn://svn-mirror/base/stable/10/usr.bin/fetch gamma # for apps in /usr/bin


Step six: Position yourself in the destination directory and modify the source. No need to copy it elsewhere. You'll just be using it privately, right? Then forget that you're in a subversion directory. Just splash and play.

Step seven: Set the destination directory for the application. This is not done for libraries. Do something like this for normal shells:
export BINDIR=/usr/bin
or, for C shells like tcsh:
setenv BINDIR /usr/bin
If you're working with an application and you forget this step, you'll find your compiled application at the root directory. For example fetch will be placed at /fetch.

Step eight: Position yourself in the directory that contains the Makefile, and do this:
make # (and make sure there are no fatal errors; warnings should be OK)
make install


Boom. You're done.

For extra credit, consider downloading the whole base source tree, wandering through it, and letting your imagination go wild:
rm -rf /usr/src
svn checkout svn://svn-mirror/base/stable/10 /usr/src
 
I would like to add that there is also svnlite in base, so you do not need to install Subversion from ports (of course it doesn't hurt). Just replace svn with svnlite in Bill's post.

BINDIR can also be set on the make command line, saving a step: make BINDIR=/usr/bin install
 
It is not necessary to set BINDIR. If you just do make (sometimes needed twice), the binary will be in the same directory as the source. Just give it an explicit path to run the new binary for testing.
 
Correct. But the setting of BINDIR was not for the straight make command, but for the make install step.

One thing has me curious, though, wblock@: why is make sometimes needed twice?
 
Back
Top