~ruther/avr-device

6c665e4dfe9ebed0aa021c1b2f3db8c5119b4929 — Rahix 5 years ago e0d031a
make: Fix dependencies of patch files

Signed-off-by: Rahix <rahix@rahix.de>
3 files changed, 73 insertions(+), 18 deletions(-)

M .gitignore
M Makefile
A patch/makedeps.py
M .gitignore => .gitignore +2 -0
@@ 3,4 3,6 @@
Cargo.lock

svd/
.deps/
src/devices/*/*
__pycache__/

M Makefile => Makefile +40 -18
@@ 1,37 1,59 @@
all: chips
all: deps chips

CHIPS := atmega8 atmega328p atmega32u4 attiny85

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

.PHONY: chips deps
chips: $(foreach chip, $(CHIPS), src/devices/$(chip)/mod.rs)
deps: $(DEPS)

svd/%.bare.svd: vendor/%.atdf
	mkdir -p svd
	atdf2svd $< $@
	@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
	if [ -f patch/$*.yaml ] ; then \
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 "No patches found for $*"; \
		echo -e "\t  - No patches found for $*"; \
		cp $< $@; \
	fi

src/devices/%/mod.full.rs: svd/%.patched.svd
	mkdir -p $(@D)
	cd $(@D); svd2rust --target none -i $(realpath $<)
	mv $(@D)/lib.rs $@
	@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
	form -i $< -o $(@D)
	rm $<
	mv $(@D)/lib.rs $@
	rustfmt $@
	@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 "1,7d" $@
	@sed -i "1,7d" $@
	@# Make DEVICE_PERIPHERALS visible crate-wide
	sed -i 's/\(static mut DEVICE_PERIPHERALS\)/pub(crate) \0/' $@
	@sed -i 's/\(static mut DEVICE_PERIPHERALS\)/pub(crate) \0/' $@

clean:
	rm -rf svd
	rm -rf src/devices/at*
	@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)

A patch/makedeps.py => patch/makedeps.py +31 -0
@@ 0,0 1,31 @@
"""
makedeps.py
Copyright 2017 Adam Greig
Licensed under the MIT and Apache 2.0 licenses.

Generate make dependency file for each device.
"""

import yaml
import os.path
import argparse
import svdpatch


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("devices", nargs="*")
    args = parser.parse_args()
    for dpath in args.devices:
        with open(dpath) as f:
            device = yaml.safe_load(f)
        device["_path"] = dpath
        deps = svdpatch.yaml_includes(device)
        depname = ".deps/{}.d".format(
            os.path.splitext(os.path.basename(dpath))[0])
        svdname = "svd/{}.patched.svd".format(
            os.path.splitext(os.path.basename(dpath))[0])
        print("{} {} {}: {}".format(dpath, svdname, depname, " ".join(deps)))

if __name__ == "__main__":
    main()

Do not follow this link