aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/porters-handbook/book.sgml
blob: e243a3d4dfd702d6c4c14ad7ca6d7f6537145b44 (plain) (blame)
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
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
<!--
     The FreeBSD Documentation Project

     $FreeBSD$
-->

<!DOCTYPE BOOK PUBLIC "-//FreeBSD//DTD DocBook V4.1-Based Extension//EN" [
<!ENTITY % man PUBLIC "-//FreeBSD//ENTITIES DocBook Manual Page Entities//EN">
%man;

<!ENTITY % bookinfo PUBLIC "-//FreeBSD//ENTITIES DocBook BookInfo Entities//EN">
%bookinfo;

<!ENTITY % authors PUBLIC "-//FreeBSD//ENTITIES DocBook Author Entities//EN"> %authors;
<!ENTITY % mailing-lists PUBLIC "-//FreeBSD//ENTITIES DocBook Mailing List Entities//EN">
%mailing-lists;

]>

<book>
  <bookinfo>
    <title>FreeBSD Porter's Handbook</title>

    <authorgroup>
      <corpauthor>The FreeBSD Documentation Project</corpauthor>
    </authorgroup>

    <pubdate>April 2000</pubdate>

    <copyright>
      <year>2000</year>
      <year>2001</year>
      <year>2002</year>
      <holder role="mailto:doc@FreeBSD.org">The FreeBSD Documentation
	Project</holder>
    </copyright>

    &bookinfo.legalnotice;
  </bookinfo>


    <chapter>
      <title>Making a port yourself</title>

      <para>So, now you are interested in making your own port or
        upgrading an existing one?  Great!</para>

      <para>What follows are some guidelines for creating a new port for
        FreeBSD.  If you want to upgrade an existing port, you should
	read this and then read <xref linkend="port-upgrading">.</para>

      <para>When this document is not sufficiently detailed, you should
        refer to <filename>/usr/ports/Mk/bsd.port.mk</filename>, which
	all port Makefiles include.  Even if you do not hack Makefiles
	daily, it is well commented, and you will still gain much
	knowledge from it.  Additionally, you may send specific questions
	to the &a.ports;.</para>

      <note>
        <para>Only a fraction of the variables
          (<makevar><replaceable>VAR</replaceable></makevar>) that can be
          overridden are mentioned in this document.  Most (if not all)
	  are documented at the start of <filename>bsd.port.mk</filename>.
	  This file uses a non-standard tab setting.
	  <application>Emacs</application> and
	  <application>Vim</application> should recognize the setting on
	  loading the file.  Both <command>vi</command> and
	  <command>ex</command> can be set to use the correct value by
	  typing <command>:set tabstop=4</command> once the file has been
	  loaded.</para>
      </note>
    </chapter>

    <chapter id="quick-porting">
      <title>Quick Porting</title>

      <para>This section tells you how to do a quick port.  In many cases, it
        is not enough, but we will see.</para>

      <para>First, get the original tarball and put it into
        <makevar>DISTDIR</makevar>, which defaults to
        <filename>/usr/ports/distfiles</filename>.</para>

      <note>
        <para>The following assumes that the software compiled out-of-the-box,
          i.e., there was absolutely no change required for the port to work
          on your FreeBSD box.  If you needed to change something, you will
          have to refer to the next section too.</para>
      </note>

      <sect1>
        <title>Writing the <filename>Makefile</filename></title>

        <para>The minimal <filename>Makefile</filename> would look something
          like this:</para>

        <programlisting># New ports collection makefile for:   oneko
# Date created:        5 December 1994
# Whom:                asami
#
# &dollar;FreeBSD&dollar;
#

PORTNAME=      oneko
PORTVERSION=   1.1b
CATEGORIES=    games
MASTER_SITES=  ftp://ftp.cs.columbia.edu/archives/X11R5/contrib/

MAINTAINER=    asami@FreeBSD.org

MAN1=          oneko.1
MANCOMPRESSED= yes
USE_IMAKE=     yes

.include &lt;bsd.port.mk&gt;</programlisting>

        <para>See if you can figure it out.  Do not worry about the contents
          of the <literal>&dollar;FreeBSD&dollar;</literal> line, it will be
          filled in automatically by CVS when the port is imported to our main
          ports tree.  You can find a more detailed example in the <link
            linkend="porting-samplem">sample Makefile</link> section.</para>
      </sect1>

      <sect1>
        <title>Writing the description files</title>

        <para>There are three description files that are required for
          any port, whether they actually package or not. They are
          <filename>pkg-comment</filename>,
          <filename>pkg-descr</filename>, and
          <filename>pkg-plist</filename>, and their
          <filename>pkg-</filename> prefix distinguishes them from
          other files.</para>

        <sect2>
          <title><filename>pkg-comment</filename></title>

          <para>This is the one-line description of the port.
            <emphasis>Please</emphasis> do not include the package name (or
            version number of the software) in the comment.  The comment
            should begin with a capital, and end without a period.  Here
            is an example:</para>

          <programlisting>A cat chasing a mouse all over the screen</programlisting>
        </sect2>

        <sect2>
          <title><filename>pkg-descr</filename></title>

          <para>This is a longer description of the port.  One to a few
            paragraphs concisely explaining what the port does is
            sufficient.</para>

          <note>
            <para>This is <emphasis>not</emphasis> a manual or an in-depth
              description on how to use or compile the port! <emphasis>Please
              be careful if you are copying from the
              <filename>README</filename> or manpage</emphasis>; too often
              they are not a concise description of the port or are in an
              awkward format (e.g., manpages have justified spacing).  If the
              ported software has an official WWW homepage, you should list it
              here.  Prefix <emphasis>one</emphasis> of the websites with
              <literal>WWW:</literal> so that automated tools will work
              correctly.</para>
          </note>

          <para>It is recommended that you sign your name at the end of this
            file, as in:</para>

          <programlisting>This is a port of oneko, in which a cat chases a poor mouse all over
the screen.
 :
(etc.)

WWW: http://www.oneko.org/

- Satoshi
asami@cs.berkeley.edu</programlisting>
        </sect2>

        <sect2>
          <title><filename>pkg-plist</filename></title>

          <para>This file lists all the files installed by the port.  It is
            also called the <quote>packing list</quote> because the package is
            generated by packing the files listed here.  The pathnames are
            relative to the installation prefix (usually
            <filename>/usr/local</filename> or
            <filename>/usr/X11R6</filename>).  If you are using the
            <makevar>MAN<replaceable>n</replaceable></makevar> variables (as
            you should be), do not list any manpages here.</para>

          <para>Here is a small example:</para>

          <programlisting>bin/oneko
