最近在写makefile记录一下,一个简单通用的makefile直接放到.c和.h下 输入make即可。帮助初学者,我也是初学者,分享一下~
下面是我的通用模板放在.c .h中直接 make即可 生成TARGET
1.在CFLAGS = -g -Wall -I${DIR_INC} -I/usr/include/lua5.1/ 此处加依赖库头文件
2.在 $(CC) $(OBJ) -o $@ -lm -llua5.1 此处加依赖库so
方便大家copy:源码如下。DIR_INC = ./
DIR_SRC = ./
DIR_OBJ = ./
DIR_BIN = ./
#iDIR_INC = ./include
#DIR_SRC = ./src
#DIR_OBJ = ./obj
#DIR_BIN = ./bin
SRC = $(wildcard ${DIR_SRC}/*.c)
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TARGET = main
BIN_TARGET = ${DIR_BIN}/${TARGET}
CC = gcc
CFLAGS = -g -Wall -I${DIR_INC} -I/usr/include/lua5.1/
${BIN_TARGET}:${OBJ}
$(CC) $(OBJ) -o $@ -lm -llua5.1
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
$(CC) $(CFLAGS) -c $< -o $@
.PHONY:clean
clean:
find ${PWD} -name *.o -exec rm -rf {}
网友评论