求高手详解一下这个makefile
## 需要修改的地方 ##
#单片机类型 MCU = atmega16 #工作频率 CPU_FREQ = 14745600UL #生成文件名 TARGET = demo #要包含的路径(本用例包含add sub mul 三个目录) VPATH = ./add:./sub:./mul #优化等级 OPTIMIZATION = 0 #编译器路径(不一定要指定,如果用20060119版本的,需要指定) #GCC_PATH = c:/winavr
############# 以下均不需要修改 ###################
## 编译器参数设置 ## TCHAIN = avr CC = $(TCHAIN)-gcc C++ = $(TCHAIN)-g++ OBJCOPY = $(TCHAIN)-objcopy OBJDUMP = $(TCHAIN)-objdump SIZE = $(TCHAIN)-size
MKDIR = mkdir RMDIR = rmdir RM = rm -f
#定义输出目录名 OUTPUT_PATH=output
EXE_PATH = $(OUTPUT_PATH)/exe LST_PATH = $(OUTPUT_PATH)/lst OBJ_PATH = $(OUTPUT_PATH)/obj EXT_EXE_PATH = ./$(EXE_PATH)/ EXT_LST_PATH = ./$(LST_PATH)/ EXT_OBJ_PATH = ./$(OBJ_PATH)/ #定义文件类型 C_SUFFIX = *.c CPP_SUFFIX = *.cpp ASM_SUFFIX = *.s
#能否详细说明一下以下一段具体是什么意思?
C_SUF = $(suffix $(C_SUFFIX)) CPP_SUF = $(suffix $(CPP_SUFFIX)) ASM_SUF = $(suffix $(ASM_SUFFIX))
CSRC = $(notdir $(wildcard $(C_SUFFIX) $(addsuffix /$(C_SUFFIX),$(subst :, ,$(VPATH))))) ASRC = $(notdir $(wildcard $(ASM_SUFFIX) $(addsuffix /$(ASM_SUFFIX),$(subst :, ,$(VPATH))))) CPPSRC = $(notdir $(wildcard $(CPP_SUFFIX) $(addsuffix /$(CPP_SUFFIX),$(subst :, ,$(VPATH)))))
ELF = $(addprefix $(EXT_EXE_PATH),$(TARGET).elf) HEX = $(addprefix $(EXT_EXE_PATH),$(TARGET).hex) EEP = $(addprefix $(EXT_EXE_PATH),$(TARGET)_eeprom.hex) LST = $(addprefix $(EXT_LST_PATH),$(TARGET).lst)
OBJS = $(addprefix $(EXT_OBJ_PATH),$(CSRC:$(C_SUF)=.o)) OBJS += $(addprefix $(EXT_OBJ_PATH),$(ASRC:$(ASM_SUF)=.o)) OBJS += $(addprefix $(EXT_OBJ_PATH),$(CPPSRC:$(CPP_SUF)=.o))
ASM = $(addprefix $(EXT_LST_PATH),$(CSRC:$(C_SUF)=$(ASM_SUF))) ASM += $(addprefix $(EXT_LST_PATH),$(CPPSRC:$(CPP_SUF)=$(ASM_SUF)))
#能否详细说明一下以上一段具体是什么意思?
COMMON_FLAGS = -I. -I$(GCC_PATH)/avr/include COMMON_FLAGS += -mmcu=$(MCU) COMMON_FLAGS += -O$(OPTIMIZATION) COMMON_FLAGS += -Wall COMMON_FLAGS += -funsigned-char COMMON_FLAGS += -funsigned-bitfields COMMON_FLAGS += -fpack-struct COMMON_FLAGS += -fshort-enums COMMON_FLAGS += -Wstrict-prototypes COMMON_FLAGS += -DF_CPU=$(CPU_FREQ) COMMON_FLAGS += -std=gnu99
COMPILE_FLAGS = $(COMMON_FLAGS) -g ASSEMBLER_FLAGS = $(COMMON_FLAGS) -g -assembler-with-cpp FLASH_FLAGS = -j .text -j .data
#EEPROM_FLAGS = -j .eeprom --change-section-lma .eeprom=0 EEPROM_FLAGS = -R .eeprom EEPROM_FLAGS = -j .eeprom EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
all: CreatePath $(ASM) $(ELF) $(HEX) $(EEP) $(LST) size
no_eeprom: CreatePath $(ASM) $(ELF) $(HEX) $(LST) size
$(ELF): $(OBJS) $(CC) $(COMPILE_FLAGS) $(OBJS) -o $@
$(HEX): $(ELF) $(OBJCOPY) $(FLASH_FLAGS) -O ihex $< $@
$(EEP): $(ELF) -$(OBJCOPY) $(EEPROM_FLAGS) -O ihex $< $@ || exit
$(LST): $(ELF) $(OBJDUMP) -h -S $^ > $@
size: $(ELF) @$(SIZE) $< @$(SIZE) -A $< @echo
##将cpp文件编译成目标文件(.o)## $(EXT_OBJ_PATH)%.o : %$(suffix $(CPP_SUFFIX)) $(CC) $(COMPILE_FLAGS) -c $< -o $@ ##将c文件编译成目标文件(.o)## $(EXT_OBJ_PATH)%.o : %$(suffix $(C_SUFFIX)) $(CC) $(COMPILE_FLAGS) -c $< -o $@ ##将s文件编译成目标文件(.o)## $(EXT_OBJ_PATH)%.o : %$(suffix $(ASM_SUFFIX)) $(CC) $(ASSEMBLER_FLAGS) -c $< -o $@
##将c文件编译成汇编文件(.s)## $(EXT_LST_PATH)%$(ASM_SUF) : %$(suffix $(C_SUFFIX)) $(CC) $(COMPILE_FLAGS) -S $< -o $@ ##将cpp文件编译成汇编文件(.s)## $(EXT_LST_PATH)%$(ASM_SUF) : %$(suffix $(CPP_SUFFIX)) $(CC) $(COMPILE_FLAGS) -S $< -o $@
CreatePath: @if test -d $(OUTPUT_PATH);then echo >nul; else $(MKDIR) $(OUTPUT_PATH);fi @if test -d $(OBJ_PATH); then echo >nul; else $(MKDIR) $(OBJ_PATH);fi @if test -d $(EXE_PATH); then echo >nul; else $(MKDIR) $(EXE_PATH);fi @if test -d $(LST_PATH); then echo >nul; else $(MKDIR) $(LST_PATH);fi
clean: @if test -d $(OBJ_PATH); then $(RM) $(EXT_OBJ_PATH)*.*; $(RMDIR) $(OBJ_PATH); else echo >nul; fi
@if test -d $(EXE_PATH); then $(RM) $(EXT_EXE_PATH)*.*; $(RMDIR) $(EXE_PATH); else echo >nul; fi
@if test -d $(LST_PATH); then $(RM) $(EXT_LST_PATH)*.*; $(RMDIR) $(LST_PATH); else echo >nul; fi
@if test -d $(OUTPUT_PATH); then $(RM) $(OUTPUT_PATH)*.*; $(RMDIR) $(OUTPUT_PATH); else echo >nul; fi
.PHONY: all clean CreatePath size
|