automatic dependencies with make and nvcc

Since nvcc can’t inline device functions, I’ve taken to #including .cu files in other .cu files. This led me to try to get rebuilding in make working with auto-dependencies via the -M flag. (Also, nvcc is slow to begin with.) How are you implementing automatic dependency generation with make and nvcc?

nvcc can’t inline device functions that are in separate compilation units

Nsight eclipse edition uses auto dependency generation with -M

You could study how it works.

Yes, forgot to say that.

I got it to work by following Automatic Prerequisites (GNU make)

Namely, what works for me is

$(OBJ)/%.d: $(SRC)/
	@ set -e; rm -f $@; \
	$(NVCC) -M $(NVCCFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

and including the .d files as a prerequisite for the corresponding .o. $(OBJ) is the object directory and $(SRC) the source directory.