You need a file called a makefile to tell make
what to do. Most often, the makefile tells make
how to compile and link a program.
In this chapter, we will discuss a simple makefile that describes how to compile and link a text editor which consists of eight C source files and three header files. The makefile can also tell make
how to run miscellaneous commands when explicitly asked (for example, to remove certain files as a clean-up operation). To see a more complex example of a makefile, see Complex Makefile.
When make
recompiles the editor, each changed C source file must be recompiled. If a header file has changed, each 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 editor.
• Rule Introduction | What a rule looks like. | |
• Simple Makefile | A simple makefile. | |
• How Make Works | How make processes this makefile. |
|
• Variables Simplify | Variables make makefiles simpler. | |
• make Deduces | Letting make deduce the recipes. |
|
• Combine By Prerequisite | Another style of makefile. | |
• Cleanup | Rules for cleaning the directory. |
Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Free Software Foundation, Inc.
Licensed under the GNU Free Documentation License.
https://www.gnu.org/software/make/manual/html_node/Introduction.html