OSDN Git Service

M系列信号による乱数発生器を追加。
[bluetank/bluetank.git] / firm / bare_metal / karaoke_machine / Makefile
1 #
2 # Project name (also used for output file name)
3 #
4 PROJECT = bluetank
5
6 #
7 # Source files and search directories
8 #
9 CSRC   += lcd.c led.c rotenc.c
10 CSRC   += mmc.c pff.c
11 CSRC   += twi.c uart.c
12 CSRC   += ssm2603.c at24c.c
13 CSRC   += bfin_util.c uzura.c
14 CSRC   += tinyrand.c
15 CSRC   += effect.c system.c main.c
16 ASRC   +=
17 VPATH   = ../common/
18
19 #
20 # Optimization level (0, 1, 2, 3, 4 or s)
21 #
22 OPTIMIZE = s
23
24 #
25 # C Standard level (c89, gnu89, c99 or gnu99)
26 #
27 CSTD = gnu89
28
29 #
30 # Processor type for CSRC/ASRC files.
31 #
32 CPU = bf592-any
33
34 #
35 # Linker script for the target MCU
36 #
37 LINKSCRIPT =
38
39 #
40 # Output file format (ihex, bin or both) and debugger type
41 #
42 OUTPUT  = ihex
43 DEBUG   = dwarf-2
44
45 #
46 # Include dirs, library dirs and definitions
47 #
48 LIBS    =
49 LIBDIRS =
50 INCDIRS = ../common/
51 DEFS    =
52 ADEFS   =
53
54 #
55 # Warning contorls
56 #
57 WARNINGS = all extra
58
59 #
60 # Object output directory
61 #
62 OBJDIR = obj
63
64 #
65 # Programs to build porject
66 #
67 CC      = bfin-elf-gcc
68 OBJCOPY = bfin-elf-objcopy
69 OBJDUMP = bfin-elf-objdump
70 SIZE    = bfin-elf-size
71 NM      = bfin-elf-nm
72
73 #
74 # Define all object files
75 #
76 COBJ      = $(CSRC:.c=.o)
77 AOBJ      = $(ASRC:.S=.o)
78 COBJ      := $(addprefix $(OBJDIR)/,$(COBJ))
79 AOBJ      := $(addprefix $(OBJDIR)/,$(AOBJ))
80 PROJECT   := $(OBJDIR)/$(PROJECT)
81
82 #
83 # Flags for C files
84 #
85 CFLAGS += -std=$(CSTD)
86 CFLAGS += -g$(DEBUG)
87 CFLAGS += -O$(OPTIMIZE)
88 CFLAGS += -fmessage-length=0
89 CFLAGS += $(addprefix -W,$(WARNINGS))
90 CFLAGS += $(addprefix -I,$(INCDIRS))
91 CFLAGS += $(addprefix -D,$(DEFS))
92 CFLAGS += -Wp,-M,-MP,-MT,$(OBJDIR)/$(*F).o,-MF,$(OBJDIR)/$(*F).d
93
94 #
95 # Assembler flags
96 #
97 ASFLAGS += $(addprefix -D,$(ADEFS)) -Wa,-g$(DEBUG)
98
99 #
100 # Linker flags
101 #
102 LDFLAGS += -Wl,-Map=$(PROJECT).map,--cref,--gc-sections
103 LDFLAGS += -lc -lgcc
104 LDFLAGS += $(patsubst %,-L%,$(LIBDIRS)) $(patsubst %,-l%,$(LIBS))
105 #LDFLAGS += -T$(LINKSCRIPT)
106 #LDFLAGS += -nostartfiles
107 #LDFLAGS += -nodefaultlibs
108 #LDFLAGS += -nostdlib
109 #LDFLAGS += -fno-builtin
110
111 # Combine all necessary flags and optional flags.
112 # Add target processor to flags.
113 ALL_CFLAGS  = -mcpu=$(CPU) -I. $(CFLAGS)
114 ALL_ASFLAGS = -mcpu=$(CPU) -I. -x assembler-with-cpp $(ASFLAGS)
115
116 #
117 # Default target.
118 #
119 all: version build size
120
121 ifeq ($(OUTPUT),ihex)
122 build: elf hex lst sym
123 hex: $(PROJECT).hex
124 else
125 ifeq ($(OUTPUT),binary)
126 build: elf bin lst sym
127 bin: $(PROJECT).bin
128 else
129 ifeq ($(OUTPUT),both)
130 build: elf hex bin lst sym
131 hex: $(PROJECT).hex
132 bin: $(PROJECT).bin
133 else
134 $(error "Invalid format: $(OUTPUT)")
135 endif
136 endif
137 endif
138
139 elf: $(PROJECT).elf
140 lst: $(PROJECT).lst
141 sym: $(PROJECT).sym
142
143 #
144 # Display compiler version information.
145 #
146 version :
147         @$(CC) --version
148
149 #
150 # Create final output file (.hex or .bin) from ELF output file.
151 #
152 %.hex: %.elf
153         @echo
154         $(OBJCOPY) -O ihex $< $@
155
156 %.bin: %.elf
157         @echo
158         $(OBJCOPY) -O binary $< $@
159
160 #
161 # Create extended listing file from ELF output file.
162 #
163 %.lst: %.elf
164         @echo
165         $(OBJDUMP) -h -S -C $< > $@
166
167 #
168 # Create a symbol table from ELF output file.
169 #
170 %.sym: %.elf
171         @echo
172         $(NM) -n $< > $@
173
174 #
175 # Display size of file.
176 #
177 size:
178         @echo
179         $(SIZE) -A $(PROJECT).elf
180
181 #
182 # Link: create ELF output file from object files.
183 #
184 %.elf:  $(AOBJ) $(COBJ)
185         @echo
186         @echo Linking...
187         $(CC) $(ALL_CFLAGS) $(AOBJ) $(COBJ) --output $@ $(LDFLAGS)
188
189 #
190 # Compile: create object files from C source files.
191 #
192 $(COBJ) : $(OBJDIR)/%.o : %.c
193         @echo
194         @echo $< :
195         $(CC) -c $(ALL_CFLAGS) $< -o $@
196
197 #
198 # Assemble: create object files from assembler source files.
199 #
200 $(AOBJ) : $(OBJDIR)/%.o : %.S
201         @echo
202         @echo $< :
203         $(CC) -c $(ALL_ASFLAGS) $< -o $@
204
205 #
206 # Target: clean project.
207 #
208 clean:
209         @echo
210         rm -f -r $(OBJDIR) | exit 0
211
212 #
213 # Load: Load ldr for Blackfin
214 #
215 load:
216         bfin-elf-ldr -T BF592 -c $(PROJECT).ldr $(PROJECT).elf
217         bfin-elf-ldr -l $(PROJECT).ldr /dev/ttyUSB0 -b 57600 -C
218
219 #
220 # Console: Console
221 #
222 console:
223         minicom -b 57600 -D /dev/ttyUSB0
224
225 #
226 # Include the dependency files.
227 #
228 -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)
229