Makefile万能模板

通过json文件配置万能的Makefile

{
    "target":{
        "exe":"main",
        "a_lib":"libwebsocket",
        "so_lib":"libcJSON"
    },
    "lib":{
        "libwebsocket":{
            "dir_lib": "./",
            "dir_inc": "./lib_dir",
            "dir_lib_not_default": "./"
        },
        "libcJSON":{
            "dir_lib": "./",
            "dir_inc": "./",
            "dir_no_default": "./"
        }
    },
    "src":{
        "file_c": ["xx.c", "2.c", "3.c"],
        "file_h": "xx.h",
        "dir_c": "./",
        "dir_h": "./",
        "need_lib":"libcJSON"
    },
    "cflags":"-std=gnu9x",
    "cxxflags":"-std=c++11",
    "config_macor_define":"-DINVG_RELEASE",
    "version": "1.0.0",
    "cross_prefix": "/home/arm-linux-"
}

使用*.o文件方法:

ifeq ($(ver), release)
	RELEASE_FLAG = -D RELEASE
endif

CC = gcc
CFLAGS += -g -std=gnu99 -Wall -Woverride-init -Wsign-compare -Wtype-limits -Wuninitialized
LIB = -lpthread -L./
# INCLUDE = -I /usr/src/linux-headers-3.13.0-32/include


OBJ_FILES = ./makefile_define.o
NAME = makefile_define

all:$(NAME)

$(NAME):$(OBJ_FILES)
	$(CC) $(CFLAGS) $^ -lpthread  -o $@ $(LIB) $(RELEASE_FLAG)
	
clean:
	rm $(NAME) *.o
	find ./ -name "*~" | xargs rm

# check_s:
# 	valgrind ./server
# check_c:
# 	valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 ./client

release:
	# Release a Version
	@make all ver=release




# .c.o:
# 	$(CC) -c -o $@ $(DEBUG) $(CFLAGS) $(IFLAGS) $<
%.o:%.c
	$(CC) -c -o $@ $(DEBUG) $(CFLAGS) $(IFLAGS) $(LIB) $< $(RELEASE_FLAG)
	@echo "------------------"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值