Полезная информация

4.6. Some Questions and Answers

Q: I thought this was going to be a discussion about modems??!
Q: I thought you were supposed to use packages to install extra programs?
Q: So why bother with ports then?
Q: What is a patch?
Q: What is all this about tarballs?
Q: And a checksum?
Q: I did what you said for compiling ports from a CDROM and it worked great until I tried to install the kermit port.
Q: I did that, but when I tried to put it into /usr/ports/distfiles I got some error about not having permission.
Q: Does the ports scheme only work if you have everything in /usr/ports? My system administrator says I must put everything under /u/people/guests/wurzburger, but it does not seem to work.
Q: I do not have a FreeBSD CDROM, but I would like to have all the tarballs handy on my system so I do not have to wait for a download every time I install a port. Is there an easy way to get them all at once?
Q: I know it is probably faster to fetch the tarballs from one of the FreeBSD mirror sites close by. Is there any way to tell the port to fetch them from servers other than ones listed in the MASTER_SITES?
Q: I want to know what files make is going to need before it tries to pull them down.
Q: Is there any way to stop the port from compiling? I want to do some hacking on the source before I install it, but it is a bit tiresome having to watch it and hit control-C every time.
Q: I am trying to make my own port and I want to be able to stop it compiling until I have had a chance to see if my patches worked properly. Is there something like make extract, but for patches?
Q: I have heard that some compiler options can cause bugs. Is this true? How can I make sure that I compile ports with the right settings?
Q: There are so many ports it is hard to find the one I want. Is there a list anywhere of what ports are available?
Q: I went to install the foo port but the system suddenly stopped compiling it and starting compiling the bar port. What is going on?
Q: I installed the grizzle program from the ports and frankly it is a complete waste of disk space. I want to delete it but I do not know where it put all the files. Any clues?
Q: Hang on a minute, you have to know the version number to use that command. You do not seriously expect me to remember that, do you??
Q: Talking of disk space, the ports directory seems to be taking up an awful lot of room. Is it safe to go in there and delete things?
Q: I tried that and it still left all those tarballs or whatever you called them in the distfiles directory. Can I delete those as well?
Q: I like having lots and lots of programs to play with. Is there any way of installing all the ports in one go?
Q: OK, I tried that, but I thought it would take a very long time so I went to bed and left it to get on with it. When I looked at the computer this morning, it had only done three and a half ports. Did something go wrong?
Q: I really do not want to spend all day staring at the monitor. Any better ideas?
Q: At work, we are using frobble, which is in your ports collection, but we have altered it quite a bit to get it to do what we need. Is there any way of making our own packages, so we can distribute it more easily around our sites?
Q: This ports stuff is really clever. I am desperate to find out how you did it. What is the secret?

Q: I thought this was going to be a discussion about modems??!

A: Ah. You must be thinking of the serial ports on the back of your computer. We are using ``port'' here to mean the result of ``porting'' a program from one version of Unix to another. (It is an unfortunate bad habit of computer people to use the same word to refer to several completely different things).

Q: I thought you were supposed to use packages to install extra programs?

A: Yes, that is usually the quickest and easiest way of doing it.

Q: So why bother with ports then?

A: Several reasons:-

  1. The licensing conditions on some software distributions require that they be distributed as source code, not binaries.

  2. Some people do not trust binary distributions. At least with source code you can (in theory) read through it and look for potential problems yourself.

  3. If you have some local patches, you will need the source to add them yourself.

  4. You might have opinions on how a program should be compiled that differ from the person who did the package --- some people have strong views on what optimisation setting should be used, whether to build debug versions and then strip them or not, etc. etc.

  5. Some people like having code around, so they can read it if they get bored, hack around with it, borrow from it (licence terms permitting, of course!) and so on.

  6. If you ain't got the source, it ain't software! ;-)

Q: What is a patch?

A: A patch is a small (usually) file that specifies how to go from one version of a file to another. It contains text that says, in effect, things like ``delete line 23'', ``add these two lines after line 468'' or ``change line 197 to this''. Also known as a ``diff'', since it is generated by a program of that name.

Q: What is all this about tarballs?

