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
|
<!-- $Id: porting.sgml,v 1.124 1999-01-28 12:07:00 asami Exp $ -->
<!-- The FreeBSD Documentation Project -->
<sect><heading>Making a port yourself<label id="porting"></heading>
<p><em>Contributed by &a.jkh;, &a.gpalmer;, &a.asami;, &a.obrien; and
&a.hoek;.<newline>28 August 1996.</em>
<p>So, now you are interested in making your own port? Great! <tt/:)/
<p>What follows are some guidelines for creating a new port for
FreeBSD. The bulk of the work is done by
<tt>/usr/share/mk/bsd.port.mk</tt>, which all port Makefiles include.
Please refer to that file for more details on the inner workings of
the ports collection. Even if you don't hack Makefiles daily, it is
well commented, and you will still gain much knowledge from it.
<p>Note: Only a fraction of the overridable variables
(<tt>${..}</tt>) are mentioned in this document. Most (if not
all) are documented at the start of <tt>bsd.port.mk</tt>. This file
uses a non-standard tab setting. <tt>Emacs</tt> and <tt>Vim</tt>
should recognize the setting on loading the file. <tt>vi</tt> or
<tt>ex</tt> can be set to using the correct value by typing `<tt>:set
tabstop=4</tt>' once the file has been loaded.
<sect1>
<heading>Quick Porting</heading>
<p>This section tells you how to do a quick port. In many
cases, it is not enough, but we will see.
<p>First, get the original tarball and put it into
<tt>${DISTDIR}</tt>, which defaults to
<tt>/usr/ports/distfiles</tt>.
<p>Note: 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.
<sect2>
<heading>Writing the Makefile</heading>
<p>The minimal <tt>Makefile</tt> would look something like this:
<tscreen><verb>
# New ports collection makefile for: oneko
# Version required: 1.1b
# Date created: 5 December 1994
# Whom: asami
#
# $Id$
#
DISTNAME= oneko-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 <bsd.port.mk>
</verb></tscreen>
<p>See if you can figure it out. Do not worry about the contents
of the <tt>$Id$</tt> 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 <ref
id="porting:samplem" name="sample Makefile"> section.
<sect2>
<heading>Writing the description files</heading>
<p>There are three description files that are
required for any port, whether they actually package or not.
They are <tt>COMMENT</tt>, <tt>DESCR</tt>, and
<tt>PLIST</tt>, and reside in the <tt>pkg</tt> subdirectory.
<sect3>
<heading>COMMENT</heading>
<p>This is the one-line description of the port. <em>Please
do not include the package name (or version number of the
software) in the comment.</em>
Here is an example:
<tscreen><verb>
A cat chasing a mouse all over the screen.
</verb></tscreen>
<sect3>
<heading>DESCR</heading>
<p>This is a longer description of the port. One to a few
paragraphs concisely explaining what the port does is
sufficient. This is <em>not</em> a manual or an
in-depth description on how to use or compile the port!
<em>Please be careful if you are copying from the
<tt>README</tt> or manpage</em>; 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.
<p>It is recommended that you sign the name at the end of
this file, as in:
<tscreen><verb>
This is a port of oneko, in which a cat chases a poor mouse all over
the screen.
:
(etc.)
http://www.oneko.org/
- Satoshi
asami@cs.berkeley.edu
</verb></tscreen>
<sect3>
<heading>PLIST</heading>
<p>This file lists all the files installed by the port. It
is also called the `packing list' because the package is
generated by packing the files listed here. The pathnames
are relative to the installation prefix (usually
<tt>/usr/local</tt> or <tt>/usr/X11R6</tt>). If you are
using the <tt/MANx/ variables (as you should be), do not list
any manpages here.
<p>Here is a small example:
<tscreen><verb>
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
</verb></tscreen>
<p>Refer to the <tt>pkg_create(1)</tt> man page for details
on the packing list. Note that 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 <tt/@dirrm/ lines as
necessary to remove them when the port is deleted.
<p>It is recommended you keep all the filenames in this file
sorted alphabetically. It will make verifying the changes
when you upgrade the port much easier.
<sect2>
<heading>Creating the checksum file</heading>
<p>Just type `<tt>make makesum</tt>'. The ports make rules
will automatically generate the file <tt>files/md5</tt>.
<sect2>
<heading>Testing the port<label id="porting:testing"></heading>
<p>You should make sure that the port rules do exactly what
you want it to do, including packaging up the port. These
are the important points you need to verify:
<itemize>
<item><tt/PLIST/ does not contain anything not installed
by your port
<item><tt/PLIST/ contains everything that is installed
by your port
<item>your port can be installed multiple times using the
<tt/reinstall/ target
<item>your port <ref id="porting:cleaning" name="cleans up">
after itself upon deinstall
</itemize>
<p>The recommended ordering of tests is:
<enum>
<item><tt>make install</tt>
<item><tt>make package</tt>
<item><tt>make deinstall</tt>
<item><tt>pkg_add `make package-name`</tt>
<item><tt>make deinstall</tt>
<item><tt>make reinstall</tt>
<item><tt>make package</tt>
</enum>
Make sure there aren't any warnings issued in any of the
<tt/package/ and <tt/deinstall/ 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.
<sect2>
<heading>Checking your port with portlint<label id="porting:portlint"></heading>
<p>Please use <tt>portlint</tt> to see if your port conforms
to our guidelines. The <tt>
<htmlurl url="http://www.freebsd.org/cgi/ports.cgi?portlint"
name="portlint"></tt> program is part of the ports collection.
In particular, you may want to check if the <ref
id="porting:samplem" name="Makefile"> is in the right shape
and the <ref id="porting:pkgname" name="package"> is named
appropriately.
<sect2>
<heading>Submitting the port<label id="porting:submitting"></heading>
<p>First, make sure you have read the <ref id="porting:dads"
name="Do's and Dont's"> section.
<p>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 <tt>work/</tt> directory or the <tt>pkgname.tgz</tt>
package, so delete them now. Next, simply include the
output of `<tt>shar `find port_dir`</tt>' in a
bug report and send it with the <tt>send-pr(1)</tt>
program (see <ref id="contrib:general" name="Bug Reports and
General Commentary"> for more information about
<tt>send-pr</tt>). If the uncompressed port is larger than 20KB,
you should compress it into a tarfile and use
<tt>uuencode(1)</tt> before including it in the bug report
(uuencoded tarfiles are acceptable even if the report is
smaller than 20KB but are not preferred). Be sure to classify
the bug report as category `ports' and class `change-request'.
(Do not mark the report `confidential'!)
<p>One more time, <em>do not include the original source distfile,
the <tt>work/</tt> directory, or the package you built with
`<tt>make package</tt>'!</em>
<p>Note: in the past, we asked you to upload new port
submissions in our ftp site (<tt/ftp.freebsd.org/). This is
no longer recommended as read access is turned off on that
<tt/incoming/ directory of that site due to the large amount
of pirated software showing up there. <tt>:<</tt>
<p>We will look at your port, get back to you if necessary, and put
it in the tree. Your name will also appear in the list of
`Additional FreeBSD contributors' on the FreeBSD Handbook
and other files. Isn't that great?!? <tt>:)</tt>
<sect1>
<heading>Slow Porting</heading>
<p>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.
<sect2>
<heading>How things work</heading>
<p>First, this is the sequence of events which occurs when the
user first types `<tt>make</tt>' in your port's directory,
and you may find that having <tt>bsd.port.mk</tt> in another
window while you read this really helps to understand it.
<p>But do not worry if you do not really understand what
<tt>bsd.port.mk</tt> is doing, not many people
do... <tt>:></tt>
<enum>
<item>The fetch target is run. The fetch target is
responsible for making sure that the tarball exists
locally in <tt>${DISTDIR}</tt>. If fetch cannot
find the required files in <tt>${DISTDIR}</tt> it
will look up the URL <tt>${MASTER_SITES}</tt>,
which is set in the Makefile, as well as our main ftp
site at <htmlurl
url="ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/"
name="ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/,">
where we put sanctioned distfiles as backup. It will then
attempt to
fetch the named distribution file with
<tt>${FETCH}</tt>, assuming that the requesting
site has direct access to the Internet. If that succeeds,
it will save the file in <tt>${DISTDIR}</tt> for
future use and proceed.
<item>The extract target is run. It looks for your port's
distribution file (typically a gzip'd tarball) in
<tt>${DISTDIR}</tt> and unpacks it into a temporary
subdirectory specified by <tt>${WRKDIR}</tt>
(defaults to <tt>work</tt>).
<item>The patch target is run. First, any patches defined
in <tt>${PATCHFILES}</tt> are applied. Second, if
any patches are found in <tt>${PATCHDIR}</tt>
(defaults to the <tt>patches</tt> subdirectory), they are
applied at this time in alphabetical order.
<item>The configure target is run. This can do any one of
many different things.
<enum>
<item>If it exists, <tt>scripts/configure</tt> is run.
<item>If <tt>${HAS_CONFIGURE}</tt> or
<tt>${GNU_CONFIGURE}</tt> is set,
<tt>${WRKSRC}/configure</tt> is run.
<item>If <tt>${USE_IMAKE}</tt> is set,
<tt>${XMKMF}</tt> (default: `<tt>xmkmf
-a</tt>') is run.
</enum>
<item>The build target is run. This is responsible for
descending into the port's private working directory
(<tt>${WRKSRC}</tt>) and building it. If
<tt>${USE_GMAKE}</tt> is set, GNU <tt>make</tt>
will be used, otherwise the system <tt>make</tt> will be
used.
</enum>
<p>The above are the default actions. In addition, you can
define targets `<tt>pre-<something></tt>' or
`<tt>post-<something></tt>', or put scripts with those
names, in the <tt>scripts</tt> subdirectory, and they will
be run before or after the default actions are done.
<p>For example, if you have a <tt>post-extract</tt> target
defined in your Makefile, and a file <tt>pre-build</tt> in
the <tt>scripts</tt> subdirectory, the
<tt>post-extract</tt> target will be called after the
regular extraction actions, and the <tt>pre-build</tt>
script will be executed before the default build rules are
done. It is recommended that you use Makefile 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.
<p>The default actions are done by the <tt>bsd.port.mk</tt>
targets `<tt>do-<something></tt>'. For example, the
commands to extract a port are in the target
`<tt>do-extract</tt>'. If you are not happy with the
default target, you can fix it by redefining the
`<tt>do-<something></tt>' target in your Makefile.
<p>Note that the `main' targets (e.g., <tt>extract</tt>,
<tt>configure</tt>, 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
<tt>do-extract</tt>, but never ever touch <tt>extract</tt>!
<p>Now that you understand what goes on when the user types
`<tt>make</tt>', let us go through the recommended steps to
create the perfect port.
<sect2>
<heading>Getting the original sources</heading>
<p>Get the original sources (normally) as a compressed tarball
(<tt><foo>.tar.gz</tt> or <tt><foo>.tar.Z</tt>)
and copy it into <tt>${DISTDIR}</tt>. Always use
<em>mainstream</em> sources when and where you can.
<p>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 <tt>MASTER_SITES</tt> to
reflect your choice.
<p>If you cannot find somewhere convenient and reliable to put
the distfile (note that if you are a FreeBSD committer, you
can just put it in the <tt>public_html</tt> directory on
freefall), we can `house' it ourselves by putting it on
<tscreen><verb>
ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/LOCAL_PORTS/
</verb></tscreen>
as the last resort. Please refer to this location as
<tt>${MASTER_SITE_LOCAL}</tt>. Send mail to the &a.ports
if you are not sure what to do.
<p>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 <tt>MASTER_SITES</tt>. This will
prevent users from getting `checksum mismatch' 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 <tt>MASTER_SITES</tt>.
<p>If your port requires some additional `patches' that are
available on the Internet, fetch them too and put them in
<tt>${DISTDIR}</tt>. 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 <ref id="porting:patchfiles"
name="${PATCHFILES}"> below).
<sect2>
<heading>Modifying the port</heading>
<p>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
<em>careful track</em> 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.
<p>If your port requires significant user
interaction/customization to compile or install, you should
take a look at one of Larry Wall's classic Configure scripts
and perhaps do something similar yourself. The goal of the
new ports collection is to make each port as `plug-and-play'
as possible for the end-user while using a minimum of disk
space.
<p>Note: 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.
<sect2>
<heading>Patching</heading>
<p>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
`<tt>patch-<xx></tt>' where <tt><xx></tt>
denotes the sequence in which the patches will be applied --
these are done in <em>alphabetical order</em>, thus
`<tt>aa</tt>' first, `<tt>ab</tt>' second and so on. These
files should be stored in <tt>${PATCHDIR}</tt>, from
where they will be automatically applied. All patches
should be relative to <tt>${WRKSRC}</tt> (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., patch-aa and patch-ab both changing
<tt>${WRKSRC}</tt>/foobar.c).
<sect2>
<heading>Configuring</heading>
<p>Include any additional customization commands to your
<tt>configure</tt> script and save it in the
`<tt>scripts</tt>' subdirectory. As mentioned above, you
can also do this as Makefile targets and/or scripts with the
name <tt>pre-configure</tt> or <tt>post-configure</tt>.
<sect2>
<heading>Handling user input</heading>
<p>If your port requires user input to build, configure or
install, then set <tt>IS_INTERACTIVE</tt> in your Makefile.
This will allow `overnight builds' to skip your port if the
user sets the variable <tt>BATCH</tt> in his environment
(and if the user sets the variable <tt>INTERACTIVE</tt>,
then <em>only</em> those ports requiring interaction are
built).
<p>It is also recommended that if there are reasonable
default answers to the questions, you check the
<tt/PACKAGE_BUILDING/ variable and turn off the interactive
script when it is set. This will allow us to build the
packages for CD-ROMs and ftp.
<sect1>
<heading>Configuring the Makefile</heading>
<p>Configuring the Makefile is pretty simple, and again we
suggest that you look at existing examples before starting.
Also, there is a <ref id="porting:samplem" name="sample
Makefile"> 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.
<p>Now, consider the following problems in sequence as you
design your new Makefile:
<sect2>
<heading>The original source</heading>
<p>Does it live in <tt>${DISTDIR}</tt> as a standard
gzip'd tarball? If so, you can go on to the next step. If
not, you should look at overriding any of the
<tt>${EXTRACT_CMD}</tt>,
<tt>${EXTRACT_BEFORE_ARGS}</tt>,
<tt>${EXTRACT_AFTER_ARGS}</tt>,
<tt>${EXTRACT_SUFX}</tt>, or
<tt>${DISTFILES}</tt> variables, depending on how
alien a format your port's distribution file is. (The most
common case is `<tt>EXTRACT_SUFX=.tar.Z</tt>', when the
tarball is condensed by regular compress, not gzip.)
<p>In the worst case, you can simply create your own
`<tt>do-extract</tt>' target to override the default, though
this should be rarely, if ever, necessary.
<sect2>
<heading>DISTNAME</heading>
<p>You should set <tt>${DISTNAME}</tt> to be the base
name of your port. The default rules expect the
distribution file list (<tt>${DISTFILES}</tt>) to be
named
<tt>${DISTNAME}${EXTRACT_SUFX}</tt>
which, if it is a normal tarball, is going to be
something like:
<tscreen><verb>
foozolix-1.0.tar.gz
</verb></tscreen>
for a setting of `<tt>DISTNAME=foozolix-1.0</tt>'.
The default rules also expect the tarball(s) to extract into
a subdirectory called <tt>work/${DISTNAME}</tt>, e.g.
<tscreen><verb>
work/foozolix-1.0/
</verb></tscreen>
All this behavior can be overridden, of course; it simply
represents the most common time-saving defaults. For a port
requiring multiple distribution files, simply set
<tt>${DISTFILES}</tt> explicitly. If only a subset
of <tt>${DISTFILES}</tt> are actual extractable
archives, then set them up in
<tt>${EXTRACT_ONLY}</tt>, which will override the
<tt>${DISTFILES}</tt> list when it comes to
extraction, and the rest will be just left in
<tt>${DISTDIR}</tt> for later use.
<sect2>
<heading>PKGNAME</heading>
<p>If <tt>${DISTNAME}</tt> does not conform to our <ref
id="porting:pkgname" name="guidelines for a good package
name">, you should set the <tt>${PKGNAME}</tt>
variable to something better. See the abovementioned
guideline for more details.
<sect2>
<heading>CATEGORIES</heading>
<p>When a package is created, it is put under
<tt>/usr/ports/packages/All</tt> and links are made from one
or more subdirectories of <tt>/usr/ports/packages</tt>. The
names of these subdirectories are specified by the variable
<tt>${CATEGORIES}</tt>. 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 CD-ROM. Please take a look
at the existing <ref id="porting:categories"
name="categories"> and pick the ones that are suitable for
your port.
<p>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 <ref
id="porting:categories" name="categories"> section for more
discussion about how to pick the right categories.
<p>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.
<p>Note that there is no error checking for category names;
`<tt>make package</tt>' will happily create a new directory
if you mistype the category name, so be careful!
<sect2>
<heading>MASTER_SITES</heading>
<p>Record the directory part of the ftp/http-URL pointing at
the original tarball in <tt>${MASTER_SITES}</tt>.
Do not forget the trailing slash (<tt>/</tt>)!
The make macros will try to use this specification for
grabbing the distribution file with <tt>${FETCH}</tt>
if they cannot find it already on the system.
<p>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!
<p>If the original tarball is part of one of the following
popular archives: X-contrib, GNU, Perl CPAN, TeX CTAN, or
Linux Sunsite, you refer to those sites in an easy compact
form using MASTER_SITE_XCONTRIB, MASTER_SITE_GNU,
MASTER_SITE_PERL_CPAN, MASTER_SITE_TEX_CTAN, and
MASTER_SITE_SUNSITE. Simply set MASTER_SITE_SUBDIR to the path
with in the archive. Here is an example:
<tscreen><verb>
MASTER_SITES= ${MASTER_SITE_XCONTRIB}
MASTER_SITE_SUBDIR= applications
</verb></tscreen>
<p>The user can also set the MASTER_SITE_* variables in
<tt>/etc/make.conf</tt> to override our choices, and use their
favorite mirrors of these popular archives instead.
<sect2>
<heading>PATCHFILES<label id="porting:patchfiles"></heading>
<p>If your port requires some additional patches that are
available by ftp or http, set <tt>${PATCHFILES}</tt>
to the names of the files and <tt>${PATCH_SITES}</tt>
to the URL of the directory that contains them (the format
is the same as <tt>${MASTER_SITES}</tt>).
<p>If the patch is not relative to the top of the source tree
(i.e., <tt>${WKRSRC}</tt>) because it contains some
extra pathnames, set <tt>${PATCH_DIST_STRIP}</tt>
accordingly. For instance, if all the pathnames in the
patch have an extra `<tt>foozolix-1.0/</tt>' in front of the
filenames, then set `<tt>PATCH_DIST_STRIP=-p1</tt>'.
<p>Do not worry if the patches are compressed, they will be
decompressed automatically if the filenames end with
`<tt>.gz</tt>' or `<tt>.Z</tt>'.
<p>If the patch is distributed with some other files, such as
documentation, in a gzip'd tarball, you can't just use
<tt>${PATCHFILES}</tt>. If that is the case, add the
name and the location of the patch tarball to
<tt>${DISTFILES}</tt> and
<tt>${MASTER_SITES}</tt>. Then, from the
<tt>pre-patch</tt> target, apply the patch either by running
the patch command from there, or copying the patch file into
the <tt>${PATCHDIR}</tt> directory and calling it
<tt>patch-<xx></tt>. (Note 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 <tt>pre-clean</tt> target.
<sect2>
<heading>MAINTAINER</heading>
<p>Set your mail-address here. Please. <tt>:)</tt>
<p>For detailed description of the responsibility of maintainers,
refer to <ref id="policies:maintainer"
name="MAINTAINER on Makefiles"> section.
<sect2>
<heading>Dependencies</heading>
<p>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.
<sect3>
<heading>LIB_DEPENDS</heading>
<p>This variable specifies the shared libraries this port
depends on. It is a list of `<tt>lib:dir[:target]</tt>' tuples
where <tt>lib</tt> is the name of the shared library, and
<tt>dir</tt> is the directory in which to find it in case
it is not available, and <tt/target/ is the target to call
in that directory. For example,
<tscreen><verb>
LIB_DEPENDS= jpeg.9:${PORTSDIR}/graphics/jpeg:install
</verb></tscreen>
will check for a shared jpeg library with major version 9,
and descend into the <tt>graphics/jpeg</tt> subdirectory
of your ports tree to build and install it if it is not
found. The `<tt/:target/' part can be omitted if it is
equal to <tt>${DEPENDS_TARGET}</tt> (which defaults to
`<tt/install/').
Note that the <tt>lib</tt> part is an argument given
to `<tt>ldconfig -r | grep -wF</tt>'. There shall be no
regular expressions in this variable.
The dependency is checked twice, once from within the
<tt/extract/ target and then from within the <tt/install/
target. (This is to ensure that the library is available
even if the port is installed on a different machine from
where it was built.) Also, the name of the dependency is
put in to the package so that <tt>pkg_add</tt> will
automatically install it if it is not on the user's
system.
<sect3>
<heading>RUN_DEPENDS</heading>
<p>This variable specifies executables or files this port
depends on during run-time. It is a list of
`<tt>path:dir[:target]</tt>' tuples where <tt>path</tt> is the name
of the executable or file, and <tt>dir</tt> is the
directory in which to find it in case it is not
available, and `<tt/target/' is the target to call in that
directory. If <tt>path</tt> starts with a slash
(<tt>/</tt>), it is treated as a file or directory and its
existence is
tested with `<tt>test -e</tt>'; otherwise, it is assumed
to be an executable, and `<tt>which -s</tt>' is used to
determine if the program exists in the user's search path.
<p>For example,
<tscreen><verb>
RUN_DEPENDS= ${PREFIX}/etc/innd:${PORTSDIR}/news/inn \
wish8.0:${PORTSDIR}/x11-toolkits/tk80
</verb></tscreen>
will check if the file or directory `<tt>/usr/local/etc/innd</tt>'
exists, and build and install it from the
<tt>news/inn</tt> subdirectory of the ports tree if it is
not found. It will also see if an executable called
`<tt>wish8.0</tt>' is in your search path, and descend into
the <tt>x11-toolkits/tk80</tt> subdirectory of your ports tree to
build and install it if it is not found. (Note that in
this case, `<tt>innd</tt>' 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.)
The dependency is checked from within the <tt>install</tt>
target. Also, the name of the dependency is put in to the
package so that <tt>pkg_add</tt> will automatically
install it if it is not on the user's system. The
`<tt/:target/' part can be omitted if it is the same as
<tt>${DEPENDS_TARGET}</tt>.
<sect3>
<heading>BUILD_DEPENDS</heading>
<p>This variable specifies executables or files this port
requires to build. Like <tt>RUN_DEPENDS</tt>, it is a
list of `<tt>path:dir[:target]</tt>' tuples. For example,
<tscreen><verb>
BUILD_DEPENDS= unzip:${PORTSDIR}/archivers/unzip
</verb></tscreen>
will check for an executable called `<tt>unzip</tt>', and
descend into the <tt>archivers/unzip</tt> subdirectory of
your ports tree to build and install it if it is not found.
Note that `build' here means everything from extracting to
compilation. The dependency is checked from within the
<tt>extract</tt> target. The `<tt/:target/' part can be
omitted if it is the same as <tt>${DEPENDS_TARGET}</tt>.
<sect3>
<heading>FETCH_DEPENDS</heading>
<p>This variable specifies executables or files this port
requires to fetch. Like the previous two, it is a list of
`<tt>path:dir[:target]</tt>' pairs. For example,
<tscreen><verb>
FETCH_DEPENDS= ncftp2:${PORTSDIR}/net/ncftp2
</verb></tscreen>
will check for an executable called `<tt>ncftp2</tt>', and
descend into the <tt>net/ncftp2</tt> subdirectory of
your ports tree to build and install it if it is not found.
The dependency is checked from within the <tt>fetch</tt>
target. The `<tt/:target/' part can be omitted if it is the
same as <tt>${DEPENDS_TARGET}</tt>.
<sect3>
<heading>DEPENDS</heading>
<p>If there is a dependency that does not fall into either of
the above four categories, or your port requires to have
the source of the other port extracted in addition to
having them installed, then use this variable. This is
a list of `<tt>dir[:target]</tt>', as there is nothing to check,
unlike the previous four. The `<tt/:target/' part can be
omitted if it is the same as <tt>${DEPENDS_TARGET}</tt>.
<sect3>
<heading>Common dependency variables</heading>
<p>Define `<tt>USE_XLIB=yes</tt>' if your port requires the
X Window System to be installed (it is implied by
<tt>USE_IMAKE</tt>). Define `<tt>USE_GMAKE=yes</tt>' if
your port requires GNU <tt/make/ instead of BSD <tt/make/.
Define `<tt>USE_AUTOCONF=yes</tt>' if your port requires
GNU autoconf to be run. Define `<tt>USE_QT=yes</tt>' if
your port uses the latest qt toolkit. Use
`<tt>USE_PERL5=yes</tt>' if your port requires version 5
of the perl language. (The last is especially important
since some versions of FreeBSD has perl5 as part of the
base system while others don't.)
<sect3>
<heading>Notes on dependencies</heading>
<p>As mentioned above, the default target to call when a
dependency is required is <tt>${DEPENDS_TARGET}</tt>. It
defaults to `<tt/install/'. This is a user variable; it
is never defined in a port's Makefile. If your port needs
a special way to handle a dependency, use the
`<tt/:target/' part of the <tt>*_DEPENDS</tt> variables
instead of redefining <tt>${DEPENDS_TARGET}</tt>.
<p>When you type `<tt>make clean</tt>', its dependencies are
automatically cleaned too. If you do not wish this to
happen, define the variable <tt/NOCLEANDEPENDS/ in your
environment.
<p>To depend on another port unconditionally, it is
customary to use the string `<tt/nonexistent/' as the
first field of <tt/BUILD_DEPENDS/ or <tt/RUN_DEPENDS/.
Use this only when you need the to get to the source of
the other port. You can often save compilation time by
specifying the target too. For instance,
<tscreen><verb>
BUILD_DEPENDS= /nonexistent:${PORTSDIR}/graphics/jpeg:extract
</verb></tscreen>
will always descend to the JPEG port and extract it.
<p>Do not use `<tt/DEPENDS/' unless there is no other way
the behavior you want can be accomplished. It will cause
the other port to be always built (and installed, by
default), and the dependency will go into the package as
well. If this is really what you need, I recommend you
write it as <tt/BUILD_DEPENDS/ and <tt/RUN_DEPENDS/
instead -- at least the intention will be clear.
<sect2>
<heading>Building mechanisms</heading>
<p>If your package uses GNU <tt>make</tt>, set
`<tt>USE_GMAKE=yes</tt>'. If your package uses configure,
set `<tt>HAS_CONFIGURE=yes</tt>'. If your package uses
GNU <tt/configure/, set `<tt>GNU_CONFIGURE=yes</tt>' (this
implies <tt/HAS_CONFIGURE/). If you want to give some extra
arguments to <tt/configure/ (the default argument list
`<tt>--prefix=${PREFIX}</tt>' for GNU <tt/configure/ and
empty for non-GNU <tt/configure/), set those extra arguments in
<tt>${CONFIGURE_ARGS}</tt>. If your package uses GNU
<tt/autoconf/, set `<tt>USE_AUTOCONF=yes</tt>'. This
implies <tt/GNU_CONFIGURE/, and will cause <tt/autoconf/ to
be run before <tt/configure/.
<p>If your package is an X application that creates Makefiles
from Imakefiles using <tt>imake</tt>, then set
`<tt>USE_IMAKE=yes</tt>'. This will cause the configure
stage to automatically do an <tt>xmkmf -a</tt>. If the
`<tt>-a</tt>' flag is a problem for your port, set
`<tt>XMKMF=xmkmf</tt>'.
If the port uses imake but does not understand the
`<tt>install.man</tt>' target,
`<tt>NO_INSTALL_MANPAGES=yes</tt>' should be set. In
addition, the author of the original port should be
shot. <tt>:></tt>
<p>If your port's source Makefile has something else than
`<tt>all</tt>' as the main build target, set
<tt>${ALL_TARGET}</tt> accordingly. Same goes for
`<tt>install</tt>' and <tt>${INSTALL_TARGET}</tt>.
<sect1>
<heading>Special Considerations</heading>
<p>There are some more things you have to take into account when
you create a port. This section explains the most common of those.
<sect2>
<heading><tt/ldconfig/</heading>
<p>If your port installs a shared library, add a
<tt>post-install</tt> target to your Makefile that runs
`<tt>${LDCONFIG} -m</tt>' on the directory where the new
library is installed (usually <tt>${PREFIX}/lib</tt>)
to register it into the shared library cache.
<p>Also, add a matching `<tt>@exec /sbin/ldconfig
-m</tt>'/`<tt>@unexec /sbin/ldconfig -R</tt>' pair to your
<tt>pkg/PLIST</tt> 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. These lines should immediately follow
the line for the shared library itself, as in:
<tscreen><verb>
lib/libtcl80.so.1
@exec /sbin/ldconfig -m %D/lib
@unexec /sbin/ldconfig -R
</verb></tscreen>
<p>Never, ever, <em>ever</em> add a line that says
`<tt>ldconfig</tt>' without any arguments to your Makefile
or pkg/PLIST. This will reset the shared library cache to
the contents of <tt>/usr/lib</tt> only, and will royally
screw up the user's machine ("Help, xinit does not run
anymore after I install this port!"). Anybody who does this
will be shot and cut into 65,536 pieces by a rusty knife and
have his liver chopped out by a bunch of crows and will
eternally rot to death in the deepest bowels of hell (not
necessarily in that order)....
<sect2>
<heading>ELF support</heading>
<p>Since FreeBSD moved to ELF 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 that there will
be one more release (2.2.8) from the 2.2 branch. Below
are the guidelines on how to convert a.out only ports to
support both a.out and ELF compilation.
<p>Some part of this list is only applicable during the
conversion, but will be left here for awhile for reference
in case you have come across some old port you wish to
upgrade.
<sect3>
<heading>Moving a.out libraries out of the way</heading>
<p>A.out libraries should be moved out of
<tt>/usr/local/lib</tt> and similar to an `<tt/aout/'
subdirectory. (If you don't move them out of the way,
ELF ports will happily overwrite a.out libraries.) The
`<tt/move-aout-libs/' target in the -current
<tt>src/Makefile</tt> (called from `<tt/aout-to-elf'/)
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.
<sect3>
<heading>Format</heading>
<p>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 <tt>`objformat`</tt>
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.)
<p>Note: if a port only works for a.out, set
<tt/BROKEN_ELF/ to a string describing the reason why.
Such ports will be skipped during a build on an ELF
system.
<sect3>
<heading>PORTOBJFORMAT</heading>
<p><tt/bsd.port.mk/ will set <tt/PORTOBJFORMAT/ to
`<tt/aout/' or `<tt/elf/' and export it in the
environments <tt/CONFIGURE_ENV/, <tt/SCRIPTS_ENV/ and
<tt/MAKE_ENV/. (It's always going to be `<tt/aout/' in
-stable). It is also passed to <tt/PLIST_SUB/ as
`<tt>PORTOBJFORMAT=${PORTOBJFORMAT}</tt>'. (See comment
on <tt/ldconfig/ lines below.)
<p>The variable is set using this line:
<tscreen><verb>
PORTOBJFORMAT!= test -x /usr/bin/objformat && /usr/bin/objformat || echo aout
</verb></tscreen>
in <tt/bsd.port.mk/.
<p>Ports' make processes should use this variable to
decide what to do. However, if the port's
<tt/configure/ script already automatically detects an
ELF system, it is not necessary to refer to
<tt/PORTOBJFORMAT/.
<sect3>
<heading>Building shared libraries</heading>
<p>The following are differences in handling shared
libraries for a.out and ELF.
<descrip>
<tag>Shared library versions</tag>An ELF shared library
should be called "<tt/libfoo.so.M/" where <tt/M/ is
the single version number, and an a.out library should
be called "<tt/libfoo.so.M.N/" where <tt/M/ is the
major version and <tt/N/ is the the minor version
number. Do not mix those; <em/never/ install an ELF
shared library called "<tt/libfoo.so.N.M/" or an a.out
shared library (or symlink) called "<tt/libfoo.so.N/".
<tag>Linker command lines</tag>Assuming `<tt>cc
-shared</tt>' is used rather than `<tt/ld/' directly,
the only difference is that you need to add
`<tt>-Wl,-soname,libfoo.so.M</tt>' on the command line
for ELF.
</descrip>
<p>You need to install a symlink <tt>libfoo.so</tt> ->
<tt>libfoo.so.N</tt> to make ELF linkers happy. Since
it should be listed in <tt/PLIST/ 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 <tt/PORTOBJFORMAT/.
<sect3>
<heading><tt/LIB_DEPENDS/</heading>
<p>All port Makefiles are edited to remove minor numbers
from <tt/LIB_DEPENDS/, and also to have the regexp
support removed. (E.g.,
`<tt>foo\\.1\\.\\(33|40\\)</tt>' -> `<tt>foo.2</tt>'.)
They will be matched using `<tt>grep -wF</tt>'.
<sect3>
<heading><tt/PLIST/</heading>
<p><tt/PLIST/ should contain the short (ELF) shlib names
if the a.out minor number is zero, and the long (a.out)
names otherwise. <tt/bsd.port.mk/ will automatically
add `<tt/.0/' to the end of short shlib lines if
<tt/PORTOBJFORMAT/ equals <tt/aout/, and will delete the
minor number from long shlib names if <tt/PORTOBJFORMAT/
equals <tt/elf/.
<p>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 <tt/NO_FILTER_SHLIBS/. This will
turn off the editing of <tt/PLIST/ mentioned in the
previous paragraph.
<sect3>
<heading><tt/ldconfig/</heading>
<p>The <tt/ldconfig/ line in Makefiles should read:
<tscreen><verb>
${SETENV} OBJFORMAT=${PORTOBJFORMAT} ${LDCONFIG} -m ....
</verb></tscreen>
and in <tt/PLIST/:
<tscreen><verb>
@exec /usr/bin/env OBJFORMAT=%%PORTOBJFORMAT%% /sbin/ldconfig -m ...
@unexec /usr/bin/env OBJFORMAT=%%PORTOBJFORMAT%% /sbin/ldconfig -R
</verb></tscreen>
This is to ensure that the correct <tt/ldconfig/ will be
called depending on the format of the package, not the
default format of the system.
<sect2>
<heading><tt/MASTERDIR/<label id="porting:masterdir"></heading>
<p>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
Makefile in all but one of the directories if you use
variables cleverly. In the sole Makefiles, you can use
<tt>${MASTERDIR}</tt> to specify the directory
where the rest of the files are. Also, use a variable as
part of <tt><ref id="porting:pkgname" name="PKGNAME"></tt>
so the packages will have different names.
<p>This will be best demonstrated by an example. This is
part of <tt>japanese/xdvi300/Makefile</tt>:
<tscreen><verb>
:
PKGNAME= ja-xdvi${RESOLUTION}-17
:
# 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
</verb></tscreen>
<tt>japanese/xdvi300</tt> also has all the regular
patches, package files, etc. If you type `<tt/make/'
there, it will take the default value for the resolution
(300) and build the port normally.
<p>As for other resolutions, this is the <em/entire/
<tt>xdvi118/Makefile</tt> (minus the comments):
<tscreen><verb>
RESOLUTION= 118
MASTERDIR= ${.CURDIR}/../xdvi300
.include "${MASTERDIR}/Makefile"
</verb></tscreen>
(<tt>xdvi240/Makefile</tt> and <tt>xdvi400/Makefile</tt>
are similar). The <tt>${MASTERDIR}</tt> definition
tells <tt/bsd.port.mk/ that the regular set of
subdirectories like <tt>${PATCHDIR}</tt> and
<tt>${PKGDIR}</tt> are to be found under
<tt/xdvi300/. The <tt/RESOLUTION=118/ line will override
the <tt/RESOLUTION?=300/ line in <tt>xdvi300/Makefile</tt>
and the port will be built with resolution set to 118.
<sect2>
<heading>Shared library versions</heading>
<p>First, please read our <ref id="policies:shlib"
name="policy on shared library versioning"> 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
<tt/jpeg-6b/ has a shared library version of `9.0'?).
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.
<p>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 <tt/libfoo.so.3.2/ and <tt/libfoo.so.4.0/ in
the system, there is no way to tell the linker to link a
particular application to <tt/libfoo.so.3.2/. It is
essentially completely overshadowed in terms of
compilation-time linkage. In this case, the only solution
is to rename the `base' part of the shared library. For
instance, change <tt/libfoo.so.4.0/ to
<tt/libfoo4.so.1.0/ so both version 3.2 and 4.0 can be
linked from other ports.
<sect2>
<heading>Manpages<label id="porting:manpages"></heading>
<p>The <tt/MAN[1-9LN]/ variables will automatically add any
manpages to <tt>pkg/PLIST</tt> (this means you must <em/not/
list manpages in the <tt/PLIST/ -- see <ref
id="porting:plist" name="generating PLIST"> for more).
It also makes the install stage automatically compress or
uncompress manpages depending on the setting of
<tt/NOMANCOMPRESS/ in <tt>/etc/make.conf</tt>.
<p>To specify whether the manpages are compressed upon
installation, use the <tt/MANCOMPRESSED/ variable. This
variable can take three values, `<tt/yes/', `<tt/no/' and
`<tt/maybe/'. `<tt/yes/' means manpages are already
installed compressed, `<tt/no/' means they are not, and `<tt/maybe/'
means the software already respects the value of
<tt/NOMANCOMPRESS/ so <tt/bsd.port.mk/ does not have to do
anything special.
<p><tt/MANCOMPRESSED/ is automatically set to `<tt/yes/' if
<tt/USE_IMAKE/ is set and <tt/NO_INSTALL_MANPAGES/ is not
set, and to `<tt/no/' otherwise. You don't have to
explicitly define it unless the default is not suitable for
your port.
<p>If your port anchors its man tree somewhere other than
<tt>PREFIX</tt>, you can use the <tt>MANPREFIX</tt> 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
<tt>MAN<em>sect</em>PREFIX</tt> (where
<tt><em>sect</em></tt> is one of 1-9, L or N).
<p>If your manpages go to language-specific subdirectories,
set the name of the languages to <tt/MANLANG/. The value of
this variable defaults to <tt>""</tt> (i.e., English only).
<p>Here is an example that puts it all together.
<tscreen><verb>
MAN1= foo.1
MAN3= bar.3
MAN4= baz.4
MANLANG= "" ja
MAN3PREFIX= ${PREFIX}/share/foobar
MANCOMPRESSED= yes
</verb></tscreen>
states that six files
<tscreen><verb>
${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
</verb></tscreen>
are installed by this port.
<sect2>
<heading>Ports that require Motif</heading>
<p>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
<tt>x11-toolkits/lesstif</tt>) 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).
<sect3>
<heading>REQUIRES_MOTIF</heading>
<p>If your port requires Motif, define this variable in the
Makefile. This will prevent people who don't own a copy of
Motif from even attempting to build it.
<sect3>
<heading>${MOTIFLIB}</heading>
<p>This variable will be set by <tt>bsd.port.mk</tt> to be the
appropriate reference to the Motif library. Please patch
the source to use this wherever the Motif library is
referenced in the Makefile or Imakefile.
<p>There are two common cases:
<enum>
<item>If the port refers to the Motif library as
`<tt>-lXm</tt>' in its Makefile or Imakefile, simply
substitute `<tt>${MOTIFLIB}</tt>' for it.
<item>If the port uses `<tt>XmClientLibs</tt>' in its
Imakefile, change it to `<tt>${MOTIFLIB}
${XTOOLLIB} ${XLIB}</tt>'.
</enum>
<p>Note that <tt>${MOTIFLIB}</tt> (usually) expands to
`<tt>-L/usr/X11R6/lib -lXm</tt>' or
`<tt>/usr/X11R6/lib/libXm.a</tt>', so there is no need to
add `<tt>-L</tt>' or `<tt>-l</tt>' in front.
<sect2>
<heading>X11 fonts</heading>
<p>If your port installs fonts for the X window system, put
them in <tt>${X11BASE}/lib/X11/fonts/local</tt>. 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
<tt>/etc/XF86Config</tt>.
<sect2>
<heading>Info files</heading>
<p>The new version of texinfo (included in 2.2.2-RELEASE and
onwards) contains a utility called `<tt/install-info/' to add
and delete entries to the `<tt/dir/' file. If your port
installs any info documents, please follow these instructions
so your port/package will correctly update the user's
<tt>&dollar{PREFIX}/info/dir</tt> file. (Sorry for the length
of this section, but it is imperative to weave all the info
files together. If done correctly, it will produce a
<em>beautiful</em> listing, so please bear with me! <tt/:)/
<p>First, this is what you (as a porter) need to know:
<tscreen><verb>
% install-info --help
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.
:
</verb></tscreen>
<p>Note that this program will not actually <em/install/
info files; it merely inserts or deletes entries in the
<tt/dir/ file.
<p>Here's a seven-step procedure to convert ports to use
<tt/install-info/. I will use <tt>editors/emacs</tt> as an
example.
<enum>
<item>Look at the texinfo sources and make a patch to insert
<tt/@dircategory/ and <tt/@direntry/ statements to files
that don't have them. This is part of my patch:
<tscreen><verb>
--- ./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
:
</verb></tscreen>
<p>The format should be self-explanatory. Many authors leave
a <tt/dir/ 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).
<p>Note that you can put only one info entry per file because
of a bug in `<tt>install-info --delete</tt>' that deletes
only the first entry if you specify multiple entries in the
<tt/@direntry/ section.
<p>You can give the <tt/dir/ entries to <tt/install-info/ as
arguments (<tt/--section/ and <tt/--entry/) instead of
patching the texinfo sources. I do not think this is a good
idea for ports because you need to duplicate the same
information in <em>three</em> places (<tt/Makefile/ and
<tt/@exec//<tt/@unexec/ of <tt/PLIST/; see below). However,
if you have a Japanese (or other multibyte encoding) info
files, you will have to use the extra arguments to
<tt/install-info/ because <tt/makeinfo/ can't handle those
texinfo sources. (See <tt/Makefile/ and <tt/PLIST/ of
<tt>japanese/skk</tt> for examples on how to do this).
<item>Go back to the port directory and do a `<tt>make clean;
make</tt>' 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 <tt/make/; but many <tt/Makefile/s don't include
correct dependencies for info files. In emacs' case, I had
to patch the main <tt/Makefile.in/ so it will descend into
the <tt/man/ subdirectory to rebuild the info pages.
<tscreen><verb>
--- ./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)
</verb></tscreen>
<p>The second hunk was necessary because the default target in
the <tt/man/ subdir is called <tt/info/, while the
main Makefile wants to call <tt/all/. I also deleted the
installation of the <tt/info/ info file because we already
have one with the same name in <tt>/usr/share/info</tt>
(that patch is not shown here).
<item>If there is a place in the <tt/Makefile/ that is
installing the <tt/dir/ file, delete it. Your port may not
be doing it. Also, remove any commands that are otherwise
mucking around with the <tt/dir/ file.
<tscreen><verb>
--- ./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); \
</verb></tscreen>
<item>(This step is only necessary if you are modifying an
existing port.) Take a look at <tt>pkg/PLIST</tt> and
delete anything that is trying to patch up
<tt>info/dir</tt>. They may be in <tt>pkg/INSTALL</tt> or
some other file, so search extensively.
<tscreen><verb>
Index: pkg/PLIST
===================================================================
RCS file: /usr/cvs/ports/editors/emacs/pkg/PLIST,v
retrieving revision 1.15
diff -u -r1.15 PLIST
--- PLIST 1997/03/04 08:04:00 1.15
+++ 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
</verb></tscreen>
<item>Add a <tt/post-install/ target to the Makefile to create
a <tt/dir/ file if it is not there. Also, call
<tt/install-info/ with the installed info files.
<tscreen><verb>
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,11 @@
post-install:
.for file in emacs-19.34 emacsclient etags ctags b2m
strip ${PREFIX}/bin/${file}
.endfor
+ if [ ! -f ${PREFIX}/info/dir ]; then \
+ ${SED} -ne '1,/Menu:/p' /usr/share/info/dir > ${PREFIX}/info/dir; \
+ fi
+.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 <bsd.port.mk>
</verb></tscreen>
<p>Do not use anything other than <tt>/usr/share/info/dir</tt>
and the above command to create a new info file. In fact,
I'd add the first three lines of the above patch to
<tt/bsd.port.mk/ if you (the porter) wouldn't have to do it
in <tt/PLIST/ by yourself anyway.
<item>Edit <tt/PLIST/ and add equivalent <tt/@exec/ statements
and also <tt/@unexec/ for <tt/pkg_delete/. You do not need
to delete <tt>info/dir</tt> with <tt/@unexec/.
<tscreen><verb>
Index: pkg/PLIST
===================================================================
RCS file: /usr/cvs/ports/editors/emacs/pkg/PLIST,v
retrieving revision 1.15
diff -u -r1.15 PLIST
--- PLIST 1997/03/04 08:04:00 1.15
+++ PLIST 1997/05/20 10:25:12 1.17
@@ -16,7 +14,15 @@
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 [ -f %D/info/dir ] || sed -ne '1,/Menu:/p' /usr/share/info/dir > %D/info/dir
+@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
</verb></tscreen>
<p>Note that the `<tt>@unexec install-info --delete</tt>'
commands have to be listed before the info files themselves
so they can read the files. Also, the `<tt>@exec
install-info</tt>' commands have to be after the info files
and the <tt/@exec/ command that creates the the <tt/dir/
file.
<item><ref id="porting:testing" name="Test"> and admire your
work. <tt/:)/ Check the <tt/dir/ file before and after each
step.
</enum>
<sect1>
<heading>The <tt/pkg/ Subdirectory</heading>
<p>There are some tricks we haven't mentioned yet about the
<tt/pkg/ subdirectory that come in handy sometimes.
<sect2>
<heading><tt/MESSAGE/</heading>
<p><label id="porting:message">If you need to display a
message to the installer, you may place the message in
<tt>pkg/MESSAGE</tt>. This capability is often useful to
display additional installation steps to be taken after a
<tt/pkg_add/, or to display licensing information. Note the
<tt>pkg/MESSAGE</tt> file does not need to be added to
<tt>pkg/PLIST</tt>. 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 <tt/post-install/
target by yourself.
<sect2>
<heading><tt/INSTALL/</heading>
<p>If your port needs to execute commands when the binary package
is installed with <tt/pkg_add/ you can do this via the pkg/INSTALL
script. This script will automatically be added to the
package, and will be run twice by pkg_add. The first time
will as `<tt>INSTALL ${PKGNAME} PRE-INSTALL</tt>'
and the second time as `<tt>INSTALL ${PKGNAME} POST-INSTALL</tt>'.
`<tt>$2</tt>' can be tested to determine which mode
the script is being run in.
The `<tt>PKG_PREFIX</tt>' environmental variable will be set to
the package installation directory. See man <tt>pkg_add(1)</tt>
for additional information.
Note, that this script is not run automatically if you install
the port with `<tt>make install</tt>'. If you are depending
on it being run, you will have to explicitly call it from your
port's Makefile.
<sect2>
<heading><tt/REQ/</heading>
<p>If your port needs to determine if it should install or
not, you can create a <tt>pkg/REQ</tt> ``requirements''
script. It will be invoked automatically at
installation/deinstallation time to determine whether or not
installation/deinstallation should proceed.
<sect2>
<heading>Changing <tt/PLIST/ based on make variables<label
id="porting:plist"></heading>
<p>Some ports, particularly the p5- ports, need to change
their <tt/PLIST/ 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 <tt/PLIST/
of <tt/%%OSREL%%/, <tt/%%PERL_VER%%/, and
<tt/%%PERL_VERSION%%/ will be substituted for appropriately.
The value of <tt/%%OSREL%%/ is the numeric revision of the
operating system (e.g., `2.2.7'). <tt/%%PERL_VERSION%%/ is
the full version number of perl (e.g., `5.00502') and
<tt/%%PERL_VER%%/ is the perl version number minus the
patchlevel (e.g., `5.005').
<p>If you need to make other substitutions, you
can set the <tt>PLIST_SUB</tt> variable with a list of
<tt>VAR=VALUE</tt> pairs and instances of `<tt>%%VAR%%</tt>'
will be substituted with `<tt/VALUE/' in the <tt/PLIST/.
For instance, if you have a port that installs many files in
a version-specific subdirectory, you can put something
like
<tscreen><verb>
OCTAVE_VERSION= 2.0.13
PLIST_SUB= OCTAVE_VERSION=${OCTAVE_VERSION}
</verb></tscreen>
in the <tt/Makefile/ and use <tt>%%OCTAVE_VERSION%%</tt>
wherever the version shows up in <tt/PLIST/. That way, when
you upgrade the port, you will not have to change dozens (or
in some cases, hundreds) of lines in the <tt/PLIST/.
<p>This substitution (as well as addition of any <ref
id="porting:manpages" name="man pages">) will be done
between the <tt/do-install/ and <tt/post-install/ targets,
by reading from <tt>${PLIST}</tt> and writing to
<tt>${TMPPLIST}</tt> (default:
<tt>${WRKDIR}/.PLIST.mktmp</tt>). So if your port
builds <tt>${PLIST}</tt> on the fly, do so in or
before <tt/do-install/. Also, if your port needs to edit
the resulting file, do so in <tt/post-install/ to a file
named <tt/${TMPPLIST}/.
<sect2>
<heading>Changing the names of files in the <tt/pkg/ subdirectory<label
id="porting:pkgsubdir"></heading>
<p>All the filenames in the <tt/pkg/ subdirectory are defined
using variables so you can change them in your Makefile if
need be. This is expecially useful when you are sharing the
same <tt/pkg/ subdirectory among several ports or have to
write to one of the above files (see <ref
id="porting:wrkdir" name="writing to places other than
WRKDIR"> for why it is a bad idea to write directly into the
<tt/pkg/ subdirectory).
<p>Here is a list of variable names and their default values.
<tscreen><verb>
COMMENT ${PKGDIR}/COMMENT
DESCR ${PKGDIR}/DESCR
PLIST ${PKGDIR}/PLIST
PKGINSTALL ${PKGDIR}/INSTALL
PKGDEINSTALL ${PKGDIR}/DEINSTALL
PKGREQ ${PKGDIR}/REQ
PKGMESSAGE ${PKGDIR}/MESSAGE
</verb></tscreen>
<p>Please change these variables rather than overriding
<tt>PKG_ARGS</tt>. If you change <tt>PKG_ARGS</tt>, those
files will not correctly be installed in
<tt>/var/db/pkg</tt> upon install from a port.
<sect1>
<heading>Licensing Problems</heading>
<p>Some software packages have restrictive licenses or can be in
violation to the law (PKP's patent on public key crypto,
ITAR (export of crypto software) to name just two of them).
What we can do with them varies a lot, depending on the exact
wordings of the respective licenses.
<p>Note that 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 of violating them by
redistributing the source or compiled binaries either via ftp
or CD-ROM. If in doubt, please contact the &a.ports;.
<p>There are two variables you can set in the Makefile to handle
the situations that arise frequently:
<enum>
<item>If the port has a `do not sell for profit' type of
license, set the variable <tt>NO_CDROM</tt> to the string
describing the reason why. We will make
sure such ports won't go into the CD-ROM come release time.
The distfile and package will still be available via ftp.
<item>If the resulting package needs to be built uniquely for
each site, or the resulting binary package can't be distributed
due to licensing, set the variable <tt>NO_PACKAGE</tt> to
the string describing the reason why.
We will make sure such packages won't go on the ftp site, nor
into the CD-ROM come release time. The distfile will still be
included on both however.
<item>If the port has legal restrictions on who can use it
(e.g., crypto stuff) or has a `no commercial use' license,
set the variable <tt>RESTRICTED</tt> to be the string
describing the reason why. For such ports, the
distfiles/packages will not be available even from our ftp
sites.
</enum>
<p>Note: The GNU General Public License (GPL), both version 1
and 2, should not be a problem for ports.
<p>Note: If you are a committer, make sure you update the
<tt>ports/LEGAL</tt> file too.
<sect1>
<heading>Upgrading</heading>
<p>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
<tt>ports-current</tt> directory of the ftp mirror sites.
<p>The next step is to send a mail to the maintainer, if one is
listed in the port's Makefile. 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).
<p>If the maintainer asks you to do the upgrade or there isn't
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
`<tt>superedit</tt>' and the original as in our tree is
`<tt>superedit.bak</tt>', then send us the result of `<tt>diff
-ruN superedit.bak superedit</tt>'). Please examine the output
to make sure all the changes make sense. The best way to send
us the diff is by including it to <tt>send-pr(1)</tt> (category
`ports'). 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 as is in the PR.
<sect1>
<heading>Do's and Dont's
<label id="porting:dads"></heading>
<p>Here is a list of common do's and dont's 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 <ref id="contrib:general"
name="Bug Reports and General Commentary">. 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.
<sect2>
<heading>Strip Binaries</heading>
<p>Do strip binaries. If the original source already strips
the binaries, fine; otherwise you should add a <tt>post-install</tt>
rule to do it yourself. Here is an example:
<tscreen><verb>
post-install:
strip ${PREFIX}/bin/xdl
</verb></tscreen>
<p>Use the <tt>file</tt> command on the installed executable
to check whether the binary is stripped or not. If it
does not say `not stripped', it is stripped.
<sect2>
<heading>INSTALL_* macros</heading>
<p>Do use the macros provided in <tt>bsd.port.mk</tt> to
ensure correct modes and ownership of files in your own
*-install targets. They are:
<itemize>
<item><tt>${INSTALL_PROGRAM}</tt> is a command to install
binary executables.
<item><tt>${INSTALL_SCRIPT}</tt> is a command to install
executable scripts.
<item><tt>${INSTALL_DATA}</tt> is a command to install
sharable data.
<item><tt>${INSTALL_MAN}</tt> is a command to install
manpages and other documentation (it doesn't compress anything).
</itemize>
<p>These are basically the <tt>install</tt> command with all
the appropriate flags. See below for an example on how to
use them.
<sect2>
<heading><tt/WRKDIR/<label id="porting:wrkdir"></heading>
<p>Do not write anything to files outside <tt/WKRDIR/.
<tt/WRKDIR/ is the only place that is guaranteed to be
writable during the port build (see <ref id="ports:cd"
name="compiling ports frem CDROM"> for an example of
building ports from a read-only tree). If you need to
modify some file in <tt>${PKGDIR}</tt>, do so by <ref
id="porting:pkgsubdir" name="redefining a variable">, not by
writing over it.
<sect2>
<heading><tt/WRKDIRPREFIX/</heading>
<p>Make sure your port honors <tt/WRKDIRPREFIX/. (Most ports
don't have to worry about this.) In particular, if you are
referring to a <tt>${WRKDIR}</tt> of another port,
note that the correct location is
<tt>${WRKDIRPREFIX}${PORTSDIR}/subdir/name/work</tt>,
not <tt>${PORTSDIR}/subdir/name/work</tt> or
<tt>${.CURDIR}/../../subdir/name/work</tt> or some
such.
<p>Also, if you are defining <tt/WRKDIR/ yourself, make sure
you prepend <tt>${WRKDIRPREFIX}${.CURDIR}</tt>
in the front.
<sect2>
<heading>Differentiating operating systems and OS versions<label
id="porting:versions"></heading>
<p>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.
<p>The preferred way to tell 4.3BSD/Reno (1990) and newer versions of
the BSD code apart is by using the `<tt>BSD</tt>' macro
defined in <tt><sys/param.h></tt>. Hopefully that file
is already included; if not, add the code:
<tscreen><verb>
#if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h>
#endif
</verb></tscreen>
<p>to the proper place in the <tt>.c</tt> file. We believe that every
system that defines these two symbols has sys/param.h. If you find
a system that doesn't, we would like to know. Please send
mail to the &a.ports;.
<p>Another way is to use the GNU Autoconf style of doing this:
<tscreen><verb>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
</verb></tscreen>
Don't forget to add <tt>-DHAVE_SYS_PARAM_H</tt> to the <tt>CFLAGS</tt>
in the Makefile for this method.
Once you have <tt><sys/param.h></tt> included, you may use:
<tscreen><verb>
#if (defined(BSD) && (BSD >= 199103))
</verb></tscreen>
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).
Use:
<tscreen><verb>
#if (defined(BSD) && (BSD >= 199306))
</verb></tscreen>
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).
The value of the BSD macro is 199506 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 __FreeBSD__ macro should be used instead.
<p>Use sparingly:
<itemize>
<item><tt>__FreeBSD__</tt> is defined in all versions of
FreeBSD. Use it if the change you are making ONLY affects
FreeBSD. Porting gotchas like the use of
<tt>sys_errlist[]</tt> vs <tt>strerror()</tt> are
Berkeleyisms, not FreeBSD changes.
<item>In FreeBSD 2.x, <tt>__FreeBSD__</tt> is defined to be
<tt>2</tt>. In earlier versions, it is <tt>1</tt>. Later
versions will bump it to match their major version number.
<item>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 <tt>BSD</tt> macros described above. If there
actually is a FreeBSD specific change (such as special
shared library options when using `<tt>ld</tt>') then it is
OK to use <tt>__FreeBSD__</tt> and `<tt>#if __FreeBSD__ >
1</tt>' 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:
<tscreen><verb>
#if __FreeBSD__ >= 2
#include <osreldate.h>
# if __FreeBSD_version >= 199504
/* 2.0.5+ release specific code here */
# endif
#endif
</verb></tscreen>
<tt>__FreeBSD_version</tt> values:
<tscreen><verb>
2.0-RELEASE: 199411
2.1-current's: 199501, 199503
2.0.5-RELEASE: 199504
2.2-current before 2.1: 199508
2.1.0-RELEASE: 199511
2.2-current before 2.1.5: 199512
2.1.5-RELEASE: 199607
2.2-current before 2.1.6: 199608
2.1.6-RELEASE: 199612
2.1.7-RELEASE: 199612
2.2-RELEASE: 220000
2.2.1-RELEASE: 220000 (yes, no change)
2.2-STABLE after 2.2.1-RELEASE: 220000 (yes, still no change)
2.2-STABLE after texinfo-3.9: 221001
2.2-STABLE after top: 221002
2.2.2-RELEASE: 222000
2.2-STABLE after 2.2.2-RELEASE: 222001
2.2.5-RELEASE: 225000
2.2-STABLE after 2.2.5-RELEASE: 225001
2.2-STABLE after ldconfig -R merge: 225002
2.2.6-RELEASE: 226000
2.2.7-RELEASE: 227000
2.2-STABLE after 2.2.7-RELEASE: 227001
2.2-STABLE after semctl(2) change: 227002
2.2.8-RELEASE: 228000
2.2-STABLE after 2.2.8-RELEASE: 228001
3.0-current before mount(2) change: 300000
3.0-current after mount(2) change: 300001
3.0-current after semctl(2) change: 300002
3.0-current after ioctl arg changes: 300003
3.0-current after ELF conversion: 300004
3.0-RELEASE: 300005
3.0-current after 3.0-RELEASE: 300006
3.0-stable after 3/4 branch: 300007
3.1-RELEASE: 310000
3.1-stable after 3.1-RELEASE: 310001
4.0-current after 3/4 branch: 400000
</verb></tscreen>
(Note that 2.2-STABLE sometimes identifies itself as
"2.2.[5678]-STABLE" 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.
(Note that if you are making a port now, you don't have to
worry about old -current's; they are listed here just for
your reference.)
</itemize>
<p>In the hundreds of ports that have been done, there have
only been one or two cases where <tt>__FreeBSD__</tt>
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.
<sect2>
<heading>Writing something after <tt/bsd.port.mk/</heading>
<p>Do not write anything after the `<tt>.include
<bsd.port.mk></tt>' line. It usually can be avoided
by including <tt/bsd.port.pre.mk/ somewhere in the middle of
your Makefile and <tt/bsd.port.post.mk/ at the end. (Note
that you need to include either the <tt/pre.mk//<tt/post.mk/
pair or <tt/bsd.port.mk/ only; don't mix those two.) The
former only defines a few variables, which can be used in
tests in Makefiles; the latter defines the rest. Here are
some important variables defined in <tt/bsd.port.pre.mk/.
(This is not the entire list; please read <tt/bsd.port.mk/
for the complete list.)
<descrip>
<tag>&dollar{ARCH}</tag> The architecture, as returned by
`<tt>uname -m</tt>' (e.g., `i386').
<tag>&dollar{OPSYS}</tag> The operating system type, as returned by
`<tt>uname -s</tt>' (e.g., `FreeBSD').
<tag>&dollar{OSREL}</tag> The release version of the operating
system (e.g., `2.1.5', `2.2.7').
<tag>&dollar{OSVERSION}</tag> The numeric version of the
operating system, same as <ref id="porting:versions"
name="__FreeBSD_version"> above.
<tag>&dollar{PORTOBJFORMAT}</tag> The object format of the
system (`aout' or `elf').
<tag>&dollar{LOCALBASE}</tag> The base of the `local' tree
(e.g., `/usr/local/').
<tag>&dollar{X11BASE}</tag> The base of the `X11' tree
(e.g., `/usr/X11R6/').
<tag>&dollar{PREFIX}</tag> Where the port installs itself (see
<ref id="porting:prefix" name="more on PREFIX">).
</descrip>
<p>Note: if you have to define the variables <tt/USE_IMAKE/,
<tt/USE_X_PREFIX/ or <tt/MASTERDIR/, do so before including
<tt/bsd.port.pre.mk/; everything else can be either before
or after <tt/bsd.port.pre.mk/. Here are some examples of
things you can write after <tt/bsd.port.pre.mk/:
<tscreen><verb>
# 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
</verb></tscreen>
<sect2>
<heading>Install additional documentation</heading>
<p>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 <tt>${PREFIX}/share/doc</tt>.
This can be done, like the previous item, in the
<tt>post-install</tt> target.
<p>Create a new directory for your port. The directory name
should reflect what the port is. This usually means
<tt>${PKGNAME}</tt> minus the version part. 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 <tt>${PKGNAME}</tt>.
<p>Make the installation dependent on the variable
<tt>NOPORTDOCS</tt> so that users can disable it in
<tt>/etc/make.conf</tt>, like this:
<tscreen><verb>
post-install:
.if !defined(NOPORTDOCS)
${MKDIR} ${PREFIX}/share/doc/xv
${INSTALL_MAN} ${WRKSRC}/docs/xvdocs.ps ${PREFIX}/share/doc/xv
.endif
</verb></tscreen>
<p>Do not forget to add them to <tt>pkg/PLIST</tt> too! (Do not
worry about <tt>NOPORTDOCS</tt> here; there is currently no
way for the packages to read variables from
<tt>/etc/make.conf</tt>.)
<p>Also, you can use the <tt>pkg/MESSAGE</tt> file to display
messages upon installation. See the <ref id="porting:message"
name="using pkg/MESSAGE"> section for details.
<sect2>
<heading>DIST_SUBDIR</heading>
<p>Do not let your port clutter <tt>/usr/ports/distfiles</tt>. 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., `Makefile'), set
<tt>${DIST_SUBDIR}</tt> to the name of the port
(<tt>${PKGNAME}</tt> without the version part should work
fine). This will change <tt>${DISTDIR}</tt> from the
default <tt>/usr/ports/distfiles</tt> to
<tt>/usr/ports/distfiles/${DIST_SUBDIR}</tt>, and in
effect puts everything that is required for your port into that
subdirectory.
<p>It will also look at the subdirectory with the same name on the
backup master site at <tt>ftp.freebsd.org</tt>. (Setting
<tt>${DISTDIR}</tt> explicitly in your Makefile will not
accomplish this, so please use <tt>${DIST_SUBDIR}</tt>.)
<p>Note this does not affect the <tt>${MASTER_SITES}</tt>
you define in your Makefile.
<sect2>
<heading>RCS strings</heading>
<p>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
(`<tt>$</tt>') signs, and typically start with
`<tt>$Id</tt>' or `<tt>$RCS</tt>'.
<sect2>
<heading>Recursive diff</heading>
<p>Using the recurse (`<tt>-r</tt>') option to <tt>diff</tt>
to generate patches is fine, but please take a look at the
resulting patches to make sure you don't have any
unnecessary junk in there. In particular, diffs between two
backup files, Makefiles when the port uses Imake or GNU
<tt/configure/, etc., are unnecessary and should be deleted. If
you had to edit <tt/configure.in/ and run <tt/autoconf/ to
regenerate <tt/configure/, do not take the diffs of
<tt/configure/ (it often grows to a few thousand lines!);
define <tt/USE_AUTOCONF=yes/ and take the diffs of
<tt/configure.in/.
<p>Also, if you had to delete a file, then you can do it in the
<tt>post-extract</tt> 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.
<sect2>
<heading>PREFIX<label id="porting:prefix"></heading>
<p>Do try to make your port install relative to
<tt>${PREFIX}</tt>. (The value of this variable will be
set to <tt>${LOCALBASE}</tt> (default
<tt>/usr/local</tt>), unless <tt>${USE_X_PREFIX}</tt>
or <tt>${USE_IMAKE}</tt> is set, in which case it will be
<tt>${X11BASE}</tt> (default <tt>/usr/X11R6</tt>).)
<p>Not hard-coding `<tt>/usr/local</tt>' or `<tt>/usr/X11R6</tt>'
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
imake, this is automatic; otherwise, this can often be done by
simply replacing the occurrences of `<tt>/usr/local</tt>' (or
`<tt>/usr/X11R6</tt>' for X ports that do not use imake) in the
various scripts/Makefiles in the port to read
`<tt>${PREFIX}</tt>', as this variable is automatically
passed down to every stage of the build and install processes.
<p>Do not set <tt>USE_X_PREFIX</tt> unless your port truly requires
it (i.e. it links against X libs or it needs to reference
files in <tt>${X11BASE}</tt>).
<p>The variable <tt>${PREFIX}</tt> can be reassigned in your
Makefile or in the user's environment. However, it is strongly
discouraged for individual ports to set this variable explicitly
in the Makefiles.
<p>Also, refer to programs/files from other ports with the
variables mentioned above, not explicit pathnames. For instance,
if your port requires a macro <tt>PAGER</tt> to be the full
pathname of <tt>less</tt>, use the compiler flag:
<verb>-DPAGER=\"${PREFIX}/bin/less\"</verb> or
<verb>-DPAGER=\"${LOCALBASE}/bin/less\"</verb> if this is an
X port, instead of <verb>-DPAGER=\"/usr/local/bin/less\".</verb>
This way it will have a better chance of working if the system
administrator has moved the whole `/usr/local' tree somewhere
else.
<sect2>
<heading>Subdirectories</heading>
<p>Try to let the port put things in the right subdirectories
of <tt>${PREFIX}</tt>. 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
`<tt>lib</tt>', which does not bode well with the BSD
paradigm. Many of the files should be moved to one of the
following: `<tt>etc</tt>' (setup/configuration files),
`<tt>libexec</tt>' (executables started internally),
`<tt>sbin</tt>' (executables for superusers/managers),
`<tt>info</tt>' (documentation for info browser) or
`<tt>share</tt>' (architecture independent files). See man
<tt>hier(7)</tt> for details; the rules governing
<tt>/usr</tt> pretty much apply to <tt>/usr/local</tt>
too. The exceptions are ports dealing with USENET `news'.
They may use <tt>${PREFIX}/news</tt> as a destination
for their files.
<sect2>
<heading>Cleaning up empty directories<label id="porting:cleaning"></heading>
<p>Do make your ports clean up after themselves when they are
deinstalled. This is usually accomplished by adding
<tt/@dirrm/ lines for all directories that are specifically
created by the port. Note you need to delete subdirectories
before you can delete parent directories, as in:
<tscreen><verb>
:
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
</verb></tscreen>
<p>However, sometimes <tt/@dirrm/ will give you errors because
other ports also share the same subdirectory. You can call
<tt/rmdir/ from <tt/@unexec/ to remove only empty
directories without warning:
<tscreen><verb>
:
@unexec rmdir %D/share/doc/gimp 2>/dev/null || true
</verb></tscreen>
This will neither print any error messages nor cause
<tt/pkg_delete/ to exit abnormally even if
<tt>${PREFIX}/share/doc/gimp</tt> is not empty due to other
ports installing some files in there.
<sect2>
<heading>UIDs</heading>
<p>If your port requires a certain user to be on the
installed system, let the <tt>pkg/INSTALL</tt> script call
<tt>pw</tt> to create it automatically. Look at
<tt>net/cvsup-mirror</tt> for an example.
<p>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 99 and register it
below. Look at <tt>japanese/Wnn</tt> for an example.
<p>Make sure you don't use a UID already used by the system or
other ports. This is the current list of UIDs between 50
and 99.
<tscreen><verb>
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:/nonexistent
wnn:*:69:7:Wnn:/nonexistent:/nonexistent
ifmail:*:70:66:Ifmail user:/nonexistent:/nonexistent
pgsql:*:70:70:PostgreSQL pseudo-user:/usr/local/pgsql:/bin/sh
ircd:*:72:72:IRCd hybrid:/nonexistent:/nonexistent
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
</verb></tscreen>
<p>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.
<sect2>
<heading>Do things rationally</heading>
<p>The Makefile 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 `<tt>.if</tt>' construct
instead of a shell `<tt>if</tt>' construct, not redefining
<tt>do-extract</tt> if you can redefine <tt>${EXTRACT*}</tt>
instead, and using <tt>$GNU_CONFIGURE</tt> instead of
`<tt>CONFIGURE_ARGS += --prefix=${PREFIX}</tt>'.
<sect2>
<heading>Respect CFLAGS</heading>
<p>The port should respect the <tt>${CFLAGS}</tt> variable.
If it doesn't, please add `<tt>NO_PACKAGE=ignores cflags</tt>'
to the Makefile.
<sect2>
<heading>Configuration files</heading>
<p>If your port requires some configuration files in
<tt>${PREFIX}/etc</tt>, do <em/not/ just install them
and list them in <tt>pkg/PLIST</tt>. That will cause
<tt/pkg_delete/ to delete files carefully edited by the user
and a new installation to wipe them out.
<p>Instead, install sample files with a suffix
(`<tt><filename>.sample</tt>' will work well) and
print out a <ref id="porting:message" name="message">
pointing out that the user has to copy and edit the file
before the software can be made to work.
<sect2>
<heading>Portlint</heading>
<p>Do check your port with <ref id="porting:portlint"
name="portlint"> before you submit or commit it.
<sect2>
<heading>Feedback</heading>
<p>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.
<sect2>
<heading>Miscellanea</heading>
<p>The files <tt>pkg/DESCR</tt>, <tt>pkg/COMMENT</tt>, and
<tt>pkg/PLIST</tt> should each be double-checked. If you are
reviewing a port and feel they can be worded better, do so.
<p>Don't copy more copies of the GNU General Public License into
our system, please.
<p>Please be careful to note any legal issues! Don't let us
illegally distribute software!
<sect2>
<heading>If you are stuck....</heading>
<p>Do look at existing examples and the <tt>bsd.port.mk</tt>
file before asking us questions! <tt>;)</tt>
<p>Do ask us questions if you have any trouble! Do not just
beat your head against a wall! <tt>:)</tt>
<sect1>
<heading>A Sample Makefile<label id="porting:samplem"></heading>
<p>Here is a sample Makefile that you can use to create a new
port. Make sure you remove all the extra comments (ones
between brackets)!
<p>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 <ref id="porting:portlint"
name="portlint"> to check the Makefile.
<tscreen><verb>
[the header...just to make it easier for us to identify the ports.]
# New ports collection makefile for: xdvi
[the version required header should updated when upgrading a port.]
# Version required: pl18 [things like "1.5alpha" are fine here too]
[this is the date when the first version of this Makefile was created.
Never change this when doing an update of 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 <asami@FreeBSD.ORG>
#
# $Id$
[ ^^^^ This will be automatically replaced with RCS ID string by CVS
when it is committed to our repository.]
#
[section to describe the port itself and the master site - DISTNAME
is always first, followed by PKGNAME (if necessary), CATEGORIES,
and then MASTER_SITES, which can be followed by MASTER_SITE_SUBDIR.
After those, one of EXTRACT_SUFX or DISTFILES can be specified too.]
DISTNAME= xdvi
PKGNAME= xdvi-pl18
CATEGORIES= print
[do not forget the trailing slash ("/")!
if you aren't using MASTER_SITE_* macros]
MASTER_SITES= ${MASTER_SITE_XCONTRIB}
MASTER_SITE_SUBDIR= applications
[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) who 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 <bsd.port.mk>
</verb></tscreen>
<sect1>
<heading>Package Names<label id="porting:pkgname"></heading>
<p>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!
<p>The package name should look like
<tscreen><verb>
[<language>-]<name>[[-]<compiled.specifics>]-<version.string.numbers>;
</verb></tscreen>
If your <tt>${DISTNAME}</tt> doesn't look like that,
set <tt>${PKGNAME}</tt> to something in that format.
<enum>
<item>FreeBSD strives to support the native language of its
users. The `<tt><language></tt>' 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
`ja' for Japanese, `ru' for Russian, `vi' for Vietnamese,
`zh' for Chinese, `ko' for Korean and `de' for German.
<item>The `<tt><name></tt>' part should be all
lowercases, except for a really large package (with lots of
programs in it). Things like XFree86 (yes there really is a
port of it, check it out) and ImageMagick fall into this
category. Otherwise, convert the name (or at least the
first letter) to lowercase. If the capital letters are
important to the name (for example, with one-letter names
like R or V) you may use capital letters at your discretion.
There is a tradition of naming Perl 5 modules by prepending
`p5-' and converting the double-colon separator to a hyphen;
for example, the `Data::Dumper' module becomes
`p5-Data-Dumper'. If the software in question has numbers,
hyphens, or underscores in its name, you may include them as
well (like `kinput2').
<item>If the port can be built with different <ref
id="porting:masterdir" name="hardcoded defaults">
(usually part of the directory name in a family of ports), the
`<tt><compiled.specifics></tt>' part should state the
compiled-in defaults (the hyphen is optional). Examples are
papersize and font units.
<item>The version string should be a period-separated list of
integers and single lowercase alphabetics. The only exception
is the string `pl' (meaning `patchlevel'), which can be used
<em>only</em> when there are no major and minor version
numbers in the software.
</enum>
<p>Here are some (real) examples on how to convert a
<tt>${DISTNAME}</tt> into a suitable
<tt>${PKGNAME}</tt>:
<tscreen><verb>
DISTNAME PKGNAME Reason
mule-2.2.2 mule-2.2.2 no prob at all
XFree86-3.1.2 XFree86-3.1.2 ditto
EmiClock-1.0.2 emiclock-1.0.2 no uppercase names for single programs
gmod1.4 gmod-1.4 need hyphen after `<name>'
xmris.4.02 xmris-4.02 ditto
rdist-1.3alpha rdist-1.3a no strings like `alpha' allowed
es-0.9-beta1 es-0.9b1 ditto
v3.3beta021.src tiff-3.3 what the heck was that anyway? ;)
tvtwm tvtwm-pl11 version string always required
piewm piewm-1.0 ditto
xvgr-2.10pl1 xvgr-2.10.1 `pl' allowed only when no maj/minor numbers
gawk-2.15.6 ja-gawk-2.15.6 Japanese language version
psutils-1.13 psutils-letter-1.13 papersize hardcoded at package build time
pkfonts pkfonts300-1.0 package for 300dpi fonts
</verb></tscreen>
<p>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 `1.0' (like the piewm example above). Otherwise, ask the
original author or use the date string (`yy.mm.dd') as the
version.
<sect1>
<heading>Categories<label id="porting:categories"></heading>
<p>As you already know, ports are classified in several
categories. But for this to work, it is important that
porters and users understand what each category is and how we
decide what to put in each category.
<sect2>
<heading>Current list of categories</heading>
<p>First, this is the current list of port categories. Those
marked with an asterisk (<tt/*/) are <em/virtual/ categories
-- those that do not have a corresponding subdirectory in
the ports tree. Note that for non-virtual categories, you
will find a one-line description in the <tt>pkg/COMMENT</tt>
file in that subdirectory (e.g.,
<tt>archivers/pkg/COMMENT</tt>).
<descrip>
<tag><tt/afterstep*/</tag> Ports to support the AfterStep
window manager.
<tag><tt/archivers/</tag> Archiving tools.
<tag><tt/astro/</tag> Astronomical ports.
<tag><tt/audio/</tag> Sound support.
<tag><tt/benchmarks/</tag> Benchmarking utilities.
<tag><tt/biology/</tag> Biology-related software.
<tag><tt/cad/</tag> Computer aided design tools.
<tag><tt/chinese/</tag> Chinese language support.
<tag><tt/comms/</tag> Communication software. Mostly software
to talk to your serial port.
<tag><tt/converters/</tag> Character code converters.
<tag><tt/databases/</tag> Databases.
<tag><tt/deskutils/</tag> Things that used to be on the
desktop before computers were invented.
<tag><tt/devel/</tag> Development utilities. Do not put
libraries here just because they are libraries -- unless
they truly don't belong to anywhere else, they shouldn't be
in this category.
<tag><tt/editors/</tag> General editors. Specialized editors
go in the section for those tools (e.g., a
mathematical-formula editor will go in <tt/math/).
<tag><tt/elisp/</tag> Emacs-lisp ports.
<tag><tt/emulators/</tag> Emulators for other operating
systems. Terminal emulators do <em/not/ belong here --
X-based ones should go to <tt/x11/ and text-based ones to
either <tt/comms/ or <tt/misc/, depending on the exact
functionality.
<tag><tt/games/</tag> Games.
<tag><tt/german/</tag> German language support.
<tag><tt/graphics/</tag> Graphics utilities.
<tag><tt/japanese/</tag> Japanese language support.
<tag><tt/kde*/</tag> Ports that form the K Desktop Environment
(kde).
<tag><tt/korean/</tag> Korean language support.
<tag><tt/lang/</tag> Programming languages.
<tag><tt/mail/</tag> Mail software.
<tag><tt/math/</tag> Numerical computation software and other
utilities for mathematics.
<tag><tt/mbone/</tag> MBone applications.
<tag><tt/misc/</tag> Miscellaneous utilities -- basically
things that doesn't belong to anywhere else. This is the
only category that should not appear with any other
non-virtual category. If you have <tt/misc/ with something
else in your <tt/CATEGORIES/ line, that means you can safely
delete <tt/misc/ and just put the port in that other
subdirectory! <tt/:)/
<tag><tt/net/</tag> Miscellaneous networking software.
<tag><tt/news/</tag> USENET news software.
<tag><tt/offix*/</tag> Ports from the OffiX suite.
<tag><tt/palm/</tag> Software support for the 3Com Palm(tm) series.
<tag><tt/perl5*/</tag> Ports that require perl version 5 to
run.
<tag><tt/plan9*/</tag> Various programs from Plan9.
<tag><tt/print/</tag> Printing software. Desktop publishing
tools (previewers, etc.) belong here too.
<tag><tt/python*/</tag> Software written in python.
<tag><tt/russian/</tag> Russian language support.
<tag><tt/security/</tag> Security utilities.
<tag><tt/shells/</tag> Command line shells.
<tag><tt/sysutils/</tag> System utilities.
<tag><tt/tcl75*/</tag> Ports that use tcl version 7.5 to run.
<tag><tt/tcl76*/</tag> Ports that use tcl version 7.6 to run.
<tag><tt/tcl80*/</tag> Ports that use tcl version 8.0 to run.
<tag><tt/tcl81*/</tag> Ports that use tcl version 8.1 to run.
<tag><tt/textproc/</tag> Text processing utilities. It does
not include desktop publishing tools, which go to
<tt/print/.
<tag><tt/tk41*/</tag> Ports that use tk version 4.1 to run.
<tag><tt/tk42*/</tag> Ports that use tk version 4.2 to run.
<tag><tt/tk80*/</tag> Ports that use tk version 8.0 to run.
<tag><tt/tk81*/</tag> Ports that use tk version 8.1 to run.
<tag><tt/vietnamese/</tag> Vietnamese language support.
<tag><tt/windowmaker*/</tag> Ports to support the WindowMaker
window manager.
<tag><tt/www/</tag> Software related to the World Wide Web.
HTML language support belong here too.
<tag><tt/x11/</tag> The X window system and friends. This
category is only for software that directly support the
window system. Do not put regular X applications here. If
your port is an X application, define <tt/USE_XLIB/ (implied
by <tt/USE_IMAKE/) and put it in appropriate categories.
Also, many of them go into other <tt/x11-*/ categories (see
below).
<tag><tt/x11-clocks/</tag> X11 clocks.
<tag><tt/x11-fm/</tag> X11 file managers.
<tag><tt/x11-fonts/</tag> X11 fonts and font utilities.
<tag><tt/x11-toolkits/</tag> X11 toolkits.
<tag><tt/x11-wm/</tag> X11 window managers.
</descrip>
<sect2>
<heading>Choosing the right category</heading>
<p>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.
<enum>
<item>Language specific categories always come first. For
example, if your port installs Japanese X11 fonts, then your
<tt/CATEGORIES/ line should read `<tt>japanese
x11-fonts</tt>'.
<item>Specific categories win over less-specific ones. For
instance, an HTML editor should be listed as `<tt>www
editors</tt>', not the other way around. Also, you don't
need to list <tt/net/ when the port belongs to either of
<tt/mail/, <tt/mbone/, <tt/news/, <tt/security/ or <tt/www/.
<item><tt/x11/ is used as a secondary category only when the
primary category is a natural language. In particular, you
should <em/not/ put <tt/x11/ in the category line for X
applications.
<item>If your port truly doesn't belong to anywhere else, put
it in <tt/misc/.
</enum>
<p>If you are not sure about the category, please put a
comment to that effect in your <tt/send-pr/ submission so we
can discuss it before importing it. (If you are a
committer, send a note to &a.ports; so we can discuss it
first -- too often new ports are imported to a wrong
category only to be moved right away.)
<sect1>
<heading>Changes to this document and the ports system</heading>
<p>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 <htmlurl
url="http://www.FreeBSD.ORG/cgi/cvsweb.cgi/src/share/mk/bsd.port.mk"
name="the bsd.port.mk CVS log">.
<sect1>
<heading>That is It, Folks!</heading>
<p>Boy, this sure was a long tutorial, wasn't it? Thanks for
following us to here, really.
<p>Well, now that you know how to do a port, let us go at it and
convert everything in the world into ports! That is the
easiest way to start contributing to the FreeBSD Project!
<tt>:)</tt>
|