1. Trang chủ
  2. » Giáo án - Bài giảng

kỹ thuật điện hệ điều hành os + thí nghiệm 3 en sinhvienzone com

16 52 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 598,22 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Motivation cont. Problems  Long files are harder to manage for both programmers and machines  Every change requires long compilation  Many programmers can not modify the same file

Trang 1

Makefile Utility

Trang 2

 Small program

 Single file

 “Not so small” programs

 Many lines of code

 Multiple components

 More than one programmer

Trang 3

Motivation (cont.)

 Problems

 Long files are harder to manage (for both programmers and

machines)

 Every change requires long compilation

 Many programmers can not modify the same file

simultaneously

Division to components is desired

Trang 4

Program Compiling

 Manual

 Efforts

 Shell script

 Time

 Makefile

 Convenient

 Compiling time

Trang 5

 Text file

 make

 *NIX systems

 Build, install, and uninstall programs

 Avoid re-building targets which are up-to-date

 Not limited to C/C++ programs

Trang 6

Project:

main.c, sum.c, sum.h

sum.h is included in main.c & sum.c

 executable file: sum

Trang 7

Example (cont.)

 Compile

$ gcc –o sum main.c sum.c

or

$ gcc –c main.c

$ gcc –c sum.c

$ gcc –o sum main.o sum.o

=> What happens if file main.c is modified

Trang 8

Project Structure

sum.c sum.h main.c

sum.o main.o

sum

Trang 9

Makefile content

# This is an example of Makefile

CC=gcc

sum: main.o sum.o

$(CC) –o sum main.o sum.o main.o: main.c sum.h

$(CC) –c main.c sum.o: sum.c sum.h

$(CC) –c sum.c Rule TAB

Target Dependency Action

Trang 10

Built-in Macros

sum: main.o sum.o

gcc –o $@ $^

.c.o:

gcc –c $<

main.o sum.o: sum.h

gcc –c $*.c

Trang 11

Built-in Macros (cont.)

$@ - The name of the target of the rule

$< - The name of the first dependency

$^ - The names of all the dependencies

$? - The names of all dependencies that are newer

than the target

$* - The name of the target of the rule without

extension

Trang 12

Make Operation

 Project dependencies tree is constructed

 Target of first rule should be created

 We go down the tree to see if there is a target that should

be recreated This is the case when the target file is older than one of its dependencies

 In this case we recreate the target file according to the

action specified, on our way up the tree Consequently,

more files may need to be recreated

 If something is changed, linking is usually necessary

Trang 13

Make Operation (cont.)

File Last Modified

sum 10:03

main.o 09:56

main.c 10:45

Trang 14

Make Operation (cont.)

sum.o main.o

sum

10:03

Trang 15

Make Operation (cont.)

 Operations performed:

gcc –c main.c gcc –o sum main.o sum.o

main.o should be recompiled (main.c is newer).

Consequently, main.o is newer than sum and therefore sum

should be recreated (by re-linking)

Trang 16

Questions???

Ngày đăng: 28/01/2020, 22:10

🧩 Sản phẩm bạn có thể quan tâm