-MTsets the full name of the target. If each source requires a different goal, each source needs a different argument -MT, which means multiple calls to the compiler and foreach loop:
$(TARGET): build $(OBJECTS)
$(CC) -shared -o $@ $(OBJECTS)
rm autodep
$(foreach SRC,$(SOURCES),$(CC) -MM -MT $(SRC:.c=.o) $(SRC) >> autodep;)
Alternatively, you can use sed to massage output
$(TARGET): build $(OBJECTS)
$(CC) -shared -o $@ $(OBJECTS)
$(CC) -MM $(SOURCES) | sed 's|^|src/|' > autodep
.d -MMD, :
-include $(SOURCES:.c=.d)
CFLAGS += -MMD
$(TARGET): build $(OBJECTS)
$(CC) -shared -o $@ $(OBJECTS)