summaryrefslogtreecommitdiff
path: root/jmake/files/Jmake.rules
blob: 410fbc84c3c249468ed3a68574c26957ceaf9e90 (plain)
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
;########################################################################
;# Jmake rules for building libraries, programs, scripts, and data files
;# $Id: Jmake.rules,v 3.0.1.6 1997/02/28 14:56:01 ram Exp $

/*
 *		   MACHINE-INDEPENDENT RULES -- DO NOT MODIFY
 */

/* $Id: Jmake.rules,v 3.0.1.6 1997/02/28 14:56:01 ram Exp $
 *
 *  Copyright (c) 1991-1993, Raphael Manfredi
 *  
 *  You may redistribute only under the terms of the Artistic Licence,
 *  as specified in the README file that comes with the distribution.
 *  You may reuse parts of this distribution only within the terms of
 *  that same Artistic Licence; a copy of which may be found at the root
 *  of the source tree for dist 3.0.
 *
 * $Log: Jmake.rules,v $
 * Revision 3.0.1.6  1997/02/28  14:56:01  ram
 * patch61: now handles USRINC for dependencies
 * patch61: smarter about dependencies computation
 *
 * Revision 3.0.1.5  1995/09/25  09:07:19  ram
 * patch59: smarter sed command to strip /usr/include dependencies
 *
 * Revision 3.0.1.4  1995/07/25  13:33:59  ram
 * patch56: install of script man pages can now cope with missing files
 * patch56: the clobber target now removes the .config directory as well
 *
 * Revision 3.0.1.3  1995/03/21  08:35:28  ram
 * patch52: suppressed extra argument to NormalProgramTarget call
 *
 * Revision 3.0.1.2  1995/01/11  14:49:55  ram
 * patch45: new macros ShellScriptTargetExt and SimpleShellScriptTargetExt
 * patch45: directory installation is now made via INSTALLDIR (Configure)
 *
 * Revision 3.0.1.1  1994/10/29  15:46:30  ram
 * patch36: added RemoteDependency rule
 *
 * Revision 3.0  1993/08/18  12:04:14  ram
 * Baseline for dist 3.0 netwide release.
 *
 */

/* Please, edit only with tabstops = 4 (":set ts=4" under vi) */

/*
 * AddedByConfigure:
 *	Gives name of the files generated by Configure that can safely
 *	be removed when a "make clobber" is issued. Not that it is useless
 *	to name config.h or config.sh because these are already taken care
 *	of by jmake.
 */
#define AddedByConfigure(files) @!\
>RM @!\
local_clobber::			@@\
	$(RM) files

/*
 * AddSuffix:
 *	Adds a sufix to the .SUFFIXES: list.
 */
#define AddSuffix(ext) @!\
|suffix ext


/*
 * AllTarget:
 *	Generate rules to build necessary things during make all.
 */
#define AllTarget(depends)	@!\
>RM @!\
all:: depends				@!\
							@!\
local_realclean::			@@\
	$(RM) depends

/*
 * RemoveTargetProgram:
 *	This is used in some other macros in order to remove the target
 *	before starting its building (saves disk space).  There should be
 *	no '@!' at the end of the '#define' line, because this macro is
 *	used *inside* building rules.
 */
#define RemoveTargetProgram(program) \
>RM @!\
>MV @@\
	$(RM) program @@\
	if test -f program; then $(MV) program program^^~; else exit 0; fi

/*
 * NormalProgramTarget:
 *	Generate rules to compile and link the indicated program; since
 *	it does not use any default object files, it may be used for
 *	multiple programs in the same Jmakefile.
 */
#define	NormalProgramTarget(program,sources,objects)	@!\
>CC @!\
>RM @!\
>JLDFLAGS @!\
>LIBS @!\
++OBJECTS objects @!\
++SOURCES sources @!\
NormalObjectRule()				@!\
AllTarget(program)				@!\
								@!\
program: objects				@@\
	RemoveTargetProgram($@)		@@\
	$(CC) -o $@ objects $(JLDFLAGS) $(LIBS) @!\


/*
 * SingleProgramTarget:
 *	Obsolete version of NormalProgramTarget that doesn't have
 *	deplibs.
 */
#define	SingleProgramTarget(program,objects,libs)		\
NormalProgramTarget(program,objects,libs)

/*
 * SimpleProgramTarget:
 *	Generate rules for compiling and linking programs that only have
 *	one C source file.  It should only be used in Jmakefiles that
 *	describe a single program.
 */
#define	SimpleProgramTarget(program)	@!\
NormalProgramTarget(program,program.c,program.o)



/*
 * ComplexProgramTarget:
 *	Generate rules for compiling and linking the program specified by
 *	$(OBJS) and $(SRCS), installing the program and its man page, and
 *	generating dependencies.  It should only be used in Jmakefiles
 *	that describe a single program.
 */
#define	ComplexProgramTarget(program)	@!\
>CC @!\
>JLDFLAGS @!\
>LIBS @!\
>BINDIR @!\
>MANSRC @!\
++OBJECTS $(OBJS) @!\
++SOURCES $(SRCS) @!\
NormalObjectRule()					@!\
AllTarget(program)					@!\
									@!\
program: $(OBJS)					@@\
	RemoveTargetProgram($@)			@@\
	$(CC) -o $@ $(OBJS) $(JLDFLAGS) $(LIBS) @!\
									@!\
InstallProgram(program,$(BINDIR))	@!\
InstallManPage(program,$(MANSRC))	@!\
DependTarget()						@!\
LintTarget()


/*
 * ComplexProgramTarget_1:
 *	Generate rules for compiling and linking the program specified by
 *	$(OBJS1) and $(SRCS1), installing the program and its man page,
 *	and generating dependencies for it and any programs described by
 *	$(SRCS2) and $(SRCS3).  It should be used to build the primary
 *	program in Jmakefiles that describe multiple programs.
 */
#define	ComplexProgramTarget_1(program)	@!\
>CC @!\
>JLDFLAGS @!\
>LIBS @!\
>BINDIR @!\
>MANSRC @!\
++OBJECTS $(OBJS1) @!\
++SOURCES $(SRCS1) @!\
NormalObjectRule()					@!\
AllTarget(program)					@!\
									@!\
program: $(OBJS1)					@@\
	RemoveTargetProgram($@)			@@\
	$(CC) -o $@ $(OBJS1) $(JLDFLAGS) $(LIBS) @!\
									@!\
InstallProgram(program,$(BINDIR))	@!\
InstallManPage(program,$(MANSRC))	@!\
									@!\
DependTarget()						@!\
LintTarget()


/*
 * ComplexProgramTarget_2:
 *	Generate rules for compiling and linking the program specified by
 *	$(OBJS2) and $(SRCS2) and installing the program and man page.
 *	It should be used to build the second program in Jmakefiles
 *	describing more than one program.
 */
#define	ComplexProgramTarget_2(program)	@!\
>CC @!\
>JLDFLAGS @!\
>LIBS @!\
>BINDIR @!\
>MANSRC @!\
++OBJECTS $(OBJS2) @!\
++SOURCES $(SRCS2) @!\
NormalObjectRule()					@!\
AllTarget(program)					@!\
									@!\
program: $(OBJS2)					@@\
	RemoveTargetProgram($@)			@@\
	$(CC) -o $@ $(OBJS2) $(JLDFLAGS) $(LIBS) @!\
									@!\
InstallProgram(program,$(BINDIR))	@!\
InstallManPage(program,$(MANSRC))


/*
 * ComplexProgramTarget_3:
 *	Generate rules for compiling and linking the program specified by
 *	$(OBJS3) and $(SRCS3) and installing the program and man page.  It
 *	should be used to build the third program in Jmakefiles describing
 *	more than one program.
 */
