zoukankan      html  css  js  c++  java
  • 毕业设计 Makefile 编写

    一天下来,Makefile终于完成了,可以实现c文件和头文件不同目录,并将输出文件输出到其他如output目录,将执行文件和makefile文件并列:
    源码如下:

    # ============================================================
    # Makefile for project (by chen long 2019.03.29)        ======
    # make clean        :  clean output/                    ======
    # make 					:	make clean && make all      ======
    # ============================================================
    TARGET 	:= app
    MKDIR 	:= mkdir -p
    RM       	:= rm -rf
    CC			:= gcc #arm-linux-gcc
    # LIBS 	:= -lpthread
    CFLAGS	:= -o
    
    MAKE_PATH 	:= $(CURDIR)
    INC_PATH 		:= -I$(MAKE_PATH)/include
    SRC_PATH 		:= $(MAKE_PATH)/src
    OUT_PATH 		:= $(MAKE_PATH)/output
    
    # ---------------------------------------------------------
    # ---------------------------------------------------------
    SRCS_DIR	=$(wildcard $(SRC_PATH)/*.c) 
    SRCS 	= $(notdir  $(SRCS_DIR) )
    
    OBJS 	= $(patsubst %.c,%.o,$(SRCS)) 
    OBJS_DIR = $(addprefix $(OUT_PATH)/, $(OBJS))
    
    default: all
    .PHONY: mk_output_dir   clean  cleanall
    all:clean mk_output_dir  $(OBJS)  $(TARGET) 
    # 搜索目录下.c和.o文件
    vpath %.c $(SRC_PATH)
    vpath %.o $(OUT_PATH)
    
    mk_output_dir:
    	@$(MKDIR) $(OUT_PATH)
    
    $(OBJS):%.o:%.c
    	@$(CC) $(INC_PATH) $(CFLAGS) $(OUT_PATH)/$@ -c $<
    
    $(TARGET) :$(OBJS_DIR)
    	@$(CC) $(INC_PATH) $(LIBS) $(CFLAGS) $@  $^
    
    clean:
    	$(RM) $(OUT_PATH) 
    
    cleanall:
    	$(RM) $(OUT_PATH) $(MAKE_PATH)/main
    
    
  • 相关阅读:
    Course Schedule II
    Vim笔记
    python programming
    暴风电视刷机教程
    python asyncio
    sqlalchemy lock and atomic
    rust学习(二)
    rust-vmm 学习(二)
    e3s10 网络管理
    打造VIM成为IDE - nerdtree
  • 原文地址:https://www.cnblogs.com/misfit/p/10622041.html
Copyright © 2011-2022 走看看