This file is indexed.

/usr/share/doc/make-doc/make_14.html is in make-doc 3.81-5.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- This file documents the GNU make utility, which determines
automatically which pieces of a large program need to be recompiled,
and issues the commands to recompile them.

This is Edition 0.70, last updated 1 April 2006,
of The GNU Make Manual, for GNU make version 3.81.

Copyright C 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.  A copy of the
license is included in the section entitled "GNU Free Documentation
License."

(a) The FSF's Back-Cover Text is: "You have freedom to copy and modify
this GNU Manual, like GNU software.  Copies published by the Free
Software Foundation raise funds for GNU development."

 -->
<!-- Created on August, 17 2009 by texi2html 1.78 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>

-->
<head>
<title>GNU make: 14. Makefile Conventions</title>

<meta name="description" content="GNU make: 14. Makefile Conventions">
<meta name="keywords" content="GNU make: 14. Makefile Conventions">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.78">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Makefile-Conventions"></a>
<a name="SEC136"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="make_13.html#SEC135" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC137" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make_13.html#SEC135" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 14. Makefile Conventions </h1>



<p>This
describes conventions for writing the Makefiles for GNU programs.
Using Automake will help you write a Makefile that follows these
conventions.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC137">14.1 General Conventions for Makefiles</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SEC138">14.2 Utilities in Makefiles</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SEC139">14.3 Variables for Specifying Commands</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SEC140">14.4 Variables for Installation Directories</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SEC141">14.5 Standard Targets for Users</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SEC142">14.6 Install Command Categories</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">  Three categories of commands in the `install'
                                  rule: normal, pre-install and post-install.
</td></tr>
</table>

<hr size="6">
<a name="Makefile-Basics"></a>
<a name="SEC137"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC136" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC138" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.1 General Conventions for Makefiles </h2>

<p>Every Makefile should contain this line:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">SHELL = /bin/sh
</pre></td></tr></table>

<p>to avoid trouble on systems where the <code>SHELL</code> variable might be
inherited from the environment.  (This is never a problem with GNU
<code>make</code>.)
</p>
<p>Different <code>make</code> programs have incompatible suffix lists and
implicit rules, and this sometimes creates confusion or misbehavior.  So
it is a good idea to set the suffix list explicitly using only the
suffixes you need in the particular Makefile, like this:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">.SUFFIXES:
.SUFFIXES: .c .o
</pre></td></tr></table>

<p>The first line clears out the suffix list, the second introduces all
suffixes which may be subject to implicit rules in this Makefile.
</p>
<p>Don't assume that &lsquo;<tt>.</tt>&rsquo; is in the path for command execution.  When
you need to run programs that are a part of your package during the
make, please make sure that it uses &lsquo;<tt>./</tt>&rsquo; if the program is built as
part of the make or &lsquo;<tt>$(srcdir)/</tt>&rsquo; if the file is an unchanging part
of the source code.  Without one of these prefixes, the current search
path is used.
</p>
<p>The distinction between &lsquo;<tt>./</tt>&rsquo; (the <em>build directory</em>) and
&lsquo;<tt>$(srcdir)/</tt>&rsquo; (the <em>source directory</em>) is important because
users can build in a separate directory using the &lsquo;<samp>--srcdir</samp>&rsquo; option
to &lsquo;<tt>configure</tt>&rsquo;.  A rule of the form:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">foo.1 : foo.man sedscript
        sed -e sedscript foo.man &gt; foo.1
</pre></td></tr></table>

<p>will fail when the build directory is not the source directory, because
&lsquo;<tt>foo.man</tt>&rsquo; and &lsquo;<tt>sedscript</tt>&rsquo; are in the source directory.
</p>
<p>When using GNU <code>make</code>, relying on &lsquo;<samp>VPATH</samp>&rsquo; to find the source
file will work in the case where there is a single dependency file,
since the <code>make</code> automatic variable &lsquo;<samp>$&lt;</samp>&rsquo; will represent the
source file wherever it is.  (Many versions of <code>make</code> set &lsquo;<samp>$&lt;</samp>&rsquo;
only in implicit rules.)  A Makefile target like
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">foo.o : bar.c
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
</pre></td></tr></table>

<p>should instead be written as
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">foo.o : bar.c
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c $&lt; -o $@
</pre></td></tr></table>

<p>in order to allow &lsquo;<samp>VPATH</samp>&rsquo; to work correctly.  When the target has
multiple dependencies, using an explicit &lsquo;<samp>$(srcdir)</samp>&rsquo; is the easiest
way to make the rule work well.  For example, the target above for
&lsquo;<tt>foo.1</tt>&rsquo; is best written as:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">foo.1 : foo.man sedscript
        sed -e $(srcdir)/sedscript $(srcdir)/foo.man &gt; $@
</pre></td></tr></table>

<p>GNU distributions usually contain some files which are not source
files&mdash;for example, Info files, and the output from Autoconf, Automake,
Bison or Flex.  Since these files normally appear in the source
directory, they should always appear in the source directory, not in the
build directory.  So Makefile rules to update them should put the
updated files in the source directory.
</p>
<p>However, if a file does not appear in the distribution, then the
Makefile should not put it in the source directory, because building a
program in ordinary circumstances should not modify the source directory
in any way.
</p>
<p>Try to make the build and installation targets, at least (and all their
subtargets) work correctly with a parallel <code>make</code>.
</p>
<hr size="6">
<a name="Utilities-in-Makefiles"></a>
<a name="SEC138"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC137" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC139" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.2 Utilities in Makefiles </h2>

<p>Write the Makefile commands (and any shell scripts, such as
<code>configure</code>) to run in <code>sh</code>, not in <code>csh</code>.  Don't use any
special features of <code>ksh</code> or <code>bash</code>.
</p>
<p>The <code>configure</code> script and the Makefile rules for building and
installation should not use any utilities directly except these:
</p>

<table><tr><td>&nbsp;</td><td><pre class="example">cat cmp cp diff echo egrep expr false grep install-info
ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
</pre></td></tr></table>

