Add automatic dependencies

This commit is contained in:
Nero 2018-01-29 00:48:12 +00:00 committed by Nero
parent 294553ee84
commit 24ee77720d
3 changed files with 16 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
*.hex
*.bin
*.asm
deps.mk

View File

@ -16,8 +16,10 @@ default: $(PROG).hex
clean:
rm -rf *.o drivers/*.o *.elf *.lst *.hex *.bin *.asm
# dependencies
blink.elf: drivers/led.o
# automatic dependencies
include deps.mk
deps.mk: *.c drivers/*.c
for i in *.c; do echo $${i%.c}.elf: $$(./finddeps.sh "$$i"); echo; done > deps.mk
# generic rules
%.o: %.c

11
finddeps.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
search() {
echo "$1"
prefix="$(printf "%s\n" "$1"|sed 's|[^/]*$||')"
deps="$(grep -E '^#include "[^"]*"$' "$1"|cut '-d"' -f2|
\sed "s|^|$prefix|;s|\.h\$|.c|"|grep -v "$1")"
for i in $deps; do search $i; done
}
search "$1"|grep -v "$1"|sed 's|\.c$|.o|'