#define	ComplexProgramTarget_3(program) @!\
>CC @!\
>JLDFLAGS @!\
>LIBS @!\
>BINDIR @!\
>MANSRC @!\
++OBJECTS $(OBJS3) @!\
++SOURCES $(SRCS3) @!\
NormalObjectRule()					@!\
AllTarget(program)					@!\
									@!\
program: $(OBJS3)					@@\
	RemoveTargetProgram($@)			@@\
	$(CC) -o $@ $(OBJS3) $(JLDFLAGS) $(LIBS) @!\
									@!\
InstallProgram(program,$(BINDIR))	@!\
InstallManPage(program,$(MANSRC))


/*
 * ComplexShellManualTarget:
 *	Builds manual pages that are to be extracted from .SH files into
 *	.$manext files.
 */
#define ComplexShellManualTarget(manpages) @!\
>INSTALL @!\
>MANSRC @!\
>RM @!\
++MANPAGE manpages @!\
|once _ShellManualRule_		@!\
|rule:.SH.$manext:			@!\
|rule: /bin/sh $<			@!\
|rule:						@!\
-once						@!\
AddSuffix(.SH)				@!\
AddSuffix(.$manext)			@!\
AllTarget(manpages)			@!\
							@!\
install.man::				@@\
	@if test "$(MANSRC)"; then \		@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		for file in manpages; do \		@@\
			(set -x; $(INSTALL) -c -m 444 $$file $(MANSRC)); \	@@\
		done; \				@@\
	else exit 0; fi			@!\
							@!\
deinstall.man::				@@\
	@if test "$(MANSRC)"; then \		@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		for file in manpages; do \		@@\
			(set -x; $(RM) $(MANSRC)/$$file); \	@@\
		done; \				@@\
	else exit 0; fi


/*
 * Initialize:
 *	Puts the line symbol = value in the initialization section of
 *	Makefile.SH (the one that is subject to parameter substitutions).
 */
#define Initialize(symbol,value) @!\
+symbol = value


/*
 * InstallLibrary:
 *	Generate rules to install the indicated library.
 */
#define	InstallLibrary(libname,dest)	@!\
>RANLIB @!\
>INSTALL @!\
>RM @!\
install:: lib^^libname.a	@@\
	$(INSTALL) -c -m 644 lib^^libname.a dest		@@\
	$(RANLIB) dest/lib^^libname.a	@@\
	chmod 444 dest/lib^^libnane.a	@!\
							@!\
deinstall::					@@\
	$(RM) dest/lib^^libname.a


/*
 * InstallSharedLibrary:
 *	Generate rules to install the shared library.
 */
#define	InstallSharedLibrary(libname,rev,dest)	@!\
>INSTALL @!\
>RM @!\
install:: lib^^libname.so.rev 	@@\
	$(INSTALL) -c -m 444 lib^^libname.so.rev dest @!\
							@!\
deinstall::					@@\
	$(RM) dest/lib^^libname.so.rev


/*
 * InstallSharedLibraryData:
 *	Generate rules to install the shared library data
 */
#define	InstallSharedLibraryData(libname,rev,dest)	@!\
>INSTALL @!\
>RM @!\
install:: lib^^libname.sa.rev		@@\
	$(INSTALL) -c -m 444 lib^^libname.sa.rev dest @!\
							@!\
deinstall::					@@\
	$(RM) dest/lib^^libname.sa.rev


/*
 * InstallLibraryAlias:
 *	Generate rules to create a link from one library name to another
 *	for the purposes of aliasing.
 */
#define	InstallLibraryAlias(libname,alias,dest)	@!\
>LN @!\
>RM @!\
install:: lib^^libname.a	@@\
	$(RM) lib^^alias.a		@@\
	-(cd dest; $(LN) lib^^libname.a lib^^alias.a) @!\
							@!\
deinstall::					@@\
	$(RM) dest/lib^^alias.a


/*
 * InstallLintLibrary:
 *	Generate rules to install the indicated lint library.
 */
#define	InstallLintLibrary(libname,dest)	@!\
>INSTALL @!\
>RM @!\
install.ln:: llib-l^^libname.ln	@@\
	$(INSTALL) -c -m 444 llib-l^^libname.ln dest @!\
							@!\
deinstall.ln::				@@\
	$(RM) dest/llib-l^^libname.ln


/*
 * InstallManPageLong:
 *	Generate rules to install the indicated manual page, giving it an
 *	alternate name.  This is used for installing man pages whose base
 *	name without the .man suffix would normally be longer than 8
 *	characters (the limit for using source code control systems on
 *	files systems with short file names).
 */
#define	InstallManPageLong(file,destdir,dest)	@!\
>L @!\
>INSTALL @!\
>RM @!\
install.man:: file.man			@@\
	$(INSTALL) -c -m 444 file.man destdir/dest.$(L) @!\
								@!\
deinstall.man::					@@\
	$(RM) destdir/dest.$(L)		@!\


/*
 * InstallManPage:
 *	Generate rules to install the indicated manual page.
 */
#define	InstallManPage(file,dest)	@!\
InstallManPageLong(file,dest,file)


/*
 * InstallNonExec:
 *	Generate rules to install a data file using any special
 *  install flags.
 */
#define	InstallNonExec(file,dest)	@!\
>INSTALL @!\
>RM @!\
install:: file						@@\
	$(INSTALL) -c -m 444 file dest	@!\
							@!\
deinstall::					@@\
	$(RM) dest/file


/*
 * InstallProgramWithFlags:
 *	Generate rules to install an executable program using given
 *	install flags.
 */
#define InstallProgramWithFlags(program,dest,flags)	@!\
>INSTALL @!\
>RM @!\
install:: program					@@\
	$(INSTALL) -c -s -m 555 flags program dest @!\
							@!\
deinstall::					@@\
	$(RM) dest/program


/*
 * InstallProgram:
 *	Generate rules to install an executable program using any special
 *	install flags set in $(INSTALLFLAGS).
 */
#define	InstallProgram(program,dest)	@!\
InstallProgramWithFlags(program,dest,^^)


/*
 * InstallScriptWithFlags:
 *	Generate rules to install an executable script using given
 *	install flags.
 */
#define InstallScriptWithFlags(script,dest,flags)	@!\
>INSTALL @!\
>RM @!\
install:: script					@@\
	$(INSTALL) -c -m 555 flags script dest @!\
							@!\
deinstall::					@@\
	$(RM) dest/script


/*
 * InstallScript:
 *	Generate rules to install an executable script using any special
 *	install flags set in $(INSTALLFLAGS).
 */
#define	InstallScript(script,dest)	@!\
InstallScriptWithFlags(script,dest,^^)


/*
 * InstallScripts:
 *	Generate rules to install all the scripts listed in the generated
 *  $(SCRIPTS) and $(LSCRIPTS) macros.
 */
#define	InstallScripts()	@!\
>SCRIPTDIR @!\
>INSTALL @!\
>RM @!\
|once _InstallScripts_		@!\
install:: $(SCRIPTS) $(LSCRIPTS) @@\
	@for file in $(SCRIPTS) $(LSCRIPTS); do \	@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		(set -x; $(INSTALL) -c -m 555 $$file $(SCRIPTDIR)); \	@@\
	done					@!\
							@!\
deinstall::					@@\
	@for file in $(SCRIPTS) $(LSCRIPTS); do \	@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		(set -x; $(RM) $(SCRIPTDIR)/$$file); \	@@\
	done					@!\
-once

/*
 * InstallManScripts:
 *	Generate rule to install/deinstall manual pages for scripts listed
 *	in the automatically generated $(SCRIPTS) macro.
 */