<p>The compression program <code>gzip</code> can be used in the <code>dist</code> rule.
</p>
<p>Stick to the generally supported options for these programs.  For
example, don't use &lsquo;<samp>mkdir -p</samp>&rsquo;, convenient as it may be, because
most systems don't support it.
</p>
<p>It is a good idea to avoid creating symbolic links in makefiles, since a
few systems don't support them.
</p>
<p>The Makefile rules for building and installation can also use compilers
and related programs, but should do so via <code>make</code> variables so that the
user can substitute alternatives.  Here are some of the programs we
mean:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">ar bison cc flex install ld ldconfig lex
make makeinfo ranlib texi2dvi yacc
</pre></td></tr></table>

<p>Use the following <code>make</code> variables to run those programs:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
</pre></td></tr></table>

<p>When you use <code>ranlib</code> or <code>ldconfig</code>, you should make sure
nothing bad happens if the system does not have the program in question.
Arrange to ignore an error from that command, and print a message before
the command to tell the user that failure of this command does not mean
a problem.  (The Autoconf &lsquo;<samp>AC_PROG_RANLIB</samp>&rsquo; macro can help with
this.)
</p>
<p>If you use symbolic links, you should implement a fallback for systems
that don't have symbolic links.
</p>
<p>Additional utilities that can be used via Make variables are:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">chgrp chmod chown mknod
</pre></td></tr></table>

<p>It is ok to use other utilities in Makefile portions (or scripts)
intended only for particular systems where you know those utilities
exist.
</p>
<hr size="6">
<a name="Command-Variables"></a>
<a name="SEC139"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC138" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC140" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.3 Variables for Specifying Commands </h2>

<p>Makefiles should provide variables for overriding certain commands, options,
and so on.
</p>
<p>In particular, you should run most utility programs via variables.
Thus, if you use Bison, have a variable named <code>BISON</code> whose default
value is set with &lsquo;<samp>BISON = bison</samp>&rsquo;, and refer to it with
<code>$(BISON)</code> whenever you need to use Bison.
</p>
<p>File management utilities such as <code>ln</code>, <code>rm</code>, <code>mv</code>, and
so on, need not be referred to through variables in this way, since users
don't need to replace them with other programs.
</p>
<p>Each program-name variable should come with an options variable that is
used to supply options to the program.  Append &lsquo;<samp>FLAGS</samp>&rsquo; to the
program-name variable name to get the options variable name&mdash;for
example, <code>BISONFLAGS</code>.  (The names <code>CFLAGS</code> for the C
compiler, <code>YFLAGS</code> for yacc, and <code>LFLAGS</code> for lex, are
exceptions to this rule, but we keep them because they are standard.)
Use <code>CPPFLAGS</code> in any compilation command that runs the
preprocessor, and use <code>LDFLAGS</code> in any compilation command that
does linking as well as in any direct use of <code>ld</code>.
</p>
<p>If there are C compiler options that <em>must</em> be used for proper
compilation of certain files, do not include them in <code>CFLAGS</code>.
Users expect to be able to specify <code>CFLAGS</code> freely themselves.
Instead, arrange to pass the necessary options to the C compiler
independently of <code>CFLAGS</code>, by writing them explicitly in the
compilation commands or by defining an implicit rule, like this:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
.c.o:
        $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $&lt;
</pre></td></tr></table>

<p>Do include the &lsquo;<samp>-g</samp>&rsquo; option in <code>CFLAGS</code>, because that is not
<em>required</em> for proper compilation.  You can consider it a default
that is only recommended.  If the package is set up so that it is
compiled with GCC by default, then you might as well include &lsquo;<samp>-O</samp>&rsquo;
in the default value of <code>CFLAGS</code> as well.
</p>
<p>Put <code>CFLAGS</code> last in the compilation command, after other variables
containing compiler options, so the user can use <code>CFLAGS</code> to
override the others.
</p>
<p><code>CFLAGS</code> should be used in every invocation of the C compiler,
both those which do compilation and those which do linking.
</p>
<p>Every Makefile should define the variable <code>INSTALL</code>, which is the
basic command for installing a file into the system.
</p>
<p>Every Makefile should also define the variables <code>INSTALL_PROGRAM</code>
and <code>INSTALL_DATA</code>.  (The default for <code>INSTALL_PROGRAM</code> should
be <code>$(INSTALL)</code>; the default for <code>INSTALL_DATA</code> should be
<code>${INSTALL} -m 644</code>.)  Then it should use those variables as the
commands for actual installation, for executables and nonexecutables
respectively.  Use these variables as follows:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">$(INSTALL_PROGRAM) foo $(bindir)/foo
$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
</pre></td></tr></table>

