Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

...............................................................................................

# pkg_add −f packagename.tgz

...............................................................................................

You'll see a warning that a dependency was not found, but that the install is proceeding anyway. If the software works, great! If not, uninstall it and start working with ports.

[3]No, Microsoft Word is not available on FreeBSD. Yet. But it's very difficult to think of a major, recognizable example of binary−only software for FreeBSD, as almost all of it is available in source form.

Using Ports

It takes longer to build software using ports than it does when using packages, and the ports system requires a live Internet connection. Still, the ports system can produce better results than packages.

Let's take a look at a port. We're going to pick on one of my favorite security tools, SKIP.[4]

...............................................................................................

#cd /usr/ports/security/skip

#ls

v Makefile

x

distinfo

z

pkg−comment

| pkg−plist

w

README.html y

files

{

pkg−descr

} scripts

#

 

 

 

 

 

 

...............................................................................................

The Makefile in the preceding list (v) contains the basic instructions for building this port. If you were to take a look at this file, you'd quickly notice that there isn't much in it. The Makefiles for individual ports don't contain much beyond some basic information about the port; they don't have information about how to build FreeBSD software in general. (Most of the FreeBSD ports Makefile system is contained in the directory /usr/ports/Mk; editing these files is a very advanced topic, and you really don't want to go there until you're very comfortable with Makefiles.)

The README.html file (w) gives a brief description of the port. If you're using a Web browser to skim the ports collection, you'll be directed to this file when you ask for information on this port.

The distinfo file (x) contains integrity−checking information (or checksums) for the files required to build this program.

The files directory (y) contains any add−on files required to build this port. Our particular example requires 87 patches, but many ports don't even have a files directory, and build cleanly without patching.

The pkg−comment file (z) contains a one−line description of the port. Similarly, pkg−descr ({) contains a longer, more detailed description and (usually) a URL for more information on the program.

The pkg−plist file (|) holds a list of all the files installed by the port (the "packing list"). If a file is not listed here, it will not be installed.

238

Finally, the scripts directory (}) holds a variety of scripts to be run at various stages of the port−building process. This directory might or might not exist—if the port builds without any special tweaking, it won't have any additional scripts. These scripts perform any pre− or post−processing that the port needs, for example, changing permissions on a downloaded distfile so that patch(1) can run properly.

Combined, these files create the tools and instructions needed to build the software.

Installing a Port

If you're familiar with source code, you'll quickly notice that there is no actual source code in the port. Sure, there's patches to apply to source code, and scripts to run on source code, but no actual source code! You might rightly ask just how this is supposed to work without the source code.

When you activate a port, your system automatically downloads the appropriate source code from an approved Internet site. It then checks the downloaded code for integrity errors, extracts the code to a working directory, patches it, builds it, installs everything, and records the installation under /var/db/pkg. If the port has dependencies, and those dependencies aren't installed, it will interrupt the make process to build those dependencies, and then finish its own. To trigger all this, you just have to go to a port directory and type this command:

...............................................................................................

# make install

...............................................................................................

When you do, you'll see lots of text scroll down your terminal window, ending with a "recording installation" message.

This all−in−one installation process handles any changes in dependencies. If a port requires another program, the port will simply gloss over minor changes in that program. For example, perhaps you have a version of Apache that's a few months old. A package would demand that you install the newer version, while a port will just check to see if Apache is installed.

As you grow more experienced with building source code, however, you'll find that this all−in−one approach isn't appropriate for every occasion. Not to worry; the ports system gives you the opportunity to take the port−building process exactly as far as you like, because make install is actually not one but a series of commands.

Using Make Install

The make install process starts with make fetch. During this stage of the process, make checks to see whether the source code is in /usr/ports/distfiles. If it's not, your system goes to get it.

Make Fetch The make fetch process first checks for the source code in the MASTER_SITE listed in the Makefile, then checks a list of backup sites provided by the ports system itself. If it finds the source code, it downloads it, and that downloaded source code is called a distfile.

Make Checksum Next, make checksum confirms that the distfile's digital signature matches the one that the port has in the distinfo file. This is a security measure; if the FTP server was broken into by a malicious hacker and the source code replaced by a Trojan horse, or if the download was

239

corrupted, this step will detect it and stop the build with a warning about a checksum mismatch. If the distfile has been deliberately changed, make checksum stops compilation.

NoteSoftware authors sometimes make minor changes to their code, but give the source file the same name as when they first made it available for download. The FreeBSD port might or might not work after this change. If you're sure that the distfile has not been compromised or corrupted, and want to use it despite this warning, you can override this with make NO_CHECKSUM=YES. I highly recommend that you check with your vendor to see if this is a legitimate change.

Make Depends The make depends stage checks to see if the port is dependent on any other software, and, if so, whether that software is installed. (For example, an X window manager requires an X server.) If the software on which the port depends is not found, this stage recurses through the various dependencies and completely builds them all.

Make Extract Once you have the port distfiles, you have to uncompress and extract them. This is done under a work directory in the port. To create this directory and uncompress the distfiles under it, use make extract.

Make Patch The make patch stage applies any FreeBSD−specific patches listed in the Makefile to the port.

Make Configure Next, make configure checks to see if the program needs a configure script. If it does, it runs it. If not, the port build proceeds silently to the next step.

Make Build The make build stage compiles the checked, extracted, and patched software.

