1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
|
<!-- $NetBSD: features.xml,v 1.2 2004/10/22 00:24:48 hubertf Exp $ -->
<chapter id="features"> <?dbhtml filename="features.html"?>
<title>FAQs & features of the package system</title>
<sect1>
<title>Packages using GNU autoconf</title>
<para>
If your package uses GNU autoconf created configure scripts, add the following
to your package's <filename>Makefile</filename>:
</para>
<programlisting>GNU_CONFIGURE= yes</programlisting>
<para>
Note that this appends <quote>--prefix=${PREFIX}</quote> to
<varname>CONFIGURE_ARGS</varname>, so you don't
have to do that yourself, but may not be desired.
</para>
</sect1>
<sect1>
<title>Other distrib methods than .tar.gz</title>
<para>
If your package uses a different distribution method from
<filename>.tar.gz</filename>, take a
look at the package for <pkg>editors/sam</pkg>, which uses a gzipped shell archive
(shar), but the quick solution is to set
<varname>EXTRACT_SUFX</varname> to the name after the
<varname>DISTNAME</varname> field, and add the following to your
package's <filename>Makefile</filename>:
</para>
<programlisting>EXTRACT_SUFX= .msg.gz
EXTRACT_CMD= zcat
EXTRACT_BEFORE_ARGS=
EXTRACT_AFTER_ARGS= |sh</programlisting>
</sect1>
<sect1>
<title>Packages not creating their own subdirectory</title>
<para>
Your package doesn't create a subdirectory for itself (like GNU software
does, for instance), but extracts itself in the current directory: see
<pkg>editors/sam</pkg> again, but the quick answer is:
</para>
<programlisting>WRKSRC= ${WRKDIR}</programlisting>
<para>
Please note that the old:
</para>
<programlisting>NO_WRKSUBDIR= yes</programlisting>
<para>
has been deprecated and should not be used.
</para>
</sect1>
<sect1>
<title>Custom configuration process</title>
<para>
Your package uses a weird Configure script, eg.
<pkg>sysutils/top</pkg>. The quick answer is:
</para>
<programlisting>HAS_CONFIGURE= yes
CONFIGURE_SCRIPT= Configure
CONFIGURE_ARGS+= netbsd13</programlisting>
</sect1>
<sect1>
<title>Packages not building in their DISTNAME directory</title>
<para>
Your package builds in a different directory from its base
<varname>DISTNAME</varname> (see <pkg>lang/tcl</pkg> and
<pkg>x11/tk</pkg>).
</para>
<programlisting>WRKSRC= ${WRKDIR}/${DISTNAME}/unix</programlisting>
</sect1>
<sect1>
<title>How to fetch all distfiles at once</title>
<para>
You would like to download all the distfiles in a single batch from work or
university, where you can't run a <command>make fetch</command>. There
is an archive of distfiles on <ulink
url="ftp://ftp.NetBSD.org/pub/NetBSD/packages/distfiles/">ftp.NetBSD.org</ulink>,
but downloading the entire directory may not be appropriate.
</para>
<para>
The answer here is to do a <command>make fetch-list</command> in
<filename>/usr/pkgsrc</filename>, carry the
resulting list to your machine at work/school and use it there If you don't
have a NetBSD-compatible ftp(1) (like lukemftp) at work, don't forget to
set <varname>FETCH_CMD</varname> to something that fetches a URL:
</para>
<para>
At home:
</para>
<screen><prompt>%</prompt> <userinput>cd /usr/pkgsrc</userinput>
<prompt>%</prompt> <userinput>make fetch-list FETCH_CMD=wget DISTDIR=/tmp/distfiles >/tmp/fetch.sh</userinput>
<prompt>%</prompt> <userinput>scp /tmp/fetch.sh work:/tmp</userinput></screen>
<para>
At work:
</para>
<screen><prompt>%</prompt> <userinput>sh /tmp/fetch.sh</userinput></screen>
<para>
then tar up <filename>/tmp/distfiles</filename> and take it home.
</para>
<para>
If you have a machine running NetBSD, and you want to get
<emphasis>all</emphasis> distfiles
(even ones that aren't for your machine architecture), you can do so by
using the above-mentioned <command>make fetch-list</command> approach, or
fetch the distfiles directly by running:
</para>
<screen><prompt>%</prompt> <userinput>make mirror-distfiles</userinput></screen>
<para>
If you even decide to ignore <varname>NO_{SRC,BIN}_ON_{FTP,CDROM}</varname>,
then you can get everything by running:
</para>
<screen><prompt>%</prompt> <userinput>make fetch NO_SKIP=yes</userinput></screen>
</sect1>
<sect1>
<title>How to fetch files from behind a firewall</title>
<para>
If you are sitting behind a firewall which does not allow direct connections
to Internet hosts (i.e. non-NAT), you may specify the relevant proxy hosts.
This is done using an environment variable in the form of a URL
e.g. in Amdahl, the machine <quote>orpheus.amdahl.com</quote> is one of
the firewalls, and it uses port 80 as the proxy port number. So the proxy
environment variables are:
</para>
<programlisting>ftp_proxy=ftp://orpheus.amdahl.com:80/
http_proxy=http://orpheus.amdahl.com:80/</programlisting>
</sect1>
<sect1>
<title>If your patch contains an RCS ID</title>
<para>
See <xref linkend="components.patches"/> for information on how to
remove RCS IDs from patch files.
</para>
</sect1>
<sect1>
<title>How to pull in variables from /etc/mk.conf</title>
<para>
The problem with package-defined variables that can be overridden via
<varname>MAKECONF</varname> or <filename>/etc/mk.conf</filename> is that make(1) expands a variable as it is
used, but evaluates preprocessor like statements (.if, .ifdef and
.ifndef) as they are read. So, to use any variable (which may be set
in <filename>/etc/mk.conf</filename>) in one of the .if* statements, the file
<filename>/etc/mk.conf</filename>
must be included before that .if* statement.
</para>
<para>
Rather than have a number of ad-hoc ways of including
<filename>/etc/mk.conf</filename>,
should it exist, or <varname>MAKECONF</varname>, should it exist, include the
<filename>pkgsrc/mk/bsd.prefs.mk</filename> file in the package Makefile before any
preprocessor-like .if, .ifdef, or .ifndef statements:
</para>
<programlisting>.include "../../mk/bsd.prefs.mk"
.if defined(USE_MENUS)
...
.endif</programlisting>
<para>
If you wish to set the CFLAGS variable in /etc/mk.conf please make sure
to use:
<screen>CFLAGS+= -your -flags</screen>
Using <varname>CFLAGS=</varname> (ie without the <quote>+</quote>) may
lead to problems with packages that need to add their own flags. Also,
you may want to take a look at the <pkg>devel/cpuflags</pkg> package if
you're interested in optimization for the current CPU.
</para>
</sect1>
<sect1>
<title>Is there a mailing list for pkg-related discussion?</title>
<para>
Yes, <email>tech-pkg@NetBSD.org</email> is the list for discussing package
related issues. To subscribe do:
</para>
<programlisting>% echo subscribe tech-pkg | mail majordomo@NetBSD.org</programlisting>
</sect1>
<sect1>
<title>How do I tell <command>make fetch</command> to do passive FTP?</title>
<para>
This depends on which utility is used to retrieve distfiles. From
<filename>bsd.pkg.mk</filename>, <varname>FETCH_CMD</varname> is assigned
the first available command from the following list:
</para>
<programlisting>/usr/bin/fetch
${LOCALBASE}/bsd/bin/ftp
/usr/bin/ftp</programlisting>
<para>
On a default NetBSD install, this will be
<filename>/usr/bin/ftp</filename>, which automatically
tries passive connections first, and falls back to active connections if the
server refuses to do passive. For the other tools, add the following to your
<filename>/etc/mk.conf</filename> file:
<varname>PASSIVE_FETCH=1</varname>.
</para>
<para>
Having that option present will prevent
<filename>/usr/bin/ftp</filename> from falling back to
active transfers.
</para>
</sect1>
<sect1>
<title>Dependencies on other packages</title>
<para>
Your package may depend on some other package being present - and there are
various ways of expressing this dependency. NetBSD supports the
<varname>BUILD_DEPENDS</varname> and <varname>DEPENDS</varname> definitions,
as well as dependencies via
<filename>buildlink3.mk</filename> (see <!-- <xref
linkend="buildlink3"/> -->).
</para>
<para>
The basic difference between the two definitions is as follows: The
<varname>DEPENDS</varname> definition registers that pre-requisite in the binary package,
whilst the <varname>BUILD_DEPENDS</varname> definition does not.
</para>
<para>
This means that if you only need a package present whilst you are building,
it should be noted as a <varname>BUILD_DEPENDS</varname>.
</para>
<para>
The format for a <varname>BUILD_DEPENDS</varname> and a
<varname>DEPENDS</varname> definition is:
</para>
<programlisting><pre-req-package-name>:../../<category>/<pre-req-package></programlisting>
<para>
Please note that the <quote>pre-req-package-name</quote> may include any of the wildcard
version numbers recognised by pkg_info(1).
</para>
<orderedlist>
<listitem>
<para>
If your package needs to use another package to build itself, this
is specified using the <varname>BUILD_DEPENDS</varname> definition.
</para>
<programlisting>BUILD_DEPENDS+= autoconf-2.13:../../devel/autoconf</programlisting>
</listitem>
<listitem>
<para>
If your package needs a library with which to link, this is specified
using the <varname>DEPENDS</varname> definition. An example of this is
the <pkg>print/lyx</pkg>
package, which uses the xpm library, version 3.4j to build.
</para>
<programlisting>DEPENDS+= xpm-3.4j:../../graphics/xpm</programlisting>
<para>
You can also use wildcards in package dependences:
</para>
<programlisting>DEPENDS+= xpm-[0-9]*:../../graphics/xpm</programlisting>
<para>
Note that such wildcard dependencies are retained when creating binary
packages. The dependency is checked when installing the binary
package and any package which matches the pattern will be used.
Wildcard dependencies should be used with care.
</para>
<para>
The -[0-9]* should be used instead of -* to avoid potentially
ambiguous matches such as tk-postgresql matching a tk-*
<varname>DEPENDS</varname>.
</para>
</listitem>
<listitem>
<para>
If your package needs some executable to be able to run correctly, this
is specified using the <varname>DEPENDS</varname> definition. The
<pkg>print/lyx</pkg> package needs
to be able to execute the latex binary from the teTeX package when it runs,
and that is specified:
</para>
<programlisting>DEPENDS+= teTeX-[0-9]*:../../print/teTeX</programlisting>
<para>
The comment about wildcard dependencies from previous paragraph
applies here, too.
</para>
</listitem>
</orderedlist>
<para>
If your package needs files from another package to build, see the
first part of the <quote>do-configure</quote> target
<pkg>print/ghostscript5</pkg> package
(it relies on the jpeg sources being present in source form during the
build):
</para>
<programlisting>if [ ! -e ${_PKGSRCDIR}/graphics/jpeg/${WRKDIR:T}/jpeg-6b ]; then \
cd ${_PKGSRCDIR}/../../graphics/jpeg && ${MAKE} extract; \
fi</programlisting>
<para>
If you build any other packages that way, please make sure the working
files are deleted too when this package's working files are cleaned up.
The easiest way to do so is by adding a pre-clean target:
</para>
<programlisting>pre-clean:
cd ${_PKGSRCDIR}/../../graphics/jpeg && ${MAKE} clean</programlisting>
<para>
Please also note the <varname>BUILD_USES_MSGFMT</varname> and
<varname>BUILD_USES_GETTEXT_M4</varname> definitions,
which are provided as convenience definitions. The former works out whether
msgfmt(1) is part of the base system, and, if it isn't, installs the
<pkg>devel/gettext</pkg> package. The latter adds a build dependency on either an
installed version of an older gettext package, or if it isn't, installs the
<pkg>devel/gettext-m4</pkg> package.
</para>
</sect1>
<sect1>
<title>Conflicts with other packages</title>
<para>
Your package may conflict with other packages a user might already have
installed on his system, e.g. if your package installs the same set of
files like another package in our pkgsrc tree.
</para>
<para>
In this case you can set <varname>CONFLICTS</varname> to a space separated
list of packages (including version string) your package conflicts with.
</para>
<para>
For example <pkg>x11/Xaw3d</pkg> and
<pkg>x11/Xaw-Xpm</pkg> install provide the
same shared library, thus you set in
<filename>pkgsrc/x11/Xaw3d/Makefile</filename>:
</para>
<programlisting>CONFLICTS= Xaw-Xpm-[0-9]*</programlisting>
<para>
and in <filename>pkgsrc/x11/Xaw-Xpm/Makefile</filename>:
</para>
<programlisting>CONFLICTS= Xaw3d-[0-9]*</programlisting>
<para>
Packages will automatically conflict with other packages with the name prefix
and a different version string. <quote>Xaw3d-1.5</quote> e.g. will automatically conflict
with the older version <quote>Xaw3d-1.3</quote>.
</para>
</sect1>
<sect1>
<title>Software which has a homepage</title>
<para>
The NetBSD packages system now supports a variable called
<varname>HOMEPAGE</varname>.
If the software being packaged has a home page, the Makefile should
include the URL for that page in the <varname>HOMEPAGE</varname> variable.
The definition of the variable should be placed immediately after the
<varname>MAINTAINER</varname> variable.
</para>
</sect1>
<sect1>
<title>How to handle modified distfiles with the 'old' name</title>
<para>
Sometimes authors of a software package make some modifications after the
software was released, and they put up a new distfile without changing the
package's version number. If a package is already in pkgsrc at that time,
the md5 checksum will no longer match. The correct way to work around this
is to update the package's md5 checksum to match the package on the master
site (beware, any mirrors may not be up to date yet!), and to remove the
old distfile from ftp.NetBSD.org's
<filename>/pub/NetBSD/packages/distfiles</filename> directory.
Furthermore, a mail to the package's author seems appropriate making sure
the distfile was really updated on purpose, and that no trojan horse or so
crept in.
</para>
</sect1>
<sect1>
<title>What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?</title>
<para>
When compiling the <pkg>pkgtools/pkg_install</pkg> package, you get the error
from make that it doesn't know how to make
<filename>/usr/share/tmac/tmac.andoc</filename>? This
indicates that you don't have installed the <quote>text</quote> set on your machine
(nroff, ...). It is recommended to do that.
</para>
<para>
In the case of the <pkg>pkgtools/pkg_install</pkg> package, you can get
away with setting <varname>NOMAN=YES</varname> either in the environment
or in <filename>/etc/mk.conf</filename>.
</para>
</sect1>
<sect1>
<title>How to handle incrementing versions when fixing an existing
package</title>
<para>
When making fixes to an existing package it can be useful to change
the version number in <varname>PKGNAME</varname>. To avoid conflicting with
future versions
by the original author, a <quote>nb1</quote>, <quote>nb2</quote>, ... suffix
can be used on package
versions by setting <varname>PKGREVISION=1</varname> (2,. ..). The
<quote>nb</quote> is treated like a <quote>.</quote> by the pkg tools. e.g.
</para>
<programlisting>DISTNAME= foo-17.42
PKGREVISION= 9</programlisting>
<para>
will result in a <varname>PKGNAME</varname> of <quote>foo-17.42nb9</quote>.
</para>
<para>
When a new release of the package is released, the
<varname>PKGREVISION</varname> should be
removed. e.g. on a new minor release of the above package, things should
be like:
</para>
<programlisting>DISTNAME= foo-17.43</programlisting>
</sect1>
<sect1>
<title>Could not find bsd.own.mk - what's wrong?</title>
<para>
You didn't install the compiler set, <filename>comp.tgz</filename>, when
you installed your NetBSD machine. Please get it and install it, by
extracting it in <filename>/</filename>:
</para>
<screen><prompt>#</prompt> <userinput>cd /</userinput>
<prompt>#</prompt> <userinput>tar --unlink -zxvpf .../comp.tgz</userinput></screen>
<para>
<filename>comp.tgz</filename> is part of every NetBSD release. Get
the one that corresponds to your release (determine via
<command>uname -r</command>).
</para>
</sect1>
<sect1>
<title>Restricted packages</title>
<para>
Some licenses restrict how software may be re-distributed. In order to
satisfy these restrictions, the package system defines five make variables
that can be set to note these restrictions:
</para>
<itemizedlist>
<listitem>
<para><varname>RESTRICTED</varname></para>
<para>
This variable should be set whenever a restriction exists
(regardless of its kind). Set this variable to a string
containing the reason for the restriction.
</para>
</listitem>
<listitem>
<para><varname>NO_BIN_ON_CDROM</varname></para>
<para>
Binaries may not be placed on CD-ROM. Set this variable to
<varname>${RESTRICTED}</varname> whenever a binary package may not
be included on a CD-ROM.
</para>
</listitem>
<listitem>
<para><varname>NO_BIN_ON_FTP</varname></para>
<para>
Binaries may not be placed on an FTP server. Set this
variable to <varname>${RESTRICTED}</varname> whenever a binary package
may not not be made available on the Internet.
</para>
</listitem>
<listitem>
<para><varname>NO_SRC_ON_CDROM</varname></para>
<para>
Distfiles may not be placed on CD-ROM. Set this variable to
<varname>${RESTRICTED}</varname> if re-distribution of the source code
or other distfile(s) is not allowed on CD-ROMs.
</para>
</listitem>
<listitem>
<para><varname>NO_SRC_ON_FTP</varname></para>
<para>
Distfiles may not be placed on FTP. Set this variable to
<varname>${RESTRICTED}</varname> if re-distribution of the source
code or other distfile(s) via the Internet is not allowed.
</para>
</listitem>
</itemizedlist>
<para>
Please note that the use of <varname>NO_PACKAGE</varname>,
<varname>IGNORE</varname>, <varname>NO_CDROM</varname>, or other generic
make variables to denote restrictions is deprecated, because they
unconditionally prevent users from generating binary packages!
</para>
</sect1>
<sect1>
<title>Packages using (n)curses</title>
<para>
Some packages need curses functionality that wasn't present in NetBSD's own
curses prior to 1.4Y.
</para>
<para>
If <filename>../../devel/ncurses/buildlink3.mk</filename> is included in
a package's <filename>Makefile</filename>,
then a curses library and headers with ncurses functionality are linked
into <varname>${BUILDLINK_DIR}</varname> at pre-configure time. If
ncurses is actually required, then define <varname>USE_NCURSES</varname>
in the package's <filename>Makefile</filename>:
<screen>USE_NCURSES= # redrawwin</screen>
The comment should indicate which functions are missing.
</para>
</sect1>
<sect1>
<title>Automated security check</title>
<para>
Please be aware that there can often be bugs in third-party software,
and some of these bugs can leave a machine vulnerable to exploitation
by attackers. In an effort to lessen the exposure, the NetBSD
packages team maintains a database of known-exploits to packages which
have at one time been included in pkgsrc. The database can be
downloaded automatically, and a security audit of all packages
installed on a system can take place. To do this, install the
<pkg>security/audit-packages</pkg> package. It has two components:
</para>
<orderedlist>
<listitem>
<para>
<quote>download-vulnerability-list</quote>, an easy way to download a list of the
security vulnerabilities information. This list is kept up to date by
the NetBSD security officer and the NetBSD packages team, and is
distributed from the NetBSD ftp server:
</para>
<para>
<ulink
url="ftp://ftp.NetBSD.org/pub/NetBSD/packages/distfiles/pkg-vulnerabilities"/>
</para>
</listitem>
<listitem>
<para>
<quote>audit-packages</quote>, an easy way to audit the current machine, checking
each vulnerability which is known. If a vulnerable package is
installed, it will be shown by output to stdout, including a
description of the type of vulnerability, and a URL containing more
information.
</para>
</listitem>
</orderedlist>
<para>
Use of the audit-packages package is strongly recommended.
</para>
<para>
The following message is displayed as part of the audit-packages
installation procedure:
</para>
<screen>
======================================================================
You may wish to have the vulnerabilities file downloaded daily so that
it remains current. This may be done by adding an appropriate entry
to the root users crontab(5) entry. For example the entry
# download vulnerabilities file
0 3 * * * ${PREFIX}/sbin/download-vulnerability-list >/dev/null 2>&1
will update the vulnerability list every day at 3AM.
In addition, you may wish to run the package audit from the daily
security script. This may be accomplished by adding the following
lines to /etc/security.local
if [ -x ${PREFIX}/sbin/audit-packages ]; then
${PREFIX}/sbin/audit-packages
fi
======================================================================
</screen>
<para>
Note to package developers: When a vulnerability is found, this should be
noted in
<filename>localsrc/security/advisories/pkg-vulnerabilities</filename>, and after the
commit of that file, it should be copied to both
<filename>/pub/NetBSD/packages/distfiles/pkg-vulnerabilities</filename>
and
<filename>/pub/NetBSD/packages/distfiles/vulnerabilities</filename> on
ftp.NetBSD.org by
<filename>localsrc/security/advisories/Makefile</filename>.
</para>
</sect1>
<sect1>
<title>What's the proper way to create an account from a package?</title>
<para>
There are two make variables used to control the creation of package-specific
groups and users at pre-install time. The first is
<varname>PKG_GROUPS</varname>, which is a
list of group[:groupid] elements, where the groupid is optional. The second
is <varname>PKG_USERS</varname>, which is a list of elements of the form:
</para>
<programlisting>user:group[:[userid][:[description][:[home][:shell]]]]</programlisting>
<para>
where only the user and group are required, the rest being optional. A
simple example is:
</para>
<programlisting>PKG_GROUPS= foogroup
PKG_USERS= foouser:foogroup</programlisting>
<para>
A more complex example is that creates two groups and two users is:
</para>
<programlisting>PKG_GROUPS= group1 group2:1005
PKG_USERS= first:group1::First\\ User \
second:group2::Second\\ User:/home/second:${SH}</programlisting>
<para>
By default, a new user will have home directory
<filename>/nonexistent</filename>, and login shell
<filename>/sbin/nologin</filename> unless they are specified as part of
the user element.
</para>
<para>
The package Makefile must also set
<varname>USE_PKGINSTALL=YES</varname>. This will cause the users and groups
to be created at pre-install time, and the admin will be prompted to remove
them at post-deinstall time. Automatic creation of the users and groups
can be toggled on and off by setting the environment variable
<varname>PKG_CREATE_USERGROUP</varname> prior to package installation.
</para>
</sect1>
<sect1>
<title>How to handle compiler bugs</title>
<para>
Some source files trigger bugs in the compiler, based on combinations
of compiler version and architecture and almost always relation to
optimisation being enabled. Common symptoms are gcc internal errors
or never finishing compiling a file.
</para>
<para>
Typically a workaround involves testing the <varname>MACHINE_ARCH</varname>
and compiler version, disabling optimisation for that
file/<varname>MACHINE_ARCH</varname>/compiler
combination, and documenting it in <filename>doc/HACKS</filename>. See
<filename>doc/HACKS</filename> for examples.
</para>
</sect1>
<sect1 id="features.info-files">
<title>Packages providing info files</title>
<para>
Some packages install info files or use the <quote>makeinfo</quote>
or <quote>install-info</quote> commands. Each of the info files:
<itemizedlist>
<listitem>is considered to be installed in the directory
<filename>${PREFIX}/${INFO_DIR}</filename>,</listitem>
<listitem>is registered in the Info directory file
<filename>${PREFIX}/${INFO_DIR}/dir</filename>,</listitem>
<listitem>and must be listed as a filename in the
<varname>INFO_FILES</varname> variable in the package
Makefile.</listitem>
</itemizedlist>
</para>
<para>
<varname>INFO_DIR</varname> defaults to <quote>info</quote> and can be
overridden in the package Makefile. <filename>INSTALL</filename> and
<filename>DEINSTALL</filename> scripts will be generated to handle
registration of the info files in the Info directory file. The
<quote>install-info</quote> command used for the info files registration is
either provided by the system, or by a special purpose package
automatically added as dependency if needed.
</para>
<para>
A package which needs the <quote>makeinfo</quote> command at build
time must define the variable <varname>USE_MAKEINFO</varname> in its
Makefile. If a minimum version of the <quote>makeinfo</quote> command
is needed it should be noted with the <varname>TEXINFO_REQD</varname>
variable in the package <filename>Makefile</filename>. By default, a
minimum version of 3.12 is required. If the system does not provide a
<command>makeinfo</command> command or if it does not match the required
minimum, a build dependency on the <pkg>devel/gtexinfo</pkg> package
will be added automatically.
</para>
<para>
The build and installation process of the software provided by the package
should not use the <command>install-info</command> command as the
registration of info files is the task of the package
<filename>INSTALL</filename> script, and it must use the appropriate
<command>makeinfo</command> command.
</para>
<para>
To achieve this goal the pkgsrc infrastructure creates overriding scripts
for the <command>install-info</command> and <command>makeinfo</command>
commands in a directory listed early in <varname>PATH</varname>.
</para>
<para>
The script overriding <command>install-info</command> has no effect except
the logging of a message. The script overriding <command>makeinfo</command>
logs a message and according to the value of <varname>USE_MAKEINFO</varname>
and <varname>TEXINFO_REQD</varname> either run the appropriate
<command>makeinfo</command> command or exit on error.
</para>
</sect1>
<sect1>
<title>Packages whose distfiles aren't available for plain downloading</title>
<para>
If you need to download from a dynamic URL you can set
<varname>DYNAMIC_MASTER_SITES</varname>
and a <command>make fetch</command> will call
<filename>files/getsite.sh</filename> with the name of each file
to download as an argument, expecting it to output the URL of the directory
from which to download it. <pkg>graphics/ns-cult3d</pkg> is an example of this usage.
</para>
<para>
If the download can't be automated, because the user must submit personal
information to apply for a password, or must pay for the source, or whatever,
you can set <varname>_FETCH_MESSAGE</varname> to a macro which displays
a message explaining the situation. <varname>_FETCH_MESSAGE</varname> must
be executable shell commands, not just a message. (Generally, it executes
<varname>${ECHO}</varname>). As of this writing, the following
packages use this: <pkg>audio/realplayer</pkg>,
<pkg>cad/simian</pkg>, <pkg>devel/ipv6socket</pkg>,
<pkg>emulators/vmware-module</pkg>,
<pkg>fonts/acroread-jpnfont</pkg>,
<pkg>sysutils/storage-manager</pkg>,
<pkg>www/ap-aolserver</pkg>, <pkg>www/openacs</pkg>. Try to be consistent
with them.
</para>
</sect1>
<sect1>
<title>Configuration files handling and placement</title>
<para>
The global variable <varname>PKG_SYSCONFBASE</varname> (and some others)
can be set by the system administrator in <filename>/etc/mk.conf</filename>
to define the place where
configuration files get installed. Therefore, packages must be adapted to
support this feature. Keep in mind that you should only install files that
are strictly necessary in the configuration directory, files that can
go to <filename>$PREFIX/share</filename> should go there.
</para>
<para>
We will take a look at available variables first
(<filename>bsd.pkg.mk</filename> contains more
information). <varname>PKG_SYSCONFDIR</varname> is where the
configuration files for a package
may be found (that is, the full path, e.g. <filename>/etc</filename>
or <filename>/usr/pkg/etc</filename>). This
value may be customized in various ways:
</para>
<orderedlist>
<listitem>
<para>
<varname>PKG_SYSCONFBASE</varname> is the main config directory under
which all package configuration files are to be found. Users will
typically want to set it to <filename>/etc</filename>, or accept the
default location of <filename>$PREFIX/etc</filename>.
</para>
</listitem>
<listitem>
<para>
<varname>PKG_SYSCONFSUBDIR</varname> is the subdirectory of
<varname>PKG_SYSCONFBASE</varname> under which
the configuration files for a particular package may be found. Defaults
to <varname>${SYSCONFBASE}</varname>.
</para>
</listitem>
<listitem>
<para>
<varname>PKG_SYSCONFVAR</varname> is the special suffix used to
distinguish any overriding values for a particular package
(see next item). It defaults to <varname>${PKGBASE}</varname>, but
for a collection of related packages that should all have the same
<varname>PKG_SYSCONFDIR</varname> value, it can be set in each of
the package Makefiles to a common value.
</para>
</listitem>
<listitem>
<para>
<varname>PKG_SYSCONFDIR.${PKG_SYSCONFVAR}</varname> overrides the value of
<varname>${PKG_SYSCONFDIR}</varname> for packages with the same value
for <varname>PKG_SYSCONFVAR</varname>.
</para>
<para>
As an example, all the various KDE packages may want to set
<varname>PKG_SYSCONFVAR</varname> to <quote>kde</quote> so admins can
set <varname>PKG_SYSCONFDIR.kde</varname> in
<filename>/etc/mk.conf</filename> to define where to install KDE
config files.
</para>
</listitem>
</orderedlist>
<para>
Programs' configuration directory should be defined during the configure
stage. Packages that use GNU autoconf can usually do this by using the
<quote>--sysconfdir</quote> parameter, but this brings some problems as
we will see now.
When you change this pathname in packages, you should not allow them to
install files in that directory directly. Instead they need to install
those files under <filename>share/examples/${PKGNAME}</filename> so
<filename>PLIST</filename> can register them.
</para>
<para>
Once you have the required configuration files in place (under the
<filename>share/examples</filename> directory) the variable
<varname>CONF_FILES</varname> should be set to copy
them into <varname>PKG_SYSCONFDIR</varname>. The contents of this variable
is formed by pairs
of filenames; the first element of the pair specifies the file inside the
examples directory (registered by <filename>PLIST</filename>) and the
second element specifies
the target file. This is done this way to allow binary packages to place
files in the right directory using
<filename>INSTALL</filename>/<filename>DEINSTALL</filename> scripts which are
created automatically. The package <filename>Makefile</filename> must also
set <varname>USE_PKGINSTALL=YES</varname> to use
these automatically generated scripts. The automatic copying of config
files can be toggled by setting the environment variable
<varname>PKG_CONFIG</varname> prior to package installation.
</para>
<para>
Here is an example, taken from mail/mutt/Makefile:
</para>
<programlisting>EGDIR= ${PREFIX}/share/doc/mutt/samples
CONF_FILES= ${EGDIR}/Muttrc ${PKG_SYSCONFDIR}/Muttrc</programlisting>
<para>
As you can see, this package installs configuration files inside
<varname>EGDIR</varname>, which are registered by
<filename>PLIST</filename>. After that, the variable
<varname>CONF_FILES</varname> lists
the installed file first and then the target file. Users will also get an
automatic message when files are installed using this method.
</para>
</sect1>
<sect1>
<title>Packages providing login shells</title>
<para>
If the purpose of the package is to provide a login shell, the variable
<varname>PKG_SHELL</varname> should contain the full pathname of the
shell executable installed by this package. The package
<filename>Makefile</filename> must also set
<varname>USE_PKGINSTALL=YES</varname> to use the automatically generated
<filename>INSTALL</filename>/<filename>DEINSTALL</filename> scripts.
</para>
<para>
An example taken from shells/zsh:
</para>
<programlisting>USE_PKGINSTALL= YES
...
PKG_SHELL= ${PREFIX}/bin/zsh</programlisting>
<para>
The shell is registered into <filename>/etc/shells</filename> file automatically in the
post-install target by the generated <filename>INSTALL</filename> script
and removed in the deinstall
target by the <filename>DEINSTALL</filename> script.
</para>
</sect1>
<sect1>
<title>Packages providing locale catalogues</title>
<para>
If the package provides its own locale catalogues, the variable
<varname>USE_PKGLOCALEDIR</varname> should be defined. It will ensure
that the package's <filename>Makefile</filename> template files are fixed
and point to the correct locale directories
(which may vary, depending on OS), if necessary. See <xref
linkend="plist.misc"/> for details about <varname>PKGLOCALEDIR</varname>.
This functionality is buildlink3-only.
</para>
</sect1>
<sect1>
<title>Using 'sudo' with pkgsrc</title>
<para>
When installing packages as non-root user and using the just-in-time
su(1) feature of pkgsrc, it can become annoying to type in the root
password for each required package installed. To avoid this, the sudo
package can be used, which does password caching over a limited time.
To use it, install sudo (either as binary package or from
<pkg>security/sudo</pkg>) and then put the following
into your <filename>/etc/mk.conf</filename>:
</para>
<programlisting>SU_CMD=/usr/pkg/bin/sudo /bin/sh -c</programlisting>
</sect1>
<sect1>
<title>Packages containing perl scripts</title>
<para>
If your package contains interpreted perl scripts, set
<varname>REPLACE_PERL</varname> to ensure that the proper interpreter
path is set. <varname>REPLACE_PERL</varname> should contain a list of
scripts, relative to <varname>WRKSRC</varname>, that you want adjusted.
</para>
</sect1>
<sect1>
<title>Packages with hardcoded paths to other interpreters</title>
<para>
Your package may also contain scripts with hardcoded paths to other
interpreters besides (or as well as) perl. To correct the full
pathname to the script interpreter, you need to set the following
definitions in your <filename>Makefile</filename> (we shall use
<command>tclsh</command> in this example):
<programlisting>REPLACE_INTERPRETER+= tcl
_REPLACE.tcl.old= .*/bin/tclsh
_REPLACE.tcl.new= ${PREFIX}/bin/tclsh
_REPLACE_FILES.tcl= ...list of tcl scripts which need to be fixed,
relative to ${WRKSRC}, just as in REPLACE_PERL</programlisting>
</para>
</sect1>
<sect1>
<title>Utilities for package management (pkgtools)</title>
<para>
The directory pkgtools contains a number of useful utilities. This section
attempts only to make the reader aware of the utilities and when they might
be useful, and not to duplicate the documentation that comes with each
package.
</para>
<para>
Utilities used by pkgsrc (automatically installed when needed):
<itemizedlist>
<listitem>x11-links
<para>
symlinks for use by buildlink
</para>
</listitem>
</itemizedlist>
</para>
<para>
OS tool augmentation (automatically installed when needed):
<itemizedlist>
<listitem>digest
<para>
calculates SHA1 checksums (and other kinds)
</para>
</listitem>
<listitem>libnbcompat
<para>
compat library for pkg tools
</para>
</listitem>
<listitem>mtree
<para>
installed on non-BSD systems due to lack of native mtree
</para>
</listitem>
<listitem>pkg_install
<para>
up-to-date replacement for /usr/sbin/pkg_install, or for
use on operating systems where pkg_install is not present
</para>
</listitem>
</itemizedlist>
</para>
<para>
Utilities used by pkgsrc (not automatically installed):
<itemizedlist>
<listitem>pkg_tarup
<para>
create a binary package from an already-installed package.
used by 'make replace' to save the old package
</para>
</listitem>
<listitem>xpkgwedge
<para>
put X11 packages someplace else (see above)
</para>
</listitem>
</itemizedlist>
</para>
<para>
Utilities for keeping track of installed packages, being up to date, etc:
<itemizedlist>
<listitem>pkgchk
<para>
installs pkg_chk, which reports on packages whose installed
versions do not match the latest pkgsrc entries
</para>
</listitem>
<listitem>pkgdep
<para>
makes dependency graphs of packages, to aid in choosing a
strategy for updating
</para>
</listitem>
<listitem>pkgdepgraph
<para>
make graph from above (uses graphviz)
</para>
</listitem>
<listitem>pkglint
<para>
This provides two distinct abilities:
check a pkgsrc entry for correctness (pkglint)
check for and remove out-of-date distfiles and binary
packages (lintpkgsrc)
</para>
</listitem>
<listitem>pkgsurvey
<para>
report what packages you have installed
</para>
</listitem>
</itemizedlist>
</para>
<para>
Utilities for people maintaining or creating individual packages:
<itemizedlist>
<listitem>pkgdiff
<para>
automate making and maintaining patches for a package
</para>
</listitem>
<listitem>rpm2pkg, url2pkg
<para>
aids in converting to pkgsrc
</para>
</listitem>
<listitem>gensolpkg
<para>
convert pkgsrc to a Solaris package
</para>
</listitem>
</itemizedlist>
</para>
<para>
Utilities for people maintaining pkgsrc (or more obscure pkg utilities)
<itemizedlist>
<listitem>pkgconflict
<para>
find packages that conflict but aren't marked as such
</para>
</listitem>
<listitem>pkgcomp
<para>
build packages in a chrooted area
</para>
</listitem>
<listitem>libkver
<para>
spoof kernel version for chrooted cross builds
</para>
</listitem>
</itemizedlist>
</para>
</sect1>
<sect1>
<title>How to use pkgsrc as non-root</title>
<para>
If you want to use pkgsrc as non-root user, you can set some variables
to make pkgsrc work under these conditions. Please see
<ulink
url="http://mail-index.netbsd.org/tech-pkg/2003/09/27/0023.html">this
message</ulink> for more details.
</para>
</sect1>
<sect1>
<title>Packages that cannot or should not be built</title>
<para>
There are several reasons why a package might be instructed to not
build under certain circumstances. If the package builds and runs
on most platforms, the exceptions should be noted with
<varname>NOT_FOR_PLATFORM</varname>. If the package builds and runs on
a small handful of platforms, set <varname>ONLY_FOR_PLATFORM</varname>
instead. If the package should be skipped (for example, because it
provides functionality already provided by the system), set
<varname>PKG_SKIP_REASON</varname> to a descriptive message. If
the package should fail because some preconditions are not met,
set <varname>PKG_FAIL_REASON</varname> to a descriptive message.
</para>
<para>
<varname>IGNORE</varname> is deprecated because it didn't provide enough
information to determine whether the build should fail.
</para>
</sect1>
</chapter>
|