@[ -z "$(Q)" ] || echo 'CC $<'
$(Q) $(CC) -c -o $@ $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
-# We depend on the *.cmdline.[ch] files as these must be present for depend.sh
-# to work. The first dependency is explititly given as it is used by $<.
-
-$(object_dir)/%.cmdline.d: %.cmdline.c $(cmdline_generated) | $(object_dir)
+$(object_dir)/%.cmdline.d: $(cmdline_dir)/%.cmdline.c | $(object_dir)
@[ -z "$(Q)" ] || echo 'DEP $<'
- $(Q) ./depend.sh $(object_dir) $(CPPFLAGS) $< > $@
+ $(Q) ./depend.sh $(object_dir) $(cmdline_dir) $(CPPFLAGS) $< > $@
-$(object_dir)/%.d: %.c $(cmdline_generated) | $(object_dir)
+$(object_dir)/%.d: %.c | $(object_dir)
@[ -z "$(Q)" ] || echo 'DEP $<'
- $(Q) ./depend.sh $(object_dir) $(CPPFLAGS) $< > $@
+ $(Q) ./depend.sh $(object_dir) $(cmdline_dir) $(CPPFLAGS) $< > $@
recv_objs := $(addprefix $(object_dir)/, @recv_objs@)
filter_objs := $(addprefix $(object_dir)/, @filter_objs@)
#!/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_]\+\.cmdline.h\)@ $cmdline_dir/\1@g"