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

Nội dung

Makefile Utility SinhVienZone.com https://fb.com/sinhvienzonevn Motivation  Small program  Single file  “Not so small” programs  Many lines of code  Multiple components  More than one programmer SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 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 SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Program Compiling  Manual  Efforts  Shell script  Time  Makefile  Convenient  Compiling time SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Makefile  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 SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Example Project: main.c, sum.c, sum.h sum.h is included in main.c & sum.c executable file: sum SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 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 SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Project Structure sum sum.o sum.c SinhVienZone.com main.o sum.h main.c https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 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 Rule $(CC) –c sum.c TAB Target Dependency SinhVienZone.com Action https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Built-in Macros sum: main.o sum.o gcc –o $@ $^ c.o: gcc –c $< main.o sum.o: sum.h gcc –c $*.c SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 10 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 SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 11 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 SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 12 Make Operation (cont.) File sum main.o sum.o main.c sum.c sum.h SinhVienZone.com Last Modified 10:03 09:56 09:35 10:45 09:14 08:39 https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 13 Make Operation (cont.) sum sum.o 9:35 sum.c 9:14 SinhVienZone.com 10:03 main.o 9:56 sum.h 8:39 main.c 10:45 https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 14 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) SinhVienZone.com https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 15 Questions??? SinhVienZone.com https://fb.com/sinhvienzonevn ... 10: 03 09:56 09 :35 10:45 09:14 08 :39 https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT 13 Make Operation (cont.) sum sum.o 9 :35 sum.c 9:14 SinhVienZone.com 10: 03. .. 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 SinhVienZone.com... Rule $(CC) –c sum.c TAB Target Dependency SinhVienZone.com Action https://fb.com/sinhvienzonevn Faculty of Computer Science and Engineering - HCMUT Built-in Macros sum: main.o sum.o gcc –o $@ $^

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