一个简单的Makefile

来源:互联网 发布:tiva数据库 编辑:程序博客网 时间:2024/05/16 11:17

一个简易的小万能Makefile

target := helloobj = $(patsubst *.c, *.o, $(wildcard *.c))$(target): $(obj)        gcc -o $(target) $(obj) clean:        rm -r $(target) *.o
exp

#include <stdio.h>int main(int argc, char *argv[]){        printf("Hello, world\n");        return 0;}
do

root@ubuntuServer:~/test# makegcc -o hello  hello.c root@ubuntuServer:~/test# ./hello Hello, worldroot@ubuntuServer:~/test# 
分析

target += hello
定义一个变量target,想要输出怎么样的可执行程序,替换hello就可以了。对于:=附加操作符,表明hello是立即变量

obj = $(patsubst *.c, *.o, $(wildcard *.c))
$(patsubst a, b, c)表示替换通配符,意思是说将c中的a替换成b;$(wildacrd *.c)是扩展通配符,即将当前目录下的所有.c文件的后缀换成.o

$(target): $(obj)        gcc -o $(target) $(obj) 
这条是执行规则,生成可执行程序

最后一条伪指令用于清理