makefile求助:如何修改makefile,使编译生成的.o,.lst,.elf,.map,.sym都在文件家./defualt里? <br />(类似avr_studio). <br /><br /><br /><br />TCHAIN = arm-elf <br /><br /># Define programs and commands. <br />SHELL = sh <br />CC = $(TCHAIN)-gcc <br />CPP = $(TCHAIN)-g++ <br />AR = $(TCHAIN)-ar <br />OBJCOPY = $(TCHAIN)-objcopy <br />OBJDUMP = $(TCHAIN)-objdump <br />SIZE = $(TCHAIN)-size <br />NM = $(TCHAIN)-nm <br />REMOVE = rm -f <br />REMOVEDIR = rm -r <br />COPY = cp <br /><br /><br /><br />MCU = arm7tdmi <br />SUBMDL = LPC2106 <br />#THUMB = -mthumb <br />#THUMB_IW = -mthumb-interwork <br /><br /><br />## Create ROM-Image (final) <br />RUN_MODE=ROM_RUN <br />## Create RAM-Image (debugging) <br />#RUN_MODE=RAM_RUN <br /><br /><br /># Output format. (can be srec, ihex, binary) <br />FORMAT = ihex <br /><br /><br /># List C source files here. (C dependencies are automatically generated.) <br />SRC = $(TARGET).c <br />SRC += sysTime.c uart.c uartISR.c armVIC.c <br />SRC += onewire.c crc8.c ds18x20.c delay.c mtutil.c <br /><br /><br /># List Assembler source files here. <br /># Make them always end in a capital .S. Files ending in a lowercase .s <br /># will not be considered source files but generated files (assembler <br /># output from the compiler), and will be deleted upon "make clean"! <br /># Even though the DOS/Win* filesystem matches both .s and .S the same, <br /># it will preserve the spelling of the filenames, and gcc itself does <br /># care about how the name is spelled on its command-line. <br />ASRC = crt0.S <br /><br /><br /># Optimization level, can be [0, 1, 2, 3, s]. <br /># 0 = turn off optimization. s = optimize for size. <br /># (Note: 3 is not always the best optimization level. See avr-libc FAQ.) <br />OPT = s <br /><br /># Debugging format. <br /># Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. <br /># AVR (extended) COFF requires stabs, plus an avr-objcopy run. <br />#DEBUG = stabs <br />DEBUG = dwarf-2 <br /><br /># List any extra directories to look for include files here. <br /># Each directory must be seperated by a space. <br />#EXTRAINCDIRS = ./include <br />EXTRAINCDIRS = <br /><br /># Compiler flag to set the C Standard level. <br /># c89 - "ANSI" C <br /># gnu89 - c89 plus GCC extensions <br /># c99 - ISO C99 standard (not yet fully implemented) <br /># gnu99 - c99 plus GCC extensions <br />CSTANDARD = -std=gnu99 <br /><br /># Place -D or -U options for C here <br />CDEFS = -D$(RUN_MODE) <br /><br /># Place -I options here <br />CINCS = <br /><br /># Place -D or -U options for ASM here <br />ADEFS = -D$(RUN_MODE) <br /><br /><br /># Compiler flags. <br /># -g*: generate debugging information <br /># -O*: optimization level <br /># -f...: tuning, see GCC manual and avr-libc documentation <br /># -Wall...: warning level <br /># -Wa,...: tell GCC to pass this to the assembler. <br /># -adhlns...: create assembler listing <br />CFLAGS = -g$(DEBUG) <br />CFLAGS += $(CDEFS) $(CINCS) <br />CFLAGS += -O$(OPT) <br />CFLAGS += -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit <br />CFLAGS += -Wmissing-declarations <br />CFLAGS += -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch <br />CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused <br />CFLAGS += -Wa,-adhlns=$(<:.c=.lst) <br />CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) <br />CFLAGS += $(CSTANDARD) <br />## NONO CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums <br /><br /># Assembler flags. <br /># -Wa,...: tell GCC to pass this to the assembler. <br /># -ahlms: create listing <br /># -gstabs: have the assembler create line number information; note that <br /># for use in COFF files, additional information about filenames <br /># and function names needs to be present in the assembler source <br /># files -- see avr-libc docs [FIXME: not yet described there] <br />##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs <br />ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG) <br /><br />#Additional libraries. <br /><br />#Support for newlibc-lpc (file: libnewlibc-lpc.a) <br />#NEWLIBLPC = -lnewlib-lpc <br />NEWLIBCLPC = <br /><br />MATH_LIB = -lm <br /><br /># Linker flags. <br /># -Wl,...: tell GCC to pass this to linker. <br /># -Map: create map file <br /># --cref: add cross reference to map file <br />LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref <br />LDFLAGS += -lc <br />LDFLAGS += $(NEWLIBLPC) $(MATH_LIB) <br />LDFLAGS += -lc -lgcc <br /><br /># Set Linker-Script Depending On Selected Memory <br />ifeq ($(RUN_MODE),RAM_RUN) <br />LDFLAGS +=-T$(SUBMDL)-RAM.ld <br />else <br />LDFLAGS +=-T$(SUBMDL)-ROM.ld <br />endif <br /><br /><br /><br /># --------------------------------------------------------------------------- <br /># Flash-Programming support using lpc21isp by Martin Maurer <br /><br /># Settings and variables: <br />LPC21ISP = lpc21isp <br />LPC21ISP_PORT = com1 <br />LPC21ISP_BAUD = 115200 <br />LPC21ISP_XTAL = 14746 <br />LPC21ISP_FLASHFILE = $(TARGET).hex <br /># verbose output: <br />## LPC21ISP_DEBUG = -debug <br /># enter bootloader via RS232 DTR/RTS (only if hardware supports this <br /># feature - see Philips AppNote): <br />## LPC21ISP_CONTROL = -control <br /><br /><br /># --------------------------------------------------------------------------- <br /><br /># Define directories, if needed. <br />## DIRARM = c:/WinARM/ <br />## DIRARMBIN = $(DIRAVR)/bin/ <br />## DIRAVRUTILS = $(DIRAVR)/utils/bin/ <br /><br /><br /><br /># Define Messages <br /># English <br />MSG_ERRORS_NONE = Errors: none <br />MSG_BEGIN = -------- begin -------- <br />MSG_END = -------- end -------- <br />MSG_SIZE_BEFORE = Size before: <br />MSG_SIZE_AFTER = Size after: <br />MSG_FLASH = Creating load file for Flash: <br />MSG_EXTENDED_LISTING = Creating Extended Listing: <br />MSG_SYMBOL_TABLE = Creating Symbol Table: <br />MSG_LINKING = Linking: <br />MSG_COMPILING = Compiling: <br />MSG_ASSEMBLING = Assembling: <br />MSG_CLEANING = Cleaning project: <br />MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now. <br /><br /><br /># Define all object files. <br />OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) <br /><br /><br /># Define all listing files. <br />LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) <br /><br /><br /># Compiler flags to generate dependency files. <br />### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d <br />GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d <br /><br /># Combine all necessary flags and optional flags. <br /># Add target processor to flags. <br />ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS) <br />ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS) <br /><br /><br /># Default target. <br />all: begin gccversion sizebefore build sizeafter finished end <br /><br />build: elf hex lss sym <br /><br />elf: $(TARGET).elf <br />hex: $(TARGET).hex <br />lss: $(TARGET).lss <br />sym: $(TARGET).sym <br /><br /># Eye candy. <br />begin: <br />@echo <br />@echo $(MSG_BEGIN) <br /><br />finished: <br />@echo $(MSG_ERRORS_NONE) <br /><br />end: <br />@echo $(MSG_END) <br />@echo <br /><br /><br /># Display size of file. <br />HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex <br />ELFSIZE = $(SIZE) -A $(TARGET).elf <br />sizebefore: <br />@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi <br /><br />sizeafter: <br />@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi <br /><br /><br /># Display compiler version information. <br />gccversion : <br />@$(CC) --version <br /><br /><br /># Program the device. <br />program: $(TARGET).hex <br />@echo <br />@echo $(MSG_LPC21_RESETREMINDER) <br />$(LPC21ISP) $(LPC21ISP_CONTROL) $(LPC21ISP_DEBUG) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL) <br /><br /><br /># Create final output files (.hex, .eep) from ELF output file. <br /># TODO: handling the .eeprom-section should be redundant <br />%.hex: %.elf <br />@echo <br />@echo $(MSG_FLASH) $@ <br />$(OBJCOPY) -O $(FORMAT) $< $@ <br /><br /><br /># Create extended listing file from ELF output file. <br />%.lss: %.elf <br />@echo <br />@echo $(MSG_EXTENDED_LISTING) $@ <br />$(OBJDUMP) -h -S $< > $@ <br /><br /><br /># Create a symbol table from ELF output file. <br />%.sym: %.elf <br />@echo <br />@echo $(MSG_SYMBOL_TABLE) $@ <br />$(NM) -n $< > $@ <br /><br /><br /># Link: create ELF output file from object files. <br />.SECONDARY : $(TARGET).elf <br />.PRECIOUS : $(OBJ) <br />%.elf: $(OBJ) <br />@echo <br />@echo $(MSG_LINKING) $@ <br />$(CC) $(THUMB) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) <br /><br /><br /># Compile: create object files from C source files. <br />%.o : %.c <br />@echo <br />@echo $(MSG_COMPILING) $< <br />$(CC) -c $(THUMB) $(ALL_CFLAGS) $< -o $@ <br /><br /><br /># Compile: create assembler files from C source files. <br />%.s : %.c <br />$(CC) $(THUMB) -S $(ALL_CFLAGS) $< -o $@ <br /><br /><br /># Assemble: create object files from assembler source files. <br />%.o : %.S <br />@echo <br />@echo $(MSG_ASSEMBLING) $< <br />$(CC) -c $(ALL_ASFLAGS) $< -o $@ <br /><br /><br /># Target: clean project. <br />clean: begin clean_list finished end <br /><br /><br />clean_list : <br />@echo <br />@echo $(MSG_CLEANING) <br />$(REMOVE) $(TARGET).hex <br />$(REMOVE) $(TARGET).obj <br />$(REMOVE) $(TARGET).elf <br />$(REMOVE) $(TARGET).map <br />$(REMOVE) $(TARGET).obj <br />$(REMOVE) $(TARGET).a90 <br />$(REMOVE) $(TARGET).sym <br />$(REMOVE) $(TARGET).lnk <br />$(REMOVE) $(TARGET).lss <br />$(REMOVE) $(OBJ) <br />$(REMOVE) $(LST) <br />$(REMOVE) $(SRC:.c=.s) <br />$(REMOVE) $(SRC:.c=.d) <br />$(REMOVE) .dep/* <br /><br /><br /># Include the dependency files. <br />-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) <br /><br /><br /># Listing of phony targets. <br />.PHONY : all begin finish end sizebefore sizeafter gccversion \ <br />build elf hex lss sym \ <br />clean clean_list program <br /> |
|