#define InstallManScripts()	@!\
>RM @!\
>INSTALL @!\
>MANSRC @!\
>L @!\
|once _InstallManScripts_	@!\
?NOMAN:|skip				@!\
install.man::				@@\
	@if test "$(MANSRC)"; then \	@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		for file in $(SCRIPTS); do \	@@\
			if test -f $$file.man; then \	@@\
				(set -x; \		@@\
				$(INSTALL) -c -m 444 $$file.man $(MANSRC)/$$file.$(L)); \ @@\
			fi; \				@@\
		done; \					@@\
	else exit 0; fi			@!\
							@!\
deinstall.man::				@@\
	@if test "$(MANSRC)"; then \	@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		for file in $(SCRIPTS); do \	@@\
			(set -x; $(RM) $(MANSRC)/$$file.$(L)); \	@@\
		done; \					@@\
	else exit 0; fi			@!\
							@!\
-skip						@!\
-once



/*
 * LinkFileList:
 *	Link a list of list of files from one place to another
 */
#define LinkFileList(step,list,dir,sub)	@!\
>LN @!\
step:: list							@@\
	@case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
	echo "	cd" dir; cd dir; for i in list; do (set -x; $(LN) sub/$$i .); done


/*
 * InstallMultipleDestFlags:
 *	Generate rules to install multiple files at once during a particular
 *	step in the build using a specific set of install flags. The `step'
 *	must begin with "install".
 */
#define InstallMultipleDestFlags(step,list,dest,flags)	@!\
>INSTALL @!\
>RM @!\
step:: list							@@\
	@case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
	for i in list; do \				@@\
		(set -x; $(INSTALL) -c flags $$i dest); \	@@\
	done							@!\
									@!\
de^^step::						@@\
	@case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
	for i in list; do \				@@\
		(set -x; $(RM) dest/$$i); \	@@\
	done


/*
 * InstallMultipleDest:
 *	Generate rules to install multiple files at once during a particular
 *	step in the build using any install flags set in $(INSTALLFLAGS).
 */
#define InstallMultipleDest(step,list,dest)	@!\
InstallMultipleDestFlags(step,list,dest,$(INSTALLFLAGS))

/*
 * InstallMultiple:
 *	Generate rules to install multiple files at once during the install
 *	step of the build using any install flags set in $(INSTALLFLAGS).
 */
#define	InstallMultiple(list,dest)	@!\
InstallMultipleDest(install,list,dest)


/*
 * InstallMultipleFlags:
 *	Generate rules to install multiple files at once during the
 *	install step of the build using the given install flags.
 */
#define InstallMultipleFlags(list,dest,flags)	@!\
InstallMultipleDestFlags(install,list,dest,flags)


/*
 * InstallMultipleMan:
 *	Generate rules to install a variety of manual pages
 *	during the install.man step of the build.
 */
#define InstallMultipleMan(list,dest)	@!\
>L @!\
InstallMultipleDest(install.$(L),list,dest)


/*
 * DependDependency:
 *	Generate rules to build the makedepend program.
 */
#define DependDependency() 			@!\
depend:: TOPDIR/mkdep				@!\
									@!\
TOPDIR/mkdep:						@!\
?TOP: @echo "You have to run Configure first."; exit 1	@!\
%TOP: @echo "You have to run Configure in $(TOP) first."; exit 1


/*
 * DependTarget:
 *	Generate rules to compute dependencies for all files listed
 *	in $(SOURCES) (automatically generated macro).
 */
#define	DependTarget()				@!\
>MKDEP @!\
>SED @!\
>RM @!\
+USRINC = $usrinc @!\
|once _DependTarget_				@!\
DependDependency()					@!\
									@!\
depend::							@@\
	($(SED) '/^# DO NOT DELETE/q' Makefile && \ @@\
	$(MKDEP) $(SOURCES) | \			@@\
	$(SED) -e 's:/usr/include[^ ]*::g; s:$(USRINC)[^ ]*::g; ' \ @@\
		-e '/: / b print' -e 'H; d; n; : print' -e 'x; s/\\\n//g' \ @@\
		-e 's/ ^^ */ /g; s/ :/:/;' -e '/: *$$/d' \ @@\
	) > Makefile.new				@@\
	cp Makefile Makefile.bak		@@\
	cp Makefile.new Makefile		@@\
	$(RM) Makefile.new				@!\
									@!\
-once


/*
 * CleanTarget:
 *	Generate rules to remove any garbage files.
 */
#define	CleanTarget()				@!\
>RM @!\
?SUBDIRS:clean: sub_clean local_clean				@!\
%SUBDIRS:clean: local_clean							@!\
?SUBDIRS:realclean: sub_realclean local_realclean	@!\
%SUBDIRS:realclean: local_realclean					@!\
?SUBDIRS:clobber: sub_clobber local_clobber			@!\
%SUBDIRS:clobber: local_clobber						@!\
									@!\
local_clean:: 						@@\
	$(RM) core *~ *.o				@!\
									@!\
local_realclean:: local_clean		@!\
?TOP: $(RM) -r UU					@!\
									@!\
local_clobber:: local_realclean		@!\
%TOP: $(RM) Makefile config.sh		@!\
?TOP: $(RM) config.sh config.h		@!\
?TOP: $(RM) -r .config				@!\
?TOP: $(RM) Makefile				@!\


/*
 * TagsTarget:
 *	Generate rules to compute tags files for C source code.
 */
#define	TagsTarget()				@!\
>CTAGS @!\
>RM @!\
tags::								@@\
	$(CTAGS) -w *.[ch]				@@\
	$(CTAGS) -xw *.[ch] > tags		@!\
									@!\
local_clobber::						@@\
	$(RM) tags



/*
 * BuildMakefileSH:
 *	Generate rules to build a Makefile.SH from an Jmakefile and any
 *	special jmake flags.  This is generally done automatically by the
 *	template or by any special Jmakefiles.
 *	This function will simply touch Makefile.SH if no $(TOP)/.package
 *	exists, assuming the Jmakefile is not in a production environment.
 */
#define	BuildMakefileSH(jmakeflags)	@!\
>RM @!\
>MV @!\
Makefile.SH: Jmakefile 				@@\
	-@if test -f $(TOP)/.package; then \ @@\
		if test -f Makefile.SH; then \	@@\
			echo "	$(RM) Makefile.SH~; $(MV) Makefile.SH Makefile.SH~"; \ @@\
			$(RM) Makefile.SH~; $(MV) Makefile.SH Makefile.SH~; \	@@\
		fi; \						@@\
		echo "	$(JMAKE) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT)" jmakeflags; \ @@\
		$(JMAKE) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT) jmakeflags; \ @@\
	else touch $@; exit 0; fi


/*
 * BuildMakefile:
 *	Generate rules to build a Makefile from a Makefile.SH.
 */
#define	BuildMakefile()	@!\
Makefile: Makefile.SH				@@\
	/bin/sh Makefile.SH


/*
 * MakefileTarget:
 *	Generate rules to build a normal Makefile.
 */
#define MakefileTarget()		@!\
BuildMakefileSH(^^)				@!\
BuildMakefile()


/*
 * NormalObjectRule:
 *	Generate make rule to build usual object files.
 */
#define	NormalObjectRule()			@!\
>CC @!\
>JCFLAGS @!\
|once _ObjectRule_					@!\
|rule:.c.o:							@!\
|rule: $(CC) -c $(JCFLAGS) $<		@!\
|rule:								@!\
-once

/*
 * NormalLibraryObjectRule:
 *	Generate make rules to build "normal" objects.
 */
