Makefile Introduction Jia – Wei Lin 1. Outline Why we use make ? Create a Description File Rules of Makefile How make Processes a Makefile? GCC Flags.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

The make Utility Programming Tools and Environments Winter 2006.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Software Engineering for Digital Home 單元 2 :軟體處理程序與需求分析 2-3 需求工程處理程序 Presenter: Away.
1 第一章 Word 的基本觀念 內容概要: Word 的特色 啟動與離開 Word 的方法 滑鼠游標與外型的介紹 基本操作 Word 視窗法則 使用 Word 遭遇問題時, 應如何利用軟體特 性而獲得輔助解說.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
Compilation & linkage.h read.h.c read.c.c main.c.c list.c.h list.h prog1 Linkage: g++ read.o main.o list.o –o prog1.o main.o.o list.o.o read.o Compilation:
1 The Makefile Utility ABC – Chapter 11,
1.1 電腦的特性 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
JAVA 程式設計與資料結構 第十章 GUI Introdution III. File Chooser  File Chooser 是一個選擇檔案的圖形介面, 無論我們是要存檔還是要開啟檔案,使 用這個物件都會讓我們覺得容易且舒適。
最新計算機概論 第 5 章 系統程式. 5-1 系統程式的類型 作業系統 (OS) : 介於電腦硬體與 應用軟體之間的 程式,除了提供 執行應用軟體的 環境,還負責分 配系統資源。
Hung-Hsiang WuWindows Processing Design1 Chapter 3 基本觀念 變數宣告與型態 特殊運算子符號 字串與數值的轉換 類別與物件的觀念 建立新的專案 WinMain 程式進入點 Include Header File.
研究資料的分析. 資料分析的基本策略  General data analysis strategies 1.Sketching ideas 2.Taking notes 3.Summarize field nores 4.Getting feedback on ideas 5.Working with.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
物件導向程式 授課教師 : 王耀德 研究室 : 靜宜大學 二研 105 電話 : (04) # Web site:
概念性產品企劃書 呂學儒 李政翰.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2010.
Introduction to Make Updated by Prasad Spring 2000.
Guide To UNIX Using Linux Third Edition
二十一世紀數位化公務員應具備數位化基 本能力 一 應了解每日數位媒體所提供的日常數位 資訊的常識(乃至知識)及常使用的標準 化技能 二 搜尋與公務相關的資訊,相關工作資料 庫的能力 三 快速中文輸入的能力.
CS465 - Unix C Programming (cc/make and configuration control)
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Chapter 2 Introduction to C Programming Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Homework K&R chapter 4. HW3: ASCII Hex to Integer int axtoi (char s[ ]) { int i, n, flag; n = 0; flag = 1; for ( i = 0; flag; i++) /* for (i = 0; ; i++)
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
C Tutorial - Program Organization CS Introduction to Operating Systems.
National Taiwan University Department of Computer Science and Information Engineering Introduction to Programming Design by C Algorithms and Computational.
chap3 Chapter 3 Top-Down Design with Functions.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015 Makefile Tutorial CIS5027.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Chapter 11 Introduction to Programming in C
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Data Structures and Programming Techniques
Unix Programming Environment
Kyle Fitzpatrick Konstantin Zak 11/29/2004
Build Tools (make) CSE 333 Autumn 2018
Appendix F C Programming Environment on UNIX Systems
CSc 352: Elementary “make”
GNU Make.
CSc 352 An Introduction to make
Makefiles, GDB, Valgrind
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Makefile Introduction Jia – Wei Lin 1

Outline Why we use make ? Create a Description File Rules of Makefile How make Processes a Makefile? GCC Flags Implicit rule (Suffix rules) Variables(Macros) Phony Targets More about Variables Summary 2

Why we use make ? Simplify the commands that we input when we compile. Automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. Just need to read “makefile” file and we will know how this program compile and link the other programs. 3

Create a Description File To use “make”,we have to create a Description File at first. Both “Makefile” or “makefile” are description files’ name. Write your instructions in file. Typing “make ”,and it will read the instructions from description file by default ! 4

Rules of Makefile Target : dependencies commands to make target character MUST NOT be replaced be spaces. target : usually the name of a file. dependencies : files are used as input to create the target. 5

How make Processes a Makefile? By default, make starts with the first target (not targets whose names start with ‘.’). Recompile : if the source file, or any of the header files named as dependencies, is more recent than the object file, or if the object file does not exist. 6

GCC Flags -c : Only compile the source files, but do not link. Output is an object file. Ex : filename.o -o file : Link and place output in file file. If `-o' is not specified, the default is to put an executable file in `a.out‘ -l : add a library. -L/PATH : find the library in PATH. 7

main.c :讓使用者輸 入資料與呼叫其他三 支副程式 haha.c : Print String sin_value.c :計算輸 入的角度 (360) sin 值 cos_value.c :計算輸 入的角度 (360) cos 值 Example - original 8

Example – using make  Get the executable file “main”, and we can execute the program by./main now! 9

Implicit rule (Suffix rules) More implicit rules : make -p 10 Using Implicit rule

Variables(Macros) Basics of Variable References  foo = c $(foo) or ${foo}  Get the value ‘c’  OBJS = program.o foo.o utils.o program : $(OBFS) cc -o program $(OBJS) Simply expanded(using ‘:’ ) and recursively expand variables  x = foo y = $(x) bary = later bar x= later  x := foo y := $(x) bary = foo bar x := later recursively simply 11

Variables Make Makefiles Simpler 12 Edit the code by variables

Phony Targets It is not really the name of a file. Just a name for a command to be executed when you make an explicit request. Special Built-in Target Names :  all .PHONY : make will run its command unconditionally. .SILENT : make will not print the command used to remake those particular files before executing them.  More 13

Phony Targets : all > make prog1 prog2 prog3> make 14

More about Variables Automatic Variables : : The file name of the target of the rule. $< : The name of the first dependency. $? : The names of all the prerequisites that are newer than the target. Macro String Substitution TEST = apple.c banana.c orange.c TEST_SUB = ${ TEST :.c =.o}  TEST_SUB = apple.o banana.o orange.o 15

Summary make is a tool to make the compile procedure more simpler and easy to understand. There are still more syntax and rule details about make. 16

Reference GNU Make CLDP -- Linux 中文文件計劃, 第一章 如何寫一個簡單的 Makefile. 用 Open Source 工具開發軟體 : 新軟體開發關念 Chapter 5. Makefile 撰寫 鳥哥的 Linux 私房菜 : 第二十一章 Makefile 語法簡介 --基礎 2.compiler 、 linker 與 library -- Options Controlling the Kind of Output 17