---
# System prepended metadata

title: makefile
tags: [makefile]

---

###### tags: `makefile`
# makefile

---

## makefile frist rule
#### default rule
分成三個部分
1.target --> file or something
2.prerequisite --> already exist file
3.command --> shell command
```make=
target: prereq1 prereq2
    commands
```
Example
```make=
foo.o: foo.c foo.h
    gcc -c foo.c
```
## makefile 風格
#### two-phase execution model 
#### recursive variable

## make 分析 makefile 工作流程
**從target到prerequisite,從prerequisite到target,再從target到prerequisite** 
叫做 chaining 典型執行那些命令地的做法。

## make -l rule
```shell=
## -l<filename>
gcc main.c -o -ldai
```
make 先搜尋 dai.so file
if not exist then
    search dai.a file