词条 | Makefile |
释义 |
| name = Makefile | icon = | iconcaption = | icon_size = | screenshot = | screenshot_size = | caption = |_noextcode = | extension = |_nomimecode = | mime = text/x-makefile | type code = | uniform_type = | conforms_to = | magic = | developer = | released = | latest_release_version = | latest_release_date = | genre = Build automation | container_for = | contained_by = | extended_from = | extended_to = | standard = POSIX | free = | url = }} A makefile is a file (by default named "Makefile") containing a set of directives used by a make build automation tool to generate a target/goal. OverviewMost often, the makefile directs Make on how to compile and link a program. A makefile works upon the principle that files only need recreating if their dependencies are newer than the file being created/recreated. The makefile is recursively carried out (with dependency prepared before each target depending upon them) until everything has been updated (that requires updating) and the primary/ultimate target is complete. These instructions with their dependencies are specified in a makefile. If none of the files that are prerequisites have been changed since the last time the program was compiled, no actions take place. For large software projects, using Makefiles can substantially reduce build times if only a few source files have changed. Using C/C++ as an example, when a C/C++ source file is changed, it must be recompiled. If a header file has changed, each C/C++ source file that includes the header file must be recompiled to be safe. Each compilation produces an object file corresponding to the source file. Finally, if any source file has been recompiled, all the object files, whether newly made or saved from previous compilations, must be linked together to produce the new executable program.[1] Operating systemUnix-likeMakefiles originated on Unix-like systems and are still a primary software build mechanism in such environments. Microsoft WindowsWindows supports a variation of makefiles with its nmake utility. Standard Unix like makefiles can be executed in Windows in a Cygwin environment or Mingw. ContentsMakefiles contain five kinds of things: explicit rules, implicit rules, variable definitions, directives, and comments.
RulesA makefile consists of “rules” in the following form: target: dependencies A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as "clean". A dependency (also called prerequisite) is a file that is used as input to create the target. A target often depends on several files. However, the rule that specifies a recipe for the target need not have any prerequisites. For example, the rule containing the delete command associated with the target "clean" does not have prerequisites. The system command(s) (also called recipe) is an action that make carries out. A recipe may have more than one command, either on the same line or each on its own line. Note the use of meaningful indentation in specifying commands; also note that the indentation must consist of a single ExecutionA makefile is executed with the By default, when make looks for the makefile, if a makefile name was not included as a parameter, it tries the following names, in order: makefile and Makefile.[1] ExampleHere is a simple makefile that describes the way an executable file called edit depends on four object files which, in turn, depend on four C source and two header files. To be concrete, edit: main.o kbd.o command.o display.o cc -o edit main.o kbd.o command.o display.o main.o: main.c defs.h kbd.o: kbd.c defs.h command.h command.o: command.c defs.h command.h display.o: display.c defs.h clean: To use this makefile to create the executable file called edit, type See also
References{{Wikibooks | make }}1. ^1 {{cite web | url=http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html#tag_20_76_13_04| title=POSIX Target Rules}} 3 : Compilers|Computer programming tools|Computer file formats |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。