A: It is a file ending in .tar or .tar.gz (with variations like .tar.Z, or even .tgz if you are trying to squeeze the names into a DOS filesystem).

Basically, it is a directory tree that has been archived into a single file (.tar) and optionally compressed (.gz). This technique was originally used for Tape ARchives (hence the name tar), but it is a widely used way of distributing program source code around the Internet.

You can see what files are in them, or even extract them yourself, by using the standard Unix tar program, which comes with the base FreeBSD system, like this:-

    % tar tvzf foobar.tar.gz       
    % tar xzvf foobar.tar.gz
    % tar tvf foobar.tar
    % tar xvf foobar.tar

Q: And a checksum?

A: It is a number generated by adding up all the data in the file you want to check. If any of the characters change, the checksum will no longer be equal to the total, so a simple comparison will allow you to spot the difference. (In practice, it is done in a more complicated way to spot problems like position-swapping, which will not show up with a simplistic addition).

Q: I did what you said for compiling ports from a CDROM and it worked great until I tried to install the kermit port.

    # make install
    >> cku190.tar.gz doesn't seem to exist on this system.
    >> Attempting to fetch from ftp://kermit.columbia.edu/kermit/archives/.

Why can it not be found? Have I got a dud CDROM?

A: As was explained in the compiling ports from a CDROM section, some ports are unable to be put on the CDROM due to licensing limitations. Kermit is an example of that. The licensing terms for kermit do not allow us to put the tarball for it on the CDROM, so you will have to fetch it by hand---sorry!

