From 6c665e4dfe9ebed0aa021c1b2f3db8c5119b4929 Mon Sep 17 00:00:00 2001 From: Rahix Date: Sat, 11 May 2019 22:22:57 +0200 Subject: [PATCH] make: Fix dependencies of patch files Signed-off-by: Rahix --- .gitignore | 2 ++ Makefile | 58 ++++++++++++++++++++++++++++++++--------------- patch/makedeps.py | 31 +++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 patch/makedeps.py diff --git a/.gitignore b/.gitignore index b402ca3..22be92f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ Cargo.lock svd/ +.deps/ src/devices/*/* +__pycache__/ diff --git a/Makefile b/Makefile index 3803d56..df1f418 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/patch/makedeps.py b/patch/makedeps.py new file mode 100644 index 0000000..5e88484 --- /dev/null +++ b/patch/makedeps.py @@ -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() -- 2.48.1