Makefile 使用方法

我们在平时的日常运维中, 经常会遇到要源码安装一些软件,在安装的过程中, 总会遇到 make &&make install 等类似的make的命令,之前一直没有对这个进行过深入的了解。其实make命令是依赖于一个Makefile的文件的, 在文件中定义make的使用方法,用以告诉make怎么去执行命令,怎么去编译。

今天自己做了一个小的实验:

[root@yangdong tmp]# cat Makefile 

usage:
    @echo "Usage: "
    @echo " make test"

test:
    date
    echo "this is a test!"

这是我自己写的一个简单的Makefile 的文本文件。用以输出当前的时间同时打印出字符串:this is a test!

运行结果:

[root@yangdong tmp]# make         #获取make的一些信息。类似--help
Makefile:13: warning: overriding recipe for target `usage'
Makefile:2: warning: ignoring old recipe for target `usage'
Usage: 
 make test   #使用方法
[root@yangdong tmp]# make test  #调用make的test方法date
Tue Jul 23 21:47:06 EDT 2019
echo "this is a test!"
this is a test!

在了解了Makefile的使用方法后,我们可以在以后的运维中使用上。比如我在安装tomcat的时候,我完全可以在当前目录下写一个Makefile。来方便后期的一些操作

root@dev-java001:~/projects$ cat Makefile 

usage:
    @echo "Usage: "
    @echo "    APP_NAME=<appName> make init"


init:
    cp -R appname $(APP_NAME) && \
        mkdir -p /home/souchelogs/applogs/$(APP_NAME) && \
        rm -rf $(APP_NAME)/logs && \
        ln -s /home/souchelogs/applogs/$(APP_NAME) $(APP_NAME)/logs

比如这个文件,我在使用的时候就可以 很方便我做后面的一些频繁的操作。

 

posted @ 2019-07-26 16:40  爱热闹的杨小厨  阅读(1066)  评论(0编辑  收藏  举报