最近有个项目,不能在Keil uVision4 MDK中开发,只能在linux下并使用命令行的GCC编译器,手动写makefile,对于习惯了IDE的开发者来说多少有些不适应,尤其是查找函数定义之类的不方便。于是成功的实现了使用Eclipse的IDE,并配合GCC编译器开发嵌入式应用程序。Eclipse和GCC环境的搭建先略过,查资料都好解决。先贴出makefile模版,因为没有使用Eclpise的CDT自动生成的makefile,所以这里的 makefile是必须的。GCC编译器用的sourcery codebench,这样能轻松获取GCC工具链,较方便。
#**************************************************************************** # Author information # Created on : 2013-12-26 # Author: yangyongzhen #**************************************************************************** #**************************************************************************** # Cross complie path #**************************************************************************** GCC_PATH=c:\tools\arm2013.05 CROSS_COMPILE=$(GCC_PATH)\bin\arm-none-eabi- CC := $(CROSS_COMPILE)gcc CXX := $(CROSS_COMPILE)g++ AS := $(CROSS_COMPILE)as AR := $(CROSS_COMPILE)ar LD := $(CROSS_COMPILE)ld RANLIB := $(CROSS_COMPILE)ranlib OBJDUMP:= $(CROSS_COMPILE)objdump OBJCOPY:= $(CROSS_COMPILE)objcopy STRIP := $(CROSS_COMPILE)strip #**************************************************************************** # Include paths #**************************************************************************** INCS := -I .\LIB_Includes\LIB_Include_A303 #**************************************************************************** # Libs #**************************************************************************** LIB_C := $(GCC_PATH)\arm-none-eabi\lib\libc.a LIB_GCC := $(GCC_PATH)\lib\gcc\arm-none-eabi\4.7.3\libgcc.a LIB_A303 := LIBS := $(LIB_C) $(LIB_GCC) $(LIB_A303) #**************************************************************************** # Flags #**************************************************************************** CFLAGS= -std=gnu99 -O0 -DNDEBUG -msoft-float -mlittle-endian -Wall -mno-unaligned-access -fno-zero-initialized-in-bss -D_POS_S80 -D_APPMANAGER LDSCRIPT = mapp.ld LDFLAGS = -nostdlib -M -T $(LDSCRIPT) APPFLAG = PAX-S80-MAPP STRIP_RELEASE :=NO #**************************************************************************** # Targets of the build #**************************************************************************** TARGET := .\Output\A303_YJJC all: prebuild $(TARGET).elf #**************************************************************************** # Source files #**************************************************************************** SRC_C=$(shell gfind . -name "*.c") SRC_S=$(shell gfind . -name "*.s") OBJ_C=$(patsubst %.c, %.o, $(SRC_C)) OBJ_S=$(patsubst %.s, %.o, $(SRC_S)) SRCS := $(SRC_C) $(SRC_C) OBJS := $(OBJ_C) $(OBJ_S) #**************************************************************************** # TARGET #**************************************************************************** prebuild: @echo Building app... $(TARGET).elf : $(OBJS) $(LIBS) @echo (LD) $@: $^ ${LD} ${LDFLAGS} -o $@ $^ > $(TARGET).map @echo Generating bin... @elftobin $@ $(TARGET).bin $(APPFLAG) @echo Generating hex... @$(OBJCOPY) -O ihex $@ $(TARGET).hex @echo Generating asm... @$(OBJDUMP) -D -S $@ > $(TARGET).asm @echo OK! ifeq (YES, ${STRIP_RELEASE}) ${STRIP} ${TARGET}.elf endif %.o : %.c ${CC} -c ${CFLAGS} ${INCS} -o $@ $< %.o : %.s $(AS) $(ASFLAG) -o $@ $< clean: @echo The following files: rm -f $(TARGET) *.o gfind . -name "*.[o]" |xargs rm @echo Removed! #*************************************************************************** #makefile file end #*************************************************************************** #*************************************************************************** #windows下的代码拷贝到linux下中文会乱码,以下为转码用 #*************************************************************************** DIRS := .\AH_Driver \ .\AH_Driver\AH_Card \ .\AH_Driver\AH_Card\CPU_Card \ .\AH_Driver\AH_Card\CPU_Card\INC_Lib \ .\AH_Driver\AH_Card\M1_Card \ .\AH_Driver\AH_Comm \ .\AH_Driver\AH_Display \ .\AH_Driver\AH_Display\Out_LIB \ .\AH_Driver\AH_Display\Out_LIB\INC_Lib \ .\AH_Driver\AH_Oth \ .\APP_Driver \ .\APP_Task\Task_Main \ .\APP_Task\Task_AppSel \ .\HW_Driver \ .\HW_Driver\INC_Lib \ .\NC_FileSys \ .\NC_FileSys\INC_Lib \ .\OS_Kernel \ .\PRJ_Cfg \ .\SysDebug \ .\LIBS\LIB_A303 fileencoding: @ for dir in $(DIRS); do \ enconv -L zh_CN -x cp936 $$dir/*; done