<p>Optionally, you may prepend the value of <code>DESTDIR</code> to the target
filename.  Doing this allows the installer to create a snapshot of the
installation to be copied onto the real target filesystem later.  Do not
set the value of <code>DESTDIR</code> in your Makefile, and do not include it
in any installed files.  With support for <code>DESTDIR</code>, the above
examples become:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">$(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
$(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
</pre></td></tr></table>

<p>Always use a file name, not a directory name, as the second argument of
the installation commands.  Use a separate command for each file to be
installed.
</p>
<hr size="6">
<a name="Directory-Variables"></a>
<a name="SEC140"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC139" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC141" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.4 Variables for Installation Directories </h2>

<p>Installation directories should always be named by variables, so it is
easy to install in a nonstandard place.  The standard names for these
variables and the values they should have in GNU packages are
described below.  They are based on a standard filesystem layout;
variants of it are used in GNU/Linux and other modern operating
systems.
</p>
<p>Installers are expected to override these values when calling
<code>make</code> (e.g., <kbd>make prefix=/usr install</kbd> or
<code>configure</code> (e.g., <kbd>configure --prefix=/usr</kbd>).  GNU
packages should not try to guess which value should be appropriate for
these variables on the system they are being installed onto: use the
default settings specified here so that all GNU packages behave
identically, allowing the installer to achieve any desired layout.
</p>
<p>These two variables set the root for the installation.  All the other
installation directories should be subdirectories of one of these two,
and nothing should be directly installed into these two directories.
</p>
<dl compact="compact">
<dt> <code>prefix</code></dt>
<dd><a name="IDX632"></a>
<p>A prefix used in constructing the default values of the variables listed
below.  The default value of <code>prefix</code> should be &lsquo;<tt>/usr/local</tt>&rsquo;.
When building the complete GNU system, the prefix will be empty and
&lsquo;<tt>/usr</tt>&rsquo; will be a symbolic link to &lsquo;<tt>/</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@prefix@</samp>&rsquo;.)
</p>
<p>Running &lsquo;<samp>make install</samp>&rsquo; with a different value of <code>prefix</code> from
the one used to build the program should <em>not</em> recompile the
program.
</p>
</dd>
<dt> <code>exec_prefix</code></dt>
<dd><a name="IDX633"></a>
<p>A prefix used in constructing the default values of some of the
variables listed below.  The default value of <code>exec_prefix</code> should
be <code>$(prefix)</code>.
(If you are using Autoconf, write it as &lsquo;<samp>@exec_prefix@</samp>&rsquo;.)
</p>
<p>Generally, <code>$(exec_prefix)</code> is used for directories that contain
machine-specific files (such as executables and subroutine libraries),
while <code>$(prefix)</code> is used directly for other directories.
</p>
<p>Running &lsquo;<samp>make install</samp>&rsquo; with a different value of <code>exec_prefix</code>
from the one used to build the program should <em>not</em> recompile the
program.
</p></dd>
</dl>

<p>Executable programs are installed in one of the following directories.
</p>
<dl compact="compact">
<dt> <code>bindir</code></dt>
<dd><a name="IDX634"></a>
<p>The directory for installing executable programs that users can run.
This should normally be &lsquo;<tt>/usr/local/bin</tt>&rsquo;, but write it as
&lsquo;<tt>$(exec_prefix)/bin</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@bindir@</samp>&rsquo;.)
</p>
</dd>
<dt> <code>sbindir</code></dt>
<dd><a name="IDX635"></a>
<p>The directory for installing executable programs that can be run from
the shell, but are only generally useful to system administrators.  This
should normally be &lsquo;<tt>/usr/local/sbin</tt>&rsquo;, but write it as
&lsquo;<tt>$(exec_prefix)/sbin</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@sbindir@</samp>&rsquo;.)
</p>
</dd>
<dt> <code>libexecdir</code></dt>
<dd><a name="IDX636"></a>
<p>The directory for installing executable programs to be run by other
programs rather than by users.  This directory should normally be
&lsquo;<tt>/usr/local/libexec</tt>&rsquo;, but write it as &lsquo;<tt>$(exec_prefix)/libexec</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@libexecdir@</samp>&rsquo;.)
</p>
<p>The definition of &lsquo;<samp>libexecdir</samp>&rsquo; is the same for all packages, so
you should install your data in a subdirectory thereof.  Most packages
install their data under &lsquo;<tt>$(libexecdir)/<var>package-name</var>/</tt>&rsquo;,
possibly within additional subdirectories thereof, such as
&lsquo;<tt>$(libexecdir)/<var>package-name</var>/<var>machine</var>/<var>version</var></tt>&rsquo;.
</p></dd>
</dl>

<p>Data files used by the program during its execution are divided into
categories in two ways.
</p>
<ul>
<li>
Some files are normally modified by programs; others are never normally
modified (though users may edit some of these).

</li><li>
Some files are architecture-independent and can be shared by all
machines at a site; some are architecture-dependent and can be shared
only by machines of the same kind and operating system; others may never
be shared between two machines.
</li></ul>

<p>This makes for six different possibilities.  However, we want to
discourage the use of architecture-dependent files, aside from object
files and libraries.  It is much cleaner to make other data files
architecture-independent, and it is generally not hard.
</p>
<p>Here are the variables Makefiles should use to specify directories
to put these various kinds of files in:
</p>
<dl compact="compact">
<dt> &lsquo;<samp>datarootdir</samp>&rsquo;</dt>
<dd><p>The root of the directory tree for read-only architecture-independent
data files.  This should normally be &lsquo;<tt>/usr/local/share</tt>&rsquo;, but
write it as &lsquo;<tt>$(prefix)/share</tt>&rsquo;.  (If you are using Autoconf, write
it as &lsquo;<samp>@datarootdir@</samp>&rsquo;.)  &lsquo;<samp>datadir</samp>&rsquo;'s default value is
based on this variable; so are &lsquo;<samp>infodir</samp>&rsquo;, &lsquo;<samp>mandir</samp>&rsquo;, and
others.
</p>
</dd>
<dt> &lsquo;<samp>datadir</samp>&rsquo;</dt>
<dd><p>The directory for installing idiosyncratic read-only
architecture-independent data files for this program.  This is usually
the same place as &lsquo;<samp>datarootdir</samp>&rsquo;, but we use the two separate
variables so that you can move these program-specific files without
altering the location for Info files, man pages, etc.
</p>
<p>This should normally be &lsquo;<tt>/usr/local/share</tt>&rsquo;, but write it as
&lsquo;<tt>$(datarootdir)</tt>&rsquo;.  (If you are using Autoconf, write it as
&lsquo;<samp>@datadir@</samp>&rsquo;.)
</p>
<p>The definition of &lsquo;<samp>datadir</samp>&rsquo; is the same for all packages, so you
should install your data in a subdirectory thereof.  Most packages
install their data under &lsquo;<tt>$(datadir)/<var>package-name</var>/</tt>&rsquo;.
</p>
</dd>
<dt> &lsquo;<samp>sysconfdir</samp>&rsquo;</dt>
<dd><p>The directory for installing read-only data files that pertain to a
single machine&ndash;that is to say, files for configuring a host.  Mailer
and network configuration files, &lsquo;<tt>/etc/passwd</tt>&rsquo;, and so forth belong
here.  All the files in this directory should be ordinary ASCII text
files.  This directory should normally be &lsquo;<tt>/usr/local/etc</tt>&rsquo;, but
write it as &lsquo;<tt>$(prefix)/etc</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@sysconfdir@</samp>&rsquo;.)
</p>
<p>Do not install executables here in this directory (they probably belong
in &lsquo;<tt>$(libexecdir)</tt>&rsquo; or &lsquo;<tt>$(sbindir)</tt>&rsquo;).  Also do not install
files that are modified in the normal course of their use (programs
whose purpose is to change the configuration of the system excluded).
Those probably belong in &lsquo;<tt>$(localstatedir)</tt>&rsquo;.
</p>
</dd>
<dt> &lsquo;<samp>sharedstatedir</samp>&rsquo;</dt>
<dd><p>The directory for installing architecture-independent data files which
the programs modify while they run.  This should normally be
&lsquo;<tt>/usr/local/com</tt>&rsquo;, but write it as &lsquo;<tt>$(prefix)/com</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@sharedstatedir@</samp>&rsquo;.)
</p>
</dd>
<dt> &lsquo;<samp>localstatedir</samp>&rsquo;</dt>
<dd><p>The directory for installing data files which the programs modify while
they run, and that pertain to one specific machine.  Users should never
need to modify files in this directory to configure the package's
operation; put such configuration information in separate files that go
in &lsquo;<tt>$(datadir)</tt>&rsquo; or &lsquo;<tt>$(sysconfdir)</tt>&rsquo;.  &lsquo;<tt>$(localstatedir)</tt>&rsquo;
should normally be &lsquo;<tt>/usr/local/var</tt>&rsquo;, but write it as
&lsquo;<tt>$(prefix)/var</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@localstatedir@</samp>&rsquo;.)
</p></dd>
</dl>

