zoukankan      html  css  js  c++  java
  • 翻译和修改的AVRgcc3.3的makefile。(用法:make clean /make all)

    摘自:http://www.61ic.com/Technology/embed/200604/3222.html

    #============= MCU选择 ===========================
    # MCU name
    MCU = atmega8

    #============= 输出格式选择 ======================
    # Output format. (can be srec, ihex)
    FORMAT = ihex

    #============= 目标文件名(不带扩展名) ============
    # Target file name (without extension).
    TARGET = main

    #============= 优化级别选择 ======================
    # Optimization level (can be 0, 1, 2, 3, s)
    # (Note: 3 is not always the best optimization level. See avr-libc FAQ)
    OPT = s

    #============= C 源文件列表("\"为换行符号) =======
    # List C source files here. (C dependencies are automatically generated.)
    SRC = $(TARGET).c timer.c extdrv.c adc.c sd2k.c mylib.c

    #============= ASM 源文件列表 ====================
    # List Assembler source files here.
    ASRC =

    #============= C编译选项 =========================
    # Optional compiler flags.
    CFLAGS = -g -O$(OPT) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)

    #============= 汇编器选项 ========================
    # Optional assembler flags.
    ASFLAGS = -Wa,-ahlms=$(<:.s=.lst), -gstabs

    #============= 连接器选项 ========================
    # Optional linker flags.
    LDFLAGS = -Wl,-Map=$(TARGET).map,--cref

    #============= 附加库选项 ========================
    # Additional library flags (-lm = math library).
    LIBFLAGS = -lm

    #***********************************************************************************
    # WinAVR Sample makefile (c) 2002-2003 Eric B. Weddington
    # Released to the Public Domain
    # Please read the make user manual!
    #
    # On command line:
    # make all = Make software. 编译
    # make clean = Clean out built project files. 清除以前编译生成的文件
    # make coff = Convert ELF to COFF using objtool. 转换elf文件为cof文件
    #
    # To rebuild project do make clean then make all.
    #
    #***********************************************************************************

    #============= 指定目录,如果需要 ================
    # Define directories, if needed.
    DIRAVR = c:/ele/winavr
    DIRAVRBIN = $(DIRAVR)/bin
    DIRAVRUTILS = $(DIRAVR)/utils/bin
    DIRINC = .
    DIRLIB = $(DIRAVR)/avr/lib

    #============= 定义命令(工具软件名称) ============
    # Define programs and commands.
    SHELL = sh
    CC = avr-gcc
    OBJCOPY = avr-objcopy
    OBJDUMP = avr-objdump
    REMOVE = rm -f
    COPY = cp
    ELFCOFF = objtool

    #============= 一些字符串的定义和数据的取得 =======
    HEXSIZE = @avr-size --target=$(FORMAT) $(TARGET).hex
    ELFSIZE = @avr-size $(TARGET).elf

    FINISH = @echo Errors: none
    BEGIN = @echo -------- begin --------
    END = @echo --------  end  --------

    #============== 指定所有的连接文件 ================
    # Define all object files.
    OBJ = $(SRC:.c=.o) $(ASRC:.s=.o)

    #============== 指定所有的列表文件 ================
    # Define all listing files.
    LST = $(ASRC:.s=.lst) $(SRC:.c=.lst)

    #============== 指定全部.d文件 ====================
    # Define all listing files.
    ALLD = $(SRC:.c=.d) $(ASRC:.c=.d)

    #============== 编译所有可选的和必须的选项标志,增加处理标志 =
    # Combine all necessary flags and optional flags. Add target processor to flags.
    ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
    ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
    ALL_LDFLAGS = -mmcu=$(MCU) $(LDFLAGS)

    #============== 默认的处理(指执行make时,相当于执行make all),真正的编译过程,超级重要,要看懂!!! ==
    # Default target.
    all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).cof sizeafter finished end
    #    开始->gcc版权信息>旧文件大小>编译生成.elf----->生成.hex----->生成.eep----->生成.lss----->生成.cof>新文件大小--->完成>结束

    #***********************************************************************************
    #============== 待输出的一些编译信息 =============
    # Eye candy.
    begin:
        $(BEGIN)

    finished:
        $(FINISH)

    end:
        $(END)

    #============== 显示文件的大小信息(先前的和之后的) ==
    # Display size of file.
    sizebefore:
        @echo Size before:
        -$(HEXSIZE)

    sizeafter:
        @echo Size after:
        $(HEXSIZE)

    #=============== 显示编译版本信息 ===================
    # Display compiler version information.
    gccversion :
        $(CC) --version

    #=============== 功能:转换ELF文件为COFF文件,以便在AVR Studio 中仿真/调试。==
    # Target: Convert ELF to COFF for use in debugging / simulating in AVR Studio.
    coff: $(TARGET).cof end
    %.cof: %.elf
        $(ELFCOFF) loadelf $< mapfile $*.map writecof $@

    #=============== 从ELF输出文件中生成最终的输出文件(.hex,.eep) ==
    # Create final output files (.hex, .eep) from ELF output file.
    %.hex: %.elf
        $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

    %.eep: %.elf
        -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
        
    #=============== 从ELF输出文件中生成扩充的列表文件(.lss) ==
    # Create extended listing file from ELF output file.
    %.lss: %.elf
        $(OBJDUMP) -h -S $< > $@

    #=============== 连接:从OBJ文件中生成ELF文件(.elf) ==
    # Link: create ELF output file from object files.
    .SECONDARY : $(TARGET).elf
    .PRECIOUS : $(OBJ)
    %.elf: $(OBJ)
        $(CC) $(ALL_LDFLAGS) $(OBJ) $(LIBFLAGS) --output $@

    #=============== 编译:从C源文件中生成OBJ文件(.o) ==
    # Compile: create object files from C source files.
    %.o : %.c
        $(CC) -c $(ALL_CFLAGS) $< -o $@

    #=============== 汇编:从汇编源文件中生成OBJ文件(.o) ==
    # Assemble: create object files from assembler source files.
    %.o : %.s
        $(CC) -c $(ALL_ASFLAGS) $< -o $@

    3=============== 功能:清除上次编译结果 ==
    # Target: clean project.
    clean: begin clean_list finished end

    clean_list :
        $(REMOVE) $(TARGET).hex
        $(REMOVE) $(TARGET).eep
        $(REMOVE) $(TARGET).obj
        $(REMOVE) $(TARGET).cof
        $(REMOVE) $(TARGET).elf
        $(REMOVE) $(TARGET).map
        $(REMOVE) $(TARGET).obj
        $(REMOVE) $(TARGET).a90
        $(REMOVE) $(TARGET).sym
        $(REMOVE) $(TARGET).lnk
        $(REMOVE) $(TARGET).lss
        $(REMOVE) $(TARGET).cof
        $(REMOVE) $(OBJ)
        $(REMOVE) $(LST)
        $(REMOVE) $(ALLD)


    #==================================================================
    # Automatically generate C source code dependencies. (Code taken from the GNU make user manual.)
    # Note that this will work with sh (bash) and sed that is shipped with WinAVR (see the SHELL variable defined above).
    # This may not work with other shells or other seds.
    #%.d: %.c
    #    set -e; $(CC) -MM $(ALL_CFLAGS) $< #    | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; #    [ -s $@ ] || rm -f $@

    # Remove the '-' if you want to see the dependency files generated.
    #-include $(SRC:.c=.d)

    # Listing of phony targets.
    #.PHONY : all begin finish end sizebefore sizeafter gccversion coff clean clean_list


    原文来自winavr的一个makefile的例子,我做的主要修改之处有:

    1、make all 增加了cof文件的生成
    2、make clean 删除了*.o等更多文件
    3、其它小修改还有..但是我忘了

    说明:
    make clean :
       用于清除上次变编结果(如果*.h的文件改变,一定要先执行make clean,再执行make all)

    make all:
       编译全部(如果只有*,c文件改变,则可以不用执行make clean)

  • 相关阅读:
    IDEA SpringBoot项目连接数据库报Acess denied错误解决方法
    字符流中出现的第一个字符
    数组中重复的数字
    替换空格
    数组中次数超过一半的数字
    表示数值的字符串
    正则表达式匹配
    SpringMVC中的视图和视图解析器
    IntelliJ Idea取消Could not autowire. No beans of 'xxxx' type found的错误提示
    spring中注解注入 context:component-scan 的使用说明
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/12007768.html
Copyright © 2011-2022 走看看