2 # Project name (also used for output file name)
7 # Source files and search directories
9 CSRC += lcd.c led.c main.c mmc.c pff.c twi.c ssm2603.c bfin_util.c uzume.c
14 # Optimization level (0, 1, 2, 3, 4 or s)
19 # C Standard level (c89, gnu89, c99 or gnu99)
24 # Processor type for CSRC/ASRC files.
29 # Linker script for the target MCU
34 # Output file format (ihex, bin or both) and debugger type
40 # Include dirs, library dirs and definitions
44 INCDIRS = ../common/bfuart
54 # Object output directory
59 # Programs to build porject
62 OBJCOPY = bfin-elf-objcopy
63 OBJDUMP = bfin-elf-objdump
68 # Define all object files
72 COBJ := $(addprefix $(OBJDIR)/,$(COBJ))
73 AOBJ := $(addprefix $(OBJDIR)/,$(AOBJ))
74 PROJECT := $(OBJDIR)/$(PROJECT)
79 CFLAGS += -std=$(CSTD)
81 CFLAGS += -O$(OPTIMIZE)
82 CFLAGS += -fmessage-length=0
83 CFLAGS += $(addprefix -W,$(WARNINGS))
84 CFLAGS += $(addprefix -I,$(INCDIRS))
85 CFLAGS += $(addprefix -D,$(DEFS))
86 CFLAGS += -Wp,-M,-MP,-MT,$(OBJDIR)/$(*F).o,-MF,$(OBJDIR)/$(*F).d
91 ASFLAGS += $(addprefix -D,$(ADEFS)) -Wa,-g$(DEBUG)
96 LDFLAGS += -Wl,-Map=$(PROJECT).map,--cref,--gc-sections
98 LDFLAGS += $(patsubst %,-L%,$(LIBDIRS)) $(patsubst %,-l%,$(LIBS))
99 #LDFLAGS += -T$(LINKSCRIPT)
100 #LDFLAGS += -nostartfiles
101 #LDFLAGS += -nodefaultlibs
102 #LDFLAGS += -nostdlib
103 #LDFLAGS += -fno-builtin
105 # Combine all necessary flags and optional flags.
106 # Add target processor to flags.
107 ALL_CFLAGS = -mcpu=$(CPU) -I. $(CFLAGS)
108 ALL_ASFLAGS = -mcpu=$(CPU) -I. -x assembler-with-cpp $(ASFLAGS)
113 all: version build size
115 ifeq ($(OUTPUT),ihex)
116 build: elf hex lst sym
119 ifeq ($(OUTPUT),binary)
120 build: elf bin lst sym
123 ifeq ($(OUTPUT),both)
124 build: elf hex bin lst sym
128 $(error "Invalid format: $(OUTPUT)")
138 # Display compiler version information.
144 # Create final output file (.hex or .bin) from ELF output file.
148 $(OBJCOPY) -O ihex $< $@
152 $(OBJCOPY) -O binary $< $@
155 # Create extended listing file from ELF output file.
159 $(OBJDUMP) -h -S -C $< > $@
162 # Create a symbol table from ELF output file.
169 # Display size of file.
173 $(SIZE) -A $(PROJECT).elf
176 # Link: create ELF output file from object files.
178 %.elf: $(AOBJ) $(COBJ)
181 $(CC) $(ALL_CFLAGS) $(AOBJ) $(COBJ) --output $@ $(LDFLAGS)
184 # Compile: create object files from C source files.
186 $(COBJ) : $(OBJDIR)/%.o : %.c
189 $(CC) -c $(ALL_CFLAGS) $< -o $@
192 # Assemble: create object files from assembler source files.
194 $(AOBJ) : $(OBJDIR)/%.o : %.S
197 $(CC) -c $(ALL_ASFLAGS) $< -o $@
200 # Target: clean project.
204 rm -f -r $(OBJDIR) | exit 0
207 # Load: Load ldr for Blackfin
210 bfin-elf-ldr -T BF592 -c $(PROJECT).ldr $(PROJECT).elf
211 bfin-elf-ldr -l $(PROJECT).ldr /dev/ttyUSB0 -b 57600 -C
217 minicom -b 57600 -D /dev/ttyUSB0
220 # Include the dependency files.
222 -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)