Make Install Finally, make install installs the software and records its presence under /var/db/pkg.

Make Target Dependencies Each make target depends on the make targets before it. You cannot patch source code that you have not yet fetched, for example. Whenever you use any make target, make runs all previous stages that have not yet been run. For example, make extract performs a make fetch, make checksum, and make extract.

How might you use these make stages in practice? Say that you want to apply some patches to a program before you compile it—patches that address stability or security problems. You want to apply the patch to your source code after you've extracted it and applied the FreeBSD−specific patches. To do so, you could run make patch, apply the new patches to the software under the work directory according to the vendor's instructions, and then return to the port directory and type make install.

Built−In Port Features

Ports allow you to do a great deal of customization, which you can read about in the port's Makefile. Since the port's Makefile includes specific instructions for building this particular piece of software, it's where options for that software are most likely to be found.

Many ports announce additional features when you first type make install, though not all will work (especially some older ones). Whether a feature will work depends on the port maintainer's skills, time, and inclination—remember, this is a volunteer project!

240

You can always get information about a port's additional features from the Makefile, but let's look at an announcement and see how to use it first. For example, when you try to install /usr/ports/security/snort you'll see a notice:

...............................................................................................

Set WITH_FLEXRESP, WITH_MYSQL, WITH_ODBC or WITH_POSTGRES

to get additional support.

...............................................................................................

A bit of Web searching would show you that mysql, odbc, and postgresql are database packages, and this message tells you that you could build Snort with support for these databases. A similar search would show that flexresp is part of the libnet software package.

If you get an announcement, and you want to use one of these options, press CONTROL−C to abort the port build. You can then set these options on the install command line like this:

...............................................................................................

# make WITH_ODBC=YES install

...............................................................................................

This command changes the way the port will be built and will build your version of Snort with support for ODBC database connections. With this feature built into Snort, you would then be able to log data across the network to any database that supports ODBC, such as Microsoft SQL Server or an Oracle database.

Here's one area where ports shine over packages. You couldn't do this customization with a package, unless you had multiple versions of the same package. And sorting through snort−odbc−1.9.tgz, snort−mysql−1.9.tgz, snort−postgres−mysql−libnet−1.9.tgz, and so on would be utterly hideous, waste space on the CD, and be mostly unused.

The Makefile itself will tell you the build options for a port. At the top of the Makefile, you'll see a lot of stuff that describes the port, like this:

...............................................................................................

v PORTNAME=

snort

w PORTVERSION=

1.8

x CATEGORIES=

security

y MASTER_SITES=

http://www.snort.org/Files/ \

 

http://www.physik.TU−Berlin.DE/~ibex/

 

ports/distfiles/

z DISTNAME=

${PORTNAME}−${PORTVERSION}−RELEASE

{ MAINTAINER=

dirk@FreeBSD.org

| GNU_CONFIGURE=

yes

} CONFIGURE_ARGS=

−−with−mysql=no −−with−odbc=no −−with−po stgresql=no

~ MAN8=

snort.8

...............................................................................................

Much of this is obvious to people who habitually build software from source. If you're not at that point yet, don't worry. You'll get there with practice. Let's consider this particular example. Not all of

241

these entries are mandatory, and there are many other possible entries in port Makefiles, but these are fairly common.

The PORTNAME (v) is the name the software uses in FreeBSD's ports system. This is not necessarily the same as the software name, as we saw earlier in our search for Midnight Commander. The PORTVERSION (w) is the version number of the software, as given by the software's author.

CATEGORIES (x) lists all the ports directories where the port can be found. For example, this port is under /usr/ports/security.

MASTER_SITES (y) contains a list of Internet sites where the software can be found. This is where the ports system tries to get the software from. If one site is unreachable, it tries the next.

The DISTNAME (z) is the name of the original file of software source code. The ports system tries to grab this file from the MASTER_SITES given earlier.

The MAINTAINER ({) is the person responsible for maintaining the FreeBSD port. This person doesn't actually write the software, but just makes sure that it installs on FreeBSD.

GNU_CONFIGURE (|) tells the ports system if the software needs to use the classic GNU program autoconf. In a related entry, CONFIGURE_ARGS (}) lists arguments to be given to autoconf.

There is usually a list of man pages that the program installs (~). You can check these pages with man(1) to see how to use the program. You might then see a bunch of "if defined" statements like this one:

...............................................................................................

.if defined v (WITH_FLEXRESP)

BUILD_DEPENDS w += ${LOCALBASE}/lib/libnet.a:$ ? {PORTSDIR}/net/libnet CONFIGURE_ARGS +=−−enable−flexresp

CONFIGURE_ENV += CPPFLAGS="−I${LOCALBASE}/include" LDFLAGS+= "−L${LOCALBASE}/lib"

.endif

...............................................................................................

This is a build option for the port. The first line in this example is the variable (v) you need to set—in this case, WITH_FLEXRESP. The second line shows that this adds a dependency (w) for the port, /usr/ports/net/libnet. The remainder is a bunch of software−building commands that are altered by setting this variable.

You set this variable on the command line. To set WITH_FLEXRESP, you would type

...............................................................................................

# make install WITH_FLEXRESP=YES

...............................................................................................

You don't need to understand the balance of this listing right now, but notice the little question mark

(?) and plus and equal (+=) symbols scattered throughout it. These mean that you're adding commands to the build process, literally changing how the software is built just by setting this

242