-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
190 lines (159 loc) · 5.11 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# project name
PRJNAME = mod-dwarf-controller
# toolchain configuration
TOOLCHAIN_PREFIX = arm-none-eabi-
ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
# cpu configuration
THUMB = -mthumb
MCU = cortex-m3
endif
# build configuration
mod=$(MAKECMDGOALS)
ifeq ($(mod),$(filter $(mod),moddwarf))
CPU = LPC1778
CPU_SERIE = LPC177x_8x
endif
# target configuration
TARGET_ADDR = root@192.168.51.1
# project directories
DEVICE_INC = ./nxp-lpc
CMSIS_INC = ./nxp-lpc/CMSISv2p00_$(CPU_SERIE)/inc
CMSIS_SRC = ./nxp-lpc/CMSISv2p00_$(CPU_SERIE)/src
CDL_INC = ./nxp-lpc/$(CPU_SERIE)Lib/inc
CDL_SRC = ./nxp-lpc/$(CPU_SERIE)Lib/src
APP_INC = ./app/inc
APP_SRC = ./app/src
RTOS_SRC = ./freertos/src
RTOS_INC = ./freertos/inc
DRIVERS_INC = ./drivers/inc
DRIVERS_SRC = ./drivers/src
PROTOCOL_INC = ./mod-controller-proto
OUT_DIR = ./out
CDL_LIBS = lpc177x_8x_clkpwr.c
CDL_LIBS += lpc177x_8x_adc.c lpc177x_8x_gpio.c lpc177x_8x_pinsel.c
CDL_LIBS += lpc177x_8x_systick.c lpc177x_8x_timer.c
CDL_LIBS += lpc177x_8x_uart.c lpc177x_8x_ssp.c
CDL_LIBS += lpc177x_8x_eeprom.c
SRC = $(wildcard $(CMSIS_SRC)/*.c) $(addprefix $(CDL_SRC)/,$(CDL_LIBS)) $(wildcard $(RTOS_SRC)/*.c) \
$(wildcard $(DRIVERS_SRC)/*.c) $(wildcard $(APP_SRC)/*.c)
# Object files
OBJ = $(SRC:.c=.o)
ALL_OBJ = `find -name "*.o"`
# include directories
INC = $(DEVICE_INC) $(CMSIS_INC) $(CDL_INC) $(RTOS_INC) $(DRIVERS_INC) $(APP_INC) $(USB_INC) $(PROTOCOL_INC)
# C flags
ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
CFLAGS += -mcpu=$(MCU)
else
CFLAGS += -DCCC_ANALYZER -Wshadow -Wno-attributes -m32
endif
CFLAGS += -std=gnu99
CFLAGS += -fcommon
CFLAGS += -Wall -Wextra -Wpointer-arith -Wredundant-decls -Wsizeof-pointer-memaccess
# CFLAGS += -Werror
CFLAGS += -Wdisabled-optimization
CFLAGS += -Wdouble-promotion -Wfloat-equal
CFLAGS += -Wformat=2 -Woverlength-strings
CFLAGS += -Wredundant-decls
CFLAGS += -Wshadow -Wundef -Wuninitialized -Wunused
CFLAGS += -Wstrict-aliasing -fstrict-aliasing
CFLAGS += -Wstrict-overflow -fstrict-overflow
CFLAGS += -Wnull-dereference
CFLAGS += -Wformat-truncation=2 -Wformat-overflow=2
CFLAGS += -Wstringop-overflow=4 -Wstringop-truncation
CFLAGS += -Wclobbered -Wlogical-op
CFLAGS += -Wduplicated-cond
CFLAGS += -Winit-self -Wwrite-strings
CFLAGS += -Wjump-misses-init -fcommon
CFLAGS += -Wa,-adhlns=$(addprefix $(OUT_DIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
CFLAGS += -MMD -MP -MF $(OUT_DIR)/dep/$(@F).d
CFLAGS += -I. $(patsubst %,-I%,$(INC))
CFLAGS += -D$(CPU_SERIE)
CFLAGS += -O2
# Linker flags
LDFLAGS = -Wl,-Map=$(OUT_DIR)/$(PRJNAME).map,--cref
ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
LDFLAGS += -specs=rdimon.specs
LDFLAGS += -Wl,--start-group -lgcc -lc -lm -lrdimon -Wl,--end-group
LDFLAGS += -T./link/LPC.ld
else
LDFLAGS += -lm
endif
# Define programs and commands.
CC = $(TOOLCHAIN_PREFIX)gcc
OBJCOPY = $(TOOLCHAIN_PREFIX)objcopy
OBJDUMP = $(TOOLCHAIN_PREFIX)objdump
NM = $(TOOLCHAIN_PREFIX)nm
SIZE = $(TOOLCHAIN_PREFIX)size
# define the output files
ELF = $(OUT_DIR)/$(PRJNAME).elf
BIN = $(OUT_DIR)/$(PRJNAME).bin
HEX = $(OUT_DIR)/$(PRJNAME).hex
SYM = $(OUT_DIR)/$(PRJNAME).sym
LSS = $(OUT_DIR)/$(PRJNAME).lss
# Colors definitions
GREEN = '\e[0;32m'
NOCOLOR = '\e[0m'
ifeq ($(mod),)
all:
@echo -e "Usage: to build, use one of the following:"
@echo -e "\tmake moddwarf"
else
all: prebuild build
endif
moddwarf: all
ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
build: elf lss sym hex bin
else
build: elf
endif
# output files
elf: $(OUT_DIR)/$(PRJNAME).elf
lss: $(OUT_DIR)/$(PRJNAME).lss
sym: $(OUT_DIR)/$(PRJNAME).sym
hex: $(OUT_DIR)/$(PRJNAME).hex
bin: $(OUT_DIR)/$(PRJNAME).bin
prebuild:
ifneq ($(shell cat .last_built),$(mod))
@make clean
endif
@mkdir -p $(OUT_DIR)
@mkdir -p $(OUT_DIR)/dep
@ln -fs ./$(CPU).ld ./link/LPCmem.ld
@ln -fs ./config-$(mod).h ./app/inc/config.h
@echo $(mod) > .last_built
# Create final output file in ihex format from ELF output file (.hex).
$(HEX): $(ELF)
@echo -e ${GREEN}Creating HEX${NOCOLOR}
@$(OBJCOPY) -O ihex $< $@
# Create final output file in raw binary format from ELF output file (.bin)
$(BIN): $(ELF)
@echo -e ${GREEN}Creating BIN${NOCOLOR}
@$(OBJCOPY) -O binary $< $@
# Create extended listing file/disassambly from ELF output file.
# using objdump (testing: option -C)
$(LSS): $(ELF)
@echo -e ${GREEN}Creating listing file/disassambly${NOCOLOR}
@$(OBJDUMP) -h -S -C -r $< > $@
# Create a symbols table from ELF output file.
$(SYM): $(ELF)
@echo -e ${GREEN}Creating symbols table${NOCOLOR}
@$(NM) -n $< > $@
# Link: create ELF output file from object files.
$(ELF): $(OBJ)
@echo -e ${GREEN}Linking objects: generating ELF${NOCOLOR}
@$(CC) $(THUMB) $(CFLAGS) $(OBJ) --output $@ -nostartfiles $(LDFLAGS)
# ignore warnings for 3rd-party CPU code
freertos/src/%.o: freertos/src/%.c
$(CC) $(CFLAGS) -o $@ -c $< -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-nested-externs
%.o: %.c
@echo -e ${GREEN}Building $<${NOCOLOR}
@$(CC) $(THUMB) $(CFLAGS) -c $< -o $@
clean:
@echo -e ${GREEN}Object files cleaned out $<${NOCOLOR}
@rm -rf $(ALL_OBJ) $(OUT_DIR)
size:
@$(SIZE) out/mod-controller.elf
install:
scp -O $(OUT_DIR)/$(PRJNAME).bin $(TARGET_ADDR):/tmp && \
ssh $(TARGET_ADDR) 'hmi-update /tmp/$(PRJNAME).bin && systemctl restart mod-ui'