⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make-stds.texi

📁 autoconf 2.59版,可用于redhat系统.用于编译原码,编写makefile文件.
💻 TEXI
📖 第 1 页 / 共 3 页
字号:
@comment This file is included by both standards.texi and make.texinfo.@comment It was broken out of standards.texi on 1/6/93 by roland.@node Makefile Conventions@chapter Makefile Conventions@comment standards.texi does not print an index, but make.texinfo does.@cindex makefile, conventions for@cindex conventions for makefiles@cindex standards for makefiles@c Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001 Free@c Software Foundation, Inc.@c Permission is granted to copy, distribute and/or modify this document@c under the terms of the GNU Free Documentation License, Version 1.1@c or any later version published by the Free Software Foundation;@c with no Invariant Sections, with no@c Front-Cover Texts, and with no Back-Cover Texts.@c A copy of the license is included in the section entitled ``GNU@c Free Documentation License''.This@ifinfonode@end ifinfo@iftex@ifset CODESTDsection@end ifset@ifclear CODESTDchapter@end ifclear@end iftexdescribes conventions for writing the Makefiles for GNU programs.Using Automake will help you write a Makefile that follows theseconventions.@menu* Makefile Basics::             General Conventions for Makefiles* Utilities in Makefiles::      Utilities in Makefiles* Command Variables::           Variables for Specifying Commands* Directory Variables::         Variables for Installation Directories* Standard Targets::            Standard Targets for Users* Install Command Categories::  Three categories of commands in the `install'                                  rule: normal, pre-install and post-install.@end menu@node Makefile Basics@section General Conventions for MakefilesEvery Makefile should contain this line:@exampleSHELL = /bin/sh@end example@noindentto avoid trouble on systems where the @code{SHELL} variable might beinherited from the environment.  (This is never a problem with GNU@code{make}.)Different @code{make} programs have incompatible suffix lists andimplicit rules, and this sometimes creates confusion or misbehavior.  Soit is a good idea to set the suffix list explicitly using only thesuffixes you need in the particular Makefile, like this:@example.SUFFIXES:.SUFFIXES: .c .o@end example@noindentThe first line clears out the suffix list, the second introduces allsuffixes which may be subject to implicit rules in this Makefile.Don't assume that @file{.} is in the path for command execution.  Whenyou need to run programs that are a part of your package during themake, please make sure that it uses @file{./} if the program is built aspart of the make or @file{$(srcdir)/} if the file is an unchanging partof the source code.  Without one of these prefixes, the current searchpath is used.The distinction between @file{./} (the @dfn{build directory}) and@file{$(srcdir)/} (the @dfn{source directory}) is important becauseusers can build in a separate directory using the @samp{--srcdir} optionto @file{configure}.  A rule of the form:@smallexamplefoo.1 : foo.man sedscript        sed -e sedscript foo.man > foo.1@end smallexample@noindentwill fail when the build directory is not the source directory, because@file{foo.man} and @file{sedscript} are in the source directory.When using GNU @code{make}, relying on @samp{VPATH} to find the sourcefile will work in the case where there is a single dependency file,since the @code{make} automatic variable @samp{$<} will represent thesource file wherever it is.  (Many versions of @code{make} set @samp{$<}only in implicit rules.)  A Makefile target like@smallexamplefoo.o : bar.c        $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o@end smallexample@noindentshould instead be written as@smallexamplefoo.o : bar.c        $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@@end smallexample@noindentin order to allow @samp{VPATH} to work correctly.  When the target hasmultiple dependencies, using an explicit @samp{$(srcdir)} is the easiestway to make the rule work well.  For example, the target above for@file{foo.1} is best written as:@smallexamplefoo.1 : foo.man sedscript        sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@@end smallexampleGNU distributions usually contain some files which are not sourcefiles---for example, Info files, and the output from Autoconf, Automake,Bison or Flex.  Since these files normally appear in the sourcedirectory, they should always appear in the source directory, not in thebuild directory.  So Makefile rules to update them should put theupdated files in the source directory.However, if a file does not appear in the distribution, then theMakefile should not put it in the source directory, because building aprogram in ordinary circumstances should not modify the source directoryin any way.Try to make the build and installation targets, at least (and all theirsubtargets) work correctly with a parallel @code{make}.@node Utilities in Makefiles@section Utilities in MakefilesWrite the Makefile commands (and any shell scripts, such as@code{configure}) to run in @code{sh}, not in @code{csh}.  Don't use anyspecial features of @code{ksh} or @code{bash}.The @code{configure} script and the Makefile rules for building andinstallation should not use any utilities directly except these:@c dd find@c gunzip gzip md5sum@c mkfifo mknod tee uname@examplecat cmp cp diff echo egrep expr false grep install-infoln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true@end exampleThe compression program @code{gzip} can be used in the @code{dist} rule.Stick to the generally supported options for these programs.  Forexample, don't use @samp{mkdir -p}, convenient as it may be, becausemost systems don't support it.It is a good idea to avoid creating symbolic links in makefiles, since afew systems don't support them.The Makefile rules for building and installation can also use compilersand related programs, but should do so via @code{make} variables so that theuser can substitute alternatives.  Here are some of the programs wemean:@examplear bison cc flex install ld ldconfig lexmake makeinfo ranlib texi2dvi yacc@end exampleUse the following @code{make} variables to run those programs:@example$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)@end exampleWhen you use @code{ranlib} or @code{ldconfig}, you should make surenothing bad happens if the system does not have the program in question.Arrange to ignore an error from that command, and print a message beforethe command to tell the user that failure of this command does not meana problem.  (The Autoconf @samp{AC_PROG_RANLIB} macro can help withthis.)If you use symbolic links, you should implement a fallback for systemsthat don't have symbolic links.Additional utilities that can be used via Make variables are:@examplechgrp chmod chown mknod@end exampleIt is ok to use other utilities in Makefile portions (or scripts)intended only for particular systems where you know those utilitiesexist.@node Command Variables@section Variables for Specifying CommandsMakefiles should provide variables for overriding certain commands, options,and so on.In particular, you should run most utility programs via variables.Thus, if you use Bison, have a variable named @code{BISON} whose defaultvalue is set with @samp{BISON = bison}, and refer to it with@code{$(BISON)} whenever you need to use Bison.File management utilities such as @code{ln}, @code{rm}, @code{mv}, andso on, need not be referred to through variables in this way, since usersdon't need to replace them with other programs.Each program-name variable should come with an options variable that isused to supply options to the program.  Append @samp{FLAGS} to theprogram-name variable name to get the options variable name---forexample, @code{BISONFLAGS}.  (The names @code{CFLAGS} for the Ccompiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, areexceptions to this rule, but we keep them because they are standard.)Use @code{CPPFLAGS} in any compilation command that runs thepreprocessor, and use @code{LDFLAGS} in any compilation command thatdoes linking as well as in any direct use of @code{ld}.If there are C compiler options that @emph{must} be used for propercompilation of certain files, do not include them in @code{CFLAGS}.Users expect to be able to specify @code{CFLAGS} freely themselves.Instead, arrange to pass the necessary options to the C compilerindependently of @code{CFLAGS}, by writing them explicitly in thecompilation commands or by defining an implicit rule, like this:@smallexampleCFLAGS = -gALL_CFLAGS = -I. $(CFLAGS).c.o:        $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<@end smallexampleDo include the @samp{-g} option in @code{CFLAGS}, because that is not@emph{required} for proper compilation.  You can consider it a defaultthat is only recommended.  If the package is set up so that it iscompiled with GCC by default, then you might as well include @samp{-O}in the default value of @code{CFLAGS} as well.Put @code{CFLAGS} last in the compilation command, after other variablescontaining compiler options, so the user can use @code{CFLAGS} tooverride the others.@code{CFLAGS} should be used in every invocation of the C compiler,both those which do compilation and those which do linking.Every Makefile should define the variable @code{INSTALL}, which is thebasic command for installing a file into the system.Every Makefile should also define the variables @code{INSTALL_PROGRAM}and @code{INSTALL_DATA}.  (The default for @code{INSTALL_PROGRAM} shouldbe @code{$(INSTALL)}; the default for @code{INSTALL_DATA} should be@code{$@{INSTALL@} -m 644}.)  Then it should use those variables as thecommands for actual installation, for executables and nonexecutablesrespectively.  Use these variables as follows:@example$(INSTALL_PROGRAM) foo $(bindir)/foo$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a@end exampleOptionally, you may prepend the value of @code{DESTDIR} to the targetfilename.  Doing this allows the installer to create a snapshot of theinstallation to be copied onto the real target filesystem later.  Do notset the value of @code{DESTDIR} in your Makefile, and do not include itin any installed files.  With support for @code{DESTDIR}, the aboveexamples become:@example$(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo$(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a@end example@noindentAlways use a file name, not a directory name, as the second argument ofthe installation commands.  Use a separate command for each file to beinstalled.@node Directory Variables@section Variables for Installation DirectoriesInstallation directories should always be named by variables, so it iseasy to install in a nonstandard place.  The standard names for thesevariables are described below.  They are based on a standard filesystemlayout; variants of it are used in SVR4, 4.4BSD, GNU/Linux, Ultrix v4,and other modern operating systems.These two variables set the root for the installation.  All the otherinstallation directories should be subdirectories of one of these two,and nothing should be directly installed into these two directories.@table @code@item prefix@vindex prefixA prefix used in constructing the default values of the variables listedbelow.  The default value of @code{prefix} should be @file{/usr/local}.When building the complete GNU system, the prefix will be empty and@file{/usr} will be a symbolic link to @file{/}.(If you are using Autoconf, write it as @samp{@@prefix@@}.)Running @samp{make install} with a different value of @code{prefix} fromthe one used to build the program should @emph{not} recompile theprogram.@item exec_prefix@vindex exec_prefixA prefix used in constructing the default values of some of thevariables listed below.  The default value of @code{exec_prefix} shouldbe @code{$(prefix)}.(If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)Generally, @code{$(exec_prefix)} is used for directories that containmachine-specific files (such as executables and subroutine libraries),while @code{$(prefix)} is used directly for other directories.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -