1 / 16

CS201 – Makefile

CS201 – Makefile. Tutorial. A Trivial Makefile. # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c. A Trivial Makefile. # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 #

lerato
Download Presentation

CS201 – Makefile

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. CS201 – Makefile Tutorial

  2. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c

  3. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c COMMENTS

  4. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c Target Target’s Prerequisites Dependency Line

  5. What’s happening here? Source File puzzle1.c Gnu C compiler gcc RunImage Depends on puzzle1

  6. So what’s a “run image” file? • A run image file is an exact copy of the computer’s ram memory containing the binary equivalent of the program. • To “run” the program, you load the run image file and point your computer to the start of the program. This is done by typing the run image file name at the operating system prompt. • $ puzzle1

  7. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c Time stamp on this file is compared to the time stamp on this file. Dependency Line

  8. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c Time stamp on this file is compared to the time stamp on this file. Dependency Line If the target’s time stamp is earlier than the prerequisite’s time stamp, the rule below this dependency line is executed.

  9. So what is a time stamp? • The time that the file was last modified. • If the target’s time is earlier than the prerequisite’s time, this means that the prerequisite file has been changed, but the run image has not been updated.

  10. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c Rule Line Must be a tab!!

  11. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc –o puzzle1 puzzle1.c Rule Line Any Linux command

  12. Example time stamps • Assume puzzle1 has TS Jan 16 14:00 • Assume puzzle1.c has TS Jan 16 13:55 • Target is LATER than prerequisite, so rule is NOT executed!

  13. Example time stamps • Assume puzzle1 has TS Jan 16 13:00 • Assume puzzle1.c has TS Jan 16 13:55 • Target is EARLIER than prerequisite, so rule is executed!

  14. Example • Build a source file with code for puzzle1.c • Build a Makefile with an appropriate dependency line. • Run make • $ make • gcc -o puzzle1 puzzle1.c • The rule executes since the file puzzle1 does not even exist yet!

  15. What if you tried make again? • $ make make: ‘puzzle1’ is up to date $

  16. Makefile Summary • Build a dependency line for every target. • Add a rule line to rebuild the target. • Start the rule line with a tab. • Add comments to the top of the file. • Save these lines in an ASCII file called Makefile. (For now assume it must be exactly that name, with a capital M).

More Related