<p>These variables specify the directory for installing certain specific
types of files, if your program has them.  Every GNU package should
have Info files, so every program needs &lsquo;<samp>infodir</samp>&rsquo;, but not all
need &lsquo;<samp>libdir</samp>&rsquo; or &lsquo;<samp>lispdir</samp>&rsquo;.
</p>
<dl compact="compact">
<dt> &lsquo;<samp>includedir</samp>&rsquo;</dt>
<dd><p>The directory for installing header files to be included by user
programs with the C &lsquo;<samp>#include</samp>&rsquo; preprocessor directive.  This
should normally be &lsquo;<tt>/usr/local/include</tt>&rsquo;, but write it as
&lsquo;<tt>$(prefix)/include</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@includedir@</samp>&rsquo;.)
</p>
<p>Most compilers other than GCC do not look for header files in directory
&lsquo;<tt>/usr/local/include</tt>&rsquo;.  So installing the header files this way is
only useful with GCC.  Sometimes this is not a problem because some
libraries are only really intended to work with GCC.  But some libraries
are intended to work with other compilers.  They should install their
header files in two places, one specified by <code>includedir</code> and one
specified by <code>oldincludedir</code>.
</p>
</dd>
<dt> &lsquo;<samp>oldincludedir</samp>&rsquo;</dt>
<dd><p>The directory for installing &lsquo;<samp>#include</samp>&rsquo; header files for use with
compilers other than GCC.  This should normally be &lsquo;<tt>/usr/include</tt>&rsquo;.
(If you are using Autoconf, you can write it as &lsquo;<samp>@oldincludedir@</samp>&rsquo;.)
</p>
<p>The Makefile commands should check whether the value of
<code>oldincludedir</code> is empty.  If it is, they should not try to use
it; they should cancel the second installation of the header files.
</p>
<p>A package should not replace an existing header in this directory unless
the header came from the same package.  Thus, if your Foo package
provides a header file &lsquo;<tt>foo.h</tt>&rsquo;, then it should install the header
file in the <code>oldincludedir</code> directory if either (1) there is no
&lsquo;<tt>foo.h</tt>&rsquo; there or (2) the &lsquo;<tt>foo.h</tt>&rsquo; that exists came from the Foo
package.
</p>
<p>To tell whether &lsquo;<tt>foo.h</tt>&rsquo; came from the Foo package, put a magic
string in the file&mdash;part of a comment&mdash;and <code>grep</code> for that string.
</p>
</dd>
<dt> &lsquo;<samp>docdir</samp>&rsquo;</dt>
<dd><p>The directory for installing documentation files (other than Info) for
this package.  By default, it should be
&lsquo;<tt>/usr/local/share/doc/<var>yourpkg</var></tt>&rsquo;, but it should be written as
&lsquo;<tt>$(datarootdir)/doc/<var>yourpkg</var></tt>&rsquo;.  (If you are using Autoconf,
write it as &lsquo;<samp>@docdir@</samp>&rsquo;.)  The <var>yourpkg</var> subdirectory, which
may include a version number, prevents collisions among files with
common names, such as &lsquo;<tt>README</tt>&rsquo;.
</p>
</dd>
<dt> &lsquo;<samp>infodir</samp>&rsquo;</dt>
<dd><p>The directory for installing the Info files for this package.  By
default, it should be &lsquo;<tt>/usr/local/share/info</tt>&rsquo;, but it should be
written as &lsquo;<tt>$(datarootdir)/info</tt>&rsquo;.  (If you are using Autoconf,
write it as &lsquo;<samp>@infodir@</samp>&rsquo;.)  <code>infodir</code> is separate from
<code>docdir</code> for compatibility with existing practice.
</p>
</dd>
<dt> &lsquo;<samp>htmldir</samp>&rsquo;</dt>
<dt> &lsquo;<samp>dvidir</samp>&rsquo;</dt>
<dt> &lsquo;<samp>pdfdir</samp>&rsquo;</dt>
<dt> &lsquo;<samp>psdir</samp>&rsquo;</dt>
<dd><p>Directories for installing documentation files in the particular
format.  (It is not required to support documentation in all these
formats.)  They should all be set to <code>$(docdir)</code> by default.  (If
you are using Autoconf, write them as &lsquo;<samp>@htmldir@</samp>&rsquo;,
&lsquo;<samp>@dvidir@</samp>&rsquo;, etc.)  Packages which supply several translations
of their documentation should install them in
&lsquo;<samp>$(htmldir)/</samp>&rsquo;<var>ll</var>, &lsquo;<samp>$(pdfdir)/</samp>&rsquo;<var>ll</var>, etc. where
<var>ll</var> is a locale abbreviation such as &lsquo;<samp>en</samp>&rsquo; or &lsquo;<samp>pt_BR</samp>&rsquo;.
</p>
</dd>
<dt> &lsquo;<samp>libdir</samp>&rsquo;</dt>
<dd><p>The directory for object files and libraries of object code.  Do not
install executables here, they probably ought to go in &lsquo;<tt>$(libexecdir)</tt>&rsquo;
instead.  The value of <code>libdir</code> should normally be
&lsquo;<tt>/usr/local/lib</tt>&rsquo;, but write it as &lsquo;<tt>$(exec_prefix)/lib</tt>&rsquo;.
(If you are using Autoconf, write it as &lsquo;<samp>@libdir@</samp>&rsquo;.)
</p>
</dd>
<dt> &lsquo;<samp>lispdir</samp>&rsquo;</dt>
<dd><p>The directory for installing any Emacs Lisp files in this package.  By
default, it should be &lsquo;<tt>/usr/local/share/emacs/site-lisp</tt>&rsquo;, but it
should be written as &lsquo;<tt>$(datarootdir)/emacs/site-lisp</tt>&rsquo;.
</p>
<p>If you are using Autoconf, write the default as &lsquo;<samp>@lispdir@</samp>&rsquo;.
In order to make &lsquo;<samp>@lispdir@</samp>&rsquo; work, you need the following lines
in your &lsquo;<tt>configure.in</tt>&rsquo; file:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">lispdir='${datarootdir}/emacs/site-lisp'
AC_SUBST(lispdir)
</pre></td></tr></table>