lib/X11/app-defaults/Oneko
lib/X11/oneko/cat1.xpm
lib/X11/oneko/cat2.xpm
lib/X11/oneko/mouse.xpm
@dirrm lib/X11/oneko</programlisting>

          <para>Refer to the &man.pkg.create.1; manual page for details on the
            packing list.</para>

          <note>
            <para>You should list all the files, but not the name directories,
              in the list.  Also, if the port creates directories for itself
              during installation, make sure to add <literal>@dirrm</literal>
              lines as necessary to remove them when the port is
              deleted.</para>

            <para>It is recommended that you keep all the filenames in this
              file sorted alphabetically.  It will make verifying the changes
              when you upgrade the port much easier.</para>

            <para>Creating a packing list manually can be a very tedious
              task.  If the port installs a large numbers of files, <link
                linkend="porting-autoplist">creating the packing list
                automatically</link> might save time.</para>
          </note>
        </sect2>
      </sect1>

      <sect1>
        <title>Creating the checksum file</title>

        <para>Just type <command>make makesum</command>. The ports make rules
          will automatically generate the file
          <filename>distinfo</filename>.</para>
      </sect1>

      <sect1 id="porting-testing">
        <title>Testing the port</title>

        <para>You should make sure that the port rules do exactly what you
          want them to do, including packaging up the port.  These are the
          important points you need to verify.</para>

        <itemizedlist>
          <listitem>
            <para><filename>pkg-plist</filename> does not contain anything not
              installed by your port</para>
          </listitem>

          <listitem>
            <para><filename>pkg-plist</filename> contains everything that is
              installed by your port</para>
          </listitem>

          <listitem>
            <para>Your port can be installed multiple times using the
              <maketarget>reinstall</maketarget> target</para>
          </listitem>

          <listitem>
            <para>Your port <link linkend="porting-cleaning">cleans up</link>
              after itself upon deinstall</para>
          </listitem>
        </itemizedlist>

        <procedure>
          <title>Recommended test ordering</title>

          <step>
            <para><command>make install</command></para>
          </step>

          <step>
            <para><command>make package</command></para>
          </step>

          <step>
            <para><command>make deinstall</command></para>
          </step>

          <step>
            <para><command>pkg_add <replaceable>package-name</replaceable>
              </command></para>
          </step>

          <step>
            <para><command>make deinstall</command></para>
          </step>

          <step>
            <para><command>make reinstall</command></para>
          </step>

          <step>
            <para><command>make package</command></para>
          </step>
        </procedure>

        <para>Make sure that there are not any warnings issued in any of the
          <maketarget>package</maketarget> and
          <maketarget>deinstall</maketarget> stages.  After step 3, check to
          see if all the new directories are correctly deleted.  Also, try
          using the software after step 4, to ensure that it works correctly
          when installed from a package.</para>
      </sect1>

      <sect1 id="porting-portlint">
        <title>Checking your port with <command>portlint</command></title>

        <para>Please use <command>portlint</command> to see if your port
          conforms to our guidelines.  The <command>portlint</command> program
          is part of the ports collection.  In particular, you may want to
          check if the <link linkend="porting-samplem">Makefile</link> is in
          the right shape and the <link
            linkend="porting-pkgname">package</link> is named
          appropriately.</para>
      </sect1>

      <sect1 id="porting-submitting">
        <title>Submitting the port</title>

        <para>First, make sure you have read the <link
            linkend="porting-dads">DOs and DON'Ts</link> section.</para>

        <para>Now that you are happy with your port, the only thing remaining
          is to put it in the main FreeBSD ports tree and make everybody else
          happy about it too.  We do not need your <filename>work</filename>
          directory or the <filename>pkgname.tgz</filename> package, so delete
          them now.  Next, simply include the output of <command>shar `find
            port_dir`</command> in a bug report and send it with the
            &man.send-pr.1; program (see <ulink url="../../articles/contributing/contrib-how.html#CONTRIB-GENERAL">Bug
            Reports and General Commentary</ulink> for more information about
            &man.send-pr.1;.  If the uncompressed port is larger than 20KB,
          you should compress it into a tarfile and use &man.uuencode.1;
          before including it in the bug report (uuencoded tarfiles are
          acceptable even if the bug report is smaller than 20KB but are not
          preferred).  Be sure to classify the bug report as category
          <literal>ports</literal> and class
          <literal>change-request</literal>  (Do not mark the report
          <literal>confidential</literal>!).
          Also add a short description of the program you ported
          to the <quote>Description</quote> field of the PR and
          the shar or uuencoded tarfile to the
          <quote>Fix</quote> field.  The latter one helps the committers
          a lot, who use scripts for the ports-work.</para>

        <para>One more time, <emphasis>do not include the original source
            distfile, the <filename>work</filename> directory, or the package
            you built with <command>make package</command></emphasis>.</para>

        <note>
          <para>In the past, we asked you to upload new port submissions in
            our FTP site (<hostid role="fqdn">ftp.FreeBSD.org</hostid>). This
            is no longer recommended as read access is turned off on the
            <filename>incoming/</filename> directory of that site due to the
            large amount of pirated software showing up there.</para>
        </note>

	<para>After you have submitted your port, please be patient.
	  Sometimes it can take a few months before a port is included
	  in FreeBSD, although it might only take a few days.  You can
	  view the list of <ulink
	  url="http://www.FreeBSD.org/cgi/query-pr-summary.cgi?category=ports">ports
	  waiting to be committed to FreeBSD</ulink>.</para>

        <para>Once we have looked at your port, we will get back to you if necessary, and put
          it in the tree.  Your name will also appear in the list of
          <quote>Additional FreeBSD contributors</quote> in the FreeBSD
          Handbook and other files. Isn't that great?!? <!-- smiley
          -->:-)</para>

        <note>
          <para>You can make our work a lot easier, if you use a good
            description in the synopsis of the problem report.
            We prefer something like
            <quote>New port: &lt;short description of the port&gt;</quote> for
            new ports and
            <quote>Update port: &lt;category&gt;/&lt;port&gt; &lt;short description
            of the update&gt;</quote> for port updates.
            If you stick to this scheme, the chance that one takes a look at
            your PR soon is much bigger.</para>
        </note>
      </sect1>
    </chapter>

    <chapter>
      <title>Slow Porting</title>

      <para>Ok, so it was not that simple, and the port required some
        modifications to get it to work.  In this section, we will explain,
        step by step, how to modify it to get it to work with the ports
        paradigm.</para>

      <sect1>
        <title>How things work</title>

        <para>First, this is the sequence of events which occurs when the user
          first types <command>make</command> in your port's directory.
          You may find that having <filename>bsd.port.mk</filename> in another
          window while you read this really helps to understand it.</para>

        <para>But do not worry if you do not really understand what
          <filename>bsd.port.mk</filename> is doing, not many people do...
          <!-- smiley --><emphasis>:-&gt;</emphasis></para>

        <procedure>

          <step>
            <para>The <maketarget>fetch</maketarget> target is run.  The
              <maketarget>fetch</maketarget> target is responsible for making
              sure that the tarball exists locally in
              <makevar>DISTDIR</makevar>. If <maketarget>fetch</maketarget>
              cannot find the required files in <makevar>DISTDIR</makevar> it
              will look up the URL <makevar>MASTER_SITES</makevar>, which is
              set in the Makefile, as well as our main FTP site at <ulink
                url="ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/">ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/</ulink>,
              where we put sanctioned distfiles as backup.  It will then
              attempt to fetch the named distribution file with
              <makevar>FETCH</makevar>, assuming that the requesting site has
              direct access to the Internet.  If that succeeds, it will save
              the file in <makevar>DISTDIR</makevar> for future use and
              proceed.</para>
          </step>

          <step>
            <para>The <maketarget>extract</maketarget> target is run.  It
              looks for your port's distribution file (typically a gzip'd
              tarball) in <makevar>DISTDIR</makevar> and unpacks it into a
              temporary subdirectory specified by <makevar>WRKDIR</makevar>
              (defaults to <filename>work</filename>).</para>
          </step>

          <step>
            <para>The <maketarget>patch</maketarget> target is run.  First,
              any patches defined in <makevar>PATCHFILES</makevar> are
              applied.  Second, if any patch files named
              <filename>patch-<replaceable>*</replaceable></filename> are found in
              <makevar>PATCHDIR</makevar> (defaults to the
              <filename>files</filename> subdirectory), they are applied at
              this time in alphabetical order.</para>
          </step>

          <step>
            <para>The <maketarget>configure</maketarget> target is run.  This
              can do any one of many different things.</para>

            <orderedlist>
              <listitem>
                <para>If it exists, <filename>scripts/configure</filename> is
                  run.</para>
              </listitem>

              <listitem>
                <para>If <makevar>HAS_CONFIGURE</makevar> or
                  <makevar>GNU_CONFIGURE</makevar> is set,
                  <filename><makevar>WRKSRC</makevar>/configure</filename> is
                  run.</para>
              </listitem>

              <listitem>
                <para>If <makevar>USE_IMAKE</makevar> is set,
                  <makevar>XMKMF</makevar> (default: <command>xmkmf
                    -a</command>) is run.</para>
              </listitem>
            </orderedlist>
          </step>

          <step>
            <para>The <maketarget>build</maketarget> target is run.  This is
              responsible for descending into the port's private working
              directory (<makevar>WRKSRC</makevar>) and building it.  If
              <makevar>USE_GMAKE</makevar> is set, GNU <command>make</command>
              will be used, otherwise the system <command>make</command> will
              be used.</para>
          </step>
        </procedure>

        <para>The above are the default actions.  In addition, you can define
          targets
          <maketarget>pre-<replaceable>something</replaceable></maketarget> or
          <maketarget>post-<replaceable>something</replaceable></maketarget>,
          or put scripts with those names, in the <filename>scripts</filename>
          subdirectory, and they will be run before or after the default
          actions are done.</para>

        <para>For example, if you have a <maketarget>post-extract</maketarget>
          target defined in your Makefile, and a file
          <filename>pre-build</filename> in the <filename>scripts</filename>
          subdirectory, the <maketarget>post-extract</maketarget> target will
          be called after the regular extraction actions, and the
          <filename>pre-build</filename> script will be executed before the
          default build rules are done.  It is recommended that you use
          <filename>Makefile</filename> targets if the actions are simple
          enough, because it will be easier for someone to figure out what
          kind of non-default action the port requires.</para>

        <para>The default actions are done by the
          <filename>bsd.port.mk</filename> targets
          <maketarget>do-<replaceable>something</replaceable></maketarget>.
          For example, the commands to extract a port are in the target
          <maketarget>do-extract</maketarget>.  If you are not happy with the
          default target, you can fix it by redefining the
          <maketarget>do-<replaceable>something</replaceable></maketarget>
          target in your <filename>Makefile</filename>.</para>

        <note>
          <para>The <quote>main</quote> targets (e.g.,
            <maketarget>extract</maketarget>,
            <maketarget>configure</maketarget>, etc.) do nothing more than
            make sure all  the stages up to that one are completed and call
            the real targets or scripts, and they are not intended to be
            changed.  If you want to fix the extraction, fix
            <maketarget>do-extract</maketarget>, but never ever touch
            <maketarget>extract</maketarget>!</para>
        </note>

        <para>Now that you understand what goes on when the user types
          <command>make</command>, let us go through the recommended steps to
          create the perfect port.</para>
      </sect1>

      <sect1>
        <title>Getting the original sources</title>

        <para>Get the original sources (normally) as a compressed tarball
          (<filename><replaceable>foo</replaceable>.tar.gz</filename> or
          <filename><replaceable>foo</replaceable>.tar.Z</filename>) and copy
          it into <makevar>DISTDIR</makevar>.  Always use
          <emphasis>mainstream</emphasis> sources when and where you
          can.</para>

        <para>If you cannot find a FTP/HTTP site that is well-connected to the
          net, or can only find sites that have irritatingly non-standard
          formats, you might want to put a copy on a reliable FTP or HTTP
          server that you control (e.g., your home page).  Make sure you set
          <makevar>MASTER_SITES</makevar> to reflect your choice.</para>

        <para>If you cannot find somewhere convenient and reliable to put the
          distfile
          we can <quote>house</quote> it ourselves
          on <hostid>ftp.FreeBSD.org</hostid>.
          The distfile must be placed into
          <filename>~/public_distfiles/</filename> of someone's
          <hostid>freefall</hostid> account.
          Ask the person who commits your port to do this.
          This person will also set <makevar>MASTER_SITES</makevar> to
          <makevar>MASTER_SITE_LOCAL</makevar> and
          <makevar>MASTER_SITE_SUBDIR</makevar> to their
          <hostid>freefall</hostid> username.</para>

        <para>If your port's distfile changes all the time for no good reason,
          consider putting the distfile in your home page and listing it as
          the first <makevar>MASTER_SITES</makevar>.  This will prevent users
          from getting <errorname>checksum mismatch</errorname> errors, and
          also reduce the workload of maintainers of our FTP site.  Also, if
          there is only one master site for the port, it is recommended that
          you house a backup at your site and list it as the second
          <makevar>MASTER_SITES</makevar>.</para>

        <para>If your port requires some additional `patches' that are
          available on the Internet, fetch them too and put them in
          <makevar>DISTDIR</makevar>.  Do not worry if they come from a site
          other than where you got the main source tarball, we have a way to
          handle these situations (see the description of <link
            linkend="porting-patchfiles">PATCHFILES</link> below).</para>
      </sect1>

      <sect1>
        <title>Modifying the port</title>

        <para>Unpack a copy of the tarball in a private directory and make
          whatever changes are necessary to get the port to compile properly
          under the current version of FreeBSD.  Keep <emphasis>careful
            track</emphasis> of everything you do, as you will be automating
          the process shortly.  Everything, including the deletion, addition,
          or modification of files should be doable using an automated script
          or patch file when your port is finished.</para>

        <para>If your port requires significant user interaction/customization
          to compile or install, you should take a look at one of Larry Wall's
          classic <application>Configure</application> scripts and perhaps do
          something similar yourself.  The goal of the new ports collection is
          to make each port as <quote>plug-and-play</quote> as possible for the
          end-user while using a minimum of disk space.</para>

        <note>
          <para>Unless explicitly stated, patch files, scripts, and other
            files you have created and contributed to the FreeBSD ports
            collection are assumed to be covered by the standard BSD copyright
            conditions.</para>
        </note>
      </sect1>

      <sect1>
        <title>Patching</title>

        <para>In the preparation of the port, files that have been added or
          changed can be picked up with a recursive diff for later feeding to
          patch.  Each set of patches you wish to apply should be collected
          into a file named
          <filename>patch-<replaceable>*</replaceable></filename> where
          <replaceable>*</replaceable> denotes the sequence in which the
          patches will be applied &mdash; these are done in
          <emphasis>alphabetical order</emphasis>, thus <literal>aa</literal>
          first, <literal>ab</literal> second and so on.  If you wish,
          you can use names that indicate the pathnames of the files that
          are patched, such as <filename>patch-Imakefile</filename> or
          <filename>patch-src-config.h</filename>.  These files should
          be stored in <makevar>PATCHDIR</makevar>, from where they will be
          automatically applied.  All patches should be relative to
          <makevar>WRKSRC</makevar> (generally the directory your port's
          tarball unpacks itself into, that being where the build is done).
          To make fixes and upgrades easier, you should avoid having more than
          one patch fix the same file (e.g., <filename>patch-aa</filename> and
          <filename>patch-ab</filename> both changing
          <filename><makevar>WRKSRC</makevar>/foobar.c</filename>).</para>

        <para>Do not put RCS strings in patches.  CVS will mangle them when we
          put the files into the ports tree, and when we check them out again,
          they will come out different and the patch will fail.  RCS strings
          are surrounded by dollar (<literal>&dollar;</literal>) signs, and
          typically start with <literal>&dollar;Id</literal> or
          <literal>&dollar;RCS</literal>.</para>

        <para>Using the recurse (<option>-r</option>) option to
          <command>diff</command> to generate patches is fine, but please take
          a look at the resulting patches to make sure you do not have any
          unnecessary junk in there.  In particular, diffs between two backup
          files, <filename>Makefiles</filename> when the port uses
          <command>Imake</command> or GNU <command>configure</command>, etc.,
          are unnecessary and should be deleted.  If you had to edit
          <filename>configure.in</filename> and run
          <command>autoconf</command> to regenerate
          <command>configure</command>, do not take the diffs of
          <command>configure</command> (it often grows to a few thousand
          lines!); define <literal>USE_AUTOCONF=yes</literal> and take the
          diffs of <filename>configure.in</filename>.</para>

        <para>Also, if you had to delete a file, then you can do it in the
          <maketarget>post-extract</maketarget> target rather than as part of
          the patch.  Once you are happy with the resulting diff, please split
          it up into one source file per patch file.</para>
      </sect1>

      <sect1>
        <title>Configuring</title>

        <para>Include any additional customization commands in your
          <filename>configure</filename> script and save it in the
          <filename>scripts</filename> subdirectory.  As mentioned above, you
          can also do this with <filename>Makefile</filename> targets and/or
          scripts with the name <filename>pre-configure</filename> or
          <filename>post-configure</filename>.</para>
      </sect1>

      <sect1>
        <title>Handling user input</title>

        <para>If your port requires user input to build, configure, or install,
          then set <makevar>IS_INTERACTIVE</makevar> in your Makefile.  This
          will allow <quote>overnight builds</quote> to skip your port if the
          user sets the variable <envar>BATCH</envar> in his environment (and
          if the user sets the variable <envar>INTERACTIVE</envar>, then
          <emphasis>only</emphasis> those ports requiring interaction are
          built).</para>

        <para>It is also recommended that if there are reasonable default
          answers to the questions, you check the
          <makevar>PACKAGE_BUILDING</makevar> variable and turn off the
          interactive script when it is set.  This will allow us to build the
          packages for CDROMs and FTP.</para>
      </sect1>
    </chapter>

    <chapter>
      <title>Configuring the Makefile</title>

      <para>Configuring the Makefile is pretty simple, and again we suggest
        that you look at existing examples before starting. Also, there is a
        <link linkend="porting-samplem">sample Makefile</link> in this
        handbook, so take a look and please follow the ordering of variables
        and sections in that template to make your port easier for others to
        read.</para>

      <para>Now, consider the following problems in sequence as you design
        your new Makefile:</para>

      <sect1>
        <title>The original source</title>

        <para>Does it live in <makevar>DISTDIR</makevar> as a standard
	  gzip'd tarball named something like
	  <filename>foozolix-1.2.tar.gz</filename>? If so, you can go on
	  to the next step.  If not, you should look at overriding any of
	  the <makevar>DISTNAME</makevar>, <makevar>EXTRACT_CMD</makevar>,
	  <makevar>EXTRACT_BEFORE_ARGS</makevar>,
	  <makevar>EXTRACT_AFTER_ARGS</makevar>,
	  <makevar>EXTRACT_SUFX</makevar>, or <makevar>DISTFILES</makevar>
	  variables, depending on how alien a format your port's
	  distribution file is.  (The most common case is
	  <literal>EXTRACT_SUFX=.tar.Z</literal>, when the tarball is
	  condensed by regular <command>compress</command>, not
	  <command>gzip</command>.)</para>

        <para>In the worst case, you can simply create your own
	  <maketarget>do-extract</maketarget> target to override the
	  default, though this should be rarely, if ever,
	  necessary.</para>
      </sect1>
    
    <sect1>
      <title>Naming</title>

      <para>The first part of the port's <filename>Makefile</filename> names
	the port, describes it's version number, and lists it in the correct
	category.</para>

      <sect2>
        <title><makevar>PORTNAME</makevar> and <makevar>PORTVERSION</makevar></title>

        <para>You should set <makevar>PORTNAME</makevar> to the
          base name of your port, and <makevar>PORTVERSION</makevar>
          to the version number of the port.</para>
      </sect2>

      <sect2>
	<title><makevar>PORTREVISION</makevar> and
	  <makevar>PORTEPOCH</makevar></title>

	<sect3>
	  <title><makevar>PORTREVISION</makevar></title>

	  <para>The <makevar>PORTREVISION</makevar> variable is a
	    monotonically increasing value which is reset to 0 with
	    every increase of <makevar>PORTVERSION</makevar> (i.e.
	    every time a new official vendor release is made), and
	    appended to the package name if non-zero.
	    <makevar>PORTREVISION</makevar> is increased each time a
	    change is made to the FreeBSD port which significantly
	    affects the content or structure of the derived
	    package.</para>

	  <para>Examples of when PORTREVISION should be bumped:</para>

	  <itemizedlist>
	    <listitem>
	      <para>Addition of patches to correct security
		vulnerabilities, bugs, or to add new functionality to
		the FreeBSD port.</para>
	    </listitem>

	    <listitem>
	      <para>Changes to the port makefile to enable or disable
		compile-time options in the package.</para>
	    </listitem>

	    <listitem>
	      <para>Changes in the packing list or the install-time
		behavior of the package (e.g. change to a script
		which generates initial data for the package, like ssh
		host keys).</para>
	    </listitem>

	    <listitem>
	      <para>Version bump of a port's shared library dependency
		(in this case, someone trying to install the old
		package after installing a newer version of the
		dependency will fail since it will look for the old
		libfoo.x instead of libfoo.(x+1)).</para>
	    </listitem>

	    <listitem>
	      <para>Silent changes to the port distfile which have
		significant functional differences, i.e. changes to
		the distfile requiring a correction to
		<filename>distinfo</filename> with no corresponding change to
		<makevar>PORTVERSION</makevar>, where a <command>diff
		-ru</command> of the old and new versions shows
		non-trivial changes to the code.</para>
	    </listitem>
	  </itemizedlist>

	  <para>Examples of changes which do not require a
	    <makevar>PORTREVISION</makevar> bump:</para>

	  <itemizedlist>
	    <listitem>
	      <para>Style changes to the port skeleton with no
		functional change to what appears in the resulting
		package.</para>
	    </listitem>

	    <listitem>
	      <para>Changes to <makevar>MASTER_SITES</makevar> or
		other functional changes to the port which do not
		affect the resulting package.</para>
	    </listitem>

	    <listitem>
	      <para>Trivial patches to the distfile such as correction
		of typos, which are not important enough that users of
		the package should go to the trouble of
		upgrading.</para>
	    </listitem>

	    <listitem>
	      <para>Build fixes which cause a package to become
		compilable where it was previously failing (as long as
		the changes do not introduce any functional change on
		any other platforms on which the port did previously
		build). Since <makevar>PORTREVISION</makevar> reflects
		the content of the package, if no package was
		previously buildable then there is no need to increase
		<makevar>PORTREVISION</makevar> to mark a
		change.</para>
	    </listitem>
	  </itemizedlist>

	  <para>A rule of thumb is to ask yourself whether a change
	    committed to a port is something which someone, somewhere,
	    would benefit from having (either because of an
	    enhancement, fix, or by virtue that the new package will
	    actually work for them). If yes, the
	    <makevar>PORTREVISION</makevar> should be bumped so that
	    automated tools (e.g.  <command>pkg_version</command>)
	    will highlight the fact that a new package is
	    available.</para>
	</sect3>

	<sect3>
	  <title><makevar>PORTEPOCH</makevar></title>

	  <para>From time to time a software vendor or FreeBSD porter
	    will do something silly and release a version of their
	    software which is actually numerically less than the
	    previous version. An example of this is a port which goes
	    from foo-20000801 to foo-1.0 (the former will be
	    incorrectly treated as a newer version since 20000801 is a
	    numerically greater value than 1).</para>

	  <para>In situations such as this, the
	    <makevar>PORTEPOCH</makevar> version should be increased.
	    If <makevar>PORTEPOCH</makevar> is nonzero it is appended
	    to the package name as described in section 0 above.
	    <makevar>PORTEPOCH</makevar> is never decreased or reset
	    to zero, because that would cause comparison to a package
	    from an earlier epoch to fail (i.e. the package would not
	    be detected as out of date): the new version number (e.g.
	    <literal>1.0,1</literal> in the above example) is still
	    numerically less than the previous version (20000801), but
	    the <literal>,1</literal> suffix is treated specially by
	    automated tools and found to be greater than the implied
	    suffix ",0" on the earlier package.</para>

	  <para>It is expected that <makevar>PORTEPOCH</makevar> will
	    not be used for the majority of ports, and that sensible
	    use of <makevar>PORTVERSION</makevar> can often pre-empt
	    it becoming necessary if a future release of the software
	    should change the version structure. However, care is
	    needed by FreeBSD porters when a vendor release is made
	    without an official version number - such as a code
	    "snapshot" release.  The temptation is to label the
	    release with the release date, which will cause problems
	    as in the example above when a new "official" release is
	    made.</para>

	  <para>For example, if a snapshot release is made on the date
	    20000917, and the previous version of the software was
	    version 1.2, the snapshot release should be given a
	    <makevar>PORTVERSION</makevar> of 1.2.20000917 or similar,
	    not 20000917, so that the succeeding release, say 1.3, is
	    still a numerically greater value.</para>
	</sect3>

	<sect3>
	  <title>Example of <makevar>PORTREVISION</makevar> and
	    <makevar>PORTEPOCH</makevar> usage</title>

	  <para>The gtkmumble port, version 0.10, is committed to the
	    ports collection.</para>

	  <programlisting>PORTNAME=	gtkmumble
PORTVERSION=	0.10</programlisting>

	  <para><makevar>PKGNAME</makevar> becomes
	    <literal>gtkmumble-0.10</literal>.</para>

	  <para>A security hole is discovered which requires a local
	    FreeBSD patch. <makevar>PORTREVISION</makevar> is bumped
	    accordingly.</para>

	  <programlisting>PORTNAME=	gtkmumble
PORTVERSION=	0.10
PORTREVISION=	1</programlisting>

	  <para><makevar>PKGNAME</makevar> becomes
	    <literal>gtkmumble-0.10_1</literal></para>

	  <para>A new version is released by the vendor, numbered 0.2
	    (it turns out the author actually intended
	    <literal>0.10</literal> to actually mean
	    <literal>0.1.0</literal>, not <quote>what comes after
	      0.9</quote> - oops, too late now). Since the new minor
	    version <literal>2</literal> is numerically less than the
	    previous version <literal>10</literal> the
	    <makevar>PORTEPOCH</makevar> must be bumped to manually
	    force the new package to be detected as "newer". Since it
	    is a new vendor release of the code,
	    <makevar>PORTREVISION</makevar> is reset to 0 (or removed
	    from the makefile).</para>

	  <programlisting>PORTNAME=	gtkmumble
PORTVERSION=	0.2
PORTEPOCH=	1</programlisting>

	  <para><makevar>PKGNAME</makevar> becomes
	    <literal>gtkmumble-0.2,1</literal></para>

	  <para>The next release is 0.3. Since
	    <makevar>PORTEPOCH</makevar> never decreases, the version
	    variables are now:</para>
	    
	  <programlisting>PORTNAME=	gtkmumble
PORTVERSION=	0.3
PORTEPOCH=	1</programlisting>

	  <para><makevar>PKGNAME</makevar> becomes
	    <literal>gtkmumble-0.3,1</literal></para>

          <note>
            <para>If <makevar>PORTEPOCH</makevar> were reset
              to <literal>0</literal> with this upgrade, someone who had
              installed the gtkmumble-0.10_1 package would not detect
              the gtkmumble-0.3 package as newer, since
              <literal>3</literal> is still numerically less than
              <literal>10</literal>.</para>
	  </note>
        </sect3>
      </sect2>

      <sect2>
        <title><makevar>PKGNAMEPREFIX</makevar> and <makevar>PKGNAMESUFFIX</makevar></title>

	<para>Two optional variables, <makevar>PKGNAMEPREFIX</makevar> and
	  <makevar>PKGNAMESUFFIX</makevar>, are combined with
	  <makevar>PORTNAME</makevar> and
	  <makevar>PORTVERSION</makevar> to 
          form <makevar>PKGNAME</makevar> as
          <literal>${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}-${PORTVERSION}</literal>.
          Make sure this conforms to our <link
          linkend="porting-pkgname">guidelines for a good package
          name</link>.  In particular, you are not allowed to use a
          hyphen (<literal>-</literal>) in
          <makevar>PORTVERSION</makevar>.  Also, if the package name
          has the <replaceable>language-</replaceable> or the
          <replaceable>compiled.specifics</replaceable> part, use
          <makevar>PKGNAMEPREFIX</makevar> and
          <makevar>PKGNAMESUFFIX</makevar>, respectively.  Do not make
          them part of <makevar>PORTNAME</makevar>.</para>
      </sect2>

    <sect2 id="porting-pkgname">
      <title>Package Naming Conventions</title>

      <para>The following are the conventions you should follow in naming your
        packages.  This is to have our package directory easy to scan, as
        there are already lots and lots of packages and users are going to
        turn away if they hurt their eyes!</para>

      <para>The package name should look like
        <filename><replaceable><optional>language<optional>_region</optional></optional>-name<optional><optional>-</optional>compiled.specifics</optional>-version.numbers</replaceable></filename>.</para>

      <para>The package name is defined as
        <literal>${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}-${PORTVERSION}</literal>.
        Make sure to set the variables to conform to that format.</para>

      <orderedlist>
        <listitem>
          <para>FreeBSD strives to support the native language of its users.
            The <replaceable>language-</replaceable> part should be a two
            letter abbreviation of the natural language defined by ISO-639 if
            the port is specific to a certain language.  Examples are
            <literal>ja</literal> for Japanese, <literal>ru</literal> for
            Russian, <literal>vi</literal> for Vietnamese,
            <literal>zh</literal> for Chinese, <literal>ko</literal> for
            Korean and <literal>de</literal> for German.</para>

	  <para>If the port is specific to a certain region within the
            language area, add the two letter country code as well.
            Examples are <literal>en_US</literal> for US English and
            <literal>fr_CH</literal> for Swiss French.</para>

          <para>The <replaceable>language-</replaceable> part should
            be set in the <makevar>PKGNAMEPREFIX</makevar> variable.</para>
        </listitem>

        <listitem>
          <para>The first letter of <filename>name</filename> part
            should be lowercase.  (The rest of the name can contain
            capital letters, so use your own discretion when you are
            converting a software name that has some capital letters in it.)
            There is a tradition of naming Perl 5 modules by
            prepending <literal>p5-</literal> and converting the double-colon
            separator to a hyphen; for example, the
            <literal>Data::Dumper</literal> module becomes
            <literal>p5-Data-Dumper</literal>.  If the software in question
            has numbers, hyphens, or underscores in its name, you may include
            them as well (like <literal>kinput2</literal>).</para>
        </listitem>

        <listitem>
          <para>If the port can be built with different <link
              linkend="porting-masterdir">hardcoded defaults</link> (usually
            part of the directory name in a family of ports), the
            <replaceable>-compiled.specifics</replaceable> part should state
            the compiled-in defaults (the hyphen is optional).  Examples are
            papersize and font units.</para>

          <para>The <replaceable>compiled.specifics</replaceable> part
            should be set in the <makevar>PKGNAMESUFFIX</makevar>
            variable.</para>
        </listitem>

        <listitem>
          <para>The version string should follow a dash
            (<literal>-</literal>) and be a period-separated list of
            integers and single lowercase alphabetics.  In particular,
            it is not permissible to have another dash inside the
            version string.  The only exception is the string
            <literal>pl</literal> (meaning `patchlevel'), which can be
            used <emphasis>only</emphasis> when there are no major and
            minor version numbers in the software.  If the software
            version has strings like "alpha", "beta", "rc", or "pre", take
            the first letter and put it immediately after a period.
            If the version string continues after those names, the
            numbers should follow the single alphabet without an extra
            period between them.</para>

          <para>The idea is to make it easier to sort ports by looking
            at the version string.  In particular, make sure version
            number components are always delimited by a period, and
            if the date is part of the string, use the
            <literal><replaceable>yyyy</replaceable>.<replaceable>mm</replaceable>.<replaceable>dd</replaceable></literal>
            format, not
            <literal><replaceable>dd</replaceable>.<replaceable>mm</replaceable>.<replaceable>yyyy</replaceable></literal>
            or the non-Y2K compliant
            <literal><replaceable>yy</replaceable>.<replaceable>mm</replaceable>.<replaceable>dd</replaceable></literal>
            format.</para>
        </listitem>
      </orderedlist>

      <para>Here are some (real) examples on how to convert the name
        as called by the software authors to a suitable package
        name:</para>

      <informaltable frame="none">
        <tgroup cols="6">
          <thead>
            <row>
              <entry>Distribution Name</entry>
              <entry><makevar>PKGNAMEPREFIX</makevar></entry>
              <entry><makevar>PORTNAME</makevar></entry>
              <entry><makevar>PKGNAMESUFFIX</makevar></entry>
              <entry><makevar>PORTVERSION</makevar></entry>
              <entry>Reason</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry>mule-2.2.2</entry>
              <entry>(empty)</entry>
              <entry>mule</entry>
              <entry>(empty)</entry>
              <entry>2.2.2</entry>
              <entry>No changes required</entry>
            </row>

            <row>
              <entry>XFree86-3.3.6</entry>
              <entry>(empty)</entry>
              <entry>XFree86</entry>
              <entry>(empty)</entry>
              <entry>3.3.6</entry>
              <entry>No changes required</entry>
            </row>

            <row>
              <entry>EmiClock-1.0.2</entry>
              <entry>(empty)</entry>
              <entry>emiclock</entry>
              <entry>(empty)</entry>
              <entry>1.0.2</entry>
              <entry>No uppercase names for single programs</entry>
            </row>

            <row>
              <entry>rdist-1.3alpha</entry>
              <entry>(empty)</entry>
              <entry>rdist</entry>
              <entry>(empty)</entry>
              <entry>1.3.a</entry>
              <entry>No strings like <literal>alpha</literal>
                allowed</entry>
            </row>

            <row>
              <entry>es-0.9-beta1</entry>
              <entry>(empty)</entry>
              <entry>es</entry>
              <entry>(empty)</entry>
              <entry>0.9.b1</entry>
              <entry>No strings like <literal>beta</literal>
                allowed</entry>
            </row>

            <row>
              <entry>mailman-2.0rc3</entry>
              <entry>(empty)</entry>
              <entry>mailman</entry>
              <entry>(empty)</entry>
              <entry>2.0.r3</entry>
              <entry>No strings like <literal>rc</literal>
                allowed</entry>
            </row>

            <row>
              <entry>v3.3beta021.src</entry>
              <entry>(empty)</entry>
              <entry>tiff</entry>
              <entry>(empty)</entry>
              <entry>3.3</entry>
              <entry>What the heck was that anyway?</entry>
            </row>

            <row>
              <entry>tvtwm</entry>
              <entry>(empty)</entry>
              <entry>tvtwm</entry>
              <entry>(empty)</entry>
              <entry>pl11</entry>
              <entry>Version string always required</entry>
            </row>

            <row>
              <entry>piewm</entry>
              <entry>(empty)</entry>
              <entry>piewm</entry>
              <entry>(empty)</entry>
              <entry>1.0</entry>
              <entry>Version string always required</entry>
            </row>

            <row>
              <entry>xvgr-2.10pl1</entry>
              <entry>(empty)</entry>
              <entry>xvgr</entry>
              <entry>(empty)</entry>
              <entry>2.10.1</entry>
              <entry><literal>pl</literal> allowed only when no
                major/minor version numbers</entry>
            </row>

            <row>
              <entry>gawk-2.15.6</entry>
              <entry>ja-</entry>
              <entry>gawk</entry>
              <entry>(empty)</entry>
              <entry>2.15.6</entry>
              <entry>Japanese language version</entry>
            </row>

            <row>
              <entry>psutils-1.13</entry>
              <entry>(empty)</entry>
              <entry>psutils</entry>
              <entry>-letter</entry>
              <entry>1.13</entry>
              <entry>Papersize hardcoded at package build time</entry>
            </row>

            <row>
              <entry>pkfonts</entry>
              <entry>(empty)</entry>
              <entry>pkfonts</entry>
              <entry>300</entry>
              <entry>1.0</entry>
              <entry>Package for 300dpi fonts</entry>
            </row>
          </tbody>
        </tgroup>
      </informaltable>

      <para>If there is absolutely no trace of version information in the
        original source and it is unlikely that the original author will ever
        release another version, just set the version string to
        <literal>1.0</literal> (like the piewm example above).  Otherwise, ask
        the original author or use the date string
        (<literal><replaceable>yyyy</replaceable>.<replaceable>mm</replaceable>.<replaceable>dd</replaceable></literal>)
	as the version.</para>
    </sect2>
    </sect1>

    <sect1>
      <title>Categorisation</title>

      <sect2>
        <title><makevar>CATEGORIES</makevar></title>

        <para>When a package is created, it is put under
          <filename>/usr/ports/packages/All</filename> and links are made from
          one or more subdirectories of
          <filename>/usr/ports/packages</filename>.  The names of these
          subdirectories are specified by the variable
          <makevar>CATEGORIES</makevar>.  It is intended to make life easier
          for the user when he is wading through the pile of packages on the
          FTP site or the CDROM.  Please take a look at the existing <link
            linkend="porting-categories">categories</link> and pick the ones
          that are suitable for your port.</para>

        <para>This list also determines where in the ports tree the port is
          imported.  If you put more than one category here, it is assumed
          that the port files will be put in the subdirectory with the name in
          the first category.  See the <link
            linkend="porting-categories">categories</link> section for more
          discussion about how to pick the right categories.</para>

        <para>If your port truly belongs to something that is different from
          all the existing ones, you can even create a new category name.  In
          that case, please send mail to the &a.ports; to propose a new
          category.</para>
      </sect2>

      <sect2 id="porting-categories">
        <title>Current list of categories</title>

        <para>First, this is the current list of port categories.  Those
          marked with an asterisk (<literal>*</literal>) are
          <emphasis>virtual</emphasis> categories&mdash;those that do not have
          a corresponding subdirectory in the ports tree.</para>

        <note>
          <para>For non-virtual categories, you will find a one-line
            description in the <filename>pkg/COMMENT</filename> file in that
            subdirectory (e.g.,
            <filename>archivers/pkg/COMMENT</filename>).</para>
        </note>

        <informaltable frame="none">
          <tgroup cols="2">
            <thead>
              <row>
                <entry>Category</entry>
                <entry>Description</entry>
              </row>
            </thead>

            <tbody>
              <row>
                <entry><filename>afterstep*</filename></entry>
                <entry>Ports to support the AfterStep window manager.</entry>
              </row>

              <row>
                <entry><filename>archivers</filename></entry>
                <entry>Archiving tools.</entry>
              </row>

              <row>
                <entry><filename>astro</filename></entry>
                <entry>Astronomical ports.</entry>
              </row>

              <row>
                <entry><filename>audio</filename></entry>
                <entry>Sound support.</entry>
              </row>

              <row>
                <entry><filename>benchmarks</filename></entry>
                <entry>Benchmarking utilities.</entry>
              </row>

              <row>
                <entry><filename>biology</filename></entry>
                <entry>Biology-related software.</entry>
              </row>

              <row>
                <entry><filename>cad</filename></entry>
                <entry>Computer aided design tools.</entry>
              </row>

              <row>
                <entry><filename>chinese</filename></entry>
                <entry>Chinese language support.</entry>
              </row>

              <row>
                <entry><filename>comms</filename></entry>
                <entry>Communication software.  Mostly software to talk to
                  your serial port.</entry>
              </row>

              <row>
                <entry><filename>converters</filename></entry>
                <entry>Character code converters.</entry>
              </row>

              <row>
                <entry><filename>databases</filename></entry>
                <entry>Databases.</entry>
              </row>

              <row>
                <entry><filename>deskutils</filename></entry>
                <entry>Things that used to be on the desktop before
                  computers were invented.</entry>
              </row>

              <row>
                <entry><filename>devel</filename></entry>
                <entry>Development utilities.  Do not put libraries here just
                  because they are libraries&mdash;unless they truly do not
                  belong anywhere else, they should not be in this
                  category.</entry>
              </row>

              <row>
                <entry><filename>editors</filename></entry>
                <entry>General editors.  Specialized editors go in the section
                  for those tools (e.g., a mathematical-formula editor will go
                  in <filename>math</filename>).</entry>
              </row>

              <row>
                <entry><filename>elisp*</filename></entry>
                <entry>Emacs-lisp ports.</entry>
              </row>

              <row>
                <entry><filename>emulators</filename></entry>
                <entry>Emulators for other operating systems.  Terminal
                  emulators do <emphasis>not</emphasis> belong
                  here&mdash;X-based ones should go to
                  <filename>x11</filename> and text-based ones to either
                  <filename>comms</filename> or <filename>misc</filename>,
                  depending on the exact functionality.</entry>
              </row>

              <row>
                <entry><filename>french</filename></entry>
                <entry>French language support.</entry>
              </row>

              <row>
                <entry><filename>ftp</filename></entry>
                <entry>FTP client and server utilities.  If your
                  port speaks both FTP and HTTP, put it in
                  <filename>ftp</filename> with a secondary
                  category of <filename>www</filename>.</entry>
              </row>

              <row>
                <entry><filename>games</filename></entry>
                <entry>Games.</entry>
              </row>

              <row>
                <entry><filename>german</filename></entry>
                <entry>German language support.</entry>
              </row>

              <row>
                <entry><filename>gnome*</filename></entry>
                <entry>Ports from the GNU Object Model Environment (GNOME)
                  Project.</entry>
              </row>

              <row>
                <entry><filename>graphics</filename></entry>
                <entry>Graphics utilities.</entry>
              </row>

              <row>
                <entry><filename>hebrew</filename></entry>
                <entry>Hebrew language support.</entry>
              </row>

              <row>
                <entry><filename>irc</filename></entry>
                <entry>Internet Relay Chat utilities.</entry>
              </row>

              <row>
                <entry><filename>ipv6*</filename></entry>
                <entry>IPv6 related software.</entry>
              </row>

              <row>
                <entry><filename>japanese</filename></entry>
                <entry>Japanese language support.</entry>
              </row>

              <row>
                <entry><filename>java</filename></entry>
                <entry>Java language support.</entry>
              </row>

              <row>
                <entry><filename>kde*</filename></entry>
                <entry>Ports from the K Desktop Environment (KDE)
                  Project.</entry>
              </row>

              <row>
                <entry><filename>korean</filename></entry>
                <entry>Korean language support.</entry>
              </row>

              <row>
                <entry><filename>lang</filename></entry>
                <entry>Programming languages.</entry>
              </row>

              <row>
                <entry><filename>linux*</filename></entry>
                <entry>Linux applications and support utilities.</entry>
              </row>

              <row>
                <entry><filename>mail</filename></entry>
                <entry>Mail software.</entry>
              </row>

              <row>
                <entry><filename>math</filename></entry>
                <entry>Numerical computation software and other utilities
                  for mathematics.</entry>
              </row>

              <row>
                <entry><filename>mbone</filename></entry>
                <entry>MBone applications.</entry>
              </row>

              <row>
                <entry><filename>misc</filename></entry>
                <entry>Miscellaneous utilities&mdash;basically things that
                  do not belong anywhere else.  This is the only category
                  that should not appear with any other non-virtual category.
                  If you have <literal>misc</literal> with something else in
                  your <makevar>CATEGORIES</makevar> line, that means you can
                  safely delete <literal>misc</literal> and just put the port
                  in that other subdirectory!</entry>
              </row>

              <row>
                <entry><filename>net</filename></entry>
                <entry>Miscellaneous networking software.</entry>
              </row>

              <row>
                <entry><filename>news</filename></entry>
                <entry>USENET news software.</entry>
              </row>

              <row>
                <entry><filename>offix*</filename></entry>
                <entry>Ports from the OffiX suite.</entry>
              </row>

              <row>
                <entry><filename>palm</filename></entry>
                <entry>Software support for the 3Com Palm(tm) series.</entry>
              </row>

              <row>
                <entry><filename>perl5*</filename></entry>
                <entry>Ports that require perl version 5 to run.</entry>
              </row>

              <row>
                <entry><filename>picobsd</filename></entry>
                <entry>Ports to support PicoBSD.</entry>
              </row>

              <row>
                <entry><filename>plan9*</filename></entry>
                <entry>Various programs from Plan9.</entry>
              </row>

              <row>
                <entry><filename>print</filename></entry>
                <entry>Printing software.  Desktop publishing tools
                  (previewers, etc.) belong here too.</entry>
              </row>

              <row>
                <entry><filename>python*</filename></entry>
                <entry>Software written in python.</entry>
              </row>

              <row>
                <entry><filename>ruby*</filename></entry>
                <entry>Software written in ruby.</entry>
              </row>

              <row>
                <entry><filename>russian</filename></entry>
                <entry>Russian language support.</entry>
              </row>

              <row>
                <entry><filename>science</filename></entry>
                <entry>Scientific ports that don't fit into other
                  categories such as <filename>astro</filename>,
                  <filename>biology</filename> and
                  <filename>math</filename>.</entry>
              </row>

              <row>
                <entry><filename>security</filename></entry>
                <entry>Security utilities.</entry>
              </row>

              <row>
                <entry><filename>shells</filename></entry>
                <entry>Command line shells.</entry>
              </row>

              <row>
                <entry><filename>sysutils</filename></entry>
                <entry>System utilities.</entry>
              </row>

              <row>
                <entry><filename>tcl76*</filename></entry>
                <entry>Ports that use Tcl version 7.6 to run.</entry>
              </row>

              <row>
                <entry><filename>tcl80*</filename></entry>
                <entry>Ports that use Tcl version 8.0 to run.</entry>
              </row>

              <row>
                <entry><filename>tcl81*</filename></entry>
                <entry>Ports that use Tcl version 8.1 to run.</entry>
              </row>

              <row>
                <entry><filename>tcl82*</filename></entry>
                <entry>Ports that use Tcl version 8.2 to run.</entry>
              </row>

              <row>
                <entry><filename>textproc</filename></entry>
                <entry>Text processing utilities.  It does not include
                  desktop publishing tools, which go to print/.</entry>
              </row>

              <row>
                <entry><filename>tk42*</filename></entry>
                <entry>Ports that use Tk version 4.2 to run.</entry>
              </row>

              <row>
                <entry><filename>tk80*</filename></entry>
                <entry>Ports that use Tk version 8.0 to run.</entry>
              </row>

              <row>
                <entry><filename>tk81*</filename></entry>
                <entry>Ports that use Tk version 8.1 to run.</entry>
              </row>

              <row>
                <entry><filename>tk82*</filename></entry>
                <entry>Ports that use Tk version 8.2 to run.</entry>
              </row>

              <row>
                <entry><filename>tkstep80*</filename></entry>
                <entry>Ports that use TkSTEP version 8.0 to run.</entry>
              </row>

              <row>
                <entry><filename>ukrainian</filename></entry>
                <entry>Ukrainian language support.</entry>
              </row>

              <row>
                <entry><filename>vietnamese</filename></entry>
                <entry>Vietnamese language support.</entry>
              </row>

              <row>
                <entry><filename>windowmaker*</filename></entry>
                <entry>Ports to support the WindowMaker window
                  manager</entry>
              </row>

              <row>
                <entry><filename>www</filename></entry>
                <entry>Software related to the World Wide Web.  HTML language
                  support belongs here too.</entry>
              </row>

              <row>
                <entry>x11</entry>
                <entry>The X window system and friends.  This category is only
                  for software that directly supports the window system.  Do not
                  put regular X applications here.  If your port is an X
                  application, define <makevar>USE_XLIB</makevar> (implied by
                  <makevar>USE_IMAKE</makevar>) and put it in the appropriate
                  categories.  Also, many of them go into other
                  <filename>x11-*</filename> categories (see below).</entry>
              </row>

              <row>
                <entry><filename>x11-clocks</filename></entry>
                <entry>X11 clocks.</entry>
              </row>

              <row>
                <entry><filename>x11-fm</filename></entry>
                <entry>X11 file managers.</entry>
              </row>

              <row>
                <entry><filename>x11-fonts</filename></entry>
                <entry>X11 fonts and font utilities.</entry>
              </row>

              <row>
                <entry><filename>x11-servers</filename></entry>
                <entry>X11 servers.</entry>
              </row>

              <row>
                <entry><filename>x11-toolkits</filename></entry>
                <entry>X11 toolkits.</entry>
              </row>

              <row>
                <entry><filename>x11-wm</filename></entry>
                <entry>X11 window managers.</entry>
              </row>

              <row>
                <entry><filename>zope*</filename></entry>
                <entry>Zope support.</entry>
              </row>
            </tbody>
          </tgroup>
        </informaltable>
      </sect2>

      <sect2>
        <title>Choosing the right category</title>

        <para>As many of the categories overlap, you often have to choose
          which of the categories should be the primary category of your port.
          There are several rules that govern this issue.  Here is the list of
          priorities, in decreasing order of precedence.</para>

        <itemizedlist>
          <listitem>
            <para>Language specific categories always come first.  For
              example, if your port installs Japanese X11 fonts, then your
              <makevar>CATEGORIES</makevar> line would read <literal>japanese
                x11-fonts</literal>.</para>
          </listitem>

          <listitem>
            <para>Specific categories win over less-specific ones.  For
              instance, an HTML editor should be listed as <literal>www
                editors</literal>, not the other way around.  Also, you do not
              need to list <literal>net</literal> when the port belongs to
              any of <literal>irc</literal>, <literal>mail</literal>,
              <literal>mbone</literal>, <literal>news</literal>,
              <literal>security</literal>, or <literal>www</literal>.</para>
          </listitem>

          <listitem>
            <para><literal>x11</literal> is used as a secondary category only
              when the primary category is a natural language.  In particular,
              you should not put <literal>x11</literal> in the category line
              for X applications.</para>
          </listitem>

          <listitem>
            <para><application>Emacs</application> modes should be
	      placed in the same ports category as the application
	      supported by the mode, not in
	      <filename>editors</filename>.  For example, an
	      <application>Emacs</application> mode to edit source
	      files of some programming language should go into
	      <filename>lang</filename>.
              </para>
          </listitem>

          <listitem>
            <para>If your port truly does not belong anywhere else, put it in
              <literal>misc</literal>.</para>
          </listitem>
        </itemizedlist>

        <para>If you are not sure about the category, please put a comment to
          that effect in your <command>send-pr</command> submission so we can
          discuss it before we import it.  If you are a committer, send a note
          to the &a.ports; so we can discuss it first&mdash;too often new ports are
          imported to the wrong category only to be moved right away.</para>
      </sect2>
    </sect1>

    <sect1>
      <title>The distribution files</title>

      <para>The second part of the <filename>Makefile</filename> describes the
	files that must be downloaded in order to build the port, and where
	they can be downloaded from.</para>

      <sect2>
        <title><makevar>DISTNAME</makevar></title>

        <para><makevar>DISTNAME</makevar> is the name of the port as
          called by the authors of the software.
          <makevar>DISTNAME</makevar> defaults to
          <literal>${PORTNAME}-${PORTVERSION}</literal>, so override it if necessary.
          <makevar>DISTNAME</makevar> is only used in two places.
          First, the distribution file list
          (<makevar>DISTFILES</makevar>) defaults to
          <makevar>${DISTNAME}</makevar><makevar>${EXTRACT_SUFX}</makevar>.
          Second, the distribution file is expected to extract into a
          subdirectory named <makevar>WRKSRC</makevar>, which defaults
          to <filename>work/<makevar>${DISTNAME}</makevar></filename>.</para>

	<note>
          <para><makevar>PKGNAMEPREFIX</makevar> and
            <makevar>PKGNAMESUFFIX</makevar> do not affect
            <makevar>DISTNAME</makevar>.  Also note that when
            <makevar>WRKSRC</makevar> is equal to
            <filename>work/<makevar>${PORTNAME}-${PORTVERSION}</makevar></filename>
            while the original source archive is named something other than
            <makevar>${PORTNAME}-${PORTVERSION}${EXTRACT_SUFX}</makevar>,
            you should probably leave <makevar>DISTNAME</makevar>
            alone&mdash; you are better off defining
            <makevar>DISTFILES</makevar> than having to set both
            <makevar>DISTNAME</makevar> and <makevar>WRKSRC</makevar>
            (and possibly <makevar>EXTRACT_SUFX</makevar>).</para>
	</note>
      </sect2>

      <sect2>
        <title><makevar>MASTER_SITES</makevar></title>

        <para>Record the directory part of the FTP/HTTP-URL pointing at the
          original tarball in <makevar>MASTER_SITES</makevar>.  Do not forget
          the trailing slash (<filename>/</filename>)!</para>

        <para>The <command>make</command> macros will try to use this
          specification for grabbing the distribution file with
          <makevar>FETCH</makevar> if they cannot find it already on the
          system.</para>

        <para>It is recommended that you put multiple sites on this list,
          preferably from different continents.  This will safeguard against
          wide-area network problems, and we are even planning to add support
          for automatically determining the closest master site and fetching
          from there!</para>

        <para>If the original tarball is part of one of the popular
          archives such as X-contrib, GNU, or Perl CPAN, you may be able
          refer to those sites in an easy compact form using
          <makevar>MASTER_SITE_<replaceable>*</replaceable></makevar>
          (e.g., <makevar>MASTER_SITE_XCONTRIB</makevar> and
          <makevar>MASTER_SITE_PERL_GNU</makevar>).  Simply set
          <makevar>MASTER_SITES</makevar> to one of these variables and 
          <makevar>MASTER_SITE_SUBDIR</makevar> to the path within the
          archive.  Here is an example:</para>

        <programlisting>MASTER_SITES=         ${MASTER_SITE_XCONTRIB}
