-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
174 lines (139 loc) · 5.86 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
####################################################################
# Makefile #
####################################################################
.SUFFIXES: # ignore builtin rules
.PHONY: all debug release clean
####################################################################
# Definitions #
####################################################################
DEVICE = EFM32GG990F1024
PROJECTNAME = slip
OBJ_DIR = build
EXE_DIR = exe
LST_DIR = lst
####################################################################
# Definitions of toolchain. #
# You might need to do changes to match your system setup #
####################################################################
# Change path to CodeSourcery tools according to your system configuration
WINDOWSCS = CodeSourcery/Sourcery G++ Lite
LINUXCS = /cad/codesourcery/arm-none-eabi/arm-2010q1
GCCVERSION = $(shell $(CC) -dumpversion)
TOOLDIR = /Users/janek/Developer/Cross/arm-cs-tools-2011.09-69-0084249-20121009
RM = rm -rf
CC = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-gcc$(QUOTE)
LD = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ld$(QUOTE)
AR = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ar$(QUOTE)
OBJCOPY = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objcopy$(QUOTE)
DUMP = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objdump$(QUOTE) --disassemble
GDB = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-gdb$(QUOTE)
####################################################################
# Flags #
####################################################################
# -MMD : Don't generate dependencies on system header files.
# -MP : Add phony targets, useful when a h-file is removed from a project.
# -MF : Specify a file to write the dependencies to.
DEPFLAGS = -MMD -MP -MF $(@:.o=.d)
# Add -Wa,-ahld=$(LST_DIR)/$(@F:.o=.lst) to CFLAGS to produce assembly list files
CFLAGS += -std=c99 -D$(DEVICE) -mcpu=cortex-m3 -mthumb -ffunction-sections -fno-short-enums -fdata-sections \
-mfix-cortex-m3-ldrd -fomit-frame-pointer -Wall -fwide-exec-charset=UTF-16LE -fshort-wchar $(DEPFLAGS)
ASMFLAGS += -Ttext 0x0
LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3 -mthumb \
-TCMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/startup/cs3/efm32gg.ld -L"$(TOOLDIR)/arm-none-eabi/lib/thumb2" \
-L"$(TOOLDIR)/lib/gcc/arm-none-eabi/$(GCCVERSION)/thumb2" \
-Wl,--gc-sections -Wl,--no-wchar-size-warning
LIBS += -lc -lcs3 -lcs3unhosted
INCLUDEPATHS += \
-I.. \
-I. \
-ICMSIS/CM3/CoreSupport \
-ICMSIS/CM3/DeviceSupport/EnergyMicro/EFM32 \
-Iefm32lib/inc \
-Iefm32usb/inc \
-Ifatfs/src \
-Idrivers
####################################################################
# Files #
####################################################################
C_SRC += \
CMSIS/CM3/CoreSupport/core_cm3.c \
CMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/system_efm32.c \
efm32lib/src/efm32_assert.c \
efm32lib/src/efm32_system.c \
efm32lib/src/efm32_gpio.c \
efm32lib/src/efm32_cmu.c \
efm32lib/src/efm32_usart.c \
efm32lib/src/efm32_i2c.c \
efm32lib/src/efm32_dma.c \
efm32lib/src/efm32_timer.c \
efm32lib/src/efm32_int.c \
efm32lib/src/efm32_emu.c \
efm32lib/src/efm32_adc.c \
efm32lib/src/efm32_rtc.c \
NRF24.c \
MMA845.c \
syscalls.c \
config.c \
main.c
#i2cdrv.c \
#fatfs/src/diskio.c \
#fatfs/src/ff.c\
#microsd.c \
S_SRC += \
CMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/startup/cs3/startup_efm32gg.s
####################################################################
# Rules #
####################################################################
C_FILES = $(notdir $(C_SRC) )
S_FILES = $(notdir $(S_SRC) )
#make list of source paths, sort also removes duplicates
C_PATHS = $(sort $(dir $(C_SRC) ) )
S_PATHS = $(sort $(dir $(S_SRC) ) )
C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
S_OBJS = $(addprefix $(OBJ_DIR)/, $(S_FILES:.s=.o))
C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
vpath %.c $(C_PATHS)
vpath %.s $(S_PATHS)
# Default build is debug build
all: debug
debug: CFLAGS += -DDEBUG -O0 -g3
debug: $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXE_DIR)/$(PROJECTNAME).bin
release: CFLAGS += -DNDEBUG -O3
release: $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXE_DIR)/$(PROJECTNAME).bin
# Create directories
$(OBJ_DIR):
mkdir $(OBJ_DIR)
@echo "Created build directory."
$(EXE_DIR):
mkdir $(EXE_DIR)
@echo "Created executable directory."
$(LST_DIR):
mkdir $(LST_DIR)
@echo "Created list directory."
# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c
@echo "Building file: $<"
$(CC) $(CFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Assemble .s files
$(OBJ_DIR)/%.o: %.s
@echo "Assembling $<"
$(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Link
$(EXE_DIR)/$(PROJECTNAME).elf: $(C_OBJS) $(S_OBJS)
@echo "Linking target: $@"
$(CC) $(LDFLAGS) $(C_OBJS) $(S_OBJS) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME).elf
# Create binary file
$(EXE_DIR)/$(PROJECTNAME).bin: $(EXE_DIR)/$(PROJECTNAME).elf
@echo "Creating binary file"
$(OBJCOPY) -O binary $(EXE_DIR)/$(PROJECTNAME).elf $(EXE_DIR)/$(PROJECTNAME).bin
# Uncomment next line to produce assembly listing of entire program
# $(DUMP) $(EXE_DIR)/$(PROJECTNAME).out>$(LST_DIR)/$(PROJECTNAME)out.lst
program: $(EXE_DIR)/$(PROJECTNAME).elf
@echo "Programming"
$(GDB) --se $(EXE_DIR)/$(PROJECTNAME).elf
clean:
$(RM) $(OBJ_DIR) $(LST_DIR) $(EXE_DIR)
# include auto-generated dependency files (explicit rules)
ifneq (clean,$(findstring clean, $(MAKECMDGOALS)))
-include $(C_DEPS)
endif