diff --git a/.gitignore b/.gitignore index a715db0..a227983 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.hex *.bin *.asm +deps.mk diff --git a/Makefile b/Makefile index 67e23ac..fabc06f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/finddeps.sh b/finddeps.sh new file mode 100755 index 0000000..7b3f986 --- /dev/null +++ b/finddeps.sh @@ -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|'