-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·169 lines (141 loc) · 4.37 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
# project name
PRJNAME = mod-duox-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),modduox))
CPU = LPC1777
CPU_SERIE = LPC177x_8x
endif
# target configuration
TARGET_ADDR = [email protected]
# 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
endif
CFLAGS += -Wall -Wextra -Wpointer-arith -Wredundant-decls -Wsizeof-pointer-memaccess
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 += -O3
CFLAGS += -fcommon
# 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
else
LDFLAGS += -lm
endif
LDFLAGS += -T./link/LPC.ld
# 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 modduox"
else
all: prebuild build
endif
#modduo: all
modduox: 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)
%.o: %.c prebuild
@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 $(OUT_DIR)/$(PRJNAME).bin $(TARGET_ADDR):/tmp && \
ssh $(TARGET_ADDR) 'hmi-update /tmp/$(PRJNAME).bin && systemctl restart mod-ui'