MASTER_SITE_SUBDIR=   applications</programlisting>

        <para>These variables are defined in
          <filename>/usr/ports/Mk/bsd.sites.mk</filename>.  There are
          new archives added all the time, so make sure to check the
          latest version of this file before submitting a port.</para>

        <para>The user can also set the <makevar>MASTER_SITE_*</makevar>
          variables in <filename>/etc/make.conf</filename> to override our
          choices, and use their favorite mirrors of these popular archives
          instead.</para>
      </sect2>

      <sect2>
	<title><makevar>EXTRACT_SUFX</makevar></title>

	<para>If you have one distribution file, and it uses an odd suffix to
	  indicate the compression mechanism, set
	  <makevar>EXTRACT_SUFX</makevar>.</para>
	
	<para>For example, if the distribution file was named
	  <filename>foo.tgz</filename> instead of the more normal
	  <filename>foo.tar.gz</filename>, you would write:</para>

	<programlisting>DISTNAME=      foo
EXTRACT_SUFX=  .tgz</programlisting>

	<para>The <makevar>USE_BZIP2</makevar> and <makevar>USE_ZIP</makevar>
	  variables automatically set <makevar>EXTRACT_SUFX</makevar> to
	  <literal>.bz2</literal> or <literal>.zip</literal> as necessary.  If
	  neither of these are set then <makevar>EXTRACT_SUFX</makevar>
	  defaults to <literal>.tar.gz</literal>.</para>

	<para>You never need to set both <makevar>EXTRACT_SUFX</makevar> and
	  <makevar>DISTFILES</makevar>.</para>
      </sect2>

      <sect2>
	<title><makevar>DISTFILES</makevar></title>

	<para>Sometimes the names of the files to be downloaded have no
	  resemblance to the name of the port.  For example, it might be
	  called <filename>source.tar.gz</filename> or similar.  In other
	  cases the application's source code might be in several different
	  archives, all of which must be downloaded.</para>

	<para>If this is the case, set <makevar>DISTFILES</makevar> to be a
	  space separated list of all the files that must be
	  downloaded.</para>

	<programlisting>DISTFILES=     source1.tar.gz source2.tar.gz</programlisting>

	<para>If not explicitly set, <makevar>DISTFILES</makevar> defaults to
	  <literal>${DISTNAME}${EXTRACT_SUFX}</literal>.</para>
      </sect2>

      <sect2>
	<title><makevar>EXTRACT_ONLY</makevar></title>

	<para>If only some of the <makevar>DISTFILES</makevar> must be
	  extracted&mdash;for example, one of them is the source code, while
	  another is an uncompressed document&mdash;list the filenames that
	  must be extracted in <makevar>EXTRACT_ONLY</makevar>.</para>

	<programlisting>DISTFILES=     source.tar.gz manual.html
