1 / 15

makefiles

makefiles. makefiles. Problem: You are working on one part of a large programming project (e. g., MS Word). It consists of hundreds of individual .c files all linked together to form winword.exe. You make a change to one of these .c files and now need to rebuild word.exe.

nellie
Download Presentation

makefiles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. makefiles

  2. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word). • It consists of hundreds of individual .c files all linked together to form winword.exe. • You make a change to one of these .c files and now need to rebuild word.exe. • How do you do it without having to recompile hundreds of .c files that haven’t changed?

  3. w/out makefiles g++ -o word.exe f1.c f2.c f3.c f4.c … f999.c But only f4.c has changed and only needs to be recompiled! Compiler option to create intermediate (object modules) files: g++ -c f1.c g++ -c f2.c … g++ -c f999.c g++ -o word.exe f1.o f2.o f3.o … f999.o Then I just manually do: g++ -c f4.c and then relink.

  4. But how can I automatically determine only what needs to be recompiled? • Write a program that looks at the modification time of the .c file and the .o (or .exe) file. If the mod time of the .c file is more recent than the mod time of the .o (or .exe) file, then we know that we know that we need to recompile and relink. • But I don’t want to write this program! (Someone already built this into the Java compiler, and MS Visual Studio.)

  5. makefiles Consist of: • Comments (begin with #) • Definitions • Dependencies • Commands

  6. makefiles Consist of: • Comments (begin with #) • Definitions • Dependencies • Commands • Comments: # # this is a comment. #

  7. makefiles Consist of: • Comments (begin with #) • Definitions • Dependencies • Commands • Definitions (are like constants): CC = g++ -g or CC = g++ -O3 … • to use these definitions, evaluate with $(CC)

  8. 3. Dependencies a:<tab>b c d … • This means that a is dependent upon (needs) b and c and d … • What is word.exe dependent upon (below)? • g++ -o word.exe f1.o f2.o f3.o … f999.o • word.exe is dependent upon f1.o, f2.o, …, f999.o word.exe:<tab>f1.o f2.o … f999.o • What is f1.o dependent upon?

  9. Dependencies & 4. Commands • Usually, a dependency is followed by a command to rebuild/recreate/update the entity to the left of the colon (called a tag). • Dependencies are hierarchical (i.e., top-down). word.exe:<tab> f1.o f2.o … f999.o <tabs> g++ -o word.exe f1.o f2.o … f999.o f1.o:<tab> f1.c <tabs> g++ -c f1.c f2.o:<tab> f2.c <tabs> g++ -c f2.c …

  10. makefile syntax target1 target2 target3 : prerequisite1 prerequisite2 <tab>command1 <tab>command2 <tab>command3 One or more targets (to the left of the colon). Zero or more prereqs (after the colon). Zero or more commands (each must be preceeded by a tab).

  11. “Standard phony” targets all Perform all tasks to build the application install Create an installation of the application from the compiled binaries clean Delete the binary files generated from sources distcleanDelete all the generated files that were not in the original source distribution TAGS Create a tags table for use by editors info Create GNU info files from their Texinfo sources check Run any tests associated with this application docs Create (doxygen) documentation. (gjg)

  12. Example (including definitions and comments) #for debug version: CC = g++ -g #for production version: #CC = g++ -O3 word.exe:<tab> f1.o f2.o … f999.o <tabs> $(CC) -o word.exe f1.o f2.o … f999.o f1.o:<tab> f1.c <tabs> $(CC) -c f1.c …

  13. Example (more than 1 command) #for debug version: CC = g++ -g word.exe: f1.o f2.o … f999.o echo link word.exe $(CC) -o word.exe f1.o f2.o … f999.o f1.o: f1.c echo compile f1.c $(CC) -c f1.c …

  14. Example (make more than one) #for debug version: CC = g++ -g all: word.exe fred.exe … word.exe: f1.o f2.o … f999.o echo link word.exe $(CC) -o word.exe f1.o f2.o … f999.o f1.o: f1.c echo compile f1.c $(CC) -c f1.c …

  15. Example make commands • make • Checks the first dependency that appears in the file makefile. • make all • Checks the all dependency in makefile. • make word.exe • make f1.o • make fred.exe • make –f myMakeFile all • Checks the all dependency in file myMakeFile.

More Related