The reason why you got all those error messages was because you were not connected to the Internet at the time. Once you have downloaded it from any of the sites above, you can re-start the process (try and choose the nearest site to you, though, to save your time and the Internet's bandwidth).

Q: I did that, but when I tried to put it into /usr/ports/distfiles I got some error about not having permission.

A: The ports mechanism looks for the tarball in /usr/ports/distfiles, but you will not be able to copy anything there because it is sym-linked to the CDROM, which is read-only. You can tell it to look somewhere else by doing

    # make DISTDIR=/where/you/put/it install

Q: Does the ports scheme only work if you have everything in /usr/ports? My system administrator says I must put everything under /u/people/guests/wurzburger, but it does not seem to work.

A: You can use the PORTSDIR and PREFIX variables to tell the ports mechanism to use different directories. For instance,

    # make PORTSDIR=/u/people/guests/wurzburger/ports install

will compile the port in /u/people/guests/wurzburger/ports and install everything under /usr/local.

    # make PREFIX=/u/people/guests/wurzburger/local install

will compile it in /usr/ports and install it in /u/people/guests/wurzburger/local.

And of course

    # make PORTSDIR=.../ports PREFIX=.../local install

will combine the two (it is too long to fit on the page if I write it in full, but I am sure you get the idea).

If you do not fancy typing all that in every time you install a port (and to be honest, who would?), it is a good idea to put these variables into your environment.

Q: I do not have a FreeBSD CDROM, but I would like to have all the tarballs handy on my system so I do not have to wait for a download every time I install a port. Is there an easy way to get them all at once?

A: To get every single tarball for the ports collection, do

    # cd /usr/ports
    # make fetch

For all the tarballs for a single ports directory, do

    # cd /usr/ports/directory
    # make fetch

and for just one port --- well, I think you have guessed already.

Q: I know it is probably faster to fetch the tarballs from one of the FreeBSD mirror sites close by. Is there any way to tell the port to fetch them from servers other than ones listed in the MASTER_SITES?

A: Yes. If you know, for example, ftp.FreeBSD.org is much closer than sites listed in MASTER_SITES, do as following example.

    # cd /usr/ports/directory
    # make MASTER_SITE_OVERRIDE=ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/ fetch

Q: I want to know what files make is going to need before it tries to pull them down.

A: make fetch-list will display a list of the files needed for a port.

Q: Is there any way to stop the port from compiling? I want to do some hacking on the source before I install it, but it is a bit tiresome having to watch it and hit control-C every time.

A: Doing make extract will stop it after it has fetched and extracted the source code.

Q: I am trying to make my own port and I want to be able to stop it compiling until I have had a chance to see if my patches worked properly. Is there something like make extract, but for patches?

A: Yep, make patch is what you want. You will probably find the PATCH_DEBUG option useful as well. And by the way, thank you for your efforts!

Q: I have heard that some compiler options can cause bugs. Is this true? How can I make sure that I compile ports with the right settings?

A: Yes, with version 2.6.3 of gcc (the version shipped with FreeBSD 2.1.0 and 2.1.5), the -O2 option could result in buggy code unless you used the -fno-strength-reduce option as well. (Most of the ports do not use -O2). You should be able to specify the compiler options used by something like

    # make CFLAGS='-O2 -fno-strength-reduce' install

or by editing /etc/make.conf, but unfortunately not all ports respect this. The surest way is to do make configure, then go into the source directory and inspect the Makefiles by hand, but this can get tedious if the source has lots of sub-directories, each with their own Makefiles.

Q: There are so many ports it is hard to find the one I want. Is there a list anywhere of what ports are available?

A: Look in the INDEX file in /usr/ports. If you would like to search the ports collection for a keyword, you can do that too. For example, you can find ports relevant to the LISP programming language using:

    % cd /usr/ports
    % make search key=lisp

Q: I went to install the foo port but the system suddenly stopped compiling it and starting compiling the bar port. What is going on?

A: The foo port needs something that is supplied with bar --- for instance, if foo uses graphics, bar might have a library with useful graphics processing routines. Or bar might be a tool that is needed to compile the foo port.

Q: I installed the grizzle program from the ports and frankly it is a complete waste of disk space. I want to delete it but I do not know where it put all the files. Any clues?

A: No problem, just do

    # pkg_delete grizzle-6.5

Alternatively, you can do

    # cd /usr/ports/somewhere/grizzle
    # make deinstall

Q: Hang on a minute, you have to know the version number to use that command. You do not seriously expect me to remember that, do you??

A: Not at all, you can find it out by doing

    # pkg_info -a | grep grizzle
    Information for grizzle-6.5:
    grizzle-6.5 - the combined piano tutorial, LOGO interpreter and shoot 'em up arcade game.

Q: Talking of disk space, the ports directory seems to be taking up an awful lot of room. Is it safe to go in there and delete things?

A: Yes, if you have installed the program and are fairly certain you will not need the source again, there is no point in keeping it hanging around. The best way to do this is

    # cd /usr/ports
    # make clean

which will go through all the ports subdirectories and delete everything except the skeletons for each port.

Q: I tried that and it still left all those tarballs or whatever you called them in the distfiles directory. Can I delete those as well?

A: Yes, if you are sure you have finished with them, those can go as well.

Q: I like having lots and lots of programs to play with. Is there any way of installing all the ports in one go?

A: Just do

    # cd /usr/ports
    # make install

Q: OK, I tried that, but I thought it would take a very long time so I went to bed and left it to get on with it. When I looked at the computer this morning, it had only done three and a half ports. Did something go wrong?

A: No, the problem is that some of the ports need to ask you questions that we cannot answer for you (eg ``Do you want to print on A4 or US letter sized paper?'') and they need to have someone on hand to answer them.

Q: I really do not want to spend all day staring at the monitor. Any better ideas?

A: OK, do this before you go to bed/work/the local park:-

    # cd /usr/ports
    # make -DBATCH install

This will install every port that does not require user input. Then, when you come back, do

    # cd /usr/ports
    # make -DIS_INTERACTIVE install

to finish the job.

Q: At work, we are using frobble, which is in your ports collection, but we have altered it quite a bit to get it to do what we need. Is there any way of making our own packages, so we can distribute it more easily around our sites?

A: No problem, assuming you know how to make patches for your changes:-

    # cd /usr/ports/somewhere/frobble
    # make extract
    # cd work/frobble-2.8
    [Apply your patches]
    # cd ../..
    # make package

Q: This ports stuff is really clever. I am desperate to find out how you did it. What is the secret?

A: Nothing secret about it at all, just look at the bsd.ports.mk and bsd.ports.subdir.mk files in your makefiles directory.

Readers with an aversion to intricate shell-scripts are advised not to follow this link...)