EXTRACT_ONLY=  source.tar.gz</programlisting>

	<para>If <emphasis>none</emphasis> of the <makevar>DISTFILES</makevar>
	  should be uncompressed then set <makevar>EXTRACT_ONLY</makevar> to
	  the empty string.</para>

	<programlisting>EXTRACT_ONLY=</programlisting>
      </sect2>

      <sect2 id="porting-patchfiles">
        <title><makevar>PATCHFILES</makevar></title>

        <para>If your port requires some additional patches that are available
          by FTP or HTTP, set <makevar>PATCHFILES</makevar> to the names of
          the files and <makevar>PATCH_SITES</makevar> to the URL of the
          directory that contains them (the format is the same as
          <makevar>MASTER_SITES</makevar>).</para>

        <para>If the patch is not relative to the top of the source tree
          (i.e., <makevar>WRKSRC</makevar>) because it contains some extra
          pathnames, set <makevar>PATCH_DIST_STRIP</makevar> accordingly. For
          instance, if all the pathnames in the patch have an extra
          <literal>foozolix-1.0/</literal> in front of the filenames, then set
          <literal>PATCH_DIST_STRIP=-p1</literal>.</para>

        <para>Do not worry if the patches are compressed; they will be
          decompressed automatically if the filenames end with
          <filename>.gz</filename> or <filename>.Z</filename>.</para>

        <para>If the patch is distributed with some other files, such as
          documentation, in a gzip'd tarball, you cannot just use
          <makevar>PATCHFILES</makevar>.  If that is the case, add the name
          and the location of the patch tarball to
          <makevar>DISTFILES</makevar> and <makevar>MASTER_SITES</makevar>.
          Then, use the <makevar>EXTRA_PATCHES</makevar> variable to
          point to those files and <filename>bsd.port.mk</filename>
          will automatically apply them for you.  In particular, do
          <emphasis>not</emphasis> copy patch files into the
          <makevar>PATCHDIR</makevar> directory&mdash;that directory may
          not be writable.</para>

        <note>
          <para>The tarball will have been extracted alongside the
            regular source by then, so there is no need to explicitly extract
            it if it is a regular gzip'd or compress'd tarball. If you do the
            latter, take extra care not to overwrite something that already
            exists in that directory.  Also, do not forget to add a command to
            remove the copied patch in the <maketarget>pre-clean</maketarget>
            target.</para>
        </note>
      </sect2>

      <sect2>
	<title>Multiple distribution files from different sites</title>

	<para>Some applications consist of multiple distribution files that
	  must be downloaded from a number of different sites.  For example,
	  <application>Ghostscript</application> consists of the core of the
	  program, and then a large number of driver files that are used
	  depending on the user's printer.  Some of these driver files are
	  supplied with the core, but many others must be downloaded from a
	  variety of different sites.</para>

	<para>To support this, each entry in <makevar>DISTFILES</makevar> may
	  be followed by a colon and a <quote>tag name</quote>.  Each site
	  listed in <makevar>MASTER_SITES</makevar> is then followed by a
	  colon, and the tag that indicates which distribution files should be
	  downloaded from this site.</para>

	<para>For example, consider an application with the source split in to
	  <filename>source1.tar.gz</filename> and
	  <filename>source2.tar.gz</filename>, which must be downloaded from
	  two different sites.  The port's <filename>Makefile</filename> would
	  include lines like this:</para>

	<programlisting>MASTER_SITES= ftp://ftp.example1.com/:source1 \
              ftp://ftp.example2.com/:source2
DISTFILES=    source1.tar.gz:source1 \
              source2.tar.gz:source2</programlisting>

	<para>Multiple distribution files can have the same tag.  Continuing
	  the previous example, suppose that there was a third distfile,
	  <filename>source3.tar.gz</filename>, that should be downloaded from
	  <hostid>ftp.example2.com</hostid>.  The
	  <filename>Makefile</filename> would then be written like
	  this.</para>

	<programlisting>MASTER_SITES= ftp://ftp.example1.com/:source1 \
              ftp://ftp.example2.com/:source2
DISTFILES=    source1.tar.gz:source1 \
              source2.tar.gz:source2 \
              source3.tar.gz:source2</programlisting>
      </sect2>

      <sect2>
        <title><makevar>DIST_SUBDIR</makevar></title>

        <para>Do not let your port clutter
          <filename>/usr/ports/distfiles</filename>.  If your port requires a
          lot of files to be fetched, or contains a file that has a name that
          might conflict with other ports (e.g.,
          <filename>Makefile</filename>), set <makevar>DIST_SUBDIR</makevar>
          to the name of the port (<literal>${PORTNAME}</literal> or
          <literal>${PKGNAMEPREFIX}${PORTNAME}</literal>
          should work fine).  This will change
          <makevar>DISTDIR</makevar> from the default
          <filename>/usr/ports/distfiles</filename> to
          <filename>/usr/ports/distfiles/<makevar>DIST_SUBDIR</makevar></filename>,
          and in effect puts everything that is required for your port into
          that subdirectory.</para>

        <para>It will also look at the subdirectory with the same name on the
          backup master site at <filename>ftp.FreeBSD.org</filename>.
          (Setting <makevar>DISTDIR</makevar> explicitly in your
          <makevar>Makefile</makevar> will not accomplish this, so please use
          <makevar>DIST_SUBDIR</makevar>.)</para>

        <note>
          <para>This does not affect the <makevar>MASTER_SITES</makevar> you
            define in your Makefile.</para>
        </note>
      </sect2>
    </sect1>

      <sect1>
        <title><makevar>MAINTAINER</makevar></title>

        <para>Set your mail-address here.  Please.  <!-- smiley
          --><emphasis>:-)</emphasis></para>

        <para>For a detailed description of the responsibilities of maintainers,
          refer to the <ulink url="../developers-handbook/policies.html#POLICIES-MAINTAINER">MAINTAINER on
            Makefiles</ulink> section.</para>
      </sect1>

      <sect1>
        <title>Dependencies</title>

        <para>Many ports depend on other ports.  There are five variables that
          you can use to ensure that all the required bits will be on the
          user's machine.  There are also some pre-supported dependency
          variables for common cases, plus a few more to control the behavior
          of dependencies.</para>

        <sect2>
          <title><makevar>LIB_DEPENDS</makevar></title>

          <para>This variable specifies the shared libraries this port depends
            on.  It is a list of
            <replaceable>lib</replaceable>:<replaceable>dir</replaceable><optional><replaceable>:target</replaceable></optional>
            tuples where <replaceable>lib</replaceable> is the name of the
            shared library, <replaceable>dir</replaceable> is the
            directory in which to find it in case it is not available, and
            <replaceable>target</replaceable> is the target to call in that
            directory.  For example, <programlisting> LIB_DEPENDS=
              jpeg.9:${PORTSDIR}/graphics/jpeg:install</programlisting>
            will check for a shared jpeg library with major version 9, and
            descend into the <filename>graphics/jpeg</filename> subdirectory
            of your ports tree to build and install it if it is not found.
            The <replaceable>target</replaceable> part can be omitted if it is
            equal to <makevar>DEPENDS_TARGET</makevar> (which defaults to
            <literal>install</literal>).</para>

          <note>
            <para>The <replaceable>lib</replaceable> part is an argument given
              to <command>ldconfig -r | grep -wF</command>.  There shall be no
              regular expressions in this variable.</para>
          </note>

          <para>The dependency is checked twice, once from within the
            <maketarget>extract</maketarget> target and then from within the
            <maketarget>install</maketarget> target.  Also, the name of the
            dependency is put into the package so that
            <command>pkg_add</command> will automatically install it if it is
            not on the user's system.</para>
        </sect2>

        <sect2>
          <title><makevar>RUN_DEPENDS</makevar></title>

          <para>This variable specifies executables or files this port depends
            on during run-time.  It is a list of
            <replaceable>path</replaceable>:<replaceable>dir</replaceable><optional><replaceable>:target</replaceable></optional>
            tuples where <replaceable>path</replaceable> is the name of the
            executable or file, <replaceable>dir</replaceable> is the
            directory in which to find it in case it is not available, and
            <replaceable>target</replaceable> is the target to call in that
            directory.  If <replaceable>path</replaceable> starts with a slash
            (<literal>/</literal>), it is treated as a file and its existence
            is  tested with <command>test -e</command>; otherwise, it is
            assumed to be an executable, and <command>which -s</command> is
            used to determine if the program exists in the user's search
            path.</para>

          <para>For example,</para>

            <programlisting>RUN_DEPENDS=   ${LOCALBASE}/etc/innd:${PORTSDIR}/news/inn \
               wish8.0:${PORTSDIR}/x11-toolkits/tk80</programlisting>

          <para>will check if the file or directory
            <filename>/usr/local/etc/innd</filename> exists, and build and
            install it from the <filename>news/inn</filename> subdirectory of
            the ports tree if it is not found.  It will also see if an
            executable called <command>wish8.0</command> is in your search
            path, and descend into the <filename>x11-toolkits/tk80</filename>
            subdirectory of your ports tree to build and install it if it is
            not found.</para>

          <note>
            <para>In this case, <command>innd</command> is actually an
              executable; if an executable is in a place that is not expected
              to be in a normal user's search path, you should use the full
              pathname.</para>
          </note>

          <para>The dependency is checked from within the
            <maketarget>install</maketarget> target.  Also, the name of the
            dependency is put into the  package so that
            <command>pkg_add</command> will automatically install it if it is
            not on the user's system.  The <replaceable>target</replaceable>
            part can be omitted if it is the same as
            <makevar>DEPENDS_TARGET</makevar>.</para>
        </sect2>

        <sect2>
          <title><makevar>BUILD_DEPENDS</makevar></title>

          <para>This variable specifies executables or files this port
            requires to build.  Like <makevar>RUN_DEPENDS</makevar>, it is a
            list of
            <replaceable>path</replaceable>:<replaceable>dir</replaceable><optional><replaceable>:target</replaceable></optional>
            tuples. For example, <programlisting> BUILD_DEPENDS=
              unzip:${PORTSDIR}/archivers/unzip</programlisting> will check
            for an executable called <command>unzip</command>, and descend
            into the <filename>archivers/unzip</filename> subdirectory of your
            ports tree to build and install it if it is not found.</para>

          <note>
            <para><quote>build</quote> here means everything from extraction to
              compilation.  The dependency is checked from within the
              <maketarget>extract</maketarget> target.  The
              <replaceable>target</replaceable> part can be omitted if it is
              the same as <makevar>DEPENDS_TARGET</makevar></para>
          </note>
        </sect2>

        <sect2>
          <title><makevar>FETCH_DEPENDS</makevar></title>

          <para>This variable specifies executables or files this port
            requires to fetch.  Like the previous two, it is a list of
            <replaceable>path</replaceable>:<replaceable>dir</replaceable><optional><replaceable>:target</replaceable></optional>
            tuples.  For example, <programlisting> FETCH_DEPENDS=
              ncftp2:${PORTSDIR}/net/ncftp2</programlisting> will check for an
            executable called <command>ncftp2</command>, and descend into the
            <filename>net/ncftp2</filename> subdirectory of your ports tree to
            build and install it if it is not found.</para>

          <para>The dependency is checked from within the
            <maketarget>fetch</maketarget> target.  The
            <replaceable>target</replaceable> part can be omitted if it is the
            same as <makevar>DEPENDS_TARGET</makevar>.</para>
        </sect2>

        <sect2>
          <title><makevar>DEPENDS</makevar></title>

          <para>If there is a dependency that does not fall into either of the
            above four categories, or your port requires having the source of
            the other port extracted in addition to having it installed,
            then use this variable.  This is a list of
            <replaceable>dir</replaceable><optional><replaceable>:target</replaceable></optional>,
            as there is nothing to check, unlike the previous four.  The
            <replaceable>target</replaceable> part can be omitted if it is the
            same as <makevar>DEPENDS_TARGET</makevar>.</para>
        </sect2>

        <sect2>
          <title>Common dependency variables</title>

          <para>Define <literal>USE_XLIB=yes</literal> if your port requires
            the X Window System to be installed (it is implied by
            <makevar>USE_IMAKE</makevar>).  Define
            <literal>USE_GMAKE=yes</literal> if your port requires GNU
            <command>make</command> instead of BSD <command>make</command>.
            Define <literal>USE_AUTOCONF=yes</literal> if your port requires
            GNU autoconf to be run.  Define <literal>USE_QT=yes</literal> if
            your port uses the latest qt toolkit.  Use
            <literal>USE_PERL5=yes</literal> if your port requires version 5
            of the perl language.  (The last is especially important since
            some versions of FreeBSD have perl5 as part of the base system
            while others do not.)</para>
        </sect2>

        <sect2>
          <title>Notes on dependencies</title>

          <para>As mentioned above, the default target to call when a
            dependency is required is <maketarget>DEPENDS_TARGET</maketarget>.
            It defaults to <literal>install</literal>.  This is a user
            variable; it is never defined in a port's
            <filename>Makefile</filename>.  If your port needs a special way
            to handle a dependency, use the <literal>:target</literal> part of
            the <makevar>*_DEPENDS</makevar> variables instead of redefining
            <makevar>DEPENDS_TARGET</makevar>.</para>

          <para>When you type <command>make clean</command>, its dependencies
            are automatically cleaned too.  If you do not wish this to happen,
            define the variable <makevar>NOCLEANDEPENDS</makevar> in your
            environment.</para>

          <para>To depend on another port unconditionally, use the
            variable <makevar>${NONEXISTENT}</makevar> as the first field 
            of <makevar>BUILD_DEPENDS</makevar> or
            <makevar>RUN_DEPENDS</makevar>.  Use this only when you need to
            the to get to the source of the other port.  You can often save
            compilation time by specifying the target too.  For
            instance

            <programlisting>BUILD_DEPENDS=   ${NONEXISTENT}:${PORTSDIR}/graphics/jpeg:extract</programlisting>

            will always descend to the JPEG port and extract it.</para>

          <para>Do not use <makevar>DEPENDS</makevar> unless there is no other
            way the behavior you want can be accomplished.  It will cause the
            other port to always be built (and installed, by default), and the
            dependency will go into the packages as well.  If this is really
            what you need, you should probably write it as
            <literal>BUILD_DEPENDS</literal> and
            <literal>RUN_DEPENDS</literal> instead&mdash;at least the
            intention will be clear.</para>
        </sect2>

     <sect2>
      <title>Optional dependencies</title>
      
      <para>Some large applications can be built in a number of
	configurations, adding functionality if one of a number of
	libraries or applications is available. Since not all users
	want those libraries or applications, the ports system
	provides hooks that the port author can use to decide which
	configuration should be built. Supporting these properly will
	make uses happy, and effectively provide 2 or more ports for the
	price of one.</para>
	
      <para>The easiest of these to use is
	<makevar>WITHOUT_X11</makevar>. If the port can be built both
	with and without X support, then it should normally be built
	with X support. If <makevar>WITHOUT_X11</makevar> is defined,
	then the version that does not have X support should be
	built.</para>
	
      <para>Various parts of GNOME have such knobs, though they are
	slightly more difficult to use. The variables to use in the
	<filename>Makefile</filename> are <makevar>WANT_*</makevar>
	and <makevar>HAVE_*</makevar>. If the application can be
	built both with or without one of the dependencies listed
	below, then the <filename>Makefile</filename> should set
	<makevar>WANT_PKG</makevar>, and should build the version that
	uses <makevar>PKG</makevar> if <makevar>HAVE_PKG</makevar>
	is defined.</para>
	
      <para>The <makevar>WANT_*</makevar> variables currently
	supported this way are <makevar>WANT_GLIB</makevar>,
	<makevar>WANT_GTK</makevar>, <makevar>WANT_ESOUND</makevar>,
	<makevar>WANT_IMLIB</makevar>, and
	<makevar>WANT_GNOME</makevar>.</para>
      </sect2>
    </sect1>

    <sect1>
      <title>Specifying the working directory</title>

      <para>Each port is extracted in to a working directory, which must be
	writeable.  The ports system assumes that the
	<makevar>DISTFILES</makevar> unpack in to a directory called
	<literal>${DISTNAME}</literal>.  In other words, if you have
	set:</para>

      <programlisting>PORTNAME=      foo
PORTVERSION=   1.0</programlisting>

      <para>then the port's distribution files contain a top-level directory,
	<filename>foo-1.0</filename>, and the rest of the files are located
	under that directory.</para>

      <para>There are a number of variables you can set if that is not the
	case.</para>

      <sect2>
	<title><makevar>WRKSRC</makevar></title>

	<para>The variable lists the name of the directoy that is created when
	  the application's distfiles are extracted.  If our previous example
	  extracted into a directory called <filename>foo</filename> (and not
	  <filename>foo-1.0</filename>) you would write:</para>

	<programlisting>WRKSRC=      foo</programlisting>

	<para>or possibly</para>

	<programlisting>WRKSRC=      ${PORTNAME}</programlisting>
      </sect2>

      <sect2>
	<title><makevar>NO_WRKSUBDIR</makevar></title>

	<para>If the port does not extract in to a subdirectory at all then
	  you should set <makevar>NO_WRKSUBDIR</makevar> to indicate
	  that.</para>

	<programlisting>NO_WRKSUBDIR= yes</programlisting>
      </sect2>
    </sect1>

      <sect1>
        <title>Building mechanisms</title>

        <para>If your package uses GNU <command>make</command>, set
          <literal>USE_GMAKE=yes</literal>.  If your package uses
          <command>configure</command>, set
          <literal>HAS_CONFIGURE=yes</literal>.  If your package uses GNU
          <command>configure</command>, set
          <literal>GNU_CONFIGURE=yes</literal> (this implies
          <literal>HAS_CONFIGURE</literal>).  If you want to give some extra
          arguments to <command>configure</command> (the default argument list
          <literal>--prefix=&dollar;{PREFIX}</literal> for GNU
          <command>configure</command> and empty for non-GNU
          <command>configure</command>), set those extra arguments in
          <makevar>CONFIGURE_ARGS</makevar>.  If your package uses GNU
          <command>autoconf</command>, set
          <literal>USE_AUTOCONF=yes</literal>.  This implies
          <makevar>GNU_CONFIGURE</makevar>, and will cause
          <command>autoconf</command> to be run before
          <command>configure</command>.</para>

        <para>If your package is an X application that creates
          <filename>Makefile</filename>s from <filename>Imakefile</filename>s
          using <command>imake</command>, then set
          <literal>USE_IMAKE=yes</literal>.  This will cause the configure
          stage to automatically do an <command>xmkmf -a</command>.  If the
          <option>-a</option> flag is a problem for your port, set
          <literal>XMKMF=xmkmf</literal>. If the port uses
          <command>imake</command> but does not understand the
          <maketarget>install.man</maketarget> target,
          <literal>NO_INSTALL_MANPAGES=yes</literal> should be set. In
          addition, the author of the original port should be shot. <!--
          smiley --><emphasis>:-&gt;</emphasis></para>

        <para>If your port's source <filename>Makefile</filename> has
          something else than <maketarget>all</maketarget> as the main build
          target, set <makevar>ALL_TARGET</makevar> accordingly.  Same goes
          for <maketarget>install</maketarget> and
          <makevar>INSTALL_TARGET</makevar>.</para>
      </sect1>
    </chapter>

    <chapter>
      <title>Special considerations</title>

      <para>There are some more things you have to take into account when you
        create a port.  This section explains the most common of those.</para>

      <sect1 id="porting-shlibs">
        <title>Shared Libraries</title>

        <para>If your port installs one or more shared libraries, define a
          <makevar>INSTALLS_SHLIB</makevar> make variable, which will instruct
          a <filename>bsd.port.mk</filename> to run
          <literal>&dollar;{LDCONFIG} -m</literal> on the directory where the
          new library is installed (usually
          <filename><makevar>PREFIX</makevar>/lib</filename>) during
          <maketarget>post-install</maketarget> target to register it into the
          shared library cache.  This variable, when defined, will also
          facilitate addition of an appropriate
          <literal>@exec /sbin/ldconfig -m</literal> and
          <literal>@unexec /sbin/ldconfig -R</literal> pair into your
          <filename>pkg-plist</filename> file, so that a user who installed
          the package can start using the shared library immediately and
          deinstallation will not cause the system to still believe the
          library is there.</para>

        <para>If you need, you can override default location where the new
          library is installed by defining <makevar>LDCONFIG_DIRS</makevar>
          make variable, which should contain a list of directories into which
          shared libraries are to be installed.  For example if your port
          installs shared libraries into
          <filename><makevar>PREFIX</makevar>/lib/foo</filename> and
          <filename><makevar>PREFIX</makevar>/lib/bar</filename> directories
          you could use the following in your
          <filename>Makefile</filename>:</para>

        <programlisting>INSTALLS_SHLIB= yes
LDCONFIG_DIRS=  %%PREFIX%%/lib/foo %%PREFIX%%/lib/bar</programlisting>

        <para>Note that content of <makevar>LDCONFIG_DIRS</makevar> is passed
          through &man.sed.1; just like the rest of <filename>pkg-plist</filename>,
          so <makevar>PLIST_SUB</makevar> substitutions also apply here.  It is
          recommended that you use <literal>%%PREFIX%%</literal> for
          <makevar>PREFIX</makevar>, <literal>%%LOCALBASE%%</literal> for
          <makevar>LOCALBASE</makevar> and <literal>%%X11BASE%%</literal> for
          <makevar>X11BASE</makevar>.</para>
      </sect1>

    <sect1 id="porting-restrictions">
      <title>Ports with distribution restrictions</title>

      <para>Licenses vary, and some of them place restrictions on how the
	application can be packaged, whether it can be sold for profit, and so
	on.</para> 

      <important>
	<para>It is your responsibility as a porter to read the licensing
	  terms of the software and make sure that the FreeBSD project will
	  not be held accountable for violating them by redistributing the
	  source or compiled binaries either via FTP or CDROM. If in doubt,
	  please contact the FreeBSD ports mailing list
	  <email>freebsd-ports@FreeBSD.org</email>.</para>
      </important>
      
      <para>In situations like this, the following variables can be set.  In
	addition, <filename>ports/LEGAL</filename> should also be
	updated.</para>

      <sect2>
	<title><makevar>NO_PACKAGE</makevar></title>

	<para>This variable indicates that we may not generate a binary
	  package of the application.  However, the port's
	  <makevar>DISTFILES</makevar> files may be freely distributed.</para>

	<para><makevar>NO_PACKAGE</makevar> should also be used if the binary
	  package is not generally useful, and the application should always
	  be compiled from the source code.  For example, if the application
	  has configuration information that is site specific hard coded in to
	  it at compile time.</para>

	<para><makevar>NO_PACKAGE</makevar> should be set to a string
	  describing the reason why the package should not be
	  generated.</para>
      </sect2>

      <sect2>
	<title><makevar>NO_CDROM</makevar></title>

	<para>This variable indicates that although we are allowed to generate
	  binary packages, we are not allowed to put those packages, or the
	  port's <makevar>DISTFILES</makevar>, on to CDROM for resale.  The
	  <makevar>DISTFILES</makevar> will still be available via FTP.</para>

	<para><makevar>NO_PACKAGE</makevar> and <makevar>NO_CDROM</makevar>
	  can be set simultaneously.</para>
      </sect2>

      <sect2>
	<title><makevar>RESTRICTED</makevar></title>

	<para>Set this variable if the application's license also forbids us
	  from mirroring the application's <makevar>DISTFILES</makevar> via
	  FTP.</para>

	<para>Also set this if the application's license has general
	  restrictions on who may use it.  Examples include:</para>

	<itemizedlist>
	  <listitem>
	    <para>The application is for non-commercial use only.</para>
	  </listitem>

	  <listitem>
	    <para>The application contains cryptography code which is
	      forbidden in some countries.</para>
	  </listitem>
	</itemizedlist>
      </sect2>

      <sect2>
	<title><makevar>RESTRICTED_FILES</makevar></title>

	<para>If only some of the distribution files are restricted then set
	  this variable to list them.  It defaults to <literal>${DISTFILES}
	    ${PATCHFILES}</literal>.</para>
      </sect2>
    </sect1>
    </chapter>

