forked from ReservedField/evic-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
155 lines (126 loc) · 4.03 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
TARGET := libevicsdk
TARGET_CRT0 := $(TARGET)_crt0
# We make the following assumptions on Windows:
# arm-none-eabi gcc and binutils are compiled for Windows,
# so they need path translation.
# Clang is compiled for Cygwin (no path translation).
# NUVOSDK must be lazily evaluated, so that we can later
# change EVICSDK when building include paths.
# We want to keep OBJS with Cygwin paths for clean target.
NUVOSDK = $(EVICSDK)/nuvoton-sdk/Library
OBJS := $(NUVOSDK)/Device/Nuvoton/M451Series/Source/system_M451Series.o \
$(NUVOSDK)/StdDriver/src/clk.o \
$(NUVOSDK)/StdDriver/src/fmc.o \
$(NUVOSDK)/StdDriver/src/gpio.o \
$(NUVOSDK)/StdDriver/src/spi.o \
$(NUVOSDK)/StdDriver/src/sys.o \
$(NUVOSDK)/StdDriver/src/timer.o \
$(NUVOSDK)/StdDriver/src/usbd.o \
$(NUVOSDK)/StdDriver/src/eadc.o \
$(NUVOSDK)/StdDriver/src/pwm.o \
src/startup/initfini.o \
src/startup/sbrk.o \
src/startup/init.o \
src/dataflash/Dataflash.o \
src/display/Display_SSD.o \
src/display/Display_SSD1306.o \
src/display/Display_SSD1327.o \
src/display/Display.o \
src/font/Font_DejaVuSansMono_8pt.o \
src/timer/TimerUtils.o \
src/button/Button.o \
src/usb/USB_VirtualCOM.o \
src/adc/ADC.o \
src/battery/Battery.o \
src/atomizer/Atomizer.o
TAGNAME := src/startup/evicsdk_tag
OBJS_CRT0 := src/startup/startup.o \
$(TAGNAME).o
AEABI_OBJS := src/aeabi/aeabi_memset-thumb2.o \
src/aeabi/aeabi_memclr.o
OUTDIR := lib
DOCDIR := doc
CPU := cortex-m4
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
CC_IS_CLANG := 1
endif
ifeq ($(ARMGCC),)
ARMGCC := $(shell cd $(shell arm-none-eabi-gcc --print-search-dir | grep 'libraries' | \
tr '=$(if $(filter Windows_NT,$(OS)),;,:)' '\n' | \
grep -E '/arm-none-eabi/lib/?$$' | head -1)/../.. && pwd)
endif
ifeq ($(OS),Windows_NT)
# Always fix binutils path
ifneq ($(ARMGCC),)
ARMGCC := $(shell cygpath -w $(ARMGCC))
endif
ifndef CC_IS_CLANG
NEED_FIXPATH := 1
endif
endif
ifneq ($(ARMGCC),)
ifdef CC_IS_CLANG
CFLAGS += -target armv7em-none-eabi -fshort-enums
AEABI_COUNT := $(shell arm-none-eabi-nm -g $(ARMGCC)/arm-none-eabi/lib/armv7e-m/libc.a | grep -Ec 'T __aeabi_mem(set|clr)[48]?$$')
ifeq ($(AEABI_COUNT), 0)
# __aeabi_memset* and __aeabi_memclr* are not exported by libc
# We provide our own implementations
OBJS += $(AEABI_OBJS)
else ifneq ($(AEABI_COUNT), 6)
# Only part of __aeabi_memset* and __aeabi_memclr* are exported by libc
# This should never happen, bail out in env_check
AEABI_ERROR := 1
endif
else
CC := arm-none-eabi-gcc
endif
ifdef NEED_FIXPATH
OBJS_FIXPATH := $(shell cygpath -w $(OBJS))
OBJS_CRT0_FIXPATH := $(shell cygpath -w $(OBJS_CRT0))
EVICSDK := $(shell cygpath -w $(EVICSDK))
else
OBJS_FIXPATH := $(OBJS)
OBJS_CRT0_FIXPATH := $(OBJS_CRT0)
endif
endif
SDKTAG := $(shell git describe --abbrev --dirty --always --tags 2> /dev/null)
ifeq ($(SDKTAG),)
SDKTAG := unknown
endif
AS := arm-none-eabi-as
LD := arm-none-eabi-ld
AR := arm-none-eabi-ar
OBJCOPY := arm-none-eabi-objcopy
INCDIRS := -I$(NUVOSDK)/CMSIS/Include \
-I$(NUVOSDK)/Device/Nuvoton/M451Series/Include \
-I$(NUVOSDK)/StdDriver/inc \
-Iinclude
CFLAGS += -Wall -mcpu=$(CPU) -mthumb -Os -fdata-sections -ffunction-sections
CFLAGS += $(INCDIRS)
ASFLAGS := -mcpu=$(CPU)
all: env_check gen_tag $(TARGET_CRT0).o $(TARGET).a
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
$(TARGET).a: $(OBJS_FIXPATH)
mkdir -p $(OUTDIR)
$(AR) -rv $(OUTDIR)/$(TARGET).a $(OBJS_FIXPATH)
$(TARGET_CRT0).o: $(OBJS_CRT0_FIXPATH)
mkdir -p $(OUTDIR)
$(LD) -r $(OBJS_CRT0_FIXPATH) -o $(OUTDIR)/$(TARGET_CRT0).o
docs:
doxygen
clean:
rm -rf $(OBJS) $(OBJS_CRT0) $(AEABI_OBJS) $(OUTDIR)/$(TARGET).a $(OUTDIR)/$(TARGET_CRT0).o $(OUTDIR) $(DOCDIR)
env_check:
ifeq ($(ARMGCC),)
$(error You must set the ARMGCC environment variable)
endif
ifneq ($(AEABI_ERROR),)
$(error Your libc is exporting only part of __aeabi symbols)
endif
gen_tag:
@rm -f $(TAGNAME).s $(TAGNAME).o
@printf '.section .evicsdk_tag\n.asciz "evic-sdk-$(SDKTAG)"\n' > $(TAGNAME).s
.PHONY: all clean docs env_check gen_tag