#define	NormalLibraryObjectRule()	@!\
>CC @!\
>JCFLAGS @!\
>RM @!\
|once _ObjectRule_					@!\
|rule:.c.o:							@!\
|rule: $(RM) $@						@!\
|rule: $(CC) -c $(JCFLAGS) $<		@!\
|rule:								@!\
-once

/*
 * ProfiledLibraryObjectRule:
 *	Generate make rules to build both profiled and "normal" objects.
 */
#define	ProfiledLibraryObjectRule()	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::								@@\
	@if [ ! -d profiled ]; then mkdir profiled; else exit 0; fi	@!\
									@!\
|rule:.c.o:							@!\
|rule: $(RM) $@ profiled/$@			@!\
|rule: $(CC) -pg -c $(JCFLAGS) $*.c	@!\
|rule: $(MV) $*.o profiled/$*.o		@!\
|rule: $(CC) -c $(JCFLAGS) $*.c		@!\
|rule:								@!\
local_clean:: 						@@\
	-@if [ -d profiled ]; then echo "	$(RM) profiled/?*.o"; \	@@\
		$(RM) profiled/?*.o; else exit 0; fi


/*
 * DebuggedLibraryObjectRule:
 *	Generate make rules to build both debuggable and "normal"
 *	objects.
 */
#define	DebuggedLibraryObjectRule()					@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
									@!\
|rule:.c.o:							@!\
|rule: $(RM) $@ debugger/$@			@!\
|rule: $(CC) -g -c $(JCFLAGS) $*.c	@!\
|rule: $(MV) $*.o debugger/$*.o		@!\
|rule: $(CC) -c $(JCFLAGS) $*.c		@!\
|rule:								@!\
local_clean::						@@\
	-@if [ -d debugger ]; then echo "	$(RM) debugger/?*.o"; \ @@\
		$(RM) debugger/?*.o; else exit 0; fi


/*
 * DebuggedAndProfiledLibraryOjbectRule:
 *	Generate make rules to build debuggable, profiled, and "normal"
 *	objects.
 */
#define	DebuggedAndProfiledLibraryObjectRule()	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d profiled ]; then mkdir profiled; else exit 0; fi	@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
										@!\
|rule:.c.o:								@!\
|rule: $(RM) $@ profiled/$@ debugger/$@	@!\
|rule: $(CC) -pg -c $(JCFLAGS) $*.c		@!\
|rule: $(MV) $*.o profiled/$*.o			@!\
|rule: $(CC) -g -c $(JCFLAGS) $*.c		@!\
|rule: $(MV) $*.o debugger/$*.o			@!\
|rule: $(CC) -c $(JCFLAGS) $*.c			@!\
|rule:									@!\
local_clean::							@@\
	-@if [ -d profiled ]; then echo "	$(RM) profiled/?*.o"; \ @@\
		$(RM) profiled/?*.o; else exit 0; fi	@@\
	-@if [ -d debugger ]; then echo "	$(RM) debugger/?*.o"; \ @@\
		$(RM) debugger/?*.o; else exit 0; fi


/*
 * SharedLibraryObjectRule:
 *	Generate make rules to build shared and "normal" object files.
 */
#define SharedLibraryObjectRule()					@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::								@@\
	@if [ ! -d shared ]; then mkdir shared; else exit 0; fi		@!\
									@!\
|rule:.c.o:							@!\
|rule: $(RM) $@ shared/$@			@!\
|rule: $(CC) -pic -c $(SHAREDCODEDEF) $(SHLIBDEF) $(JCFLAGS) $*.c	@!\
|rule: $(MV) $*.o shared/$*.o		@!\
|rule: $(CC) -c $(SHLIBDEF) $(JCFLAGS) $*.c				@!\
|rule:								@!\
local_clean::						@@\
	-@if [ -d shared ]; then echo "	$(RM) shared/?*.o"; \		@@\
		$(RM) shared/?*.o; else exit 0; fi

/*
 * SharedAndDebuggedLibraryObjectRule:
 *	Generate make rules to build shared, debuggable, and "normal"
 *	object files.
 */
#define SharedAndDebuggedLibraryObjectRule()	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::										@@\
	@if [ ! -d shared ]; then mkdir shared; else exit 0; fi		@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
											@!\
|rule:.c.o:									@!\
|rule: $(RM) $@ shared/$@ debugger/$@		@!\
|rule: $(CC) -pic -c $(SHAREDCODEDEF) $(SHLIBDEF) $(JCFLAGS) $*.c	@!\
|rule: $(MV) $*.o shared/$*.o				@!\
|rule: $(CC) -g -c $(SHLIBDEF) $(JCFLAGS) $*.c	@!\
|rule: $(MV) $*.o debugger/$*.o				@!\
|rule: $(CC) -c $(SHLIBDEF) $(JCFLAGS) $*.c	@!\
|rule:										@!\
local_clean:: 								@@\
	-@if [ -d shared ]; then echo "	$(RM) shared/?*.o"; \		@@\
		$(RM) shared/?*.o; else exit 0; fi	@@\
	-@if [ -d debugger ]; then echo "	$(RM) debugger/?*.o"; \ @@\
		$(RM) debugger/?*.o; else exit 0; fi

/*
 * SpecialSharedAndDebuggedObjectRule:
 *	Generate rules to compile a file with special flags and to make
 *	shared and debuggable versions.
 */
#define	SpecialSharedAndDebuggedObjectRule(objs,depends,options)	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d shared ]; then mkdir shared; else exit 0; fi		@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
										@!\
objs:	depends							@@\
	$(RM) $@ shared/$@ debugger/$@		@@\
	$(CC) -pic -c $(SHAREDCODEDEF) $(SHLIBDEF) $(JCFLAGS) options $*.c @@\
	$(MV) $*.o shared/$*.o				@@\
	$(CC) -g -c $(SHLIBDEF) $(JCFLAGS) options $*.c			@@\
	$(MV) $*.o debugger/$*.o			@@\
	$(CC) -c $(SHLIBDEF) $(JCFLAGS) options $*.c

/*
 * SpecialSharedObjectRule:
 *	Generate rules to compile a file with special flags and to make
 *	shared and debuggable versions.
 */
#define	SpecialSharedObjectRule(objs,depends,options)		@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d shared ]; then mkdir shared; else exit 0; fi		@!\
										@!\
objs:	depends							@@\
	$(RM) $@ shared/$@ 					@@\
	$(CC) -pic -c $(SHAREDCODEDEF) $(SHLIBDEF) $(JCFLAGS) options $*.c @@\
	$(MV) $*.o shared/$*.o				@@\
	$(CC) -c $(SHLIBDEF) $(JCFLAGS) options $*.c


/*
 * SpecialObjectRule:
 *	Generate rules to compile a file with special flags.
 */
#define SpecialObjectRule(objs,depends,options)		@!\
>RM @!\
>CC @!\
>JCFLAGS @!\
objs:	depends							@@\
	$(RM) $@							@@\
	$(CC) -c $(JCFLAGS) options $*.c


/*
 * SpecialProfiledObjectRule:
 *	Generate rules to compile a file with special flags and to make a
 *	profiled version.
 */
#define	SpecialProfiledObjectRule(objs,depends,options)			@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d profiled ]; then mkdir profiled; else exit 0; fi	@!\
										@!\
objs:	depends							@@\
	$(RM) $@ profiled/$@				@@\
	$(CC) -pg -c $(JCFLAGS) options $*.c	@@\
	$(MV) $*.o profiled/$*.o			@@\
	$(CC) -c $(JCFLAGS) options $*.c


/*
 * SpecialDebuggedObjectRule:
 *	Generate rules to compile a file with special flags and to make a
 *	debuggable version.
 */
#define	SpecialDebuggedObjectRule(objs,depends,options)	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
										@!\