<!--

    <chapter>
      <title>ELF support</title>

      <para>Since FreeBSD changed to an ELF binary format shortly after
        3.0-RELEASE, we need to convert many ports that build shared
        libraries to support ELF.  Complicating this task is that a 3.0
        system can run as both ELF and a.out, and we wish to unofficially
        support the 2.2 branch as long as possible.  Below are the guidelines on
        how to convert a.out only ports to support both a.out and ELF
        compilation.</para>

      <para>Some part of this list is only applicable during the conversion,
        but will be left here for a while for reference in case you have come
        across some old port you wish to upgrade.</para>

      <sect1>
        <title>Moving a.out libraries out of the way</title>

        <para>Any a.out libraries should be moved out of
          <filename>/usr/local/lib</filename> and similar to an
          <filename>aout</filename> subdirectory.  (If you do not move them out
          of the way, ELF ports will happily overwrite a.out libraries.) The
          <maketarget>move-aout-libs</maketarget> target in the 3.0-CURRENT
          <filename>src/Makefile</filename> (called from
          <maketarget>aout-to-elf</maketarget>) will do this for you.  It will
          only move a.out libs so it is safe to call it on a system with both
          ELF and a.out libs in the standard directories.</para>
      </sect1>

      <sect1>
        <title>Format</title>

        <para>The ports tree will build packages in the format the machine is
          in.  This means a.out for 2.2 and a.out or ELF for 3.0 depending on
          what <command>`objformat`</command> returns.  Also, once users move
          a.out libraries to a subdirectory, building a.out libraries will be
          unsupported.  (I.e., it may still work if you know what you are
          doing, but you are on your own.)</para>

        <note>
          <para>If a port only works for a.out, set
            <makevar>BROKEN_ELF</makevar> to a string describing the reason
            why.  Such ports will be skipped during a build on an ELF
            system.</para>
        </note>
      </sect1>

      <sect1>
        <title><makevar>PORTOBJFORMAT</makevar></title>

        <para><filename>bsd.port.mk</filename> will set
          <makevar>PORTOBJFORMAT</makevar> to <literal>aout</literal> or
          <literal>elf</literal> and export it in the environments
          <envar>CONFIGURE_ENV</envar>, <envar>SCRIPTS_ENV</envar> and
          <envar>MAKE_ENV</envar>.  (It's always going to be
          <literal>aout</literal> in 2.2-STABLE).  It is also passed to
          <maketarget>PLIST_SUB</maketarget> as
          <literal>PORTOBJFORMAT=${PORTOBJFORMAT}</literal>.  (See comment on
          <literal>ldconfig</literal> lines below.)</para>

        <para>The variable is set using this line in
          <filename>bsd.port.mk</filename>:</para>

        <programlisting>PORTOBJFORMAT!= test -x /usr/bin/objformat && /usr/bin/objformat || echo aout</programlisting>

        <para>Ports' make processes should use this variable to decide what to
          do.  However, if the port's <filename>configure</filename> script
          already automatically detects an ELF system, it is not necessary to
          refer to <makevar>PORTOBJFORMAT</makevar>.</para>
      </sect1>

      <sect1>
        <title>Building shared libraries</title>

        <para>The following are differences in handling shared libraries for
          a.out and ELF.</para>

        <itemizedlist>
          <listitem>
            <para>Shared library versions</para>

            <para>An ELF shared library should be called
              <filename>libfoo.so.<replaceable>M</replaceable></filename>
              where <replaceable>M</replaceable> is the single version number,
              and an a.out library should be called
              <filename>libfoo.so.<replaceable>M</replaceable>.<replaceable>N</replaceable></filename>
              where <replaceable>M</replaceable> is the major version and
              <replaceable>N</replaceable> is the minor version number.
              Do not mix those; <emphasis>never</emphasis> install an ELF
              shared library called
              <filename>libfoo.so.<replaceable>N</replaceable>.<replaceable>M</replaceable></filename>
              or an a.out shared library (or symlink) called
              <filename>libfoo.so.<replaceable>N</replaceable></filename>.</para>
          </listitem>

          <listitem>
            <para>Linker command lines</para>

            <para>Assuming <command>cc -shared</command> is used rather than
              <command>ld</command> directly, the only difference is that you
              need to add
              <option>-Wl,-<replaceable>soname,libfoo.so.M</replaceable></option>
              on the command line for ELF.</para>
            </listitem>
        </itemizedlist>

        <para>You need to install a symlink from
          <filename>libfoo.so</filename> to
          <filename>libfoo.so.<replaceable>N</replaceable></filename> to make
          ELF linkers happy.  Since it should be listed in
          <filename>pkg-plist</filename> too, and it won't hurt in the a.out case
          (some ports even require the link for dynamic loading), you should
          just make this link regardless of the setting of
          <makevar>PORTOBJFORMAT</makevar>.</para>
      </sect1>

      <sect1>
        <title><makevar>LIB_DEPENDS</makevar></title>

        <para>All port Makefiles are edited to remove minor numbers from
          <makevar>LIB_DEPENDS</makevar>, and also to have the regexp support
          removed.  (E.g., <literal>foo\\.1\\.\\(33|40\\)</literal> becomes
          <literal>foo.2</literal>.)  They will be matched using <command>grep
            -wF</command>.</para>
      </sect1>

      <sect1>
        <title><filename>pkg-plist</filename></title>

        <para><filename>pkg-plist</filename> should contain the short (ELF) shlib
          names if the a.out minor number is zero, and the long (a.out) names
          otherwise.  <filename>bsd.port.mk</filename> will automatically add
          <literal>.0</literal> to the end of short shlib lines if
          <makevar>PORTOBJFORMAT</makevar> equals <literal>aout</literal>, and
          will delete the minor number from long shlib names if
          <makevar>PORTOBJFORMAT</makevar> equals
          <literal>elf</literal>.</para>

        <para>In cases where you really need to install shlibs with two
          versions on an ELF system or those with one version on an a.out
          system (for instance, ports that install compatibility libraries for
          other operating systems), define the variable
          <makevar>NO_FILTER_SHLIBS</makevar>.  This will turn off the editing
          of <filename>pkg-plist</filename> mentioned in the previous
          paragraph.</para>
      </sect1>

      <sect1>
        <title><literal>ldconfig</literal></title>

        <para>The <literal>ldconfig</literal> line in Makefiles should
          read:</para>

        <programlisting>${SETENV} OBJFORMAT=${PORTOBJFORMAT} ${LDCONFIG} -m ....</programlisting>

        <para>In <filename>pkg-plist</filename> it should read;</para>

        <programlisting>@exec /usr/bin/env OBJFORMAT=%%PORTOBJFORMAT%% /sbin/ldconfig -m ...
@unexec /usr/bin/env OBJFORMAT=%%PORTOBJFORMAT%% /sbin/ldconfig -R</programlisting>

        <para>This is to ensure that the correct <command>ldconfig</command>
          will be called depending on the format of the package, not the
          default format of the system.</para>
      </sect1>
    </chapter>

-->

    <chapter id="porting-masterdir">
      <title><makevar>MASTERDIR</makevar></title>

      <para>If your port needs to build slightly different versions of
        packages by having a variable (for instance, resolution, or paper
        size) take different values, create one subdirectory per package to
        make it easier for users to see what to do, but try to share as many
        files as possible between ports.  Typically you only need a very short
        <filename>Makefile</filename> in all but one of the directories if you
        use variables cleverly.  In the sole <filename>Makefiles</filename>,
        you can use <makevar>MASTERDIR</makevar> to specify the directory
        where the rest of the files are.  Also, use a variable as part of
        <link linkend="porting-pkgname"><makevar>PKGNAMESUFFIX</makevar></link> so
        the packages will have different names.</para>

      <para>This will be best demonstrated by an example.  This is part of
        <filename>japanese/xdvi300/Makefile</filename>;</para>

      <programlisting>PORTNAME=       xdvi
PORTVERSION=    17
PKGNAMEPREFIX=  ja-
PKGNAMESUFFIX=  ${RESOLUTION}
 :
# default
RESOLUTION?=   300
.if ${RESOLUTION} != 118 && ${RESOLUTION} != 240 && \
       ${RESOLUTION} != 300 && ${RESOLUTION} != 400
       @${ECHO} "Error: invalid value for RESOLUTION: \"${RESOLUTION}\""
       @${ECHO} "Possible values are: 118, 240, 300 (default) and 400."
       @${FALSE}
.endif</programlisting>

      <para><filename role="package">japanese/xdvi300</filename> also has all the regular
        patches, package files, etc.  If you type <command>make</command>
        there, it will take the default value for the resolution (300) and
        build the port normally.</para>

      <para>As for other resolutions, this is the <emphasis>entire</emphasis>
        <filename>xdvi118/Makefile</filename>:</para>

      <programlisting>RESOLUTION=     118
MASTERDIR=      ${.CURDIR}/../xdvi300

.include "${MASTERDIR}/Makefile"</programlisting>

      <para>(<filename>xdvi240/Makefile</filename> and
        <filename>xdvi400/Makefile</filename> are similar).  The
        <makevar>MASTERDIR</makevar> definition tells
        <filename>bsd.port.mk</filename> that the regular set of
        subdirectories like <makevar>FILESDIR</makevar> and
        <makevar>SCRIPTDIR</makevar> are to be found under
        <filename>xdvi300</filename>.  The <literal>RESOLUTION=118</literal>
        line will override the <literal>RESOLUTION=300</literal> line in
        <filename>xdvi300/Makefile</filename> and the port will be built with
        resolution set to 118.</para>
    </chapter>

    <chapter>
      <title>Shared library versions</title>

      <para>Please read our <ulink url="../developers-handbook/policies-shlib.html">policy on
        shared library versioning</ulink> to understand what to do with
        shared library versions in general.  Do not blindly assume software
        authors know what they are doing; many of them do not.  It is very
        important that these details are carefully considered, as we have
        quite a unique situation where we are trying to have dozens of
        potentially incompatible software pairs co-exist. Careless port
        imports have caused great trouble regarding shared libraries in the
        past (ever wondered why the port <filename>jpeg-6b</filename> has a
        shared library version of 9?). If in doubt, send a message to the
        &a.ports;.  Most of the time, your job ends by determining the right
        shared library version and making appropriate patches to implement
        it.</para>

<!--
      <para>However, if there is a port which is a different version of the
        same software already in the tree, the situation is much more complex.
        In short, the FreeBSD implementation does not allow the user to
        specify to the linker which version of shared library to link against
        (the linker will always pick the highest numbered version).  This
        means, if there is a <filename>libfoo.so.3.2</filename> and
        <filename>libfoo.so.4.0</filename> in the system, there is no way to
        tell the linker to link a particular application to
        <filename>libfoo.so.3.2</filename>.  It is essentially completely
        overshadowed in terms of compilation-time linkage.  In this case, the
        only solution  is to rename the <emphasis>base</emphasis> part of the
        shared library.  For instance, change
        <filename>libfoo.so.4.0</filename> to
        <filename>libfoo4.so.1.0</filename> so both version 3.2 and 4.0 can be
        linked from other ports.</para>
-->
    </chapter>

    <chapter id="porting-manpages">
      <title>Manpages</title>

      <para>The <makevar>MAN[1-9LN]</makevar> variables will automatically add
        any manpages to <filename>pkg-plist</filename> (this means you must
        <emphasis>not</emphasis> list manpages in the
        <filename>pkg-plist</filename>&mdash;see <link
          linkend="porting-plist">generating PLIST</link> for more).  It also
        makes the install stage automatically compress or uncompress manpages
        depending on the setting of <makevar>NOMANCOMPRESS</makevar> in
        <filename>/etc/make.conf</filename>.</para>

      <para>If your port tries to install multiple names for manpages using
        symlinks or hardlinks, you must use the <makevar>MLINKS</makevar>
        variable to identify these.  The link installed by your port will
        be destroyed and recreated by <filename>bsd.port.mk</filename>
        to make sure it points to the correct file.  Any manpages
        listed in MLINKS must not be listed in the
        <filename>pkg-plist</filename>.</para>

      <para>To specify whether the manpages are compressed upon installation,
        use the <makevar>MANCOMPRESSED</makevar> variable. This variable can
        take three values, <literal>yes</literal>, <literal>no</literal> and
        <literal>maybe</literal>. <literal>yes</literal> means manpages are
        already installed compressed, <literal>no</literal> means they are
        not, and <literal>maybe</literal> means the software already respects
        the value of <makevar>NOMANCOMPRESS</makevar> so
        <filename>bsd.port.mk</filename> does not have to do anything
        special.</para>

      <para><makevar>MANCOMPRESSED</makevar> is automatically set to
        <literal>yes</literal> if <makevar>USE_IMAKE</makevar> is set and
        <makevar>NO_INSTALL_MANPAGES</makevar> is not set, and to
        <literal>no</literal> otherwise.  You do not have to explicitly define
        it unless the default is not suitable for your port.</para>

      <para>If your port anchors its man tree somewhere other than
        <makevar>PREFIX</makevar>, you can use the
        <makevar>MANPREFIX</makevar> to set it.  Also, if only manpages in
        certain sections go in a non-standard place, such as some Perl modules
        ports, you can set individual man paths using
        <makevar>MAN<replaceable>sect</replaceable>PREFIX</makevar> (where
        <replaceable>sect</replaceable> is one of <literal>1-9</literal>,
        <literal>L</literal> or <literal>N</literal>).</para>

      <para>If your manpages go to language-specific subdirectories, set the
        name of the languages to <makevar>MANLANG</makevar>.  The value of
        this variable defaults to <literal>""</literal> (i.e., English
        only).</para>

      <para>Here is an example that puts it all together.</para>

      <programlisting>MAN1=          foo.1
MAN3=          bar.3
MAN4=          baz.4
MLINKS=        foo.1 alt-name.8
MANLANG=       "" ja
MAN3PREFIX=    ${PREFIX}/share/foobar
MANCOMPRESSED= yes</programlisting>

      <para>This states that six files are installed by this port;</para>

          <programlisting>${PREFIX}/man/man1/foo.1.gz
