All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: [PATCH/RFC 2/2] Makefile: automatically compute header dependencies
Date: Fri, 27 Nov 2009 11:50:43 -0600	[thread overview]
Message-ID: <20091127175043.GC3461@progeny.tock> (raw)
In-Reply-To: <20091127174558.GA3461@progeny.tock>

Use the gcc -MMD -MP -MF options to generate dependency rules as a
byproduct when building .o files.

A bit remains to be done:

 - add the same support to the .c.s rule
 - make this optional (not all compilers support this, and not all
   developers necessarily want to litter the directory with .*.o.d
   files)
 - document what gcc version introduced these options
 - find equivalent options for other compilers (e.g., Intel C,
   SunWSPro, MSVC)

but this should give the idea.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Good idea?  Bad idea?

Good night,
Jonathan

 .gitignore |    1 +
 Makefile   |   15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/.gitignore b/.gitignore
index ac02a58..c7b2736 100644
--- a/.gitignore
+++ b/.gitignore
@@ -170,6 +170,7 @@
 *.exe
 *.[aos]
 *.py[co]
+.*.o.d
 *+
 /config.mak
 /autom4te.cache
diff --git a/Makefile b/Makefile
index ed0f461..af3f874 100644
--- a/Makefile
+++ b/Makefile
@@ -488,6 +488,7 @@ LIB_H += unpack-trees.h
 LIB_H += userdiff.h
 LIB_H += utf8.h
 LIB_H += wt-status.h
+LIB_H :=
 
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -1559,13 +1560,23 @@ git.o git.spec \
 	$(patsubst %.perl,%,$(SCRIPT_PERL)) \
 	: GIT-VERSION-FILE
 
+dep_file = $(dir $@).$(notdir $@).d
+dep_args = -MF $(dep_file) -MMD -MP
+
 %.o: %.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<
 %.s: %.c GIT-CFLAGS
 	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 %.o: %.S
 	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 
+objects := $(wildcard *.o block-sha1/*.o arm/*.o ppc/*.o \
+		compat/*.o compat/*/*.o xdiff/*.o)
+dep_files := $(wildcard $(foreach f,$(objects),$(dir $f).$(notdir $f).d))
+ifneq ($(dep_files),)
+include $(dep_files)
+endif
+
 exec_cmd.o: exec_cmd.c GIT-CFLAGS
 exec_cmd.o: ALL_CFLAGS += \
 	'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
@@ -1875,6 +1886,8 @@ distclean: clean
 clean:
 	$(RM) *.o block-sha1/*.o arm/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
 		$(LIB_FILE) $(XDIFF_LIB)
+	$(RM) .*.o.d block-sha1/.*.o.d arm/.*.o.d ppc/.*.o.d compat/.*.o.d \
+		compat/*/.*.o.d xdiff/.*.o.d
 	$(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
 	$(RM) $(TEST_PROGRAMS)
 	$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
-- 
1.6.5.3

  parent reply	other threads:[~2009-11-27 17:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27  8:04 [PATCH] Makefile: determine the list of header files using a glob Johannes Sixt
2009-11-27  8:26 ` Mike Hommey
2009-11-27  8:50   ` Johannes Sixt
2009-11-27  8:58     ` Mike Hommey
2009-11-27 18:28       ` Junio C Hamano
2009-12-30  8:00         ` Mike Hommey
2009-12-30  8:45           ` Junio C Hamano
2009-11-27  9:36 ` Johannes Schindelin
2009-11-27 17:45   ` [PATCH/RFC 0/2] Lazily generate header dependencies Jonathan Nieder
2009-11-27 17:49     ` [PATCH/RFC 1/2] Makefile: use target-specific variable to pass flags to cc Jonathan Nieder
2009-11-27 17:50     ` Jonathan Nieder [this message]
2009-11-27 22:57       ` [PATCH/RFC 2/2] Makefile: automatically compute header dependencies Sverre Rabbelier
2009-11-28  4:24         ` Jonathan Nieder
2009-11-28  9:29       ` [PATCH/RFC 2/2 v3] Makefile: lazily " Jonathan Nieder
2009-11-28  9:26         ` Andreas Schwab
2009-11-28 11:49           ` Jonathan Nieder
2010-01-01  0:05     ` [PATCH/RFC 0/2] Lazily generate " Nanako Shiraishi
2010-01-06  1:06       ` Junio C Hamano
2010-01-06  9:26         ` Johannes Schindelin
2010-01-06  9:36           ` Jonathan Nieder
2010-01-07  7:13       ` [PATCH v2 0/5] " Jonathan Nieder
2010-01-07  7:16         ` [PATCH 1/5] Makefile: rearrange dependency rules Jonathan Nieder
2010-01-07  7:18         ` [PATCH 2/5] Makefile: clear list of default rules Jonathan Nieder
2010-01-07  7:19         ` [PATCH 3/5] Makefile: add OBJECTS variable listing object files Jonathan Nieder
2010-01-07  7:23         ` [PATCH 4/5] Makefile: lazily compute header dependencies Jonathan Nieder
2010-01-07  7:30         ` [PATCH/RFC 5/5] Teach Makefile to check " Jonathan Nieder
2010-01-07 13:22         ` [PATCH v2 0/5] Lazily generate " Erik Faye-Lund
2009-11-27 18:28   ` [PATCH] Makefile: determine the list of header files using a glob Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091127175043.GC3461@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.