三、makefile 之echo \ $^ exec

来源:互联网 发布:阿里云域名使用方法 编辑:程序博客网 时间:2024/06/05 02:45

首先基于上篇文章makefile 的初认识,我们继续学习makefile 新东西(hello.cpp test.h文件和上文类同不在细谈)着重学习makefile;

mkdir -p testcd testmkdir functiontouch hello.cppvi hello.cppmkdir sourcetouch test.hvi test.hcd ..touch makefilevi makefile

同样建立操做和三个文件

#include<iostream>using namespace std;void print(){cout<<"i am a student"<<endl;}

test.h文件

#include"../function/test.h"#include<iostream>using namespace std;int main(int argc,char* argv[]){cout<<"hello world"<<endl;print();return 0;}

hello.cpp文件

VPATH=./sourceCC=g++#vpath %.cpp source#vpath %.h  functionobject=hello.o hello:$(object)    @ echo 正在编译文件 $<    $(CC)  -o $@ -g $^$(object):hello.cpp     @ echo 正在编译文件 \$<    $(CC)  -o \$@ \-c $^ exec:    cd /home/ubuntu/test;pwd #ubuntu为本机用户名clean:    -rm hello $(object)

上面是新的makefile文件

这里简单说一下,<^代表所有的依赖的文件,更多详细的说明后面到了大型makefile 会在谈论;所以这里也可以使用$^代替源文件

@ echo 信息 代表打印输出的信息,同时若一行语句写不完,可以使用\换行输入,命令和打印信息都是可以的;

当执行make exec 的时候,make 或解析到/home/ubuntu/test目录下执行一些特殊的操作 这里只是使用了pwd命令 打印出路径,当然用户可以使用其他命令完成自己特定操作;

0 0
原创粉丝点击