${PREFIX}/man/ja/man1/foo.1.gz
${PREFIX}/share/foobar/man/man3/bar.3.gz
${PREFIX}/share/foobar/man/ja/man3/bar.3.gz
${PREFIX}/man/man4/baz.4.gz
${PREFIX}/man/ja/man4/baz.4.gz</programlisting>

      <para>Additionally <filename>${PREFIX}/man/man8/alt-name.8.gz</filename>
        may or may not be installed by your port.  Regardless, a
        symlink will be made to join the foo(1) manpage and
        alt-name(8) manpage.</para>

    </chapter>

    <chapter id="porting-motif">
      <title>Ports that require Motif</title>

      <para>There are many programs that require a Motif library (available
        from several commercial vendors, while there is a free clone reported
        to be able to run many applications in
        <filename role="package">x11-toolkits/lesstif</filename>) to compile.  Since it is a
        popular toolkit and their licenses usually permit redistribution of
        statically linked binaries, we have made special provisions for
        handling ports that require Motif in a way that we can easily compile
        binaries linked either dynamically (for people who are compiling from
        the port) or statically (for people who distribute packages).</para>

      <sect1>
        <title><makevar>USE_MOTIF</makevar></title>

        <para>If your port requires Motif, define this variable in the
          Makefile.  This will prevent people who do not own a copy of Motif
          from even attempting to build it.</para>
      </sect1>

      <sect1>
        <title><makevar>MOTIFLIB</makevar></title>

        <para>This variable will be set by <filename>bsd.port.mk</filename> to
          be the appropriate reference to the Motif library.  Please patch the
          source to use this wherever the Motif library is referenced in the
          <filename>Makefile</filename> or
          <filename>Imakefile</filename>.</para>

        <para>There are two common cases:</para>

        <itemizedlist>
          <listitem>
            <para>If the port refers to the Motif library as
              <literal>-lXm</literal> in its <filename>Makefile</filename> or
              <filename>Imakefile</filename>, simply substitute
              <literal>&dollar;{MOTIFLIB}</literal> for it.</para>
          </listitem>

          <listitem>
            <para>If the port uses <literal>XmClientLibs</literal> in its
              <filename>Imakefile</filename>, change it to
              <literal>&dollar;{MOTIFLIB} &dollar;{XTOOLLIB}
                &dollar;{XLIB}</literal>.</para>
          </listitem>

        </itemizedlist>

        <para>Note that <makevar>MOTIFLIB</makevar> (usually) expands to
          <literal>-L/usr/X11R6/lib -lXm</literal> or
          <literal>/usr/X11R6/lib/libXm.a</literal>, so there is no need to
          add <literal>-L</literal> or <literal>-l</literal> in front.</para>
      </sect1>
    </chapter>

    <chapter>
      <title>X11 fonts</title>

      <para>If your port installs fonts for the X Window system, put them in
        <filename><makevar>X11BASE</makevar>/lib/X11/fonts/local</filename>.
        This directory is new to XFree86 release 3.3.3.  If it does not exist,
        please create it, and print out a message urging the user to update
        their XFree86 to 3.3.3 or newer, or at least add this directory to the
        font path in <filename>/etc/XF86Config</filename>.</para>
    </chapter>

    <chapter id="porting-info">
      <title>Info files</title>

      <para>The new version of texinfo (included in 2.2.2-RELEASE and onwards)
        contains a utility called <command>install-info</command> to add and
        delete entries to the <filename>dir</filename> file.  If your port
        installs any info documents, please follow these instructions so your
        port/package will correctly update the user's
        <filename><makevar>PREFIX</makevar>/info/dir</filename> file.  (Sorry
        for the length of this section, but is it imperative to weave all the
        info files together.  If done correctly, it will produce a
        <emphasis>beautiful</emphasis> listing, so please bear with me!</para>

      <para>First, this is what you (as a porter) need to know</para>

      <screen>&prompt.user; <userinput>install-info --help</userinput>
install-info [OPTION]... [INFO-FILE [DIR-FILE]]
  Install INFO-FILE in the Info directory file DIR-FILE.

Options:
--delete          Delete existing entries in INFO-FILE;
                    don't insert any new entries.
 :
--entry=TEXT      Insert TEXT as an Info directory entry.
 :
--section=SEC     Put this file's entries in section SEC of the directory. :</screen>

      <note>
        <para>This program will not actually <emphasis>install</emphasis> info
          files; it merely inserts or deletes entries in the
          <filename>dir</filename> file.</para>
      </note>

      <para>Here's a seven-step procedure to convert ports to use
        <command>install-info</command>.
        <filename role="package">editors/emacs</filename> will be used as an
        example.</para>

      <procedure>
        <step>
          <para>Look at the texinfo sources and make a patch to insert
            <literal>@dircategory</literal> and <literal>@direntry</literal>
            statements to files that do not have them.  This is part of my
            patch:</para>

          <programlisting>--- ./man/vip.texi.org  Fri Jun 16 15:31:11 1995
+++ ./man/vip.texi      Tue May 20 01:28:33 1997
@@ -2,6 +2,10 @@

 @setfilename ../info/vip
 @settitle VIP
+@dircategory The Emacs editor and associated tools
+@direntry
+* VIP: (vip).          A VI-emulation for Emacs.
+@end direntry

 @iftex
 @finalout
 :</programlisting>

          <para>The format should be self-explanatory.  Many authors leave a
            <filename>dir</filename> file in the source tree that contains all
            the entries you need, so look around before you try to write your
            own.  Also, make sure you look into related ports and make the
            section names and entry indentations consistent (we recommend that
            all entry text start at the 4th tab stop).</para>

          <note>
            <para>Note that you can put only one info entry per file because
              of a bug in <command>install-info --delete</command> that
              deletes only the first entry if you specify multiple entries in
              the <email>@direntry</email> section.</para>
          </note>

          <para>You can give the <literal>dir</literal> entries to
            <command>install-info</command> as arguments
            (<option>--section</option> and <option>--entry</option>) instead
            of patching the texinfo sources.  This probably is not a good
            idea for ports because you need to duplicate the same information
            in <emphasis>three</emphasis> places
            (<filename>Makefile</filename> and
            <literal>@exec</literal>/<literal>@unexec</literal> of
            <filename>pkg-plist</filename>; see below).  However, if you have
            Japanese (or other multibyte encoding) info files, you will have
            to use the extra arguments to <command>install-info</command>
            because <command>makeinfo</command> cannot handle those texinfo
            sources.  (See <filename>Makefile</filename> and
            <filename>pkg-plist</filename> of <filename role="package">japanese/skk</filename>
            for examples on how to do this).</para>
        </step>

        <step>
          <para>Go back to the port directory and do a <command>make clean;
              make</command> and verify that the info files are regenerated
            from the texinfo sources. Since the texinfo sources are newer than
            the info files, they should be rebuilt when you type
            <command>make</command>; but many <filename>Makefile</filename>s
            do not include correct dependencies for info files.  In
            <command>emacs</command>' case, it was necessary to patch the main
            <filename>Makefile.in</filename> so it would descend into the
            <filename>man</filename> subdirectory to rebuild the info
            pages.</para>

          <programlisting>--- ./Makefile.in.org   Mon Aug 19 21:12:19 1996
+++ ./Makefile.in       Tue Apr 15 00:15:28 1997
@@ -184,7 +184,7 @@
 # Subdirectories to make recursively.  `lisp' is not included
 # because the compiled lisp files are part of the distribution
 # and you cannot remake them without installing Emacs first.
-SUBDIR = lib-src src
+SUBDIR = lib-src src man

 # The makefiles of the directories in $SUBDIR.
 SUBDIR_MAKEFILES = lib-src/Makefile man/Makefile src/Makefile oldXMenu/Makefile
 lwlib/Makefile
--- ./man/Makefile.in.org       Thu Jun 27 15:27:19 1996
+++ ./man/Makefile.in   Tue Apr 15 00:29:52 1997
@@ -66,6 +66,7 @@
 ${srcdir}/gnu1.texi \
 ${srcdir}/glossary.texi

+all: info
 info: $(INFO_TARGETS)

 dvi: $(DVI_TARGETS)</programlisting>

          <para>The second hunk was necessary because the default target in
            the <filename>man</filename> subdir is called
            <maketarget>info</maketarget>, while the main
            <filename>Makefile</filename> wants to call
            <maketarget>all</maketarget>.  The installation of the
            <filename>info</filename> info file was also removed because we
            already have one with the same name in
            <filename>/usr/share/info</filename> (that patch is not shown
            here).</para>
        </step>

        <step>
          <para>If there is a place in the <filename>Makefile</filename> that
            is installing the <filename>dir</filename> file, delete it.  Your
            port may not be doing it.  Also, remove any commands that are
            otherwise mucking around with the <filename>dir</filename>
            file.</para>

          <programlisting>--- ./Makefile.in.org   Mon Aug 19 21:12:19 1996
+++ ./Makefile.in       Mon Apr 14 23:38:07 1997
@@ -368,14 +368,8 @@
        if [ `(cd ${srcdir}/info && /bin/pwd)` != `(cd ${infodir} && /bin/pwd)` ]; \
        then \
          (cd ${infodir};  \
-          if [ -f dir ]; then \
-            if [ ! -f dir.old ]; then mv -f dir dir.old; \
-            else mv -f dir dir.bak; fi; \
-          fi; \
           cd ${srcdir}/info ; \
-          (cd $${thisdir}; ${INSTALL_DATA} ${srcdir}/info/dir ${infodir}/dir);
\
-          (cd $${thisdir}; chmod a+r ${infodir}/dir); \
           for f in ccmode* cl* dired-x* ediff* emacs* forms* gnus* info* message* mh-e* sc* vip*; do \
             (cd $${thisdir}; \
              ${INSTALL_DATA} ${srcdir}/info/$$f ${infodir}/$$f; \
              chmod a+r ${infodir}/$$f); \</programlisting>
        </step>

        <step>
          <para>(This step is only necessary if you are modifying an existing
            port.) Take a look at <filename>pkg-plist</filename> and delete
            anything that is trying to patch up <filename>info/dir</filename>.
            They may be in <filename>pkg-install</filename> or some other
            file, so search extensively.</para>

          <programlisting>Index: pkg-plist
===================================================================
RCS file: /usr/cvs/ports/editors/emacs/pkg-plist,v
retrieving revision 1.15
diff -u -r1.15 pkg-plist
--- pkg-plist       1997/03/04 08:04:00     1.15
+++ pkg-plist       1997/04/15 06:32:12
@@ -15,9 +15,6 @@
 man/man1/emacs.1.gz
 man/man1/etags.1.gz
 man/man1/ctags.1.gz
-@unexec cp %D/info/dir %D/info/dir.bak
-info/dir
-@unexec cp %D/info/dir.bak %D/info/dir
 info/cl
 info/cl-1
 info/cl-2</programlisting>
        </step>

        <step>
          <para>Add a <maketarget>post-install</maketarget> target to the
            <filename>Makefile</filename> to call
            <maketarget>install-info</maketarget> with the installed
            info files.  (It is no longer necessary to create the
            <filename>dir</filename> file yourself;
            <command>install-info</command> automatically creates this
            file if it does not exist.)</para>

          <programlisting>Index: Makefile
===================================================================
RCS file: /usr/cvs/ports/editors/emacs/Makefile,v
retrieving revision 1.26
diff -u -r1.26 Makefile
--- Makefile    1996/11/19 13:14:40     1.26
+++ Makefile    1997/05/20 10:25:09     1.28
@@ -20,5 +20,8 @@
 post-install:
 .for file in emacs-19.34 emacsclient etags ctags b2m
        strip ${PREFIX}/bin/${file}
 .endfor
+.for info in emacs vip viper forms gnus mh-e cl sc dired-x ediff ccmode
+       install-info ${PREFIX}/info/${info} ${PREFIX}/info/dir
+.endfor

 .include &lt;bsd.port.mk&gt;</programlisting>
        </step>

        <step>
          <para>Edit <filename>pkg-plist</filename> and add equivalent
            <literal>@exec</literal> statements and also
            <literal>@unexec</literal> for
            <command>pkg_delete</command>.</para>

          <programlisting>Index: pkg-plist
===================================================================
RCS file: /usr/cvs/ports/editors/emacs/pkg-plist,v
retrieving revision 1.15
diff -u -r1.15 pkg-plist
--- pkg-plist       1997/03/04 08:04:00     1.15
+++ pkg-plist       1997/05/20 10:25:12     1.17
@@ -16,7 +14,14 @@
 man/man1/etags.1.gz
 man/man1/ctags.1.gz
+@unexec install-info --delete %D/info/emacs %D/info/dir
 :
+@unexec install-info --delete %D/info/ccmode %D/info/dir
 info/cl
 info/cl-1
@@ -87,6 +94,18 @@
 info/viper-3
 info/viper-4
+@exec install-info %D/info/emacs %D/info/dir
 :
+@exec install-info %D/info/ccmode %D/info/dir
 libexec/emacs/19.34/i386--freebsd/cvtmail
 libexec/emacs/19.34/i386--freebsd/digest-doc</programlisting>

          <note>
            <para>The <literal>@unexec install-info --delete</literal>
              commands have to be listed before the info files themselves so
              they can read the files. Also, the <literal>@exec
                install-info</literal> commands have to be after the info
              files and the <literal>@exec</literal> command that creates the
              the <filename>dir</filename> file.</para>
          </note>
        </step>

        <step>
          <para><link linkend="porting-testing">Test</link> and admire your
            work.  <!-- smiley --><emphasis>:-)</emphasis>.  Check the
            <filename>dir</filename> file before and after each step.</para>
        </step>
      </procedure>
    </chapter>

    <chapter>
      <title>The <filename>pkg-<replaceable>*</replaceable></filename> files</title>

      <para>There are some tricks we have not mentioned yet about the
        <filename>pkg-<replaceable>*</replaceable></filename> files
        that come in handy sometimes.</para>

      <sect1 id="porting-message">
        <title><filename>pkg-message</filename></title>

        <para>If you need to display a message to the installer, you may place
          the message in <filename>pkg-message</filename>.  This capability is
          often useful to display additional installation steps to be taken
          after a <command>pkg_add</command> or to display licensing
          information.</para>

        <note>
          <para>The <filename>pkg-message</filename> file does not need to be
            added to <filename>pkg-plist</filename>.  Also, it will not get
            automatically printed if the user is using the port, not the
            package, so you should probably display it from the
            <maketarget>post-install</maketarget> target yourself.</para>
        </note>
      </sect1>

      <sect1>
        <title><filename>pkg-install</filename></title>

        <para>If your port needs to execute commands when the binary package
          is installed with <command>pkg_add</command> you can do this via the
          <filename>pkg-install</filename> script.  This script will
          automatically be added to the package, and will be run twice by
          <command>pkg_add</command>.  The first time as
          <literal>&dollar;{SH} pkg-install &dollar;{PKGNAME}
          PRE-INSTALL</literal> and the second time as
          <literal>&dollar;{SH} pkg-install &dollar;{PKGNAME} POST-INSTALL</literal>. 
          <literal>&dollar;2</literal> can be tested to determine which mode
          the script is being run in.  The <envar>PKG_PREFIX</envar>
          environmental variable will be set to the package installation
          directory.  See &man.pkg.add.1; for
          additional information.</para>

        <note>
          <para>This script is not run automatically if you install the port
            with <command>make install</command>.  If you are depending on it
            being run, you will have to explicitly call it from your port's
            <filename>Makefile</filename>.</para>
        </note>
      </sect1>

      <sect1>
        <title><filename>pkg-req</filename></title>

        <para>If your port needs to determine if it should install or not, you
          can create a <filename>pkg-req</filename> <quote>requirements</quote>
          script.  It will be invoked automatically at
          installation/deinstallation time to determine whether or not
          installation/deinstallation should proceed.</para>

        <para>The script will be run at installation time by
          <command>pkg_add</command> as
          <literal>pkg-req &dollar;{PKGNAME} INSTALL</literal>.
          At deinstallation time it will be run by
          <command>pkg_delete</command> as
          <literal>pkg-req &dollar;{PKGNAME} DEINSTALL</literal>.</para>
      </sect1>

      <sect1 id="porting-plist">
        <title>Changing <filename>pkg-plist</filename> based on make
          variables</title>

        <para>Some ports, particularly the p5- ports, need to change their
          <filename>pkg-plist</filename> depending on what options they are
          configured with (or version of perl, in the case of p5- ports).  To
          make this easy, any instances in the <filename>pkg-plist</filename> of
          <literal>%%OSREL%%</literal>, <literal>%%PERL_VER%%</literal>, and
          <literal>%%PERL_VERSION%%</literal> will be substituted for
          appropriately.  The value of <literal>%%OSREL%%</literal> is the
          numeric revision of the operating system (e.g.,
          <literal>2.2.7</literal>).  <literal>%%PERL_VERSION%%</literal> is
          the full version number of perl (e.g., <literal>5.00502</literal>)
          and <literal>%%PERL_VER%%</literal> is the perl version number minus
          the patchlevel (e.g., <literal>5.005</literal>).</para>

        <para>If you need to make other substitutions, you can set the
          <makevar>PLIST_SUB</makevar> variable with a list of
          <literal><replaceable>VAR</replaceable>=<replaceable>VALUE</replaceable></literal>
          pairs and instances of
          <literal>%%<replaceable>VAR</replaceable>%%</literal>' will be
          substituted with <replaceable>VALUE</replaceable> in the
          <filename>pkg-plist</filename>.</para>

        <para>For instance, if you have a port that installs many files in a
          version-specific subdirectory, you can put something like

          <programlisting>OCTAVE_VERSION= 2.0.13
PLIST_SUB=      OCTAVE_VERSION=${OCTAVE_VERSION}</programlisting>

          in the <filename>Makefile</filename> and use
          <literal>%%OCTAVE_VERSION%%</literal> wherever the version shows up
          in <filename>pkg-plist</filename>.  That way, when you upgrade the port,
          you will not have to change dozens (or in some cases, hundreds) of
          lines in the <filename>pkg-plist</filename>.</para>

        <para>This substitution (as well as addition of any <link
          linkend="porting-manpages">manual pages</link>) will be done between
          the <maketarget>do-install</maketarget> and
          <maketarget>post-install</maketarget> targets, by reading from
          <makevar>PLIST</makevar> and writing to <makevar>TMPPLIST</makevar>
          (default:
          <filename><makevar>WRKDIR</makevar>/.PLIST.mktmp</filename>).  So if
          your port builds <makevar>PLIST</makevar> on the fly, do so in or
          before <maketarget>do-install</maketarget>.  Also, if your port
          needs to edit the resulting file, do so in
          <maketarget>post-install</maketarget> to a file named
          <makevar>TMPPLIST</makevar>.</para>
      </sect1>

      <sect1>
        <title id="porting-pkgfiles">Changing the names of
          <filename>pkg-<replaceable>*</replaceable></filename> files</title>

        <para>All the names of <filename>pkg-<replaceable>*</replaceable></filename> files
          are defined using variables so you can change them in your
          <filename>Makefile</filename> if need be.  This is especially useful
          when you are sharing the same <filename>pkg-<replaceable>*</replaceable></filename> files
          among  several ports or have to write to one of the above files (see
          <link linkend="porting-wrkdir">writing to places other than
          <makevar>WRKDIR</makevar></link> for why it is a bad idea to write
          directly into the <filename>pkg-<replaceable>*</replaceable></filename> subdirectory).</para>

        <para>Here is a list of variable names and their default
          values.  (<makevar>PKGDIR</makevar> defaults to
          <makevar>${MASTERDIR}</makevar>.)</para>

        <informaltable frame="none">
          <tgroup cols="2">
            <thead>
              <row>
                <entry>Variable</entry>
                <entry>Default value</entry>
              </row>
            </thead>

            <tbody>
              <row>
                <entry><makevar>COMMENT</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-comment</literal></entry>
              </row>

              <row>
                <entry><makevar>DESCR</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-descr</literal></entry>
              </row>

              <row>
                <entry><makevar>PLIST</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-plist</literal></entry>
              </row>

              <row>
                <entry><makevar>PKGINSTALL</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-install</literal></entry>
              </row>

              <row>
                <entry><makevar>PKGDEINSTALL</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-deinstall</literal></entry>
              </row>

              <row>
                <entry><makevar>PKGREQ</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-req</literal></entry>
              </row>

              <row>
                <entry><makevar>PKGMESSAGE</makevar></entry>
                <entry><literal>${PKGDIR}/pkg-message</literal></entry>
              </row>
            </tbody>
          </tgroup>
        </informaltable>

        <para>Please change these variables rather than overriding
          <makevar>PKG_ARGS</makevar>.  If you change
          <makevar>PKG_ARGS</makevar>, those files will not correctly be
          installed in <filename>/var/db/pkg</filename> upon install from a
          port.</para>
      </sect1>
    </chapter>

  <chapter id="testing">
    <title>Testing your port</title>

      <sect1>
        <title>Portlint</title>

        <para>Do check your work with <link
            linkend="porting-portlint"><command>portlint</command></link>
          before you submit or commit it.</para>
      </sect1>


      <sect1 id="porting-prefix">
        <title><makevar>PREFIX</makevar></title>

        <para>Do try to make your port install relative to
          <makevar>PREFIX</makevar>.  (The value of this variable will be set
          to <makevar>LOCALBASE</makevar> (default
          <filename>/usr/local</filename>), unless
          <makevar>USE_X_PREFIX</makevar> or <makevar>USE_IMAKE</makevar> is
          set, in which case it will be <makevar>X11BASE</makevar> (default
          <filename>/usr/X11R6</filename>).)</para>

        <para>Not hard-coding <filename>/usr/local</filename> or
          <filename>/usr/X11R6</filename> anywhere in the source will make the
          port much more flexible and able to cater to the needs of other
          sites.  For X ports that use <command>imake</command>, this is
          automatic; otherwise, this can often be done by simply replacing the
          occurrences of <filename>/usr/local</filename> (or
          <filename>/usr/X11R6</filename> for X ports that do not use imake)
          in the various scripts/Makefiles in the port to read
          <makevar>PREFIX</makevar>, as this variable is automatically passed
          down to every stage of the build and install processes.</para>

	<para>Make sure your application isn't installing things in 
	<filename>/usr/local</filename> instead of <makevar>PREFIX</makevar>.
	A quick test for this is to do this is:</para>

	<screen>&prompt.root; <userinput>make clean; make package PREFIX=/var/tmp/<replaceable>port-name</replaceable></userinput></screen>
	
	<para>If anything is installed outside of <makevar>PREFIX</makevar>, 
	making the package creation process will complain that it
	can't find the files.</para>

	<!-- XXX This paragraph is confusing and poorly indented. -->
	<para>This does not test for the existence of internal references,
	or correct use of <makevar>LOCALBASE</makevar> for references to
	files from other ports.  Testing the installation in
	<filename>/var/tmp/<replaceable>port-name</replaceable></filename>
	to do that that while you have it installed would do that.</para>

        <para>Do not set <makevar>USE_X_PREFIX</makevar> unless your port
          truly requires it (i.e., it links against X libs or it needs to
          reference files in <makevar>X11BASE</makevar>).</para>

        <para>The variable <makevar>PREFIX</makevar> can be reassigned in your
          <filename>Makefile</filename> or in the user's environment.
          However, it is strongly discouraged for individual ports to set this
          variable explicitly in the <filename>Makefiles</filename>.</para>

        <para>Also, refer to programs/files from other ports with the
          variables mentioned above, not explicit pathnames.  For instance, if
          your port requires a macro <literal>PAGER</literal> to be the full
          pathname of <command>less</command>, use the compiler flag:

          <programlisting>-DPAGER=\"&dollar;{PREFIX}/bin/less\"</programlisting>

          or

          <programlisting>-DPAGER=\"&dollar;{LOCALBASE}/bin/less\"</programlisting>

          if this is an X port, instead of
          <literal>-DPAGER=\"/usr/local/bin/less\"</literal>. This way it will
          have a better chance of working if the system administrator has
          moved the whole `/usr/local' tree somewhere else.</para>
      </sect1>

  </chapter>

    <chapter id="port-upgrading">
      <title>Upgrading</title>

      <para>When you notice that a port is out of date compared to the latest
        version from the original authors, first make sure you have the latest
        port.  You can find them in the
        <filename>ports/ports-current</filename> directory of the FTP mirror
        sites.  You may also use CVSup to keep your whole ports collection
        up-to-date, as described in <ulink url="../handbook/synching.html#CVSUP-CONFIG">the Handbook</ulink>.</para>

      <para>The next step is to send a mail to the maintainer, if one is
        listed in the port's <filename>Makefile</filename>.  That person may
        already be working on an upgrade, or have a reason to not upgrade the
        port right now (because of, for example, stability problems of the new
        version).</para>

      <para>If the maintainer asks you to do the upgrade or there is not any
        such person to begin with, please make the upgrade and send the
        recursive diff (either unified or context diff is fine, but port
        committers appear to prefer unified diff more) of the new and old
        ports directories to us (e.g., if your modified port directory is
        called <filename>superedit</filename> and the original as in our tree
        is <filename>superedit.bak</filename>, then send us the result of
        <command>diff -ruN superedit.bak superedit</command>).  Please examine
        the output to make sure all the changes make sense.  The best way to
        send us the diff is by including it via &man.send-pr.1; (category
        <literal>ports</literal>).  Please mention any added or deleted files
        in the message, as they have to be explicitly specified to CVS when
        doing a commit.  If the diff is more than about 20KB, please compress
        and uuencode it; otherwise, just include it in the PR as is.</para>

      <note>
        <para>Once again, please use &man.diff.1; and not &man.shar.1; to send
          updates to existing ports!</para>
      </note>
    </chapter>

    <chapter>
      <title><anchor id="porting-dads">Dos and Don'ts</title>

      <para>Here is a list of common dos and don'ts that you encounter during
        the porting process.You should check your own port against this list,
        but you can also check ports in the PR database that others have
        submitted.  Submit any comments on ports you check as described in
        <ulink url="../../articles/contributing/contrib-how.html#CONTRIB-GENERAL">Bug Reports and General
          Commentary</ulink>.  Checking ports in the PR database will both make
        it faster for us to commit them, and prove that you know what you are
        doing.</para>

      <sect1>
        <title>Strip Binaries</title>

        <para>Do strip binaries.  If the original source already strips the
          binaries, fine; otherwise you should add a
          <literal>post-install</literal> rule to it yourself.  Here is an
          example:</para>

        <programlisting>post-install:
        strip ${PREFIX}/bin/xdl</programlisting>

        <para>Use the &man.file.1; command on the installed executable to
          check whether the binary is stripped or not.  If it does not say
          <literal>not stripped</literal>, it is stripped.</para>
      </sect1>

      <sect1>
        <title>INSTALL_* macros</title>

        <para>Do use the macros provided in <filename>bsd.port.mk</filename>
          to ensure correct modes and ownership of files in your own
          <maketarget>*-install</maketarget> targets.</para>

        <itemizedlist>
          <listitem>
            <para><makevar>INSTALL_PROGRAM</makevar> is a command to install
              binary executables.</para>
          </listitem>

          <listitem>
            <para><makevar>INSTALL_SCRIPT</makevar> is a command to install
              executable scripts.</para>
          </listitem>

          <listitem>
            <para><makevar>INSTALL_DATA</makevar> is a command to install
              sharable data.</para>
          </listitem>

          <listitem>
            <para><makevar>INSTALL_MAN</makevar> is a command to install
              manpages and other documentation (it does not compress
              anything).</para>
          </listitem>
        </itemizedlist>

        <para>These are basically the <command>install</command> command with
          all the appropriate flags.  See below for an example on how to use
          them.</para>
      </sect1>

      <sect1 id="porting-wrkdir">
        <title><makevar>WRKDIR</makevar></title>

        <para>Do not write anything to files outside
          <makevar>WRKDIR</makevar>.  <makevar>WRKDIR</makevar> is the only
          place that is guaranteed to be writable during the port build (see
          <ulink url="../handbook/ports-using.html#PORTS-CD">compiling ports from CDROM</ulink> for an
          example of building ports from a read-only tree).  If you need to
          modify one of the <filename>pkg-<replaceable>*</replaceable></filename>
          files, do so by <link
          linkend="porting-pkgfiles">redefining a variable</link>, not by
          writing over it.</para>
      </sect1>

      <sect1 id="porting-wrkdirprefix">
        <title><makevar>WRKDIRPREFIX</makevar></title>

        <para>Make sure your port honors <makevar>WRKDIRPREFIX</makevar>.
          Most ports do not have to worry about this.  In particular, if you
          are referring to a <makevar>WRKDIR</makevar> of another port, note
          that the correct location is
          <filename><makevar>WRKDIRPREFIX</makevar><makevar>PORTSDIR</makevar>/<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> not <filename><makevar>PORTSDIR</makevar>/<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> or <filename><makevar>.CURDIR</makevar>/../../<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> or some such.</para>

        <para>Also, if you are defining <makevar>WRKDIR</makevar> yourself,
          make sure you prepend
          <literal>&dollar;{WRKDIRPREFIX}&dollar;{.CURDIR}</literal> in the
          front.</para>
      </sect1>

      <sect1 id="porting-versions">
        <title>Differentiating operating systems and OS versions</title>

        <para>You may come across code that needs modifications or conditional
          compilation based upon what version of Unix it is running under.  If
          you need to make such changes to the code for conditional
          compilation, make sure you make the changes as general as possible
          so that we can back-port code to FreeBSD 1.x systems and cross-port
          to other BSD systems such as 4.4BSD from CSRG, BSD/386, 386BSD,
          NetBSD, and OpenBSD.</para>

        <para>The preferred way to tell 4.3BSD/Reno (1990) and newer versions
          of the BSD code apart is by using the <literal>BSD</literal> macro
          defined in <filename>&lt;sys/param.h&gt;</filename>.  Hopefully that
          file is already included; if not, add the code:</para>

        <programlisting>#if (defined(__unix__) || defined(unix)) &amp;&amp; !defined(USG)
#include &lt;sys/param.h&gt;
#endif</programlisting>

        <para>to the proper place in the <filename>.c</filename> file.  We
          believe that every system that defines these two symbols has
          <filename>sys/param.h</filename>.  If you find a system that
          does not, we would like to know.  Please send mail to the
          &a.ports;.</para>

        <para>Another way is to use the GNU Autoconf style of doing
          this:</para>

        <programlisting>#ifdef HAVE_SYS_PARAM_H
#include &lt;sys/param.h&gt;
#endif</programlisting>

        <para>Do not forget to add <literal>-DHAVE_SYS_PARAM_H</literal> to the
          <makevar>CFLAGS</makevar> in the <filename>Makefile</filename> for
          this method.</para>

        <para>Once you have <filename>sys/param.h</filename> included, you may
          use:</para>

        <programlisting>#if (defined(BSD) &amp;&amp; (BSD &gt;= 199103))</programlisting>

        <para>to detect if the code is being compiled on a 4.3 Net2 code base
          or newer (e.g. FreeBSD 1.x, 4.3/Reno, NetBSD 0.9, 386BSD, BSD/386
          1.1 and below).</para>

        <para>Use:</para>

        <programlisting>#if (defined(BSD) &amp;&amp; (BSD &gt;= 199306))</programlisting>

        <para>to detect if the code is being compiled on a 4.4 code base or
          newer (e.g. FreeBSD 2.x, 4.4, NetBSD 1.0, BSD/386 2.0 or
          above).</para>

        <para>The value of the <literal>BSD</literal> macro is
          <literal>199506</literal> for the 4.4BSD-Lite2 code base.  This is
          stated for informational purposes only.  It should not be used to
          distinguish between versions of FreeBSD based only on 4.4-Lite vs.
          versions that have merged in changes from 4.4-Lite2.  The
          <literal>__FreeBSD__</literal> macro should be used instead.</para>

        <para>Use sparingly:</para>

        <itemizedlist>
          <listitem>
            <para><literal>__FreeBSD__</literal> is defined in all versions of
              FreeBSD.  Use it if the change you are making
              <emphasis>only</emphasis> affects FreeBSD.  Porting gotchas like
              the use of <literal>sys_errlist[]</literal> vs
              <function>strerror()</function> are Berkeleyisms, not FreeBSD
              changes.</para>
          </listitem>

          <listitem>
            <para>In FreeBSD 2.x, <literal>__FreeBSD__</literal> is defined to
              be <literal>2</literal>.  In earlier versions, it is
              <literal>1</literal>.  Later versions will bump it to match
              their major version number.</para>
          </listitem>

          <listitem>
            <para>If you need to tell the difference between a FreeBSD 1.x
              system and a FreeBSD 2.x or 3.x system, usually the right answer
              is to use the <literal>BSD</literal> macros described above.  If
              there actually is a FreeBSD specific change (such as special
              shared library options when using <command>ld</command>) then it
              is OK to use <literal>__FreeBSD__</literal> and <literal>#if
                __FreeBSD__ &gt; 1</literal> to detect a FreeBSD 2.x and later
              system.  If you need more granularity in detecting FreeBSD
              systems since 2.0-RELEASE you can use the following:</para>

            <programlisting>#if __FreeBSD__ &gt;= 2
#include &lt;osreldate.h&gt;
#    if __FreeBSD_version &gt;= 199504
         /* 2.0.5+ release specific code here */
#    endif
#endif</programlisting>
	  </listitem>
	</itemizedlist>

        <para>In the hundreds of ports that have been done, there have only
          been one or two cases where <literal>__FreeBSD__</literal> should
          have been used.  Just because an earlier port screwed up and used it
          in the wrong place does not mean you should do so too.</para>
      </sect1>

      <sect1 id="freebsd-versions">
        <title>__FreeBSD_version values</title>

		<informaltable frame="none">
		<tgroup cols="2">
		<thead>
		  <row>
		    <entry>Release</entry>
		    <entry><literal>__FreeBSD_version</literal></entry>
		  </row>
		</thead>

		<tbody>
		  <row>
		    <entry>2.0-RELEASE</entry>
		    <entry>119411</entry>
		  </row>

		  <row>
		    <entry>2.1-CURRENT</entry>
		    <entry>199501, 199503</entry>
		  </row>

		  <row>
		    <entry>2.0.5-RELEASE</entry>
		    <entry>199504</entry>
		  </row>

		  <row>
		    <entry>2.2-CURRENT before 2.1</entry>
		    <entry>199508</entry>
		  </row>

		  <row>
		    <entry>2.1.0-RELEASE</entry>
		    <entry>199511</entry>
		  </row>

		  <row>
		    <entry>2.2-CURRENT before 2.1.5</entry>
		    <entry>199512</entry>
		  </row>

		  <row>
		    <entry>2.1.5-RELEASE</entry>
		    <entry>199607</entry>
		  </row>

		  <row>
		    <entry>2.2-CURRENT before 2.1.6</entry>
		    <entry>199608</entry>
		  </row>

		  <row>
		    <entry>2.1.6-RELEASE</entry>
		    <entry>199612</entry>
		  </row>

		  <row>
		    <entry>2.1.7-RELEASE</entry>
		    <entry>199612</entry>
		  </row>

		  <row>
		    <entry>2.2-RELEASE</entry>
		    <entry>220000</entry>
		  </row>

		  <row>
		    <entry>2.2.1-RELEASE</entry>
		    <entry>220000 (no change)</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after 2.2.1-RELEASE</entry>
		    <entry>220000 (no change)</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after texinfo-3.9</entry>
		    <entry>221001</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after top</entry>
		    <entry>221002</entry>
		  </row>

		  <row>
		    <entry>2.2.2-RELEASE</entry>
		    <entry>222000</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after 2.2.2-RELEASE</entry>
		    <entry>222001</entry>
		  </row>

		  <row>
		    <entry>2.2.5-RELEASE</entry>
		    <entry>225000</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after 2.2.5-RELEASE</entry>
		    <entry>225001</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after ldconfig -R merge</entry>
		    <entry>225002</entry>
		  </row>

		  <row>
		    <entry>2.2.6-RELEASE</entry>
		    <entry>226000</entry>
		  </row>

		  <row>
		    <entry>2.2.7-RELEASE</entry>
		    <entry>227000</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after 2.2.7-RELEASE</entry>
		    <entry>227001</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after &man.semctl.2; change</entry>
		    <entry>227002</entry>
		  </row>

		  <row>
		    <entry>2.2.8-RELEASE</entry>
		    <entry>228000</entry>
		  </row>

		  <row>
		    <entry>2.2-STABLE after 2.2.8-RELEASE</entry>
		    <entry>228001</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT before &man.mount.2; change</entry>
		    <entry>300000</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT after &man.mount.2; change</entry>
		    <entry>300001</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT after &man.semctl.2; change</entry>
		    <entry>300002</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT after ioctl arg changes</entry>
		    <entry>300003</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT after ELF conversion</entry>
		    <entry>300004</entry>
		  </row>

		  <row>
		    <entry>3.0-RELEASE</entry>
		    <entry>300005</entry>
		  </row>

		  <row>
		    <entry>3.0-CURRENT after 3.0-RELEASE</entry>
		    <entry>300006</entry>
		  </row>

		  <row>
		    <entry>3.0-STABLE after 3/4 branch</entry>
		    <entry>300007</entry>
		  </row>

		  <row>
		    <entry>3.1-RELEASE</entry>
		    <entry>310000</entry>
		  </row>

		  <row>
		    <entry>3.1-STABLE after 3.1-RELEASE</entry>
		    <entry>310001</entry>
		  </row>

		  <row>
		    <entry>3.1-STABLE after C++ constructor/destructor order
		      change</entry>
		    <entry>310002</entry>
		  </row>

		  <row>
		    <entry>3.2-RELEASE</entry>
		    <entry>320000</entry>
		  </row>

		  <row>
		    <entry>3.2-STABLE</entry>
		    <entry>320001</entry>
		  </row>

		  <row>
		    <entry>3.2-STABLE after binary-incompatible IPFW and
		      socket changes</entry>
		    <entry>320002</entry>
		  </row>

		  <row>
		    <entry>3.3-RELEASE</entry>
		    <entry>330000</entry>
		  </row>

		  <row>
		    <entry>3.3-STABLE</entry>
		    <entry>330001</entry>
		  </row>

		  <row>
		    <entry>3.3-STABLE after adding &man.mkstemp.3;
		      to libc</entry>
		    <entry>330002</entry>
		  </row>

		  <row>
		    <entry>3.4-RELEASE</entry>
		    <entry>340000</entry>
		  </row>

		  <row>
		    <entry>3.4-STABLE</entry>
		    <entry>340001</entry>
		  </row>

		  <row>
		    <entry>3.5-RELEASE</entry>
		    <entry>350000</entry>
		  </row>

		  <row>
		    <entry>3.5-STABLE</entry>
		    <entry>350001</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after 3.4 branch</entry>
		    <entry>400000</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after change in dynamic linker
		      handling</entry>
		    <entry>400001</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after C++ constructor/destructor
		      order change</entry>
		    <entry>400002</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after functioning &man.dladdr.3;</entry>
		    <entry>400003</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after __deregister_frame_info dynamic
		      linker bug fix (also 4.0-CURRENT after EGCS 1.1.2
		      integration)
		    </entry>
		    <entry>400004</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after &man.suser.9; API change
		      (also 4.0-CURRENT after newbus)</entry>
		    <entry>400005</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after cdevsw registration change</entry>
		    <entry>400006</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the addition of so_cred for
		      socket level credentials</entry>
		    <entry>400007</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the addition of a poll syscall
		      wrapper to libc_r</entry>
		    <entry>400008</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the change of the kernel's
		      <literal>dev_t</literal> type to <literal>struct
		      specinfo</literal> pointer</entry>
		    <entry>400009</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after fixing a hole
		      in &man.jail.2;</entry>
		    <entry>400010</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the <literal>sigset_t</literal>
		      datatype change</entry>
		    <entry>400011</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the cutover to the GCC 2.95.2
		      compiler</entry>
		    <entry>400012</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after adding pluggable linux-mode
		      ioctl handlers</entry>
		    <entry>400013</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after importing OpenSSL</entry>
		    <entry>400014</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after the C++ ABI change in GCC 2.95.2
		      from -fvtable-thunks to -fno-vtable-thunks by
		      default</entry>
		    <entry>400015</entry>
		  </row>

		  <row>
		    <entry>4.0-CURRENT after importing OpenSSH</entry>
		    <entry>400016</entry>
		  </row>

		  <row>
		    <entry>4.0-RELEASE</entry>
		    <entry>400017</entry>
		  </row>

		  <row>
		    <entry>4.0-STABLE after 4.0-RELEASE</entry>
		    <entry>400018</entry>
		  </row>

		  <row>
		    <entry>4.0-STABLE after the introduction of delayed
		      checksums.</entry>
		    <entry>400019</entry>
		  </row>

		  <row>
		    <entry>4.0-STABLE after merging libxpg4 code into
		      libc.</entry>
		    <entry>400020</entry>
		  </row>

		  <row>
		    <entry>4.0-STABLE after upgrading Binutils to 2.10.0, ELF
		      branding changes, and tcsh in the base system.</entry>
		    <entry>400021</entry>
		  </row>

		  <row>
		    <entry>4.1-RELEASE</entry>
		    <entry>410000</entry>
		  </row>

		  <row>
		    <entry>4.1-STABLE after 4.1-RELEASE</entry>
		    <entry>410001</entry>
		  </row>

		  <row>
		    <entry>4.1-STABLE after &man.setproctitle.3; moved from
		      libutil to libc.</entry>
		    <entry>410002</entry>
		  </row>

		  <row>
		    <entry>4.1.1-RELEASE</entry>
		    <entry>411000</entry>
		  </row>

		  <row>
		    <entry>4.1.1-STABLE after 4.1.1-RELEASE</entry>
		    <entry>411001</entry>
		  </row>

		  <row>
		    <entry>4.2-RELEASE</entry>
		    <entry>420000</entry>
		  </row>

		  <row>
		    <entry>4.2-STABLE after combining libgcc.a and
		      libgcc_r.a, and associated GCC linkage changes.</entry>
		    <entry>420001</entry>
		  </row>

		  <row>
		    <entry>4.3-RELEASE</entry>
		    <entry>430000</entry>
		  </row>

		  <row>
		    <entry>4.3-STABLE after wint_t introduction.</entry>
		    <entry>430001</entry>
		  </row>

		  <row>
		    <entry>4.3-STABLE after PCI powerstate API merge.</entry>
		    <entry>430002</entry>
		  </row>

		  <row>
		    <entry>4.4-RELEASE</entry>
		    <entry>440000</entry>
		  </row>

		  <row>
		    <entry>4.4-STABLE after d_thread_t introduction.</entry>
		    <entry>440001</entry>
		  </row>

		  <row>
		    <entry>4.4-STABLE after mount structure changes (affects
		      filesystem klds).</entry>
		    <entry>440002</entry>
		  </row>

		  <row>
		    <entry>4.4-STABLE after the userland components of smbfs
		      were imported.</entry>
		    <entry>440003</entry>
		  </row>

		  <row>
		    <entry>4.5-RELEASE</entry>
		    <entry>450000</entry>
		  </row>

		  <row>
		    <entry>4.5-STABLE after the usb structure element rename.</entry>
		    <entry>450001</entry>
		  </row>

		  <row>
		    <entry>4.5-STABLE after the
		      <literal>sendmail_enable</literal> &man.rc.conf.5;
		      variable was made to take the value
		      <literal>NONE</literal>.</entry>
		    <entry>450004</entry>
		  </row>

		  <row>
		    <entry>4.5-STABLE after moving to XFree86 4 by default
		      for package builds.</entry>
		    <entry>450005</entry>
		  </row>

		  <row>
		    <entry>4.5-STABLE after accept filtering was fixed so
		      that is no longer susceptible to an easy DoS.</entry>
		    <entry>450006</entry>
		  </row>

		  <row>
		    <entry>4.6-RELEASE</entry>
		    <entry>460000</entry>
		  </row>

		  <row>
		    <entry>4.6-STABLE &man.sendfile.2; fixed to comply with
		      documentation, not to count any headers sent against
		      the amount of data to be sent from the file.</entry>
		    <entry>460001</entry>
		  </row>

		  <row>
		    <entry>4.6-STABLE after MFC of `sed -i'.</entry>
		    <entry>460101</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT</entry>
		    <entry>500000</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after adding addition ELF header fields,
		      and changing our ELF binary branding method.</entry>
		    <entry>500001</entry>
		  </row>

                  <row>
                    <entry>5.0-CURRENT after kld metadata changes.</entry>
                    <entry>500002</entry>
                  </row>

                  <row>
                    <entry>5.0-CURRENT after buf/bio changes.</entry>
                    <entry>500003</entry>
                  </row>

                  <row>
                    <entry>5.0-CURRENT after binutils upgrade.</entry>
                    <entry>500004</entry>
                  </row>

                  <row>
                    <entry>5.0-CURRENT after merging libxpg4 code into
                      libc and after TASKQ interface introduction.</entry>
                    <entry>500005</entry>
                  </row>

                  <row>
                    <entry>5.0-CURRENT after the addition of AGP
                      interfaces.</entry>
                    <entry>500006</entry>
                  </row>

		  <row>
		    <entry>5.0-CURRENT after Perl upgrade to 5.6.0</entry>
		    <entry>500007</entry>
		  </row>

                  <row>
                    <entry>5.0-CURRENT after the update of KAME code to
                      2000/07 sources.</entry>
                    <entry>500008</entry>
                  </row>

		  <row>
		    <entry>5.0-CURRENT after ether_ifattach() and
		      ether_ifdetach() changes.</entry>
		    <entry>500009</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after changing mtree defaults	
		      back to original variant, adding -L to follow 
		      symlinks.</entry>
		    <entry>500010</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after kqueue API changed.</entry>
		    <entry>500011</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after &man.setproctitle.3; moved from
		      libutil to libc.</entry>
		    <entry>500012</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the first SMPng commit.</entry>
		    <entry>500013</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after &lt;sys/select.h&gt; moved to
		      &lt;sys/selinfo.h&gt;.</entry>
		    <entry>500014</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after combining libgcc.a and
		      libgcc_r.a, and associated GCC linkage changes.</entry>
		    <entry>500015</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after change allowing libc and libc_r
		      to be linked together, deprecating -pthread
                      option.</entry>
		    <entry>500016</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after switch from struct ucred to
                      struct xucred to stabilize kernel-exported API for
                      mountd et al.</entry>
		    <entry>500017</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after addition of CPUTYPE make variable
                      for controlling CPU-specific optimizations.</entry>
		    <entry>500018</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after moving machine/ioctl_fd.h to
                      sys/fdcio.h</entry>
		    <entry>500019</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after locale names renaming.</entry>
		    <entry>500020</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after Bzip2 import.</entry>
		    <entry>500021</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after SSE support.</entry>
		    <entry>500022</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after KSE Milestone 2.</entry>
		    <entry>500023</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after d_thread_t,
		      and moving UUCP to ports.</entry>
		    <entry>500024</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after ABI change for discriptor
		      and creds passing on 64 bit platforms.</entry>
		    <entry>500025</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after moving to XFree86 4 by default for
		      package builds, and after the new libc strnstr() function
		      was added.</entry>
		    <entry>500026</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the new libc strcasestr() function
		      was added.</entry>
		    <entry>500027</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the userland components of smbfs
		      were imported.</entry>
		    <entry>500028</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the new C99 specific-width
		      integer types were added.</entry>
		    <entry>(Not incremented.)</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after a change was made in the return
		      value of sendfile(2).</entry>
		    <entry>500029</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the introduction of the
		      type <literal>fflags_t</literal>, which is the
		      appropriate size for file flags.</entry>
		    <entry>500030</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the usb structure element rename.</entry>
		    <entry>500031</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the introduction of
		      Perl 5.6.1.</entry>
		    <entry>500032</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the
		      <literal>sendmail_enable</literal> &man.rc.conf.5;
		      variable was made to take the value
		      <literal>NONE</literal>.</entry>
		    <entry>500033</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after mtx_init() grew a third argument.</entry>
		    <entry>500034</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT with Gcc 3.1.</entry>
		    <entry>500035</entry>

		  <row>
		    <entry>5.0-CURRENT without Perl in /usr/src</entry>
		    <entry>500036</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the addition of dlfunc(3)</entry>
		    <entry>500037</entry>
		  </row>

		  <row>
		    <entry>5.0-CURRENT after the types of some struct
		      sockbuf members were changed and the structure was
		      reordered.</entry>
		    <entry>500038</entry>
		  </row>

                </tbody>
              </tgroup>
            </informaltable>

        <note>
          <para>Note that 2.2-STABLE sometimes identifies itself as
            <quote>2.2.5-STABLE</quote> after the 2.2.5-RELEASE.  The pattern
            used to be year followed by the month, but we decided to change it
            to a more straightforward major/minor system starting from 2.2.
            This is because the parallel development on several branches made
            it infeasible to classify the releases simply by their real
            release dates.  If you are making a port now, you do not have to
            worry about old -CURRENTs; they are listed here just for your
            reference.</para>
        </note>
      </sect1>

      <sect1>
        <title>Writing something after
          <filename>bsd.port.mk</filename></title>

        <para>Do not write anything after the <literal>.include
            &lt;bsd.port.mk&gt;</literal> line.  It usually can be avoided by
          including <filename>bsd.port.pre.mk</filename> somewhere in the
          middle of your <filename>Makefile</filename> and
          <filename>bsd.port.post.mk</filename> at the end.</para>

        <note>
          <para>You need to include either the
            <filename>pre.mk</filename>/<filename>post.mk</filename> pair or
            <filename>bsd.port.mk</filename> only; do not mix these two.</para>
        </note>

        <para><filename>bsd.port.pre.mk</filename> only defines a few
          variables, which can be used in tests in the
          <filename>Makefile</filename>, <filename>bsd.port.post.mk</filename>
          defines the rest.</para>

        <para>Here are some important variables defined in
          <filename>bsd.port.pre.mk</filename> (this is not the complete list,
          please read <filename>bsd.port.mk</filename> for the complete
          list).</para>

        <informaltable frame="none">
          <tgroup cols="2">
            <thead>
              <row>
                <entry>Variable</entry>
                <entry>Description</entry>
              </row>
            </thead>

            <tbody>
              <row>
                <entry><makevar>ARCH</makevar></entry>
                <entry>The architecture as returned by <command>uname
                    -m</command> (e.g., <literal>i386</literal>)</entry>
              </row>

              <row>
                <entry><makevar>OPSYS</makevar></entry>
                <entry>The operating system type, as returned by
                  <command>uname -s</command> (e.g.,
                  <literal>FreeBSD</literal>)</entry>
              </row>

              <row>
                <entry><makevar>OSREL</makevar></entry>
                <entry>The release version of the operating system (e.g.,
                  <literal>2.1.5</literal> or
                  <literal>2.2.7</literal>)</entry>
              </row>

              <row>
                <entry><makevar>OSVERSION</makevar></entry>
                <entry>The numeric version of the operating system, same as
                  <link
                    linkend="freebsd-versions"><literal>__FreeBSD_version</literal></link>.</entry>
              </row>

              <row>
                <entry><makevar>PORTOBJFORMAT</makevar></entry>
                <entry>The object format of the system
                  (<literal>aout</literal> or <literal>elf</literal>)</entry>
              </row>

              <row>
                <entry><makevar>LOCALBASE</makevar></entry>
                <entry>The base of the <quote>local</quote> tree (e.g.,
                  <literal>/usr/local/</literal>)</entry>
              </row>

              <row>
                <entry><makevar>X11BASE</makevar></entry>
                <entry>The base of the <quote>X11</quote> tree (e.g.,
                  <literal>/usr/X11R6</literal>)</entry>
              </row>

              <row>
                <entry><makevar>PREFIX</makevar></entry>
                <entry>Where the port installs itself (see <link
                    linkend="porting-prefix">more on
                    <makevar>PREFIX</makevar></link>).</entry>
              </row>
            </tbody>
          </tgroup>
        </informaltable>

        <note>
          <para>If you have to define the variables
            <makevar>USE_IMAKE</makevar>, <makevar>USE_X_PREFIX</makevar>, or
            <makevar>MASTERDIR</makevar>, do so before including
            <filename>bsd.port.pre.mk</filename>.</para>
        </note>

        <para>Here are some examples of things you can write after
          <filename>bsd.port.pre.mk</filename>:</para>

        <programlisting># no need to compile lang/perl5 if perl5 is already in system
.if ${OSVERSION} > 300003
BROKEN= perl is in system
.endif

# only one shlib version number for ELF
.if ${PORTOBJFORMAT} == "elf"
TCL_LIB_FILE=  ${TCL_LIB}.${SHLIB_MAJOR}
.else
TCL_LIB_FILE=  ${TCL_LIB}.${SHLIB_MAJOR}.${SHLIB_MINOR}
.endif

# software already makes link for ELF, but not for a.out
post-install:
.if ${PORTOBJFORMAT} == "aout"
       ${LN} -sf liblinpack.so.1.0 ${PREFIX}/lib/liblinpack.so
.endif</programlisting>
      </sect1>

      <sect1>
        <title>Install additional documentation</title>

        <para>If your software has some documentation other than the standard
          man and info pages that you think is useful for the user, install it
          under <filename><makevar>PREFIX</makevar>/share/doc</filename>.
          This can be done, like the previous item, in the
          <maketarget>post-install</maketarget> target.</para>

        <para>Create a new directory for your port.  The directory name should
          reflect what the port is.  This usually means
          <makevar>PORTNAME</makevar>. However, if you
          think the user might want different versions of the port to be
          installed at the same time, you can use the whole
          <makevar>PKGNAME</makevar>.</para>

        <para>Make the installation dependent to the variable
          <makevar>NOPORTDOCS</makevar> so that users can disable it in
          <filename>/etc/make.conf</filename>, like this:</para>

        <programlisting>post-install:
.if !defined(NOPORTDOCS)
        ${MKDIR} ${PREFIX}/share/doc/xv
        ${INSTALL_MAN} ${WRKSRC}/docs/xvdocs.ps ${PREFIX}/share/doc/xv
.endif</programlisting>

	<para>All documentation files and directories installed should
	  be included in <filename>pkg-plist</filename> with the
	  <literal>%%PORTDOCS%%</literal> prefix, for example:</para>

	<programlisting>%%PORTDOCS%%share/doc/pure-ftpd/AUTHORS
%%PORTDOCS%%share/doc/pure-ftpd/CONTACT
%%PORTDOCS%%@dirrm share/doc/pure-ftpd</programlisting>

        <para>You can also use the <filename>pkg-message</filename> file to
          display messages upon installation.  See the <link
          linkend="porting-message">using
          <filename>pkg-message</filename></link> section for
          details.</para>

        <note>
          <para><filename>pkg-message</filename> does not need to be added to
            <filename>pkg-plist</filename>.</para>
        </note>
      </sect1>

      <sect1>
        <title>Subdirectories</title>

        <para>Try to let the port put things in the right subdirectories of
          <makevar>PREFIX</makevar>.  Some ports lump everything and put it in
          the subdirectory with the port's name, which is incorrect.  Also,
          many ports put everything except binaries, header files and manual
          pages in the a subdirectory of <filename>lib</filename>, which does
          not bode well with the BSD paradigm.  Many of the files should be
          moved to one of the following: <filename>etc</filename>
          (setup/configuration files), <filename>libexec</filename>
          (executables started internally), <filename>sbin</filename>
          (executables for superusers/managers), <filename>info</filename>
          (documentation for info browser) or  <filename>share</filename>
          (architecture independent files).  See man &man.hier.7; for details,
          the rules governing
          <filename>/usr</filename> pretty much apply to
          <filename>/usr/local</filename> too.  The exception are ports
          dealing with USENET <quote>news</quote>.  They may use
          <filename><makevar>PREFIX</makevar>/news</filename> as a destination
          for their files.</para>
      </sect1>

      <sect1 id="porting-cleaning">
        <title>Cleaning up empty directories</title>

        <para>Do make your ports clean up after themselves when they are
          deinstalled.  This is usually accomplished by adding
          <literal>@dirrm</literal> lines for all directories that are
          specifically created by the port.  You need to delete subdirectories
          before you can delete parent directories.</para>

        <programlisting> :
lib/X11/oneko/pixmaps/cat.xpm
lib/X11/oneko/sounds/cat.au
 :
@dirrm lib/X11/oneko/pixmaps
@dirrm lib/X11/oneko/sounds
@dirrm lib/X11/oneko</programlisting>

        <para>However, sometimes <literal>@dirrm</literal> will give you
          errors because other ports also share the same subdirectory.  You
          can call <command>rmdir</command> from <literal>@unexec</literal> to
          remove only empty directories without warning.</para>

        <programlisting>@unexec rmdir %D/share/doc/gimp 2>/dev/null || true</programlisting>

        <para>This will neither print any error messages nor cause
          <command>pkg_delete</command> to exit abnormally even if
          <filename><makevar>PREFIX</makevar>/share/doc/gimp</filename> is not
          empty due to other ports installing some files in there.</para>
      </sect1>

      <sect1>
        <title>UIDs</title>

        <para>If your port requires a certain user to be on the installed
          system, let the <filename>pkg-install</filename> script call
          <command>pw</command> to create it automatically.  Look at
          <filename role="package">net/cvsup-mirror</filename> for an example.</para>

        <para>If your port must use the same user/group ID number when it is
          installed as a binary package as when it was compiled, then you must
          choose a free UID from 50 to 999 and register it below.  Look at
          <filename role="package">japanese/Wnn</filename> for an example.</para>

        <para>Make sure you do not use a UID already used by the system or
          other ports.  This is the current list of UIDs between 50 and
          999.</para>

        <programlisting>majordom:*:54:54:Majordomo Pseudo User:/usr/local/majordomo:/nonexistent
cyrus:*:60:60:the cyrus mail server:/nonexistent:/nonexistent
gnats:*:61:1:GNATS database owner:/usr/local/share/gnats/gnats-db:/bin/sh
uucp:*:66:66:UUCP pseudo-user:/var/spool/uucppublic:/usr/libexec/uucp/uucico
xten:*:67:67:X-10 daemon:/usr/local/xten:/nonexistent
pop:*:68:6:Post Office Owner (popper):/nonexistent:/sbin/nologin
wnn:*:69:7:Wnn:/nonexistent:/nonexistent
pgsql:*:70:70:PostgreSQL pseudo-user:/usr/local/pgsql:/bin/sh
ircd:*:72:72:IRCd hybrid:/nonexistent:/nonexistent
ifmail:*:75:66:Ifmail user:/nonexistent:/nonexistent
www:*:80:80:World Wide Web Owner:/nonexistent:/sbin/nologin
alias:*:81:81:QMail user:/var/qmail/alias:/nonexistent
qmaill:*:83:81:QMail user:/var/qmail:/nonexistent
qmaild:*:82:81:QMail user:/var/qmail:/nonexistent
qmailq:*:85:82:QMail user:/var/qmail:/nonexistent
qmails:*:87:82:QMail user:/var/qmail:/nonexistent
qmailp:*:84:81:QMail user:/var/qmail:/nonexistent
qmailr:*:86:82:QMail user:/var/qmail:/nonexistent
msql:*:87:87:mSQL-2 pseudo-user:/var/db/msqldb:/bin/sh
mysql:*:88:88:MySQL Daemon:/var/db/mysql:/sbin/nologin
vpopmail:*:89:89::0:0:User &:/usr/local/vpopmail:/nonexistent
smmsp:*:90:90:Sendmail Queue:/nonexistent:/nonexistent
mailman:*:91:91:Mailman User:/usr/local/mailman:/sbin/nologin
drweb:*:426:426:Dr.Web Mail Scanner:/nonexistent:/sbin/nologin</programlisting>

        <para>Please include a notice when you submit a port (or an upgrade)
          that reserves a new UID or GID in this range.  This allows us to
          keep the list of reserved IDs up to date.</para>
      </sect1>

      <sect1>
        <title>Do things rationally</title>

        <para>The <filename>Makefile</filename> should do things simply and
          reasonably.  If you can make it a couple of lines shorter or more
          readable, then do so.  Examples include using a make
          <literal>.if</literal> construct instead of a shell
          <literal>if</literal> construct, not redefining
          <maketarget>do-extract</maketarget> if you can redefine
          <makevar>EXTRACT*</makevar> instead, and using
          <makevar>GNU_CONFIGURE</makevar> instead of <literal>CONFIGURE_ARGS
            += --prefix=&dollar;{PREFIX}</literal>.</para>
      </sect1>

      <sect1>
        <title>Respect <makevar>CFLAGS</makevar></title>

        <para>The port should respect the <makevar>CFLAGS</makevar> variable.
          If it does not, please add <literal>NO_PACKAGE=ignores
            cflags</literal> to the <filename>Makefile</filename>.</para>

	<para>An example of a <filename>Makefile</filename> respecting
	  the <makevar>CFLAGS</makevar> variable follows.  Note the
	  <makevar>+=</makevar>:</para>

	<programlisting>CFLAGS += -Wall -Werror</programlisting>

	<para>Here is an example which does not respect the
	  <makevar>CFLAGS</makevar> variable:</para>

	<programlisting>CFLAGS = -Wall -Werror</programlisting>

	<para>The <makevar>CFLAGS</makevar> variable is defined on
	  FreeBSD systems in <filename>/etc/make.conf</filename>.  The
	  first example appends additional flags to the
	  <makevar>CFLAGS</makevar> variable, preserving any system-wide
	  definitions.  The second example clobbers anything previously
	  defined.</para>
      </sect1>

      <sect1>
        <title>Configuration files</title>

        <para>If your port requires some configuration files in
          <filename><makevar>PREFIX</makevar>/etc</filename>, do
          <emphasis>not</emphasis> just install them and list them in
          <filename>pkg-plist</filename>.  That will cause
          <command>pkg_delete</command> to delete files carefully edited by
          the user and a new installation to wipe them out.</para>

        <para>Instead, install sample files with a suffix
          (<filename><replaceable>filename</replaceable>.sample</filename>
          will work well) and print out a <link
            linkend="porting-message">message</link> pointing out that the
          user has to copy and edit the file before the software can be made
          to work.</para>
      </sect1>

      <sect1>
        <title>Feedback</title>

        <para>Do send applicable changes/patches to the original
          author/maintainer for inclusion in next release of the code.  This
          will only make your job that much easier for the next
          release.</para>
      </sect1>

      <sect1>
        <title><filename>README.html</filename></title>

        <para>Do not include the <filename>README.html</filename> file.  This
          file is not part of the cvs collection but is generated using the
          <command>make readme</command> command.
        </para>
      </sect1>

      <sect1>
        <title>Miscellanea</title>

        <para>The files <filename>pkg-comment</filename>,
          <filename>pkg-descr</filename>, and <filename>pkg-plist</filename>
          should each be double-checked.  If you are reviewing a port and feel
          they can be worded better, do so.</para>

        <para>Do not copy more copies of the GNU General Public License into
          our system, please.</para>

        <para>Please be careful to note any legal issues! Do not let us
          illegally distribute software!</para>
      </sect1>

      <sect1>
        <title>If you are stuck&hellip;</title>

        <para>Do look at existing examples and the
          <filename>bsd.port.mk</filename> file before asking us questions!
          <!-- smiley --><emphasis>;-)</emphasis></para>

        <para>Do ask us questions if you have any trouble! Do not just beat
          your head against a wall! <!-- smiley
          --><emphasis>:-)</emphasis></para>
      </sect1>
    </chapter>

    <chapter id="porting-samplem">
      <title>A Sample <filename>Makefile</filename></title>

      <para>Here is a sample <filename>Makefile</filename> that you can use to
        create a new port.  Make sure you remove all the extra comments (ones
        between brackets)!</para>

      <para>It is recommended that you follow this format (ordering of
        variables, empty lines between sections, etc.).  This format is
        designed so that the most important information is easy to locate.  We
        recommend that you use <link
          linkend="porting-portlint">portlint</link> to check the
        <filename>Makefile</filename>.</para>

      <programlisting>[the header...just to make it easier for us to identify the ports.]
