~ruther/avr-device

ref: b11ae9830db37524d0e44f335cbb920c6f39c8b3 avr-device/Makefile -rw-r--r-- 1.6 KiB
b11ae983 — Rahix Add build-script to auto-generate chip-defs 5 years ago
                                                                                
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
all: deps chips

CHIPS := atmega1280 atmega8 atmega328p atmega32u4 attiny85

PATCHES := $(foreach chip, $(CHIPS), $(wildcard patch/$(chip).yaml))
DEPS := $(foreach patch, $(PATCHES), $(patsubst patch/%.yaml, .deps/%.d, $(patch)))

.PHONY: chips deps $(CHIPS)
chips: $(CHIPS)
deps: $(DEPS)

$(foreach chip, $(CHIPS), $(eval $(chip): src/devices/$(chip)/mod.rs))

.SECONDARY:
svd/%.bare.svd: vendor/%.atdf
	@mkdir -p svd
	@echo -e "\tATDF2SVD\t$*"
	@atdf2svd $< $@ 2>/dev/null

$(foreach patch, $(PATCHES), $(eval $(patsubst patch/%.yaml, svd/%.patched.svd, $(patch)): $(patch)))

svd/%.patched.svd: svd/%.bare.svd patch/svdpatch.py
	@if [ -f patch/$*.yaml ] ; then \
		echo -e "\tPATCH\t\t$*"; \
		python3 patch/svdpatch.py patch/$*.yaml $< $@; \
	else \
		echo -e "\t  - No patches found for $*"; \
		cp $< $@; \
	fi

src/devices/%/mod.full.rs: svd/%.patched.svd
	@mkdir -p $(@D)
	@echo -e "\tSVD2RUST\t$*"
	@cd $(@D); svd2rust --target none -i $(realpath $<)
	@mv $(@D)/lib.rs $@

src/devices/%/mod.rs: src/devices/%/mod.full.rs
	@echo -e "\tFORM\t\t$*"
	@RUST_LOG=WARN form -i $< -o $(@D) >/dev/null
	@rm $<
	@mv $(@D)/lib.rs $@
	@rustfmt $@
	@# Remove the `extern crate` lines
	@sed -i'' -e "1,7d" $@
	@# Make DEVICE_PERIPHERALS visible crate-wide
	@sed -i'' -e 's/\(static mut DEVICE_PERIPHERALS\)/pub(crate) \1/' $@

clean:
	@echo -e "\tCLEAN\t\t./svd/"
	@rm -rf svd/
	@echo -e "\tCLEAN\t\t./src/devices"
	@rm -rf src/devices/at*
	@echo -e "\tCLEAN\t\t./.deps/"
	@rm -rf .deps/

# Patch dependencies
.deps/%.d: patch/%.yaml
	@mkdir -p .deps
	@echo -e "\tMAKEDEPS\t$*"
	@python3 patch/makedeps.py $< >$@

-include $(DEPS)
Do not follow this link