</dd>
<dt> &lsquo;<samp>localedir</samp>&rsquo;</dt>
<dd><p>The directory for installing locale-specific message catalogs for this
package.  By default, it should be &lsquo;<tt>/usr/local/share/locale</tt>&rsquo;, but
it should be written as &lsquo;<tt>$(datarootdir)/locale</tt>&rsquo;.  (If you are
using Autoconf, write it as &lsquo;<samp>@localedir@</samp>&rsquo;.)  This directory
usually has a subdirectory per locale.
</p></dd>
</dl>

<p>Unix-style man pages are installed in one of the following:
</p>
<dl compact="compact">
<dt> &lsquo;<samp>mandir</samp>&rsquo;</dt>
<dd><p>The top-level directory for installing the man pages (if any) for this
package.  It will normally be &lsquo;<tt>/usr/local/share/man</tt>&rsquo;, but you
should write it as &lsquo;<tt>$(datarootdir)/man</tt>&rsquo;.  (If you are using
Autoconf, write it as &lsquo;<samp>@mandir@</samp>&rsquo;.)
</p>
</dd>
<dt> &lsquo;<samp>man1dir</samp>&rsquo;</dt>
<dd><p>The directory for installing section 1 man pages.  Write it as
&lsquo;<tt>$(mandir)/man1</tt>&rsquo;.
</p></dd>
<dt> &lsquo;<samp>man2dir</samp>&rsquo;</dt>
<dd><p>The directory for installing section 2 man pages.  Write it as
&lsquo;<tt>$(mandir)/man2</tt>&rsquo;
</p></dd>
<dt> &lsquo;<samp>&hellip;</samp>&rsquo;</dt>
<dd>
<p><strong>Don't make the primary documentation for any GNU software be a
man page.  Write a manual in Texinfo instead.  Man pages are just for
the sake of people running GNU software on Unix, which is a secondary
application only.</strong>
</p>
</dd>
<dt> &lsquo;<samp>manext</samp>&rsquo;</dt>
<dd><p>The file name extension for the installed man page.  This should contain
a period followed by the appropriate digit; it should normally be &lsquo;<samp>.1</samp>&rsquo;.
</p>
</dd>
<dt> &lsquo;<samp>man1ext</samp>&rsquo;</dt>
<dd><p>The file name extension for installed section 1 man pages.
</p></dd>
<dt> &lsquo;<samp>man2ext</samp>&rsquo;</dt>
<dd><p>The file name extension for installed section 2 man pages.
</p></dd>
<dt> &lsquo;<samp>&hellip;</samp>&rsquo;</dt>
<dd><p>Use these names instead of &lsquo;<samp>manext</samp>&rsquo; if the package needs to install man
pages in more than one section of the manual.
</p></dd>
</dl>

<p>And finally, you should set the following variable:
</p>
<dl compact="compact">
<dt> &lsquo;<samp>srcdir</samp>&rsquo;</dt>
<dd><p>The directory for the sources being compiled.  The value of this
variable is normally inserted by the <code>configure</code> shell script.
(If you are using Autconf, use &lsquo;<samp>srcdir = @srcdir@</samp>&rsquo;.)
</p></dd>
</dl>

<p>For example:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample"># Common prefix for installation directories.
# NOTE: This directory must exist when you start the install.
prefix = /usr/local
datarootdir = $(prefix)/share
datadir = $(datarootdir)
exec_prefix = $(prefix)
# Where to put the executable for the command `gcc'.
bindir = $(exec_prefix)/bin
# Where to put the directories used by the compiler.
libexecdir = $(exec_prefix)/libexec
# Where to put the Info files.
infodir = $(datarootdir)/info
</pre></td></tr></table>

<p>If your program installs a large number of files into one of the
standard user-specified directories, it might be useful to group them
into a subdirectory particular to that program.  If you do this, you
should write the <code>install</code> rule to create these subdirectories.
</p>
<p>Do not expect the user to include the subdirectory name in the value of
any of the variables listed above.  The idea of having a uniform set of
variable names for installation directories is to enable the user to
specify the exact same values for several different GNU packages.  In
order for this to be useful, all the packages must be designed so that
they will work sensibly when the user does so.
</p>
<hr size="6">
<a name="Standard-Targets"></a>
<a name="SEC141"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC140" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC142" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.5 Standard Targets for Users </h2>

