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 "------------------"

你可能感兴趣的:(Makefile,linux,makefile)