objs:	depends							@@\
	$(RM) $@ debugger/$@				@@\
	$(CC) -g -c $(JCFLAGS) options $*.c	@@\
	$(MV) $*.o debugger/$*.o			@@\
	$(CC) -c $(JCFLAGS) options $*.c


/*
 * SpecialDebuggedAndProfiledObjectRule:
 *	Generate rules to compile a file with special flags and to make
 *	debuggable and profiled versions.
 */
#define	SpecialDebuggedAndProfiledObjectRule(objs,depends,options)	@!\
>RM @!\
>CC @!\
>MV @!\
>JCFLAGS @!\
all::									@@\
	@if [ ! -d profiled ]; then mkdir profiled; else exit 0; fi	@@\
	@if [ ! -d debugger ]; then mkdir debugger; else exit 0; fi	@!\
										@!\
objs:	depends							@@\
	$(RM) $@ profiled/$@ debugger/$@	@@\
	$(CC) -pg -c $(JCFLAGS) options $*.c	@@\
	$(MV) $*.o profiled/$*.o			@@\
	$(CC) -g -c $(JCFLAGS) options $*.c	@@\
	$(MV) $*.o debugger/$*.o			@@\
	$(CC) -c $(JCFLAGS) options $*.c


/*
 * NormalLibraryTarget:
 *	Generate rules to create a library. The 'srclist' and 'objlist'
 *	parameters are added to SOURCES and OBJECTS macros. The 'srclist'
 *	is not otherwise used by this rule, but is necessary for make depend.
 */
#define	NormalLibraryTarget(libname,srclist,objlist)	@!\
>RM @!\
>AR @!\
>RANLIB @!\
++OBJECTS objlist @!\
++SOURCES srclist @!\
NormalLibraryObjectRule()		@!\
AllTarget(lib^^libname.a)		@!\
								@!\
lib^^libname.a: objlist			@@\
	$(RM) $@					@@\
	$(AR) $@ objlist			@@\
	$(RANLIB) $@


/*
 * NormalSharedLibraryTarget:
 *	Generate rules to create a shared library; build it into a
 *	different name so that the we don't hose people by having the
 *	library gone for long periods.
 */
#define NormalSharedLibraryTarget(libname,rev,solist)	@!\
>RM @!\
>LD @!\
>MV @!\
AllTarget(lib^^libname.so.rev)	@!\
									@!\
lib^^libname.so.rev:  solist		@@\
	$(RM) $@~						@@\
	(cd shared; $(LD) -o ../$@~ -assert pure-text solist)		@@\
	$(RM) $@ 						@@\
	$(MV) $@~ $@

/*
 * NormalSharedLibraryDataTarget:
 *	Generate rules to create shlib data file; build it into a
 *	different name so that the we don't hose people by having the
 *	library gone for long periods.
 */
#define NormalSharedLibraryDataTarget(libname,rev,salist)	@!\
>RM @!\
>AR @!\
>RANLIB @!\
AllTarget(lib^^libname.sa.rev)	@!\
									@!\
lib^^libname.sa.rev:  salist		@@\
	$(RM) $@						@@\
	$(AR) $@ salist					@@\
	$(RANLIB) $@


/*
 * NormalLibraryTarget2:
 *	Generate rules to create a library in two steps.  This is used to
 *	create libraries with large numbers of files.
 */
#define	NormalLibraryTarget2(libname,srclist,objlist1,objlist2)	@!\
>RM @!\
>AR @!\
>RANLIB @!\
++SOURCES srclist @!\
++OBJECTS objlist1 @!\
++OBJECTS objlist2 @!\
NormalLibraryObjectRule()			@!\
AllTarget(lib^^libname.a)			@!\
									@!\
lib^^libname.a: objlist1 objlist2	@@\
	$(RM) $@						@@\
	$(AR) $@ objlist1				@@\
	$(AR) $@ objlist2				@@\
	$(RANLIB) $@


/*
 * ProfiledLibraryTarget:
 *	Generate rules to create a profiled library.
 */
#define	ProfiledLibraryTarget(libname,srclist,objlist)	@!\
>RM @!\
>AR @!\
>RANLIB @!\
++SOURCES srclist @!\
++OBJECTS objlist @!\
AllTarget(lib^^libname^^_p.a)		@!\
									@!\
lib^^libname^^_p.a: objlist			@@\
	$(RM) $@						@@\
	cd profiled; $(AR) ../$@ objlist	@@\
	$(RANLIB) $@


/*
 * DebuggedLibraryTarget:
 *	Generate rules to create a debuggable library.
 */
#define	DebuggedLibraryTarget(libname,srclist,objlist)	@!\
>RM @!\
>AR @!\
>RANLIB @!\
++SOURCES srclist @!\
++OBJECTS objlist @!\
AllTarget(lib^^libname^^_d.a)		@!\
									@!\
lib^^libname^^_d.a: objlist			@@\
	$(RM) $@							@@\
	cd debugger; $(AR) ../$@ objlist	@@\
	$(RANLIB) $@


/*
 * AliasedLibraryTarget:
 *	Generate rules to link one library to another.
 */
#define	AliasedLibraryTarget(libname,alias)	@!\
>RM @!\
>LN @!\
AllTarget(lib^^alias.a)			@!\
								@!\
lib^^alias.a: lib^^libname.a	@@\
	$(RM) $@					@@\
	$(LN) lib^^libname.a $@


/*
 * PrelinkedRelocatableTarget:
 *	Generate rules to produce a relocatable object file instead of a
 *	library.
 */
#define	PrelinkedRelocatableTarget(objname,objlist,libs)	@!\
>RM @!\
>LD @!\
>JLKFLAGS @!\
AllTarget(objname.o)				@!\
									@!\
objname.o: objlist					@@\
	$(RM) $@						@@\
	$(LD) $(JLKFLAGS) -r objlist -o $@ libs


/*
 * NormalRelocatableTarget:
 *	Generate rules to produce a relocatable object file instead of a
 *	library.
 */
#define	NormalRelocatableTarget(objname,objlist)	@!\
>RM @!\
>LD @!\
>JLKFLAGS @!\
AllTarget(objname.o)				@!\
									@!\
objname.o: objlist					@@\
	$(RM) $@						@@\
	$(LD) $(JLKFLAGS) -r objlist -o $@


/*
 * ProfiledRelocatableTarget:
 *	Generate rules to produce a profiled relocatable object file
 *	instead of a library.
 */
#define	ProfiledRelocatableTarget(objname,objlist)	@!\
>RM @!\
>LD @!\
AllTarget(objname^^_p.o)		@!\
								@!\
objname^^_p.o: objlist			@@\
	$(RM) $@					@@\
	$(LD) -X -r objlist -o $@


/*
 * DebuggedRelocatableTarget:
 *	Generate rules to produce a debuggable relocatable object file
 *	instead of a library.
 */
#define	DebuggedRelocatableTarget(objname,objlist)	@!\
>RM @!\
>LD @!\
AllTarget(objname^^_d.o)		@!\
								@!\
objname^^_d.o: objlist			@@\
	$(RM) $@					@@\
	$(LD) -X -r objlist -o $@

/*
 * LintLibraryTarget:
 *	Generate rules to create a lint library.  Note that the lint
 *	library is always forced to be newer than the library itself.
 */
#define	LintLibraryTarget(libname,srclist)	@!\
>RM @!\
>LINT @!\
lintlib:: llib-l^^libname.ln	@!\
								@!\
llib-l^^libname.ln: srclist		@@\
	$(RM) $@					@@\
	$(LINT) $(LINTLIBFLAG)^^libname $(LINTFLAGS) srclist


