CS 201 Makefile Tutorial A Trivial Makefile Trivial

  • Slides: 16
Download presentation
CS 201 – Makefile Tutorial

CS 201 – Makefile Tutorial

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock, CS 201, MSU-Bozeman # 1/5/05 # puzzle 1: puzzle 1. c gcc –o puzzle 1. c

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock, CS 201, MSU-Bozeman # 1/5/05 COMMENTS # puzzle 1: puzzle 1. c gcc –o puzzle 1. c

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

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

What’s happening here? Source File puzzle 1. c Gnu C compiler gcc Depends on

What’s happening here? Source File puzzle 1. c Gnu C compiler gcc Depends on Run Image puzzle 1

So what’s a “run image” file? n n n A run image file is

So what’s a “run image” file? n n n 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. $ puzzle 1

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

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

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

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

So what is a time stamp? n n The time that the file was

So what is a time stamp? n n 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.

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

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

A Trivial Makefile # Trivial Makefile for puzzle 1. c # Ray S. Babcock,

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

Example time stamps n n n Assume puzzle 1 has TS Jan 16 14:

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

Example time stamps n n n Assume puzzle 1 has TS Jan 16 13:

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

Example n n n Build a source file with code for puzzle 1. c

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

What if you tried make again? n $ make: ‘puzzle 1’ is up to

What if you tried make again? n $ make: ‘puzzle 1’ is up to date $

Makefile Summary n n n Build a dependency line for every target. Add a

Makefile Summary n n n 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).