Makefile 文件 -只有include和src文件夹 (自己用)

文件目录树结构为:

root@ubuntu:/home# tree
.
├── include
│   ├── client.h
│   ├── gps_module.h
│   └── jt.h
├── Makefile
└── src
    ├── client.c
    ├── gps_module.c
    └── jt.c

2 directories, 7 files
root@ubuntu:/home# 

Makefile文件源码为:

#编译器
cc = gcc
#目标文件
prom = client
#编译参数(程序中使用了多线程,所以使用lpthread)
CFLAGS = -lpthread
#源文件
src = $(shell find ./src/ -name "*.c")
#中间文件
obj = $(prom).o 
#根据中间文件编译生成 目标文件
$(prom): $(obj) 
        $(cc) $(obj) -o $(prom) $(CFLAGS) 
#根据源文件生成 中间文件
$(obj): $(src) 
        $(cc) -c $(src) 
#clean                                                                                               
clean:
        rm -rf  $(prom) *.o




编译过程:

root@ubuntu:/home# ls
include  Makefile  src
root@ubuntu:/home# make 
gcc -c ./src/client.c ./src/jt.c ./src/gps_module.c 
lgcc client.o  -o client -lpthread 
root@ubuntu:/home# ls
client  client.o  gps_module.o  include  jt.o  Makefile  src
root@ubuntu:/home#

写的不是很规范(自己的程序可以将就用)大家酌情参考。

猜你喜欢

转载自blog.csdn.net/weixin_38184741/article/details/84450937