<p>All GNU programs should have the following targets in their Makefiles:
</p>
<dl compact="compact">
<dt> &lsquo;<samp>all</samp>&rsquo;</dt>
<dd><p>Compile the entire program.  This should be the default target.  This
target need not rebuild any documentation files; Info files should
normally be included in the distribution, and DVI files should be made
only when explicitly asked for.
</p>
<p>By default, the Make rules should compile and link with &lsquo;<samp>-g</samp>&rsquo;, so
that executable programs have debugging symbols.  Users who don't mind
being helpless can strip the executables later if they wish.
</p>
</dd>
<dt> &lsquo;<samp>install</samp>&rsquo;</dt>
<dd><p>Compile the program and copy the executables, libraries, and so on to
the file names where they should reside for actual use.  If there is a
simple test to verify that a program is properly installed, this target
should run that test.
</p>
<p>Do not strip executables when installing them.  Devil-may-care users can
use the <code>install-strip</code> target to do that.
</p>
<p>If possible, write the <code>install</code> target rule so that it does not
modify anything in the directory where the program was built, provided
&lsquo;<samp>make all</samp>&rsquo; has just been done.  This is convenient for building the
program under one user name and installing it under another.
</p>
<p>The commands should create all the directories in which files are to be
installed, if they don't already exist.  This includes the directories
specified as the values of the variables <code>prefix</code> and
<code>exec_prefix</code>, as well as all subdirectories that are needed.
One way to do this is by means of an <code>installdirs</code> target
as described below.
</p>
<p>Use &lsquo;<samp>-</samp>&rsquo; before any command for installing a man page, so that
<code>make</code> will ignore any errors.  This is in case there are systems
that don't have the Unix man page documentation system installed.
</p>
<p>The way to install Info files is to copy them into &lsquo;<tt>$(infodir)</tt>&rsquo;
with <code>$(INSTALL_DATA)</code> (see section <a href="#SEC139">Variables for Specifying Commands</a>), and then run
the <code>install-info</code> program if it is present.  <code>install-info</code>
is a program that edits the Info &lsquo;<tt>dir</tt>&rsquo; file to add or update the
menu entry for the given Info file; it is part of the Texinfo package.
Here is a sample rule to install an Info file:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">$(DESTDIR)$(infodir)/foo.info: foo.info
        $(POST_INSTALL)