# New ports collection makefile for:   xdvi
[the "version required" line is only needed when the PORTVERSION
 variable is not specific enough to describe the port.]
# Date created:                26 May 1995
[this is the person who did the original port to FreeBSD, in particular, the
person who wrote the first version of this Makefile.  Remember, this should
not be changed when upgrading the port later.]
# Whom:                        Satoshi Asami &lt;asami@FreeBSD.org&gt;
#
# &dollar;FreeBSD&dollar;
[ ^^^^^^^^^ This will be automatically replaced with RCS ID string by CVS
when it is committed to our repository.  If upgrading a port, do not alter
this line back to "&dollar;FreeBSD&dollar;".  CVS deals with it automatically.]
#

[section to describe the port itself and the master site - PORTNAME
 and PORTVERSION are always first, followed by CATEGORIES,
 and then MASTER_SITES, which can be followed by MASTER_SITE_SUBDIR.
 PKGNAMEPREFIX and PKGNAMESUFFIX, if needed, will be after that.
 Then comes DISTNAME, EXTRACT_SUFX and/or DISTFILES, and then
 EXTRACT_ONLY, as necessary.]
PORTNAME=      xdvi
PORTVERSION=   18.2
CATEGORIES=    print
[do not forget the trailing slash ("/")!
 if you are not using MASTER_SITE_* macros]
