Merge branch 't/ssh_keys'
[paraslash.git] / depend.sh
index db32f6c6ab834c88dceba94cdc2dd37fd6cfcb87..60d4eba6b8fc22ca5d0431444ec65d7cb2c74ab2 100755 (executable)
--- a/depend.sh
+++ b/depend.sh
@@ -1,4 +1,22 @@
 #!/bin/sh
-dir="$1"
+
+# Call gcc to output a rule suitable for make describing the dependencies of
+# the given input file and parse the output to add a *.d target with the same
+# dependencies.
+
+# The first two arguments to that script are special: $1 is the object
+# directory. This string is prefixed to both the .o and the .d target. $2 is
+# the directory that contains the *.cmdline.h files generated by gengetopt.
+
+# As gcc outputs the dependencies on the *.cmdline.h files either as either
+# foo.cmdline.h or as $cmdline_dir/foo,cmdline.h, depending on whether the
+# latter file exists, we prefix the former with $2/
+
+object_dir="$1"
+cmdline_dir="$2"
 shift
-gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@$dir/\1.d $dir/\1.o:@"
+shift
+
+LC_ALL=C gcc -MM -MG "$@" \
+       | sed -e "s@^\(.*\)\.o:@$object_dir/\1.d $object_dir/\1.o:@" \
+       -e "s@[         ^]\([a-zA-Z0-9_]\{1,\}\.cmdline.h\)@ $cmdline_dir/\1@g"