-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
138 lines (97 loc) · 3.91 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
MODULE := ABZ78
PROGRAM := Firmware
CCPATH :=
CCARM :=$(CCPATH)arm-none-eabi-gcc
CXXARM :=$(CCPATH)arm-none-eabi-g++
ASARM := $(CCPATH)arm-none-eabi-as
ARARM := $(CCPATH)arm-none-eabi-ar
CONV := $(CCPATH)arm-none-eabi-objcopy
SIZE := $(CCPATH)arm-none-eabi-size
FLASH := $(CCPATH)/../../STM32CubeProgrammer/bin/STM32_Programmer.sh
RM := rm
PORT := /dev/ttyUSB0
TYPE :=
SRCDIR := AppSrc
LORAEZ := LoRaEz
MCU := $(LORAEZ)/mcu
SX1276 := $(LORAEZ)/sx1276
CMSIS := $(MCU)/cmsis
ARMGCC := $(CMSIS)/arm-gcc
HALDRIVER := $(MCU)/STM32L0xx_HAL_Driver/Inc
LEGACY := $(HALDRIVER)/Legacy
LORALINK := LoRaLink
MQTTSN := MQTTSN
SYSTEM := System
LOG :=
INCLUDE :=
INCLUDES += $(INCLUDE) \
-I$(SRCDIR) \
-I$(LORAEZ) \
-I$(MCU) \
-I$(CMSIS) \
-I$(ARMGCC) \
-I$(HALDRIVER) \
-I$(LEGACY) \
-I$(SX1276) \
-I$(LORALINK) \
-I$(MQTTSN) \
-I$(SYSTEM)
APPCSRCS := ${shell find $(SRCDIR) -name *.c }
LORAEZSRCS := ${shell find $(LORAEZ) -name *.c }
LORALINKSRCS := ${shell find $(LORALINK) -name *.c }
MQTTSNSRCS := ${shell find $(MQTTSN) -name *.c }
SYSTEMSRCS := ${shell find $(SYSTEM) -name *.c }
ASRCS := ${shell find $(ARMGCC) -name startup_*.s }
LD := ${shell find $(ARMGCC) -name stm32*.ld }
STM82 := STM32L082xx
DEFS := -DUSE_HAL_DRIVER
LIB :=
LIBS += $(LIB) -s -static
MCUFLAGS := -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
LDFLAGS := -specs=nosys.specs -specs=nano.specs -u _printf_float -Wl,--gc-sections -fno-rtti -s -fno-exceptions
CCFLAGS := -O3 -Wall -fmessage-length=0 -fno-strict-aliasing -ffunction-sections -fdata-sections -fno-exceptions
LDDIR :=
LDADD :=
LDADD += -lm
OUTDIR := Build
PROG := $(OUTDIR)/$(PROGRAM)
APPCOBJS := $(APPCSRCS:%.c=$(OUTDIR)/%.o)
LORAEZOBJS := $(LORAEZSRCS:%.c=$(OUTDIR)/%.o)
LORALINKOBJSS := $(LORALINKSRCS:%.c=$(OUTDIR)/%.o)
MQTTSNOBJS := $(MQTTSNSRCS:%.c=$(OUTDIR)/%.o)
SYSTEMOBJS := $(SYSTEMSRCS:%.c=$(OUTDIR)/%.o)
ASOBJS := $(ASRCS:%.s=$(OUTDIR)/%.o)
DEPS := $(APPCSRCS:%.c=$(OUTDIR)/%.d)
DEPS += $(LORAEZSRCS:%.c=$(OUTDIR)/%.d)
DEPS += $(LORALINKSRCS:%.c=$(OUTDIR)/%.d)
DEPS += $(MQTTSNSRCS:%.c=$(OUTDIR)/%.d)
DEPS += $(SYSTEMSRCS:%.c=$(OUTDIR)/%.d)
.PHONY: flash clean
all: $(PROG)
$(PROG):$(APPCOBJS) $(LORAEZOBJS) $(LORALINKOBJSS) $(MQTTSNOBJS) $(SYSTEMOBJS) $(ASOBJS)
$(CCARM) $(MCUFLAGS) $(LDFLAGS) $(LDDIR) $(LIBS) -T$(LD) -o $(PROG).elf $(APPCOBJS) $(LORAEZOBJS) $(LORALINKOBJSS) $(MQTTSNOBJS) $(SYSTEMOBJS) $(ASOBJS) $(LDADD)
$(CONV) -O binary $(PROG).elf $(PROG).bin
$(SIZE) -B $(PROG).elf
$(OUTDIR)/$(SRCDIR)/%.o : $(SRCDIR)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CCARM) -D$(STM82) -D$(MODULE) -D$(TYPE) -D$(LOG) $(MCUFLAGS) $(DEFS) $(INCLUDES) $(CCFLAGS) -std=c11 -o $@ -c $< -MMD -MP -MF $(@:%.o=%.d)
$(OUTDIR)/$(LORAEZ)/%.o : $(LORAEZ)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CCARM) -D$(STM82) -D$(MODULE) -D$(LOG) $(MCUFLAGS) $(DEFS) $(INCLUDES) $(CCFLAGS) -std=c11 -o $@ -c $< -MMD -MP -MF $(@:%.o=%.d)
$(OUTDIR)/$(LORALINK)/%.o : $(LORALINK)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CCARM) -D$(STM82) -D$(MODULE) -D$(LOG) $(MCUFLAGS) $(DEFS) $(INCLUDES) $(CCFLAGS) -std=c11 -o $@ -c $< -MMD -MP -MF $(@:%.o=%.d)
$(OUTDIR)/$(MQTTSN)/%.o : $(MQTTSN)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CCARM) -D$(STM82) -D$(MODULE) -D$(LOG) $(MCUFLAGS) $(DEFS) $(INCLUDES) $(CCFLAGS) -std=c11 -o $@ -c $< -MMD -MP -MF $(@:%.o=%.d)
$(OUTDIR)/$(SYSTEM)/%.o : $(SYSTEM)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CCARM) -D$(STM82) -D$(MODULE) -D$(LOG) $(MCUFLAGS) $(DEFS) $(INCLUDES) $(CCFLAGS) -std=c11 -o $@ -c $< -MMD -MP -MF $(@:%.o=%.d)
$(OUTDIR)/$(ARMGCC)/%.o : $(ARMGCC)/%.s
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(ASARM) $(MCUFLAGS) -o $@ -c $<
clean:
$(RM) -rf $(OUTDIR)
flash:
$(FLASH) port=$(PORT) br=500000 -w $(PROG).bin 0x08000000