Merge branch 'jn/makedepend'
authorJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:08 +0000 (12:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:08 +0000 (12:44 -0800)
* jn/makedepend:
  Makefile: clarify definition of TEST_OBJS
  Makefile: always remove .depend directories on 'make clean'
  Makefile: tuck away generated makefile fragments in .depend
  Teach Makefile to check header dependencies
  Makefile: list standalone program object files in PROGRAM_OBJS
  Makefile: lazily compute header dependencies
  Makefile: list generated object files in OBJECTS
  Makefile: disable default implicit rules
  Makefile: rearrange dependency rules
  Makefile: transport.o depends on branch.h now
  Makefile: drop dependency on $(wildcard */*.h)
  Makefile: clean up http-walker.o dependency rules
  Makefile: remove wt-status.h from LIB_H
  Makefile: make sure test helpers are rebuilt when headers change
  Makefile: add missing header file dependencies

Conflicts:
Makefile

1  2 
Makefile

diff --cc Makefile
index afedb54b48da31d9293ea43971dccf177823e68a,9dd995df752dff0360bb8bb38f6ae9a1f4e68cd3..52f2cc040ba82696b199537d3155a095939dac68
+++ b/Makefile
@@@ -315,8 -349,7 +323,8 @@@ PROGRAMS 
  SCRIPT_PERL =
  SCRIPT_PYTHON =
  SCRIPT_SH =
- TEST_PROGRAMS =
 +SCRIPT_LIB =
+ TEST_PROGRAMS_NEED_X =
  
  SCRIPT_SH += git-am.sh
  SCRIPT_SH += git-bisect.sh
@@@ -362,12 -394,31 +370,31 @@@ EXTRA_PROGRAMS 
  
  # ... and all the rest that could be moved out of bindir to gitexecdir
  PROGRAMS += $(EXTRA_PROGRAMS)
- PROGRAMS += git-fast-import$X
- PROGRAMS += git-imap-send$X
- PROGRAMS += git-shell$X
- PROGRAMS += git-show-index$X
- PROGRAMS += git-upload-pack$X
- PROGRAMS += git-http-backend$X
+ PROGRAM_OBJS += fast-import.o
+ PROGRAM_OBJS += imap-send.o
+ PROGRAM_OBJS += shell.o
+ PROGRAM_OBJS += show-index.o
+ PROGRAM_OBJS += upload-pack.o
+ PROGRAM_OBJS += http-backend.o
+ PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
+ TEST_PROGRAMS_NEED_X += test-chmtime
+ TEST_PROGRAMS_NEED_X += test-ctype
+ TEST_PROGRAMS_NEED_X += test-date
+ TEST_PROGRAMS_NEED_X += test-delta
+ TEST_PROGRAMS_NEED_X += test-dump-cache-tree
+ TEST_PROGRAMS_NEED_X += test-genrandom
+ TEST_PROGRAMS_NEED_X += test-match-trees
+ TEST_PROGRAMS_NEED_X += test-parse-options
+ TEST_PROGRAMS_NEED_X += test-path-utils
+ TEST_PROGRAMS_NEED_X += test-run-command
+ TEST_PROGRAMS_NEED_X += test-sha1
+ TEST_PROGRAMS_NEED_X += test-sigchain
+ TEST_PROGRAMS_NEED_X += test-index-version
 -TEST_PROGRAMS := $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
++TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
  
  # List built-in command $C whose implementation cmd_$C() is not in
  # builtin-$C.o but is linked in as part of some other command.
@@@ -1592,12 -1684,132 +1633,133 @@@ git.o git.spec 
        $(patsubst %.perl,%,$(SCRIPT_PERL)) \
        : GIT-VERSION-FILE
  
- %.o: %.c GIT-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+ TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
+ GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
+       git.o http.o http-walker.o remote-curl.o
+ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
+       xdiff/xmerge.o xdiff/xpatience.o
+ OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)
+ dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
+ dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
+ ifdef COMPUTE_HEADER_DEPENDENCIES
+ $(dep_dirs):
+       mkdir -p $@
+ missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
+ dep_file = $(dir $@).depend/$(notdir $@).d
+ dep_args = -MF $(dep_file) -MMD -MP
+ ifdef CHECK_HEADER_DEPENDENCIES
+ $(error cannot compute header dependencies outside a normal build. \
+ Please unset CHECK_HEADER_DEPENDENCIES and try again)
+ endif
+ endif
+ ifndef COMPUTE_HEADER_DEPENDENCIES
+ ifndef CHECK_HEADER_DEPENDENCIES
+ dep_dirs =
+ missing_dep_dirs =
+ dep_args =
+ endif
+ endif
+ ifdef CHECK_HEADER_DEPENDENCIES
+ ifndef PRINT_HEADER_DEPENDENCIES
+ missing_deps = $(filter-out $(notdir $^), \
+       $(notdir $(shell $(MAKE) -s $@ \
+               CHECK_HEADER_DEPENDENCIES=YesPlease \
+               USE_COMPUTED_HEADER_DEPENDENCIES=YesPlease \
+               PRINT_HEADER_DEPENDENCIES=YesPlease)))
+ endif
+ endif
+ ASM_SRC := $(wildcard $(OBJECTS:o=S))
+ ASM_OBJ := $(ASM_SRC:S=o)
+ C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS))
+ .SUFFIXES:
+ ifdef PRINT_HEADER_DEPENDENCIES
+ $(C_OBJ): %.o: %.c FORCE
+       echo $^
+ $(ASM_OBJ): %.o: %.S FORCE
+       echo $^
+ ifndef CHECK_HEADER_DEPENDENCIES
+ $(error cannot print header dependencies during a normal build. \
+ Please set CHECK_HEADER_DEPENDENCIES and try again)
+ endif
+ endif
+ ifndef PRINT_HEADER_DEPENDENCIES
+ ifdef CHECK_HEADER_DEPENDENCIES
+ $(C_OBJ): %.o: %.c $(dep_files) FORCE
+       @set -e; echo CHECK $@; \
+       missing_deps="$(missing_deps)"; \
+       if test "$$missing_deps"; \
+       then \
+               echo missing dependencies: $$missing_deps; \
+               false; \
+       fi
+ $(ASM_OBJ): %.o: %.S $(dep_files) FORCE
+       @set -e; echo CHECK $@; \
+       missing_deps="$(missing_deps)"; \
+       if test "$$missing_deps"; \
+       then \
+               echo missing dependencies: $$missing_deps; \
+               false; \
+       fi
+ endif
+ endif
+ ifndef CHECK_HEADER_DEPENDENCIES
+ $(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs)
+       $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<
+ $(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs)
+       $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $<
+ endif
  %.s: %.c GIT-CFLAGS FORCE
        $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
- %.o: %.S GIT-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+ ifdef USE_COMPUTED_HEADER_DEPENDENCIES
+ # Take advantage of gcc's on-the-fly dependency generation
+ # See <http://gcc.gnu.org/gcc-3.0/features.html>.
+ dep_files_present := $(wildcard $(dep_files))
+ ifneq ($(dep_files_present),)
+ include $(dep_files_present)
+ endif
+ else
+ # Dependencies on header files, for platforms that do not support
+ # the gcc -MMD option.
+ #
+ # Dependencies on automatically generated headers such as common-cmds.h
+ # should _not_ be included here, since they are necessary even when
+ # building an object for the first time.
+ #
+ # XXX. Please check occasionally that these include all dependencies
+ # gcc detects!
+ $(GIT_OBJS): $(LIB_H)
+ builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o transport.o: branch.h
+ builtin-bundle.o bundle.o transport.o: bundle.h
+ builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h
+ builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h
++builtin-grep.o: thread-utils.h
+ builtin-send-pack.o transport.o: send-pack.h
+ builtin-log.o builtin-shortlog.o: shortlog.h
+ builtin-prune.o builtin-reflog.o reachable.o: reachable.h
+ builtin-commit.o builtin-revert.o wt-status.o: wt-status.h
+ builtin-tar-tree.o archive-tar.o: tar.h
+ builtin-pack-objects.o: thread-utils.h
+ http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
+ http.o http-walker.o http-push.o remote-curl.o: http.h
+ xdiff-interface.o $(XDIFF_OBJS): \
+       xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
+       xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
+ endif
  
  exec_cmd.s exec_cmd.o: ALL_CFLAGS += \
        '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
@@@ -1935,9 -2114,10 +2065,10 @@@ distclean: clea
  clean:
        $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
                $(LIB_FILE) $(XDIFF_LIB)
 -      $(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
 +      $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
        $(RM) -r bin-wrappers
+       $(RM) -r $(dep_dirs)
        $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
        $(RM) -r autom4te.cache
        $(RM) config.log config.mak.autogen config.mak.append config.status config.cache