core: Fix OPT_DEFS for mbed build
[tmk_keyboard.git] / tmk_core / tool / mbed / gcc.mk
1 # based on Makefile exported form mbed.org
2 # see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
3
4 GCC_BIN =
5 AS = $(GCC_BIN)arm-none-eabi-as
6 CC = $(GCC_BIN)arm-none-eabi-gcc
7 CPP = $(GCC_BIN)arm-none-eabi-g++
8 LD = $(GCC_BIN)arm-none-eabi-gcc
9 OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
10 OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump
11 SIZE = $(GCC_BIN)arm-none-eabi-size
12 CHKSUM = $(TMK_DIR)/tool/mbed/lpc-vector-checksum
13
14 CC_FLAGS += \
15 $(CPU) \
16 -c \
17 -g \
18 -fno-common \
19 -fmessage-length=0 \
20 -Wall \
21 -fno-exceptions \
22 -ffunction-sections \
23 -fdata-sections \
24 -fomit-frame-pointer
25 CC_FLAGS += -MMD -MP
26 CC_FLAGS += $(OPT_DEFS)
27
28 LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs
29 #LD_FLAGS += -u _printf_float -u _scanf_float
30 LD_FLAGS += -Wl,-Map=$(OBJDIR)/$(PROJECT).map,--cref
31 LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
32
33 ifeq ($(DEBUG), 1)
34 CC_FLAGS += -DDEBUG -O0
35 else
36 CC_FLAGS += -DNDEBUG -Os
37 endif
38
39 all: $(OBJDIR)/$(PROJECT).bin $(OBJDIR)/$(PROJECT).hex
40
41 clean:
42 rm -f $(OBJDIR)/$(PROJECT).bin $(OBJDIR)/$(PROJECT).elf $(OBJDIR)/$(PROJECT).hex $(OBJDIR)/$(PROJECT).map $(OBJDIR)/$(PROJECT).lst $(OBJECTS) $(DEPS)
43 rm -fr $(OBJDIR)
44
45 $(OBJDIR)/%.o: %.s
46 mkdir -p $(@D)
47 $(AS) $(CPU) -o $@ $<
48
49 $(OBJDIR)/%.o: %.c
50 mkdir -p $(@D)
51 $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $<
52
53 $(OBJDIR)/%.o: %.cpp
54 mkdir -p $(@D)
55 $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $<
56
57
58 $(OBJDIR)/$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
59 $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS)
60 $(SIZE) $@
61
62 $(OBJDIR)/$(PROJECT).bin: $(OBJDIR)/$(PROJECT).elf
63 @$(OBJCOPY) -O binary $< $@
64 ifneq (,$(findstring TARGET_NXP,$(CC_SYMBOLS)))
65 @echo
66 @echo "For NXP writing vector checksum value into $@ ..."
67 @$(CHKSUM) $@
68 @echo
69 endif
70
71 $(OBJDIR)/$(PROJECT).hex: $(OBJDIR)/$(PROJECT).elf
72 @$(OBJCOPY) -O ihex $< $@
73
74 $(OBJDIR)/$(PROJECT).lst: $(OBJDIR)/$(PROJECT).elf
75 @$(OBJDUMP) -Sdh $< > $@
76
77 lst: $(OBJDIR)/$(PROJECT).lst
78
79 size:
80 $(SIZE) $(OBJDIR)/$(PROJECT).elf
81
82 prog: $(OBJDIR)/$(PROJECT).bin
83 @echo "Program..."
84 ifneq ($(shell mount | grep 'CRP DISABLD'),)
85 umount /dev/nxpisp >/dev/null 2>&1
86 endif
87 dd if=$< of=/dev/nxpisp seek=4
88
89 DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
90 -include $(DEPS)
Imprint / Impressum