Makefile

Makefile的基本使用

2018-08-10  本文已影响0人  stringlife

Makefile的基本使用

首先需要有一个Makefile文件
然后执行make即可完成所有的Makefile中定义的符合目标的工作

all:test.c
    gcc test.c -o all
string@asus:~/Projects/makefile$ ls
Makefile  test.c
string@asus:~/Projects/makefile$ make
gcc test.c -o all
string@asus:~/Projects/makefile$ 

接下来完善以下Makefile,增加clean目标、增加test目标,使得Makefile更像一个项目管理的Makefile

all:test

test:test.c
    gcc test.c -o test
clean:
    rm -f test 

此时的Makefile中已经有三个目标
all test clean
其中all依赖于test,test是一个单独的目标,clean是一个单独的目标
这三个目标都可以单独的进行make
make后的效果

string@asus:~/Projects/makefile$ make all
gcc test.c -o test
string@asus:~/Projects/makefile$ make clean 
rm -f test 
string@asus:~/Projects/makefile$ make test 
gcc test.c -o test
string@asus:~/Projects/makefile$

第一步生成all目标,由于all依赖于test,所有重新生成test
第二步清除掉生成test
第三步生成test目标,由于第二步已经清除掉了test目标所以第三步会重新生成test目标

上一篇下一篇

猜你喜欢

热点阅读