Put in remaining pages and wiki contents.
[ikiwiki.git] / docs / handbook / handbook-pkgsrc-sourcetree-using.mdwn
1 \r
2 \r
3 ## Using the pkgsrc® Source Tree \r
4 \r
5 The following sections provide basic instructions on using the pkgsrc source tree to install or remove programs from your system.\r
6 \r
7 ### Obtaining the pkgsrc Source Tree \r
8 \r
9 Before you can install pkgsrc® packages from source, you must first obtain the pkgsrc source tree--which is essentially a set of `Makefiles`, patches, and description files placed in `/usr/pkgsrc`.\r
10 \r
11 \r
12 #### CVS \r
13 \r
14 The primary method to obtain and keep your pkgsrc collection up to date is by using  **CVS** .\r
15 This is a quick method for getting the pkgsrc collection using  **CVS** .\r
16 \r
17   1. Run `cvs`:\r
18       \r
19     # cd /usr\r
20     # cvs -d anoncvs@anoncvs.us.netbsd.org:/cvsroot co pkgsrc\r
21   \r
22   1. Running the following command later will download and apply all the recent changes to your source tree.\r
23       \r
24     # cd /usr/pkgsrc\r
25     # cvs up\r
26   \r
27 #### Quick & Dirty Way \r
28 \r
29 As of the 1.10 release, you can use the `/usr/Makefile` to checkout & update the pkgsrc tree quickly.\r
30 \r
31 as root:\r
32 \r
33      . \r
34     # cd /usr\r
35     # make pkgsrc-checkout\r
36 \r
37 \r
38 to checkout, or\r
39 \r
40      . \r
41     # cd /usr\r
42     # make pkgsrc-update\r
43 \r
44 \r
45 to update.\r
46 \r
47 Please do edit the makefile to use an appropriately speedy CVS mirror for your location and to reduce\r
48 load on the main pkgsrc cvs server.\r
49 \r
50 ### Installing Packages from Source \r
51 \r
52 The first thing that should be explained when it comes to the source tree is what is actually meant by a ***skeleton***. In a nutshell, a source skeleton is a minimal set of files that tell your DragonFly system how to cleanly compile and install a program. Each source skeleton should include:\r
53 \r
54
55 * A `Makefile`. The `Makefile` contains various statements that specify how the application should be compiled and where it should be installed on your system.\r
56
57 * A `distinfo` file. This file contains information about the files that must be downloaded to build the port and their checksums, to verify that files have not been corrupted during the download using [md5(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#md5&section1).\r
58
59 * A `files` directory. This directory contains the application specific files that are needed for the programs appropriate run-time configuration.\r
60   This directory may also contain other files used to build the port.\r
61
62 * A `patches` directory. This directory contains patches to make the program compile and install on your DragonFly system. Patches are basically small files that specify changes to particular files. They are in plain text format, and basically say ***Remove line 10*** or ***Change line 26 to this ...***. Patches are also known as ***diffs*** because they are generated by the [diff(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#diff&section1) program.\r
63
64 * A `DESCR` file. This is a more detailed, often multiple-line, description of the program.\r
65
66 * A `PLIST` file. This is a list of all the files that will be installed by the port. It also tells the pkgsrc system what files to remove upon deinstallation.\r
67 \r
68 Some pkgsrc source skeletons have other files, such as `MESSAGE`. The pkgsrc system uses these files to handle special situations. If you want more details on these files, and on pkgsrc in general, check out [The pkgsrc guide](http://www.netbsd.org/Documentation/pkgsrc/), available at the [NetBSD website](http://www.netbsd.org/).\r
69 \r
70 Now that you have enough background information to know what the pkgsrc source tree is used for, you are ready to install your first compiled package. There are two ways this can be done, and each is explained below.\r
71 \r
72 Before we get into that, however, you will need to choose an application to install. There are a few ways to do this, with the easiest method being the [pkgsrc listing on Joerg Sonnenberger's web site](ftp://packages.stura.uni-rostock.de/pkgsrc-current/DragonFly/RELEASE/i386/All/). You can browse through the packages listed there.\r
73 \r
74 Another way to find a particular source tree is by using the pkgsrc collection's built-in search mechanism. To use the search feature, you will need to be in the `/usr/pkgsrc` directory. Once in that directory, run `bmake search key=program-name` where `program-name` is the name of the program you want to find. This searches packages names, comments, descriptions and dependencies and can be used to find packages which relate to a particular subject if you don't know the name of the program you are looking for. For example, if you were looking for `apache2`:\r
75 \r
76     \r
77     # cd /usr/pkgsrc\r
78     # bmake search key="apache2"\r
79     Extracting complete dependency database.  This may take a while...\r
80     ....................................................................................................\r
81     100\r
82     ....................................................................................................\r
83     200\r
84     <Snip />\r
85     5800\r
86     ....................................................................................................\r
87     5900\r
88     .................................................................................................Reading database file\r
89     Flattening dependencies\r
90     Flattening build dependencies\r
91     Generating INDEX file\r
92     Indexed 5999 packages\r
93     <Snip />\r
94     Pkg:    apache-2.2.6nb2\r
95     Path:   www/apache22\r
96     Info:   Apache HTTP (Web) server, version 2\r
97     Maint:  tron@NetBSD.org\r
98     Index:  www\r
99     B-deps: perl>#5.0 apr-util>1.2.8 apr>=1.2.8 libtool-base>=1.5.22nb1 pkg-config>=0.19 expat>=1.95.7 gmake>=3.78 gettext-lib>=0.14.5 {gettext-tools>=0.14.5,gettext>=0.10.36<0.14.5} expat>=1.95.4 expat>=2.0.0nb1 apr-util>=1.2.8nb1\r
100     R-deps: perl>#5.0 apr-util>1.2.8 apr>=1.2.8 expat>=1.95.7 expat>=1.95.4 expat>=2.0.0nb1 apr-util>=1.2.8nb1\r
101     Arch:   any\r
102 \r
103 \r
104 The part of the output you want to pay particular attention to is the ***Path*** line, since that tells you where to find the source tree for the requested application. The other information provided is not needed in order to install the package, so it will not be covered here.\r
105 \r
106 The search string is case-insensitive. Searching for ***APACHE*** will yield the same results as searching for ***apache***.\r
107 \r
108  **Note:** It should be noted that ***Extracting [the] complete dependency database*** does indeed take a while.\r
109 \r
110  **Note:** You must be logged in as `root` to install packages.\r
111 \r
112 Now that you have found an application you would like to install, you are ready to do the actual installation. The source package includes instructions on how to build source code, but does not include the actual source code. You can get the source code from a CD-ROM or from the Internet. Source code is distributed in whatever manner the software author desires. Frequently this is a tarred and gzipped file, but it might be compressed with some other tool or even uncompressed. The program source code, whatever form it comes in, is called a ***distfile***. You can get the distfile from a CD-ROM or from the Internet.\r
113 \r
114  **Warning:** Before installing any application, you should be sure to have an up-to-date source tree and you should check http://www.pkgsrc.org/ for security issues related to your port.\r
115 \r
116 A security vulnerabilities check can be automatically done by  **audit-packages**  before any new application installation. This tool can be found in the pkgsrc collection ([security/audit-packages](http://pkgsrc.se/security/audit-packages)). Consider running `auditpackages -d` before installing a new package, to fetch the current vulnerabilities database. A security audit and an update of the database will be performed during the daily security system check. For more informations read the audit-packages and [periodic(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#periodic&section8) manual pages.\r
117 \r
118  **Note:** It should be noted that the current setup of DragonFly requires the use of `bmake` instead of `make`. This is because the current version of make on DragonFly does not support all the parameters that NetBSD's does.\r
119 \r
120  **Note:** You can save an extra step by just running `bmake install` instead of `bmake` and `bmake install` as two separate steps.\r
121 \r
122  **Note:** Some shells keep a cache of the commands that are available in the directories listed in the `PATH` environment variable, to speed up lookup operations for the executable file of these commands. If you are using one of these shells, you might have to use the `rehash` command after installing a package, before the newly installed commands can be used. This is true for both shells that are part of the base-system (such as `tcsh`) and shells that are available as packages (for instance, [shells/zsh](http://pkgsrc.se/shells/zsh)).\r
123 \r
124 #### Installing Packages from the Internet \r
125 \r
126 As with the last section, this section makes an assumption that you have a working Internet connection. If you do not, you will need to put a copy of the distfile into `/usr/pkgsrc/distfiles` manually.\r
127 \r
128 Installing a package from the Internet is done exactly the same way as it would be if you already had the distfile. The only difference between the two is that the distfile is downloaded from the Internet on demand.\r
129 \r
130 Here are the steps involved:\r
131 \r
132     \r
133     # cd /usr/pkgsrc/chat/ircII\r
134     # bmake install clean\r
135     => ircii-20040820.tar.bz2 doesn't seem to exist on this system.\r
136     => Attempting to fetch ircii-20040820.tar.bz2 from ftp://ircii.warped.com/pub/ircII/.\r
137     => [559843 bytes]\r
138     Connected to ircii.warped.com.\r
139     220 bungi.sjc.warped.net FTP server (tnftpd 20040810) ready.\r
140     331 Guest login ok, type your name as password.\r
141     230-\r
142         A SERVICE OF WARPED.COM  -  FOR MORE INFORMATION: http://www.warped.com\r
143     \r
144         230-\r
145             Please read the file README\r
146                   it was last modified on Mon Feb  9 18:43:17 2004 - 794 days ago\r
147     230 Guest login ok, access restrictions apply.\r
148     Remote system type is UNIX.\r
149     Using binary mode to transfer files.\r
150     200 Type set to I.\r
151     250 CWD command successful.\r
152     250 CWD command successful.\r
153     local: ircii-20040820.tar.bz2 remote: ircii-20040820.tar.bz2\r
154     229 Entering Extended Passive Mode (|||60090|)\r
155     150 Opening BINARY mode data connection for 'ircii-20040820.tar.bz2' (559843 bytes).\r
156     100% |***************************************|   550 KB  110.34 KB/s   00:00 ETA\r
157     226 Transfer complete.\r
158     559843 bytes received in 00:04 (110.34 KB/s)\r
159     221-\r
160         Data traffic for this session was 559843 bytes in 1 file.\r
161         Total traffic for this session was 560993 bytes in 1 transfer.\r
162     221 Thank you for using the FTP service on bungi.sjc.warped.net.\r
163     => Checksum SHA1 OK for ircii-20040820.tar.bz2.\r
164     => Checksum RMD160 OK for ircii-20040820.tar.bz2.\r
165     work -> /usr/obj/pkgsrc/chat/ircII/work\r
166     ##=> Extracting for ircII-20040820\r
167     #########################################################################=\r
168     The supported build options for this package are:\r
169     \r
170     socks4 socks5\r
171     \r
172     You can select which build options to use by setting PKG_DEFAULT_OPTIONS\r
173     or the following variable.  Its current value is shown:\r
174     \r
175     PKG_OPTIONS.ircII (not defined)\r
176     \r
177     #########################################################################=\r
178     #########################################################################=\r
179     The following variables will affect the build process of this package,\r
180     ircII-20040820.  Their current value is shown below:\r
181     \r
182     
183 * USE_INET6 = YES\r
184     \r
185     You may want to abort the process now with CTRL-C and change their value\r
186     before continuing.  Be sure to run `/usr/pkg/bin/bmake clean' after\r
187     the changes.\r
188     #########################################################################=\r
189     ##=> Patching for ircII-20040820\r
190     ##=> Applying pkgsrc patches for ircII-20040820\r
191     ##=> Overriding tools for ircII-20040820\r
192     ##=> Creating toolchain wrappers for ircII-20040820\r
193     ##=> Configuring for ircII-20040820\r
194     ...\r
195     [configure output snipped]\r
196     ...\r
197     ##=>  Building for ircII-20040820\r
198     ...\r
199     [compilation output snipped]\r
200     ...\r
201     ##=>  Installing for ircII-20040820\r
202     ...\r
203     [installation output snipped]\r
204     ...\r
205     ##=> [Automatic manual page handling]\r
206     ##=> Registering installation for ircII-20040820\r
207     ##=> Cleaning for ircII-20040820\r
208     #\r
209 \r
210 \r
211 As you can see, the only difference are the lines that tell you where the system is fetching the package's distfile from.\r
212 \r
213 The pkgsrc system uses [ftp(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ftp&section1) to download the files, which honors various environment variables, including `FTP_PASSIVE_MODE`, `FTP_PROXY`, and `FTP_PASSWORD`. You may need to set one or more of these if you are behind a firewall, or need to use an FTP/HTTP proxy. See [ftp(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ftp&section=1) for the complete list.\r
214 \r
215 For users which cannot be connected all the time, the `bmake fetch` option is provided. Just run this command at the top level directory (`/usr/pkgsrc`) and the required files will be downloaded for you. This command will also work in the lower level categories, for example: `/usr/pkgsrc/net`. Note that if a package depends on libraries or other packages this will ***not*** fetch the distfiles of those packages as well.\r
216 \r
217  **Note:** You can build all the packages in a category or as a whole by running `bmake` in the top level directory, just like the aforementioned `bmake `fetch*** method. This is dangerous, however, as some applications cannot co-exist. In other cases, some packages can install two different files with the same filename.\r
218 \r
219 In some rare cases, users may need to acquire the tarballs from a site other than the `MASTER_SITES` (the location where files are downloaded from). You can override the `MASTER_SORT`, `MASTER_SORT_REGEX` and `INET_COUNTRY` options either within the `/etc/mk.conf`.\r
220 \r
221  **Note:** Some packages allow (or even require) you to provide build options which can enable/disable parts of the application which are unneeded, certain security options, and other customizations. A few which come to mind are [`www/mozilla`](http://pkgsrc.se/www/mozilla), [`security/gpgme`](http://pkgsrc.se/security/gpgme), and [`mail/sylpheed-claws`](http://pkgsrc.se/mail/sylpheed-claws). To find out what build options the application you are installing requires type:\r
222 \r
223     \r
224     # bmake show-options\r
225 \r
226 \r
227  To change the build process, either change the values of PKG_DEFAULT_OPTIONS or PKG_OPTIONS.`***PackageName***` in `/etc/mk.conf` or on the commandline as so:\r
228 \r
229     \r
230     # bmake PKG_OPTIONS.ircII="-ssl"\r
231 \r
232 \r
233  An option is enabled if listed. It is disabled if it is prefixed by a minus sign.\r
234 \r
235 #### Dealing with imake \r
236 \r
237 Some applications that use `imake` (a part of the X Window System) do not work well with `PREFIX`, and will insist on installing under `/usr/X11R6`. Similarly, some Perl ports ignore `PREFIX` and install in the Perl tree. Making these applications respect `PREFIX` is a difficult or impossible job.\r
238 \r
239 ### 4.5.3 Removing Installed Packages \r
240 \r
241 Now that you know how to install packages, you are probably wondering how to remove them, just in case you install one and later on decide that you installed the wrong program. We will remove our previous example (which was `ircII` for those of you not paying attention). As with installing packages, the first thing you must do is change to the package directory, `/usr/pkgsrc/chat/ircII`. After you change directories, you are ready to uninstall `ircII`. This is done with the `bmake deinstall` command:\r
242 \r
243     \r
244     # cd /usr/pkgsrc/chat/ircII\r
245     # make deinstall\r
246     ##=>  Deinstalling for ircII-20040820\r
247 \r
248 \r
249 That was easy enough. You have removed `ircII` from your system. If you would like to reinstall it, you can do so by running `bmake reinstall` from the `/usr/pkgsrc/chat/ircII` directory.\r
250 \r
251 The `bmake deinstall` and `bmake reinstall` sequence does not work once you have run `bmake clean`. If you want to deinstall a package after cleaning, use [pkg_delete(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#pkg_delete&section1) as discussed in the [pkgsrc-using.html Pkgsrc section of the Handbook].\r
252 \r
253 ### Packages and Disk Space \r
254 \r
255 Using the pkgsrc collection can definitely eat up your disk space. For this reason you should always remember to clean up the work directories using the `bmake `clean*** option. This will remove the `work` directory after a package has been built, and installed. You can also remove the tar files from the `distfiles` directory, and remove the installed package when their use has delimited.\r
256 \r
257 ### 4.5.5 Upgrading Packages \r
258 \r
259  **Note:** Once you have updated your pkgsrc collection, before attempting a package upgrade, you should check the `/usr/pkgsrc/UPDATING` file. This file describes various issues and additional steps users may encounter and need to perform when updating a port.\r
260 \r
261 Keeping your packages up to date can be a tedious job. For instance, to upgrade a package you would go to the package directory, build the package, deinstall the old package , install the new package, and then clean up after the build. Imagine doing that for five packages, tedious right? This was a large problem for system administrators to deal with, and now we have utilities which do this for us. For instance the `pkg_chk` utility will do everything for you!\r
262 \r
263 pkg_chk requires a few steps in order to work correctly. They are listed here.\r
264 \r
265     \r
266     # pkg_chk -g # make initial list of installed packages\r
267     # pkg_chk -r  # remove all packages that are not up to date and packages that depend on them\r
268     # pkg_chk -a  # install all missing packages (use binary packages, this is the default)\r
269     # pkg_chk -as # install all missing packages (build from source)\r
270     \r
271 \r
272 \r
273 \r
274 \r
275 CategoryHandbook\r
276 CategoryHandbook-pkgsrc\r