-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbuild.mk
39 lines (31 loc) · 1.28 KB
/
build.mk
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
PROG ?= firmware
ARCH ?= esp32c3
MDK ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/..)
ESPUTIL ?= $(MDK)/esputil/esputil
CFLAGS ?= -W -Wall -Wextra -Werror -Wundef -Wshadow -pedantic \
-Wdouble-promotion -fno-common -Wconversion \
-march=rv32imc -mabi=ilp32 \
-Os -ffunction-sections -fdata-sections \
-I. -I$(MDK)/$(ARCH) $(EXTRA_CFLAGS)
LINKFLAGS ?= -T$(MDK)/$(ARCH)/link.ld -nostdlib -nostartfiles -Wl,--gc-sections $(EXTRA_LINKFLAGS)
CWD ?= $(realpath $(CURDIR))
FLASH_ADDR ?= 0 # 2nd stage bootloader flash offset
DOCKER ?= docker run -it --rm -v $(CWD):$(CWD) -v $(MDK):$(MDK) -w $(CWD) mdashnet/riscv
TOOLCHAIN ?= $(DOCKER) riscv-none-elf
SRCS ?= $(MDK)/$(ARCH)/boot.c $(SOURCES)
build: $(PROG).bin
$(PROG).elf: $(SRCS)
$(TOOLCHAIN)-gcc $(CFLAGS) $(SRCS) $(LINKFLAGS) -o $@
# $(TOOLCHAIN)-size $@
$(PROG).bin: $(PROG).elf $(ESPUTIL)
$(ESPUTIL) mkbin $(PROG).elf $@
flash: $(PROG).bin $(ESPUTIL)
$(ESPUTIL) flash $(FLASH_ADDR) $(PROG).bin
monitor: $(ESPUTIL)
$(ESPUTIL) monitor
$(MDK)/esputil/esputil.c:
git submodule update --init --recursive
$(ESPUTIL): $(MDK)/esputil/esputil.c
make -C $(MDK)/esputil esputil
clean:
@rm -rf *.{bin,elf,map,lst,tgz,zip,hex} $(PROG)*