/*
 * NormalLintTarget:
 *	Generate rules to lint a set of sources.
 */
#define NormalLintTarget(srclist)	@!\
>LINT @!\
lint:								@@\
	$(LINT) $(LINTFLAGS) srclist $(LINTLIBS)


/*
 * LintTarget:
 *	Generate rules to lint $(SOURCES) (automatically generated)
 */
#define LintTarget()			@!\
|once _LintTarget_				@!\
NormalLintTarget($(SOURCES))	@!\
-once


/*
 * LinkSourceFile:
 *	Snag source file from some other directory
 */
#define LinkSourceFile(src,dir)		@!\
>RM @!\
>LN @!\
src:  dir/src			@@\
	$(RM) $@			@@\
	$(LN) $? $@			@!\


/*
 * MakeSubincludesForBuild:
 *	Make includes in sub directories.
 */
#define MakeSubincludesForBuild(step,dir,srclist)	@!\
>RM @!\
>LN @!\
step::  dir srclist								@@\
	@-(list=`echo srclist | sed -e 's/[^ ]*\///g'`; \		@@\
		set -x; cd dir; $(RM) $$list)			@@\
	@for i in srclist; do \						@@\
		(set -x; cd dir; $(LN) ../$$i .); \		@@\
	done										@!\
												@!\
MakeDirectories(dir,dir)						@!\
												@!\
local_realclean:: 								@@\
	@-(if [ -d dir ]; then \					@@\
		list=`echo srclist | sed -e 's/[^ ]*\///g'`; \		@@\
		set -x; cd dir; $(RM) $$list; else exit 0; fi)


/*
 * CommonSubdirsRule:
 *	Rule for making $(TARGET) in every subdirectory, with $(VERB) as
 *	verbose message and $(FLAGS) as additional flags.
 */
#define CommonSubdirsRule(dirs) @!\
>MAKE	@!\
subdirs: 						@@\
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \			@@\
	for i in dirs ;\					@@\
	do \								@@\
		(cd $$i ; echo $(VERB) "in $(DIR)$$i..."; \		@@\
			$(MAKE) $(MFLAGS) $(FLAGS) $(TARGET)); \		@@\
	done
	

/*
 * NamedTargetSubdirsRule:
 *	Recursively make a series of steps in the specified directories.
 */
#define NamedTargetSubdirsRule(dirs,name,verb,flags)	@!\
>MAKE @!\
name::									@@\
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \		@@\
	for i in dirs ;\					@@\
	do \								@@\
		(cd $$i ; echo verb "in $(DIR)$$i..."; \	@@\
			$(MAKE) $(MFLAGS) flags name); \			@@\
	done
	
	
/*
 * NamedTargetSubdirs:
 *	Recursively make a series of steps.
 */
#define NamedTargetSubdirs(name,verb,flags)		@!\
>MAKE	@!\
name:: 							@@\
	@$(MAKE) subdirs TARGET=name VERB=verb FLAGS=flags


/*
 * NamedCleanTargetSubdirs:
 *	Recursively make a series of cleaning. We first clean the
 *	subdirectories, in case the Makefile is removed by the
 *	clean entry.
 */
#define NamedCleanTargetSubdirs(name,verb,flags)		@!\
>MAKE	@!\
sub_^^name:: 					@@\
	@$(MAKE) subdirs TARGET=name VERB=verb FLAGS=flags	@@\
	@echo "Back to $(CURRENT) for "name^^...


/*
 * MakeSubdirs:
 *	Generate rules to do makes in the given subdirectories.
 */
#define MakeSubdirs() \
NamedTargetSubdirs(all,"Making all",^^)


/*
 * DependDirs:
 *	Generate rules to recursively compute dependencies as part of the
 *	make depend step.
 */
#define DependDirs(dirs) \
NamedTargetSubdirsRule(dirs,depend,"Depending",^^)


/*
 * DependSubdirs:
 *	Generate rules to recursively compute dependencies as part of the
 *	make depend step.
 */
#define DependSubdirs() \
DependDirs($(SUBDIRS))


/*
 * InstallSubdirs:
 *	Generate rules to recursively install and deinstall programs and
 *	files.
 */
#define InstallSubdirs() \
NamedTargetSubdirs(install,"Installing",^^) @!\
NamedTargetSubdirs(deinstall,"Deinstalling",^^)


/*
 * InstallManSubdirs:
 *	Generate rules to recursively install and deinstall manual pages.
 */
#define InstallManSubdirs() \
NamedTargetSubdirs(install.man,"Installing man pages",^^) @!\
NamedTargetSubdirs(deinstall.man,"Deinstalling man pages",^^)


/*
 * IncludesSubdirs:
 *	Generate rules to recursively put include files in build
 */
#define IncludesSubdirs() \
NamedTargetSubdirs(includes,including,^^)


/*
 * CleanSubdirs:
 *	Generate rules to recursively clean out garbage files.
 */
#define CleanSubdirs() \
NamedCleanTargetSubdirs(clean,"Cleaning",^^)	@!\
NamedCleanTargetSubdirs(realclean,"Real cleaning",^^)	@!\
NamedCleanTargetSubdirs(clobber,"Clobbering",^^)


/*
 * TagSubdirs:
 *	Generate rules to recursively create tags files.
 */
#define TagSubdirs(dirs) \
NamedTargetSubdirsRule(dirs,tag,"Tagging",^^)

/*
 * MakeLintSubdirs:
 *	Generate rules to recursively lint directories as part of the
 *	named step.
 */
#define MakeLintSubdirs(dirs,target) \
NamedTargetSubdirsRule(dirs,target,"Linting",^^)


/*
 * LintDirs:
 *	Generate rules to recursively lint directories as part of the
 *	make lint step.
 */
#define LintDirs(dirs) \
MakeLintSubdirs(dirs,lint)


/*
 * LintSubdirs:
 *	Generate rules to recursively lint directories as part of the
 *	make lint step.
 */
#define LintSubdirs() \
LintDirs($(SUBDIRS))


/*
 * MakeDirs:
 *	Creates a set of directories, even if some directories in the path
 *	do not already exist.There should be no '@!' at the end of the
 *	'#define' line, because this macro is used *inside* building rules.
 */
#define MakeDirs(dirs) \
>INSTALLDIR @@\
	@for dir in dirs; do \		@@\
		case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
		(set -x; test -d $$dir || $(INSTALLDIR) $$dir); \	@@\
	done

/*
 * MakeDirectories:
 *	Generate rules to create a hierarchy of directories.
 */
#define MakeDirectories(step,dirs)		@!\
step::									@@\
	MakeDirs(dirs)


/*
 * MakeInstallDirectories:
 *	Generate a rule to create a set of directories at installation
 *	time (removed by deinstall).
 */
#define MakeInstallDirectories(dirs) @!\
>RM @!\
install::				@@\
	MakeDirs(dirs)		@!\
						@!\
deinstall::				@@\
	$(RM) -r dirs


/*
 * MakeLintLibSubdirs:
 *	Generate rules to recursively create lint libraries.
 */
#define MakeLintLibSubdirs(dirs)	@!\
MakeLintSubdirs(dirs,lintlib)


/*
 * MakeMakeSubdirs:
 *	Generate rules to recursively recreate target as part of the
 *	specified step in the build.  This assumes Makefile.SH has
 *	already been built (which is the case for a delivery), but does
 *	not rely on the existence of a Makefile.
 */
#define MakeMakeSubdirs(target)	@!\
>MAKE	@!\
target::								@@\
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \	@@\
	for i in $(SUBDIRS);\				@@\
	do \								@@\
		echo "Making "target" in $(DIR)$$i..."; \	@@\
		(cd $$i || exit 1; \			@@\
		if test ! -f Makefile; then /bin/sh Makefile.SH; fi; \ @@\
		$(MAKE) $(MFLAGS) target) \	@@\
	done


