最近有个项目,不能在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:toolsarm2013.05 CROSS_COMPILE=$(GCC_PATH)binarm-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_IncludesLIB_Include_A303 #**************************************************************************** # Libs #**************************************************************************** LIB_C := $(GCC_PATH)arm-none-eabiliblibc.a LIB_GCC := $(GCC_PATH)libgccarm-none-eabi4.7.3libgcc.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 := .OutputA303_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_DriverAH_Card .AH_DriverAH_CardCPU_Card .AH_DriverAH_CardCPU_CardINC_Lib .AH_DriverAH_CardM1_Card .AH_DriverAH_Comm .AH_DriverAH_Display .AH_DriverAH_DisplayOut_LIB .AH_DriverAH_DisplayOut_LIBINC_Lib .AH_DriverAH_Oth .APP_Driver .APP_TaskTask_Main .APP_TaskTask_AppSel .HW_Driver .HW_DriverINC_Lib .NC_FileSys .NC_FileSysINC_Lib .OS_Kernel .PRJ_Cfg .SysDebug .LIBSLIB_A303 fileencoding: @ for dir in $(DIRS); do enconv -L zh_CN -x cp936 $$dir/*; done