# There may be a newer info file in . than in srcdir.
        -if test -f foo.info; then d=.; \
         else d=$(srcdir); fi; \
        $(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@; \
# Run install-info only if it exists.
# Use `if' instead of just prepending `-' to the
# line so we notice real errors from install-info.
# We use `$(SHELL) -c' because some shells do not
# fail gracefully when there is an unknown command.
        if $(SHELL) -c 'install-info --version' \
           &gt;/dev/null 2&gt;&amp;1; then \
          install-info --dir-file=$(DESTDIR)$(infodir)/dir \
                       $(DESTDIR)$(infodir)/foo.info; \
        else true; fi
</pre></td></tr></table>

<p>When writing the <code>install</code> target, you must classify all the
commands into three categories: normal ones, <em>pre-installation</em>
commands and <em>post-installation</em> commands.  See section <a href="#SEC142">Install Command Categories</a>.
</p>
</dd>
<dt> &lsquo;<samp>install-html</samp>&rsquo;</dt>
<dt> &lsquo;<samp>install-dvi</samp>&rsquo;</dt>
<dt> &lsquo;<samp>install-pdf</samp>&rsquo;</dt>
<dt> &lsquo;<samp>install-ps</samp>&rsquo;</dt>
<dd><p>These targets install documentation in formats other than Info;
they're intended to be called explicitly by the person installing the
package, if that format is desired.  GNU prefers Info files, so these
must be installed by the <code>install</code> target.
</p>
<p>When you have many documentation files to install, we recommend that
you avoid collisions and clutter by arranging for these targets to
install in subdirectories of the appropriate installation directory,
such as <code>htmldir</code>.  As one example, if your package has multiple
manuals, and you wish to install HTML documentation with many files
(such as the &ldquo;split&rdquo; mode output by <code>makeinfo --html</code>), you'll
certainly want to use subdirectories, or two nodes with the same name
in different manuals will overwrite each other.
</p>
</dd>
<dt> &lsquo;<samp>uninstall</samp>&rsquo;</dt>
<dd><p>Delete all the installed files&mdash;the copies that the &lsquo;<samp>install</samp>&rsquo;
and &lsquo;<samp>install-*</samp>&rsquo; targets create.
</p>
<p>This rule should not modify the directories where compilation is done,
only the directories where files are installed.
</p>
<p>The uninstallation commands are divided into three categories, just like
the installation commands.  See section <a href="#SEC142">Install Command Categories</a>.
</p>
</dd>
<dt> &lsquo;<samp>install-strip</samp>&rsquo;</dt>
<dd><p>Like <code>install</code>, but strip the executable files while installing
them.  In simple cases, this target can use the <code>install</code> target in
a simple way:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">install-strip:
        $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
                install
</pre></td></tr></table>

<p>But if the package installs scripts as well as real executables, the
<code>install-strip</code> target can't just refer to the <code>install</code>
target; it has to strip the executables but not the scripts.
</p>
<p><code>install-strip</code> should not strip the executables in the build
directory which are being copied for installation.  It should only strip
the copies that are installed.
</p>
<p>Normally we do not recommend stripping an executable unless you are sure
the program has no bugs.  However, it can be reasonable to install a
stripped executable for actual execution while saving the unstripped
executable elsewhere in case there is a bug.
</p>
</dd>
<dt> &lsquo;<samp>clean</samp>&rsquo;</dt>
<dd>
<p>Delete all files in the current directory that are normally created by
building the program.  Also delete files in other directories if they
are created by this makefile.  However, don't delete the files that
record the configuration.  Also preserve files that could be made by
building, but normally aren't because the distribution comes with
them.  There is no need to delete parent directories that were created
with &lsquo;<samp>mkdir -p</samp>&rsquo;, since they could have existed anyway.
</p>
<p>Delete &lsquo;<tt>.dvi</tt>&rsquo; files here if they are not part of the distribution.
</p>
</dd>
<dt> &lsquo;<samp>distclean</samp>&rsquo;</dt>
<dd><p>Delete all files in the current directory (or created by this
makefile) that are created by configuring or building the program.  If
you have unpacked the source and built the program without creating
any other files, &lsquo;<samp>make distclean</samp>&rsquo; should leave only the files
that were in the distribution.  However, there is no need to delete
parent directories that were created with &lsquo;<samp>mkdir -p</samp>&rsquo;, since they
could have existed anyway.
</p>
</dd>
<dt> &lsquo;<samp>mostlyclean</samp>&rsquo;</dt>
<dd><p>Like &lsquo;<samp>clean</samp>&rsquo;, but may refrain from deleting a few files that people
normally don't want to recompile.  For example, the &lsquo;<samp>mostlyclean</samp>&rsquo;
target for GCC does not delete &lsquo;<tt>libgcc.a</tt>&rsquo;, because recompiling it
is rarely necessary and takes a lot of time.
</p>
</dd>
<dt> &lsquo;<samp>maintainer-clean</samp>&rsquo;</dt>
<dd><p>Delete almost everything that can be reconstructed with this Makefile.
This typically includes everything deleted by <code>distclean</code>, plus
more: C source files produced by Bison, tags tables, Info files, and
so on.
</p>
<p>The reason we say &ldquo;almost everything&rdquo; is that running the command
&lsquo;<samp>make maintainer-clean</samp>&rsquo; should not delete &lsquo;<tt>configure</tt>&rsquo; even
if &lsquo;<tt>configure</tt>&rsquo; can be remade using a rule in the Makefile.  More
generally, &lsquo;<samp>make maintainer-clean</samp>&rsquo; should not delete anything
that needs to exist in order to run &lsquo;<tt>configure</tt>&rsquo; and then begin to
build the program.  Also, there is no need to delete parent
directories that were created with &lsquo;<samp>mkdir -p</samp>&rsquo;, since they could
have existed anyway.  These are the only exceptions;
<code>maintainer-clean</code> should delete everything else that can be
rebuilt.
</p>
<p>The &lsquo;<samp>maintainer-clean</samp>&rsquo; target is intended to be used by a maintainer of
the package, not by ordinary users.  You may need special tools to
reconstruct some of the files that &lsquo;<samp>make maintainer-clean</samp>&rsquo; deletes.
Since these files are normally included in the distribution, we don't
take care to make them easy to reconstruct.  If you find you need to
unpack the full distribution again, don't blame us.
</p>
<p>To help make users aware of this, the commands for the special
<code>maintainer-clean</code> target should start with these two:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">@echo 'This command is intended for maintainers to use; it'
@echo 'deletes files that may need special tools to rebuild.'
</pre></td></tr></table>

</dd>
<dt> &lsquo;<samp>TAGS</samp>&rsquo;</dt>
<dd><p>Update a tags table for this program.
</p>
</dd>
<dt> &lsquo;<samp>info</samp>&rsquo;</dt>
<dd><p>Generate any Info files needed.  The best way to write the rules is as
follows:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">info: foo.info

foo.info: foo.texi chap1.texi chap2.texi
        $(MAKEINFO) $(srcdir)/foo.texi
</pre></td></tr></table>

<p>You must define the variable <code>MAKEINFO</code> in the Makefile.  It should
run the <code>makeinfo</code> program, which is part of the Texinfo
distribution.
</p>
<p>Normally a GNU distribution comes with Info files, and that means the
Info files are present in the source directory.  Therefore, the Make
rule for an info file should update it in the source directory.  When
users build the package, ordinarily Make will not update the Info files
because they will already be up to date.
</p>
</dd>
<dt> &lsquo;<samp>dvi</samp>&rsquo;</dt>
<dt> &lsquo;<samp>html</samp>&rsquo;</dt>
<dt> &lsquo;<samp>pdf</samp>&rsquo;</dt>
<dt> &lsquo;<samp>ps</samp>&rsquo;</dt>
<dd><p>Generate documentation files in the given format, if possible.
Here's an example rule for generating DVI files from Texinfo:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">dvi: foo.dvi

foo.dvi: foo.texi chap1.texi chap2.texi
        $(TEXI2DVI) $(srcdir)/foo.texi
</pre></td></tr></table>

<p>You must define the variable <code>TEXI2DVI</code> in the Makefile.  It should
run the program <code>texi2dvi</code>, which is part of the Texinfo
distribution.<a name="DOCF3" href="make_fot.html#FOOT3">(3)</a>  Alternatively,
write just the dependencies, and allow GNU <code>make</code> to provide the command.
</p>
<p>Here's another example, this one for generating HTML from Texinfo:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">html: foo.html

foo.html: foo.texi chap1.texi chap2.texi
        $(TEXI2HTML) $(srcdir)/foo.texi
</pre></td></tr></table>

<p>Again, you would define the variable <code>TEXI2HTML</code> in the Makefile;
for example, it might run <code>makeinfo --no-split --html</code>
(<code>makeinfo</code> is part of the Texinfo distribution).
</p>
</dd>
<dt> &lsquo;<samp>dist</samp>&rsquo;</dt>
<dd><p>Create a distribution tar file for this program.  The tar file should be
set up so that the file names in the tar file start with a subdirectory
name which is the name of the package it is a distribution for.  This
name can include the version number.
</p>
<p>For example, the distribution tar file of GCC version 1.40 unpacks into
a subdirectory named &lsquo;<tt>gcc-1.40</tt>&rsquo;.
</p>
<p>The easiest way to do this is to create a subdirectory appropriately
named, use <code>ln</code> or <code>cp</code> to install the proper files in it, and
then <code>tar</code> that subdirectory.
</p>
<p>Compress the tar file with <code>gzip</code>.  For example, the actual
distribution file for GCC version 1.40 is called &lsquo;<tt>gcc-1.40.tar.gz</tt>&rsquo;.
</p>
<p>The <code>dist</code> target should explicitly depend on all non-source files
that are in the distribution, to make sure they are up to date in the
distribution.
See <a href="../standards/Releases.html#Releases">(standards)Releases</a> section `Making Releases' in <cite>GNU Coding Standards</cite>.
</p>
</dd>
<dt> &lsquo;<samp>check</samp>&rsquo;</dt>
<dd><p>Perform self-tests (if any).  The user must build the program before
running the tests, but need not install the program; you should write
the self-tests so that they work when the program is built but not
installed.
</p></dd>
</dl>

<p>The following targets are suggested as conventional names, for programs
in which they are useful.
</p>
<dl compact="compact">
<dt> <code>installcheck</code></dt>
<dd><p>Perform installation tests (if any).  The user must build and install
the program before running the tests.  You should not assume that
&lsquo;<tt>$(bindir)</tt>&rsquo; is in the search path.
</p>
</dd>
<dt> <code>installdirs</code></dt>
<dd><p>It's useful to add a target named &lsquo;<samp>installdirs</samp>&rsquo; to create the
directories where files are installed, and their parent directories.
There is a script called &lsquo;<tt>mkinstalldirs</tt>&rsquo; which is convenient for
this; you can find it in the Texinfo package.
You can use a rule like this:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample"># Make sure all installation directories (e.g. $(bindir))
# actually exist by making them if necessary.
installdirs: mkinstalldirs
        $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
                                $(libdir) $(infodir) \
                                $(mandir)
</pre></td></tr></table>

<p>or, if you wish to support <code>DESTDIR</code>,
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample"># Make sure all installation directories (e.g. $(bindir))
# actually exist by making them if necessary.
installdirs: mkinstalldirs
        $(srcdir)/mkinstalldirs \
            $(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \
            $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \
            $(DESTDIR)$(mandir)
</pre></td></tr></table>

<p>This rule should not modify the directories where compilation is done.
It should do nothing but create installation directories.
</p></dd>
</dl>

<hr size="6">
<a name="Install-Command-Categories"></a>
<a name="SEC142"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC141" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC136" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 14.6 Install Command Categories </h2>

<p>When writing the <code>install</code> target, you must classify all the
commands into three categories: normal ones, <em>pre-installation</em>
commands and <em>post-installation</em> commands.
</p>
<p>Normal commands move files into their proper places, and set their
modes.  They may not alter any files except the ones that come entirely
from the package they belong to.
</p>
<p>Pre-installation and post-installation commands may alter other files;
in particular, they can edit global configuration files or data bases.
</p>
<p>Pre-installation commands are typically executed before the normal
commands, and post-installation commands are typically run after the
normal commands.
</p>
<p>The most common use for a post-installation command is to run
<code>install-info</code>.  This cannot be done with a normal command, since
it alters a file (the Info directory) which does not come entirely and
solely from the package being installed.  It is a post-installation
command because it needs to be done after the normal command which
installs the package's Info files.
</p>
<p>Most programs don't need any pre-installation commands, but we have the
feature just in case it is needed.
</p>
<p>To classify the commands in the <code>install</code> rule into these three
categories, insert <em>category lines</em> among them.  A category line
specifies the category for the commands that follow.
</p>
<p>A category line consists of a tab and a reference to a special Make
variable, plus an optional comment at the end.  There are three
variables you can use, one for each category; the variable name
specifies the category.  Category lines are no-ops in ordinary execution
because these three Make variables are normally undefined (and you
<em>should not</em> define them in the makefile).
</p>
<p>Here are the three possible category lines, each with a comment that
explains what it means:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">        $(PRE_INSTALL)     # <span class="roman">Pre-install commands follow.</span>
        $(POST_INSTALL)    # <span class="roman">Post-install commands follow.</span>
        $(NORMAL_INSTALL)  # <span class="roman">Normal commands follow.</span>
</pre></td></tr></table>

<p>If you don't use a category line at the beginning of the <code>install</code>
rule, all the commands are classified as normal until the first category
line.  If you don't use any category lines, all the commands are
classified as normal.
</p>
<p>These are the category lines for <code>uninstall</code>:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">        $(PRE_UNINSTALL)     # <span class="roman">Pre-uninstall commands follow.</span>
        $(POST_UNINSTALL)    # <span class="roman">Post-uninstall commands follow.</span>
        $(NORMAL_UNINSTALL)  # <span class="roman">Normal commands follow.</span>
</pre></td></tr></table>

<p>Typically, a pre-uninstall command would be used for deleting entries
from the Info directory.
</p>
<p>If the <code>install</code> or <code>uninstall</code> target has any dependencies
which act as subroutines of installation, then you should start
<em>each</em> dependency's commands with a category line, and start the
main target's commands with a category line also.  This way, you can
ensure that each command is placed in the right category regardless of
which of the dependencies actually run.
</p>
<p>Pre-installation and post-installation commands should not run any
programs except for these:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">[ basename bash cat chgrp chmod chown cmp cp dd diff echo
egrep expand expr false fgrep find getopt grep gunzip gzip
hostname install install-info kill ldconfig ln ls md5sum
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
test touch true uname xargs yes
</pre></td></tr></table>

<a name="IDX637"></a>
<p>The reason for distinguishing the commands in this way is for the sake
of making binary packages.  Typically a binary package contains all the
executables and other files that need to be installed, and has its own
method of installing them&mdash;so it does not need to run the normal
installation commands.  But installing the binary package does need to
execute the pre-installation and post-installation commands.
</p>
<p>Programs to build binary packages work by extracting the
pre-installation and post-installation commands.  Here is one way of
extracting the pre-installation commands (the &lsquo;<samp>-s</samp>&rsquo; option to
<code>make</code> is needed to silence messages about entering
subdirectories):
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">make -s -n install -o all \
      PRE_INSTALL=pre-install \
      POST_INSTALL=post-install \
      NORMAL_INSTALL=normal-install \
  | gawk -f pre-install.awk
</pre></td></tr></table>

<p>where the file &lsquo;<tt>pre-install.awk</tt>&rsquo; could contain this:
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">$0 ~ /^(normal-install|post-install)[ \t]*$/ {on = 0}
on {print $0}
$0 ~ /^pre-install[ \t]*$/ {on = 1}
</pre></td></tr></table>

<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC136" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="make_15.html#SEC143" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="make.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="make_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="make_19.html#SEC148" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="make_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>Manoj Srivastava</em> on <em>August, 17 2009</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.78</em></a>.
 </font>
 <br>

</p>
</body>
</html>