/*
 * MakeMakefilesSH:
 *	Generate rules to recursively recreate target as part of the
 *	specified step in the build.  If $(TOP) is set to an absolute
 *	path, don't prepend the ../ prefix.  This makes running things
 *	outside of the source tree to be much easier.
 */
#define MakeMakefilesSH()		@!\
>MAKE	@!\
Makefiles.SH:: Makefile.SH				@@\
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \	@@\
	for i in $(SUBDIRS);\					@@\
	do \								@@\
		case "$(DIR)$$i/" in \								@@\
		^^*^^/^^*^^/^^*^^/^^*^^/) newtop=../../../..;; \	@@\
		^^*^^/^^*^^/^^*^^/) newtop=../../..;; \				@@\
		^^*^^/^^*^^/) newtop=../..;; \						@@\
		*^^/) newtop=..;; \									@@\
		esac; \												@@\
		case "$(TOP)" in \				@@\
		/^^*) newtop="$(TOP)" ;; \		@@\
		esac; \							@@\
		echo "Making Makefiles.SH in $(DIR)$$i..."; \	@@\
		(cd $$i || exit 1; $(MAKE) $(MFLAGS) -f ../Makefile \	@@\
		Makefile TOP=$$newtop CURRENT=$(DIR)$$i;\	 	@@\
		$(MAKE) $(MFLAGS) Makefiles.SH) \					@@\
	done


/*
 * MakefileSubdirs:
 *	Generate rules to create Makefiles.
 */
#define MakefileSubdirs()		@!\
MakeMakeSubdirs(Makefiles)		@!\
MakeMakefilesSH()


/*
 * CppScriptTarget:
 *	Generate rules to create a shell script by running the input
 *	through cpp.
 */
#define CppScriptTarget(dst,src,defs,deplist)	@!\
>RM @!\
>CPP @!\
dst::  src deplist						@@\
	$(RM) $@							@@\
	$(CPP) defs <src | \				@@\
		sed -e '/^#  *[0-9][0-9]*  *.*$$/d' >$@		@@\
	chmod a+x $@


/*
 * MakeScriptFromCpp:
 *	Generate rules to create a script from a file with a
 *	.cpp suffix.
 */
#define MakeScriptFromCpp(name,defs)	@!\
CppScriptTarget(name,name.cpp,defs,^^)


/*
 * ShellScriptTargetExt:
 *	Generate rules to create and install a set of scripts from
 *	ext files (.sh and .SH are the most common examples). Man pages
 *	derived from the name of the scripts are also installed unless
 *	NoManPages() is specified.
 */
#define ShellScriptTargetExt(scripts,ext)	@!\
++SCRIPTS scripts @!\
SimpleShellScriptTargetExt(scripts,ext)		@!\
InstallScripts()							@!\
InstallManScripts()


/*
 * ShellScriptTarget:
 *	Generate rules to create and install a set of scripts from
 *	.SH files. Man pages derived from the name of the scripts are
 *	also installed unless NoManPages() is specified.
 */
#define ShellScriptTarget(scripts)	@!\
ShellScriptTargetExt(scripts,.SH)


/*
 * SimpleShellScriptTargetExt:
 *	Generate rules to create a set of scripts from ext files where
 *	ext is usually something like .sh or .SH, or whatever file
 *	extension you like..
 */
#define SimpleShellScriptTargetExt(scripts,ext)	@!\
>RM @!\
AllTarget(scripts)			@!\
							@!\
|expand s!scripts!			@!\
!s: !s^^ext					@@\
	/bin/sh !s^^ext			@!\
							@!\
-expand


/*
 * SimpleShellScriptTarget:
 *	Generate rules to create a set of scripts from .SH files.
 */
#define SimpleShellScriptTarget(scripts)	@!\
SimpleShellScriptTargetExt(scripts,.SH)


/*
 * ShellScriptLongTarget:
 *	Generate rules to create a set of scripts from .SH files where
 *	the name of the generated file is different from the basename of
 *	the .SH file (when, for instance, the total length with the .SH
 *	extension would not leave enough space for RCS ,v extension).
 */
#define ShellScriptLongTarget(basename,scriptname) @!\
>RM @!\
>MANSRC @!\
++LSCRIPTS scriptname @!\
AllTarget(scriptname)		@!\
							@!\
scriptname: basename^^.SH	@@\
	/bin/sh basename^^.SH	@!\
							@!\
InstallScripts()			@!\
?NOMAN:|skip				@!\
InstallManPageLong(basename,$(MANSRC),scriptname)	@!\
-skip


/*
 * ForceTarget:
 *	The force target will force reconstruction of all the other
 *	targets which include .FORCE in their own dependencies.
 */
#define ForceTarget()	@!\
|once _force_			@!\
.FORCE:					@!\
						@!\
-once


/*
 * RemoteTargetDependency:
 *	A local target may rely on a remote dependency (e.g. a library)
 *	made in a separate directory. This rule explicits the dependency
 *	and forces a make of that dependency in the remote directory.
 */
#define RemoteTargetDependency(target,directory,dependency) @!\
>MAKE @!\
RemoteDependency(directory,dependency)	@!\
target: directory/dependency	@!\


/*
 * RemoteDependency:
 *	Specify rules for making a remote dependency.
 */
#define RemoteDependency(directory,dependency) @!\
>MAKE @!\
ForceTarget()							@!\
|once =directory/dependency=			@!\
directory/dependency: .FORCE			@@\
	@echo "Checking "dependency" in "directory"..."	@@\
	cd directory; $(MAKE) dependency	@@\
	@echo "Continuing in $(CURRENT)..."	@!\
					@!\
-once

/*
 * SetSubdirs:
 *	Actually forces the definition of SUBDIRS, and lets the user
 *	specify what the sub-directories are.  This will be added to the
 *	customization part.
 */
#define SetSubdirs(subdirs) @!\
>SUBDIRS @!\
+SUBDIRS = subdirs


/*
 * NoManPages:
 *	Actually forces the definition of NOMAN, which tells the jmake
 *	program to not generate rules for installing manual pages.
 */
#define NoManPages() @!\
>NOMAN


/*
 * Expand:
 *	This powerful macro expands the `rule' given a `pattern'. It
 *	relies on a built-in command in jmake. The expansion is
 *	documented in the short notes file that comes with jmake and
 *	gives some insights on the internal syntax.
 */
#define Expand(rule, pattern) @!\
|expand pattern @!\
rule @!\
-expand


/*
 * Lex and yacc stuff.
 */

/*
 * YaccRule:
 *	This is the rule which is used to build a .c file from a .y file.
 */
#define YaccRule() @!\
AddSuffix(.y)					@!\
|once _YaccRule_				@!\
|rule:.y.c:						@!\
|rule: $(YACC) $(JYFLAGS) $<	@!\
|rule: $(MV) y.tab.c $@			@!\
|rule:							@!\
-once

/*
 * SimpleYaccTarget:
 *	Declare a yacc base.y file to be used in the building of the
 *	specified target program. The source file must be given without
 *	its final .y extension. The name of the .c and .o will be
 *	derived from the source file basename provided.
 */
#define SimpleYaccTarget(program,base) @!\
>JYFLAGS @!\
>YACC @!\
>RM @!\
>MV @!\
++SOURCES base.y @!\
++OBJECTS base.o @!\
YaccRule()				@!\
program: base.c			@!\
						@!\
local_realclean::		@@\
	$(RM) base.c		@!\


