Fixup fromcvs/togit conversion
[pkgsrcv2.git] / doc / guide / files / creating.xml
1 <!-- $NetBSD: creating.xml,v 1.10 2011/05/21 16:39:03 wiz Exp $ -->
2
3 <chapter id="creating">
4 <title>Creating a new pkgsrc package from scratch</title>
5
6 <para>When you find a package that is not yet in pkgsrc, you
7 most likely have a URL from where you can download the source
8 code. Starting with this URL, creating a package involves only a
9 few steps.</para>
10
11 <procedure>
12
13 <step><para>First, install the packages <filename
14 role="pkg">pkgtools/url2pkg</filename> and <filename
15 role="pkg">pkgtools/pkglint</filename>.</para></step>
16
17 <step><para>Then, choose one of the top-level directories as the
18 category in which you want to place your package. You can also create a
19 directory of your own (maybe called <filename>local</filename>). In that
20 category directory, create another directory for your package and change
21 into it.</para></step>
22
23 <step><para>Run the program <command>url2pkg</command>, which will ask
24 you for a URL. Enter the URL of the distribution file (in most cases a
25 <filename>.tar.gz</filename> file) and watch how the basic ingredients
26 of your package are created automatically. The distribution file is
27 extracted automatically to fill in some details in the
28 <filename>Makefile</filename> that would otherwise have to be done
29 manually.</para></step>
30
31 <step><para>Examine the extracted files to determine the dependencies of
32 your package. Ideally, this is mentioned in some
33 <filename>README</filename> file, but things may differ. For each of
34 these dependencies, look where it exists in pkgsrc, and if there is a
35 file called <filename>buildlink3.mk</filename> in that directory, add a
36 line to your package <filename>Makefile</filename> which includes that
37 file just before the last line. If the
38 <filename>buildlink3.mk</filename> file does not exist, it must be
39 created first. The <filename>buildlink3.mk</filename> file makes sure that the package's include files and libraries are provided.</para>
40
41 <para>If you just need binaries from a package, add a
42 <varname>DEPENDS</varname> line to the Makefile, which specifies the
43 version of the dependency and where it can be found in pkgsrc. This line
44 should be placed in the third paragraph. If the dependency is only
45 needed for building the package, but not when using it, use
46 <varname>BUILD_DEPENDS</varname> instead of <varname>DEPENDS</varname>.
47 Your package may then look like this:</para>
48
49 <programlisting>
50 [...]
51
52 BUILD_DEPENDS+= lua>=5.0:../../lang/lua
53 DEPENDS+=       screen-[0-9]*:../../misc/screen
54 DEPENDS+=       screen>=4.0:../../misc/screen
55
56 [...]
57
58 .include "../../<replaceable>category</replaceable>/<replaceable>package</replaceable>/buildlink3.mk"
59 .include "../../devel/glib2/buildlink3.mk"
60 .include "../../mk/bsd.pkg.mk"
61 </programlisting>
62
63 </step>
64
65 <step><para>Run <command>pkglint</command> to see what things still need
66 to be done to make your package a <quote>good</quote> one. If you don't
67 know what pkglint's warnings want to tell you, try <command>pkglint
68 --explain</command> or <command>pkglint
69 -e</command>, which outputs additional
70 explanations.</para></step>
71
72 <step><para>In many cases the package is not yet ready to build. You can
73 find instructions for the most common cases in the next section, <xref
74 linkend="creating.common"/>. After you have followed the instructions
75 over there, you can hopefully continue here.</para></step>
76
77 <step><para>Run <command>bmake clean</command> to clean the working
78 directory from the extracted files. Besides these files, a lot of cache
79 files and other system information has been saved in the working
80 directory, which may become wrong after you edited the
81 <filename>Makefile</filename>.</para></step>
82
83 <step><para>Now, run <command>bmake</command> to build the package. For
84 the various things that can go wrong in this phase, consult <xref
85 linkend="fixes"/>.</para></step>
86
87 <step><para>When the package builds fine, the next step is to install
88 the package. Run <command>bmake install</command> and hope that
89 everything works.</para></step>
90
91 <step><para>Up to now, the file <filename>PLIST</filename>, which
92 contains a list of the files that are installed by the package, is
93 nearly empty. Run <command>bmake print-PLIST
94 &gt;PLIST</command> to generate a probably correct list. Check
95 the file using your preferred text editor to see if the list of
96 files looks plausible.</para></step>
97
98 <step><para>Run <command>pkglint</command> again to see if the generated
99 <filename>PLIST</filename> contains garbage or not.</para></step>
100
101 <step><para>When you ran <command>bmake install</command>, the package
102 has been registered in the database of installed files, but with an
103 empty list of files. To fix this, run <command>bmake deinstall</command>
104 and <command>bmake install</command> again. Now the package is
105 registered with the list of files from
106 <filename>PLIST</filename>.</para></step>
107
108 <step><para>Run <command>bmake package</command> to create a binary
109 package from the set of installed files.</para></step>
110
111 </procedure>
112
113 <sect1 id="creating.common">
114 <title>Common types of packages</title>
115
116 <sect2 id="creating.perl-module">
117 <title>Perl modules</title>
118
119 <para>Simple Perl modules are handled automatically by
120 <command>url2pkg</command>, including dependencies.</para>
121
122 </sect2>
123
124 <sect2 id="creating.kde-app">
125 <title>KDE applications</title>
126
127 <para>KDE applications should always include
128 <filename>meta-pkgs/kde3/kde3.mk</filename>, which contains numerous
129 settings that are typical of KDE packages.</para>
130
131 </sect2>
132
133 <sect2 id="creating.python-module">
134 <title>Python modules and programs</title>
135
136 <para>Python modules and programs packages are easily created using a
137 set of predefined variables.</para>
138
139 <para>Most Python packages use either <quote>distutils</quote> or
140 easy-setup (<quote>eggs</quote>).
141 If the software uses <quote>distutils</quote>, set the
142 <varname>PYDISTUTILSPKG</varname> variable to <quote>yes</quote> so
143 pkgsrc will make use of this framework.
144 <quote>distutils</quote> uses a script called <filename>setup.py</filename>,
145 if the <quote>distutils</quote> driver is not called
146 <filename>setup.py</filename>, set the <varname>PYSETUP</varname> variable
147 to the name of the script.</para>
148
149 <para>
150 If the default Python versions are not supported by the software, set the
151 <varname>PYTHON_VERSIONS_ACCEPTED</varname> variable to the Python versions
152 the software is known to work with, from the most recent to the older
153 one, e.g.
154 <programlisting>
155 PYTHON_VERSIONS_ACCEPTED=       25 24
156 </programlisting></para>
157
158 <para>
159 If the packaged software is a Python module, include
160 <quote><filename>../../lang/python/extension.mk</filename></quote>.
161 In this case, the package directory should be called
162 <quote>py-software</quote> and <varname>PKGNAME</varname> should be set to
163 <quote>${PYPKGPREFIX}-${DISTNAME}</quote>, e.g.
164 <programlisting>
165 DISTNAME=   foopymodule-1.2.10
166 PKGNAME=    ${PYPKGPREFIX}-${DISTNAME}
167 </programlisting></para>
168
169 <para>If it is an application, also include
170 <quote><filename>../../lang/python/application.mk</filename></quote>
171 before <quote>extension.mk</quote>.</para>
172
173 <para>If the packaged software, either it is an application or a module, is
174 egg-aware, you only need to include
175 <quote><filename>../../lang/python/egg.mk</filename></quote>.</para>
176
177 <para>In order to correctly set the path to the Python interpreter, use the
178 <varname>REPLACE_PYTHON</varname> variable and set it to the list of files
179 (paths relative to <varname>WRKSRC</varname>) that must be corrected.
180 For example :
181 <programlisting>
182 REPLACE_PYTHON=   *.py
183 </programlisting></para>
184
185 </sect2>
186
187 </sect1>
188
189 <sect1 id="creating.examples">
190 <title>Examples</title>
191
192 <sect2 id="creating.nvu">
193 <title>How the www/nvu package came into pkgsrc</title>
194
195 <sect3 id="creating.nvu.init">
196 <title>The initial package</title>
197
198 <para>Looking at the file <filename>pkgsrc/doc/TODO</filename>, I saw
199 that the <quote>nvu</quote> package has not yet been imported into
200 pkgsrc. As the description says it has to do with the web, the obvious
201 choice for the category is <quote>www</quote>.</para>
202
203 <programlisting>
204 &uprompt; mkdir www/nvu
205 &uprompt; cd www/nvu
206 </programlisting>
207
208 <para>The web site says that the sources are available as a tar file, so
209 I fed that URL to the <command>url2pkg</command> program:</para>
210
211 <programlisting>
212 &uprompt; url2pkg http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
213 </programlisting>
214
215 <para>My editor popped up, and I added a <varname>PKGNAME</varname> line
216 below the <varname>DISTNAME</varname> line, as the package name should
217 not have the word <quote>sources</quote> in it. I also filled in the
218 <varname>MAINTAINER</varname>, <varname>HOMEPAGE</varname> and
219 <varname>COMMENT</varname> fields. Then the package
220 <filename>Makefile</filename> looked like that:</para>
221
222 <programlisting>
223 # &#36;NetBSD&#36;
224 #
225
226 DISTNAME=       nvu-1.0-sources
227 PKGNAME=        nvu-1.0
228 CATEGORIES=     www
229 MASTER_SITES=   http://cvs.nvu.com/download/
230 EXTRACT_SUFX=   .tar.bz2
231
232 MAINTAINER=     rillig@NetBSD.org
233 HOMEPAGE=       http://cvs.nvu.com/
234 COMMENT=        Web Authoring System
235
236 # url2pkg-marker (please do not remove this line.)
237 .include "../../mk/bsd.pkg.mk"
238 </programlisting>
239
240 <para>Then, I quit the editor and watched pkgsrc downloading a large
241 source archive:</para>
242
243 <programlisting>
244 url2pkg> Running "make makesum" ...
245 => Required installed package digest>=20010302: digest-20060826 found
246 => Fetching nvu-1.0-sources.tar.bz2
247 Requesting http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
248 100% |*************************************| 28992 KB  150.77 KB/s00:00 ETA
249 29687976 bytes retrieved in 03:12 (150.77 KB/s)
250 url2pkg> Running "make extract" ...
251 => Required installed package digest>=20010302: digest-20060826 found
252 => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
253 => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
254 work.bacc -> /tmp/roland/pkgsrc/www/nvu/work.bacc
255 ===> Installing dependencies for nvu-1.0
256 ===> Overriding tools for nvu-1.0
257 ===> Extracting for nvu-1.0
258 url2pkg> Adjusting the Makefile.
259
260 Remember to correct CATEGORIES, HOMEPAGE, COMMENT, and DESCR when you're done!
261
262 Good luck! (See pkgsrc/doc/pkgsrc.txt for some more help :-)
263 </programlisting>
264
265 </sect3>
266
267 <sect3 id="creating.nvu.problems">
268 <title>Fixing all kinds of problems to make the package work</title>
269
270 <para>Now that the package has been extracted, let's see what's inside
271 it. The package has a <filename>README.txt</filename>, but that only
272 says something about mozilla, so it's probably useless for seeing what
273 dependencies this package has. But since there is a GNU configure script
274 in the package, let's hope that it will complain about everything it
275 needs.</para>
276
277 <programlisting>
278 &uprompt; bmake
279 => Required installed package digest>=20010302: digest-20060826 found
280 => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
281 => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
282 ===> Patching for nvu-1.0
283 ===> Creating toolchain wrappers for nvu-1.0
284 ===> Configuring for nvu-1.0
285 [...]
286 configure: error: Perl 5.004 or higher is required.
287 [...]
288 WARNING: Please add USE_TOOLS+=perl to the package Makefile.
289 [...]
290 </programlisting>
291
292 <para>That worked quite well. So I opened the package Makefile in my
293 editor, and since it already has a <varname>USE_TOOLS</varname> line, I
294 just appended <quote>perl</quote> to it. Since the dependencies of the
295 package have changed now, and since a perl wrapper is automatically
296 installed in the <quote>tools</quote> phase, I need to build the package
297 from scratch.</para>
298
299 <programlisting>
300 &uprompt; bmake clean
301 ===> Cleaning for nvu-1.0
302 &uprompt; bmake
303 [...]
304 *** /tmp/roland/pkgsrc/www/nvu/work.bacc/.tools/bin/make is not \
305 GNU Make.  You will not be able to build Mozilla without GNU Make.
306 [...]
307 </programlisting>
308
309 <para>So I added <quote>gmake</quote> to the
310 <varname>USE_TOOLS</varname> line and tried again (from scratch).</para>
311
312 <programlisting>
313 [...]
314 checking for GTK - version >= 1.2.0... no
315 *** Could not run GTK test program, checking why...
316 [...]
317 </programlisting>
318
319 <para>Now to the other dependencies. The first question is: Where is the
320 GTK package hidden in pkgsrc?</para>
321
322 <programlisting>
323 &uprompt; echo ../../*/gtk*
324 [many packages ...]
325 &uprompt; echo ../../*/gtk
326 ../../x11/gtk
327 &uprompt; echo ../../*/gtk2
328 ../../x11/gtk2
329 &uprompt; echo ../../*/gtk2/bui*
330 ../../x11/gtk2/buildlink3.mk
331 </programlisting>
332
333 <para>The first try was definitely too broad. The second one had exactly
334 one result, which is very good. But there is one pitfall with GNOME
335 packages. Before GNOME 2 had been released, there were already many
336 GNOME 1 packages in pkgsrc. To be able to continue to use these
337 packages, the GNOME 2 packages were imported as separate packages, and
338 their names usually have a <quote>2</quote> appended. So I checked
339 whether this was the case here, and indeed it was.</para>
340
341 <para>Since the GTK2 package has a <filename>buildlink3.mk</filename>
342 file, adding the dependency is very easy. I just inserted an
343 <literal>.include</literal> line before the last line of the package
344 <filename>Makefile</filename>, so that it now looks like this:</para>
345
346 <programlisting>
347 [...]
348 .include "../../x11/gtk2/buildlink3.mk"
349 .include "../../mk/bsd.pkg.mk
350 </programlisting>
351
352 <para>After another <command>bmake clean && bmake</command>, the answer
353 was:</para>
354
355 <programlisting>
356 [...]
357 checking for gtk-config... /home/roland/pkg/bin/gtk-config
358 checking for GTK - version >= 1.2.0... no
359 *** Could not run GTK test program, checking why...
360 *** The test program failed to compile or link. See the file config.log for the
361 *** exact error that occured. This usually means GTK was incorrectly installed
362 *** or that you have moved GTK since it was installed. In the latter case, you
363 *** may want to edit the gtk-config script: /home/roland/pkg/bin/gtk-config
364 configure: error: Test for GTK failed.
365 [...]
366 </programlisting>
367
368 <para>In this particular case, the assumption that <quote>every package
369 prefers GNOME 2</quote> had been wrong. The first of the lines above
370 told me that this package really wanted to have the GNOME 1 version of
371 GTK. If the package had looked for GTK2, it would have looked for
372 <command>pkg-config</command> instead of <command>gtk-config</command>.
373 So I changed the <literal>x11/gtk2</literal> to
374 <literal>x11/gtk</literal> in the package <filename>Makefile</filename>,
375 and tried again.</para>
376
377 <programlisting>
378 [...]
379 cc -o xpidl.o -c -DOSTYPE=\"NetBSD3\" -DOSARCH=\"NetBSD\"   -I../../../dist/include/xpcom -I../../../dist/include -I/tmp/roland/pkgsrc/www/nvu/work.bacc/mozilla/dist/include/nspr -I/usr/X11R6/include   -fPIC -DPIC -I/home/roland/pkg/include -I/usr/include  -I/usr/X11R6/include -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -O2 -I/home/roland/pkg/include -I/usr/include -Dunix -pthread -pipe  -DDEBUG -D_DEBUG -DDEBUG_roland -DTRACING -g -I/home/roland/pkg/include/glib/glib-1.2 -I/home/roland/pkg/lib/glib/include -I/usr/pkg/include/orbit-1.0   -I/home/roland/pkg/include -I/usr/include  -I/usr/X11R6/include -include ../../../mozilla-config.h -DMOZILLA_CLIENT -Wp,-MD,.deps/xpidl.pp xpidl.c
380 In file included from xpidl.c:42:
381 xpidl.h:53:24: libIDL/IDL.h: No such file or directory
382 In file included from xpidl.c:42:
383 xpidl.h:132: error: parse error before "IDL_ns"
384 [...]
385 </programlisting>
386
387 <para>The package still does not find all of its dependencies. Now the
388 question is: Which package provides the
389 <filename>libIDL/IDL.h</filename> header file?</para>
390
391 <programlisting>
392 &uprompt; echo ../../*/*idl*
393 ../../devel/py-idle ../../wip/idled ../../x11/acidlaunch
394 &uprompt; echo ../../*/*IDL*
395 ../../net/libIDL
396 </programlisting>
397
398 <para>Let's take the one from the second try. So I included the
399 <filename>../../net/libIDL/buildlink3.mk</filename> file and tried
400 again. But the error didn't change. After digging through some of the
401 code, I concluded that the build process of the package was broken and
402 couldn't have ever worked, but since the Mozilla source tree is quite
403 large, I didn't want to fix it. So I added the following to the package
404 <filename>Makefile</filename> and tried again:</para>
405
406 <programlisting>
407 CPPFLAGS+=              -I${BUILDLINK_PREFIX.libIDL}/include/libIDL-2.0
408 BUILDLINK_TRANSFORM+=   -l:IDL:IDL-2
409 </programlisting>
410
411 <para>The latter line is needed because the package expects the library
412 <filename>libIDL.so</filename>, but only
413 <filename>libIDL-2.so</filename> is available. So I told the compiler
414 wrapper to rewrite that on the fly.</para>
415
416 <para>The next problem was related to a recent change of the FreeType
417 interface. I looked up in <filename role="pkg">www/seamonkey</filename>
418 which patch files were relevant for this issue and copied them to the
419 <filename>patches</filename> directory. Then I retried, fixed the
420 patches so that they applied cleanly and retried again. This time,
421 everything worked.</para>
422
423 </sect3>
424
425 <sect3 id="creating.nvu.inst">
426 <title>Installing the package</title>
427
428 <programlisting>
429 &uprompt; bmake CHECK_FILES=no install
430 [...]
431 &uprompt; bmake print-PLIST >PLIST
432 &uprompt; bmake deinstall
433 &uprompt; bmake install
434 </programlisting>
435
436 </sect3>
437 </sect2>
438 </sect1>
439 </chapter>