Makefile: fixup dependency problem for files in sub dirs
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/Makefile b/Makefile
index 45b20e6..a2d671d 100644
--- a/Makefile
+++ b/Makefile
@@ -124,6 +124,7 @@
endif
OBJS = $(SOURCE:.c=.o)
+-include $(OBJS:.o=.d)
T_SMALLOC_OBJS = t/stest.o
T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o
@@ -168,7 +169,7 @@
mandir = $(prefix)/man
endif
-all: .depend $(PROGS) $(SCRIPTS) FORCE
+all: $(PROGS) $(SCRIPTS) FORCE
.PHONY: all install clean
.PHONY: FORCE cscope
@@ -179,8 +180,14 @@
override CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
-.c.o: .depend FORCE
+.c.o: FORCE
$(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
+ @$(CC) -MM $(CFLAGS) $(CPPFLAGS) $*.c > $*.d
+ @mv -f $*.d $*.d.tmp
+ @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
+ @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
+ sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
+ @rm -f $*.d.tmp
init.o: FIO-VERSION-FILE
$(QUIET_CC)$(CC) -o init.o $(CFLAGS) $(CPPFLAGS) -c init.c
@@ -200,13 +207,8 @@
fio: $(OBJS)
$(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
-.depend: $(SOURCE)
- $(QUIET_DEP)$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SOURCE) 1> .depend
-
-$(PROGS): .depend
-
clean: FORCE
- -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE config-host.mak cscope.out
+ -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE config-host.mak cscope.out *.d
cscope:
@cscope -b -R
@@ -217,7 +219,3 @@
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
$(INSTALL) -m 644 fio.1 $(DESTDIR)$(mandir)/man1
$(INSTALL) -m 644 fio_generate_plots.1 $(DESTDIR)$(mandir)/man1
-
-ifneq ($(wildcard .depend),)
-include .depend
-endif