/*
 * ComplexYaccTarget:
 *	Declare a yacc base.y file to be used in the building of the
 *	specified target program. The source file must be given without
 *	its final .y extension. The name of the .c and .o will be
 *	derived from the source file basename provided.
 *	The difference with SimpleYaccTarget is the identifying process
 *	where all the 'yy' are replaced by the specified prefix.
 */
#define ComplexYaccTarget(program,base,prefix) @!\
>JYFLAGS @!\
>YACC @!\
>RM @!\
>SED @!\
++SOURCES base.y @!\
++OBJECTS base.o @!\
program: base.c			@!\
						@!\
base.c: base.y					@@\
	$(YACC) $(JYFLAGS) base.y	@@\
	$(SED) -e 's/yy\(.\)/prefix\1/g' < y.tab.c > base.c	@@\
	$(SED) -e 's/yy\(.\)/prefix\1/g' < y.tab.h > base.h	@@\
	$(RM) y.tab.c y.tab.h	@!\
							@!\
local_realclean::		@@\
	$(RM) base.c		@!\


/*
 * SimpleYaccInclude:
 *	Declare that program will need an include file produced by
 *	the output of yacc on base.y, which typically produces a file
 *	named y.tab.h, which will be renamed as base.h.
 *	The only problem is that the dependencies towards base.h have
 *	to be manually given in the Jmakefile.
 */
#define SimpleYaccInclude(base) @!\
>MV @!\
>RM @!\
base.h: base.c		@@\
	@if test -f y.tab.h; then \	@@\
		echo "	$(MV) y.tab.h $@"; \	@@\
		$(MV) y.tab.h $@; \		@@\
	else \						@@\
		exit 0; \				@@\
	fi							@!\
								@!\
local_realclean::				@@\
	$(RM) base.h

/*
 * ComplexYaccInclude:
 *	Declare that program will need an include file produced by
 *	the output of yacc on base.y, which typically produces a file
 *	named y.tab.h, which will be renamed as base.h.
 *	The difference with SimpleYaccInclude is the identifying process
 *	of the y.tab.h file where all 'yy' are renamed to prefix.
 *	The only problem is that the dependencies towards base.h have
 *	to be manually given in the Jmakefile.
 */
#define ComplexYaccInclude(base,prefix) @!\
>RM @!\
>SED @!\
>CP @!\
base.h: base.c		@@\
	@if test -f y.tab.h; then \	@@\
		echo "	$(SED) -e 's/yy\(.\)/prefix\1/g' < y.tab.h > base.h"; \	@@\
		$(SED) -e 's/yy\(.\)/prefix\1/g' < y.tab.h > base.h; \	@@\
		echo "	$(RM) y.tab.h"; \	@@\
		$(RM) y.tab.h; \		@@\
	elif test -f base.h; then \ @@\
		echo "	$(CP) base.h base.ht"; \	@@\
		$(CP) base.h base.ht; \	@@\
		echo "	$(SED) -e 's/yy\(.\)/prefix\1/g' < base.ht > base.h"; \	@@\
		$(SED) -e 's/yy\(.\)/prefix\1/g' < base.ht > base.h; \	@@\
		echo "	$(RM) base.ht"; \ @@\
		$(RM) base.ht; \		@@\
	else \						@@\
		exit 0; \				@@\
	fi							@!\
								@!\
local_realclean::				@@\
	$(RM) base.h


/*
 * NormalYaccTarget:
 *	Declare a yacc base.y file which should produce a base.c and
 *	base.h file as derived from the output of yacc, to be used by
 *	the specified program.
 */
#define NormalYaccTarget(program,base) @!\
SimpleYaccTarget(program,base) @!\
SimpleYaccInclude(base)


/*
 * IdentifiedYaccTarget:
 *	Declare a yacc base.y file which should produce a base.c and
 *	base.h file as derived from the output of yacc, to be used by
 *	the specified program. The specified prefix is used to remplace
 *	all the 'yy' in the generated file, for use when more than a
 *	single parser is needed in one executable.
 */
#define IdentifiedYaccTarget(program,base,prefix) @!\
ComplexYaccTarget(program,base,prefix) @!\
ComplexYaccInclude(base,prefix)


/*
 * SimpleLexTarget:
 *	This declares a lex base.l file which is to be ran through
 *	lex to produce a base.c file.
 */
#define SimpleLexTarget(program,base) @!\
>JLFLAGS @!\
>LEX @!\
>RM @!\
>MV @!\
++SOURCES base.l @!\
++OBJECTS base.o @!\
|once _LexRule_					@!\
|rule:.l.c:						@!\
|rule: $(LEX) $(JLFLAGS) $<		@!\
|rule: $(MV) lex.yy.c $@		@!\
|rule:							@!\
-once							@!\
AddSuffix(.l)			@!\
program: base.c			@!\
						@!\
local_realclean::		@@\
	$(RM) base.c		@!\


/*
 * IdentifiedLexTarget:
 *	This declares a lex base.l file which is to be ran through
 *	lex to produce a base.c file. The prefix is used to replace
 *	the 'yy', so that the lexical analyzer may be identified.
 */
#define IdentifiedLexTarget(program,base,prefix) @!\
>JLFLAGS @!\
>LEX @!\
>RM @!\
>SED @!\
++SOURCES base.l @!\
++OBJECTS base.o @!\
program: base.c			@!\
						@!\
base.c: base.l					@@\
	$(LEX) $(JLFLAGS) base.l	@@\
	$(SED) -e 's/yy\(.\)/prefix\1/g' < lex.yy.c > base.c	@@\
	$(RM) lex.yy.c				@!\
						@!\
local_realclean::		@@\
	$(RM) base.c		@!\


/*
 * NormalLexDependTarget:
 *	Declare that program will need an include file produced by
 *	the output of lex on base.l, which typically produces a file
 *	named lex.yy.c which will be renamed as base.c. Besides, the
 *	lexical analyzer needs the file parser.h produced by running
 *	parser.y through yacc and renaming y.tab.h as parser.h.
 */
#define NormalLexDependTarget(program,base,parser) @!\
base.o: parser.h	@!\
					@!\
SimpleLexTarget(program,base)


/*
 * IdentifiedLexDependTarget:
 *	Declare that program will need an include file produced by
 *	the output of lex on base.l, which typically produces a file
 *	named lex.yy.c which will be renamed as base.c. Besides, the
 *	lexical analyzer needs the file parser.h produced by running
 *	parser.y through yacc and renaming y.tab.h as parser.h.
 *	The lexical analyzer is identified with the supplied prefix,
 *	which replaces the regular 'yy' prefix in the symbol names.
 */
#define IdentifiedLexDependTarget(program,base,parser,prefix) @!\
base.o: parser.h	@!\
					@!\
IdentifiedLexTarget(program,base,prefix)


/*
 * NormalParserTarget:
 *	Specify that program is using the lex/yacc combination to
 *	produce a parser. The lexic and parser parameters are the
 *	base name of the .l and .y file, respectively.
 */
#define NormalParserTarget(program,lexic,parser) @!\
NormalLexDependTarget(program,lexic,parser) @!\
NormalYaccTarget(program,parser)


/*
 * IdentifiedParserTarget:
 *	Specify that program is using the lex/yacc combination to
 *	produce a parser. The lexic and parser parameters are the
 *	base name of the .l and .y file, respectively. The parser
 *	produced is identified via its prefix, which replaces all
 *	the normally supplied 'yy' prefix, hence making it possible
 *	to have multiple parsers in a single executable.
 */
#define IdentifiedParserTarget(program,lexic,parser,prefix) @!\
IdentifiedLexDependTarget(program,lexic,parser,prefix) @!\
IdentifiedYaccTarget(program,parser,prefix)