MASTER_SITES=  ${MASTER_SITE_XCONTRIB}
MASTER_SITE_SUBDIR= applications
PKGNAMEPREFIX= ja-
DISTNAME=      xdvi-pl18
[set this if the source is not in the standard ".tar.gz" form]
EXTRACT_SUFX=  .tar.Z

[section for distributed patches -- can be empty]
PATCH_SITES=   ftp://ftp.sra.co.jp/pub/X11/japanese/
PATCHFILES=    xdvi-18.patch1.gz xdvi-18.patch2.gz

[maintainer; *mandatory*!  This is the person (preferably with commit
 privileges) whom a user can contact for questions and bug reports - this
 person should be the porter or someone who can forward questions to the
 original porter reasonably promptly.  If you really do not want to have
 your address here, set it to "ports@FreeBSD.org".]
MAINTAINER=    asami@FreeBSD.org

[dependencies -- can be empty]
RUN_DEPENDS=   gs:${PORTSDIR}/print/ghostscript
LIB_DEPENDS=   Xpm.5:${PORTSDIR}/graphics/xpm

[this section is for other standard bsd.port.mk variables that do not
 belong to any of the above]
[If it asks questions during configure, build, install...]
IS_INTERACTIVE=        yes
[If it extracts to a directory other than ${DISTNAME}...]
WRKSRC=                ${WRKDIR}/xdvi-new
[If the distributed patches were not made relative to ${WRKSRC}, you
 may need to tweak this]
PATCH_DIST_STRIP=      -p1
[If it requires a "configure" script generated by GNU autoconf to be run]
GNU_CONFIGURE= yes
[If it requires GNU make, not /usr/bin/make, to build...]
USE_GMAKE=     yes
[If it is an X application and requires "xmkmf -a" to be run...]
USE_IMAKE=     yes
[et cetera.]

[non-standard variables to be used in the rules below]
MY_FAVORITE_RESPONSE=  "yeah, right"

[then the special rules, in the order they are called]
pre-fetch:
        i go fetch something, yeah

post-patch:
        i need to do something after patch, great

pre-install:
        and then some more stuff before installing, wow

[and then the epilogue]
.include &lt;bsd.port.mk&gt;</programlisting>
    </chapter>

    <chapter id="porting-autoplist">
      <title>Automated package list creation</title>

      <para>First, make sure your port is almost complete, with only
        <filename>pkg-plist</filename> missing.  Create an empty
        <filename>pkg-plist</filename>.</para>

      <screen>&prompt.root; <userinput>touch pkg-plist</userinput></screen>

      <para>Next, create a new set of directories which your port can be
        installed, and install any dependencies.</para>

      <screen>&prompt.root; <userinput>mkdir /var/tmp/<replaceable>port-name</replaceable></userinput>
&prompt.root; <userinput>mtree -U -f /etc/mtree/BSD.local.dist -d -e -p /var/tmp/<replaceable>port-name</replaceable></userinput>
&prompt.root; <userinput>make depends PREFIX=/var/tmp/<replaceable>port-name</replaceable></userinput></screen>

      <para>Store the directory structure in a new file.</para>

      <screen>&prompt.root; <userinput>(cd /var/tmp/<replaceable>port-name</replaceable> && find -d * -type d) &gt; OLD-DIRS</userinput></screen>

      <para>If your port honors <makevar>PREFIX</makevar> (which it should)
        you can then install the port and create the package list.</para>

      <screen>&prompt.root; <userinput>make install PREFIX=/var/tmp/<replaceable>port-name</replaceable></userinput>
&prompt.root; <userinput>(cd /var/tmp/<replaceable>port-name</replaceable> && find -d * \! -type d) &gt; pkg-plist</userinput></screen>

      <para>You must also add any newly created directories to the packing
        list.</para>

      <screen>&prompt.root; <userinput>(cd /var/tmp/<replaceable>port-name && find -d * -type d) | comm -13 OLD-DIRS - | sed -e 's#^#@dirrm #' &gt;&gt; pkg-plist</replaceable></userinput></screen>

      <para>Finally, you need to tidy up the packing list by hand; it isn't
        <emphasis>all</emphasis> automated.  Manual pages should be listed in
        the port's <filename>Makefile</filename> under
        <makevar>MAN<replaceable>n</replaceable></makevar>, and not in the
        package list.  User configuration files should be removed, or
        installed as
        <filename><replaceable>filename</replaceable>.sample</filename>.
        The <filename>info/dir</filename> file should not be listed
        and appropriate <filename>install-info</filename> lines should
        be added as noted in the <link linkend="porting-info">info
        files</link> section.  Any
        libraries installed by the port should be listed as specified in the
        <link linkend="porting-shlibs">shared libraries</link> section.</para>
    </chapter>

    <chapter>
      <title>Changes to this document and the ports system</title>

      <para>If you maintain a lot of ports, you should consider following the
        &a.ports;.  Important changes to the way ports work will be announced
        there.  You can always find more detailed information on the latest
        changes by looking at <ulink
          url="http://www.FreeBSD.org/cgi/cvsweb.cgi/ports/Mk/bsd.port.mk"> the
          bsd.port.mk CVS log</ulink>.</para>

      <para>Other resources to assist port maintainers include a list of
	<ulink url="http://bento.FreeBSD.org/">package building logs and
	errors </ulink> and the <ulink
	  url="http://people.FreeBSD.org/~fenner/portsurvey/">FreeBSD
	  Ports distfiles survey</ulink>.</para>
    </chapter>
</book>

<!--
     Local Variables:
     mode: sgml
     sgml-indent-data: t
     sgml-omittag: nil
     sgml-always-quote-attributes: t
     End:
-->