From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Nieder Subject: [PATCH] Makefile: explicitly set target name for autogenerated dependencies Date: Fri, 18 Nov 2011 17:23:24 -0600 Message-ID: <20111118232324.GA8746@elie.hsd1.il.comcast.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Git Mailing List , Fredrik Kuivinen , Junio C Hamano To: Nguyen Thai Ngoc Duy X-From: git-owner@vger.kernel.org Sat Nov 19 00:23:47 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RRXmZ-0000NY-Nf for gcvg-git-2@lo.gmane.org; Sat, 19 Nov 2011 00:23:44 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753961Ab1KRXXi convert rfc822-to-quoted-printable (ORCPT ); Fri, 18 Nov 2011 18:23:38 -0500 Received: from mail-gy0-f174.google.com ([209.85.160.174]:36097 "EHLO mail-gy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754764Ab1KRXXh convert rfc822-to-8bit (ORCPT ); Fri, 18 Nov 2011 18:23:37 -0500 Received: by ghbz2 with SMTP id z2so1126170ghb.19 for ; Fri, 18 Nov 2011 15:23:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=1rAI8E21OI3ZVy/EMixLLSD8xxRhE5SzupsqFyVsrzs=; b=pBT6SnNUkBezN1//nZr9VhcvAT8IdxUU0PsGG8+u4667C9UtuS+VwdIu7BWpxcBLIN f+bcETjrBP/Eej3VxXyGnGQwQ5kqa8AGywVd3lnZ930gW7Sun2OAtWNbAi6yZRUh/nsT 5Qbr23gg9kXHdl87lTM5hs9DQ8rfRJ76id89o= Received: by 10.236.35.205 with SMTP id u53mr8299284yha.24.1321658617062; Fri, 18 Nov 2011 15:23:37 -0800 (PST) Received: from elie.hsd1.il.comcast.net (c-24-1-56-9.hsd1.il.comcast.net. [24.1.56.9]) by mx.google.com with ESMTPS id y71sm2909217yhh.6.2011.11.18.15.23.35 (version=SSLv3 cipher=OTHER); Fri, 18 Nov 2011 15:23:36 -0800 (PST) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21+46 (b01d63af6fea) (2011-07-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: "gcc -MF depfile -MMD -MP -c -o path/to/file.o" produces a makefile snippet named "depfile" describing what files are needed to build the target given by "-o". When ccache versions before v3.0pre0~187 (Fix handling of the -MD and -MDD options, 2009-11-01) run, they execute gcc -MF depfile -MMD -MP -E instead to get the final content for hashing. Notice that the "-c -o" combination is replaced by "-E". The result is a target name without a leading path. Thus when building git with such versions of ccache with COMPUTE_HEADER_DEPENDENCIES enabled, the generated makefile snippets define dependencies for the wrong target: $ make builtin/add.o GIT_VERSION =3D 1.7.8.rc3 * new build flags or prefix CC builtin/add.o $ head -1 builtin/.depend/add.o.d add.o: builtin/add.c cache.h git-compat-util.h compat/bswap.h strbuf.h= \ After a change in a header file, object files in a subdirectory are not automatically rebuilt by "make": $ touch cache.h $ make builtin/add.o $ Luckily we can prevent trouble by explicitly supplying the name of the target to ccache and gcc, using the -MQ option. Do so. Reported-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy Signed-off-by: Jonathan Nieder --- Hi, Nguyen Thai Ngoc Duy wrote: > My builtin/.depend/add.o.d says > > add.o: .... cache.h ... > > Shouldn't it be "builtin/add.o: ... cache.h ..."? The following seems to do the trick for me. Thanks again for catching it. Makefile | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ee34eab8..71ad4b26 100644 --- a/Makefile +++ b/Makefile @@ -1250,7 +1250,8 @@ USE_COMPUTED_HEADER_DEPENDENCIES =3D else ifndef COMPUTE_HEADER_DEPENDENCIES dep_check =3D $(shell $(CC) $(ALL_CFLAGS) \ - -c -MF /dev/null -MMD -MP -x c /dev/null -o /dev/null 2>&1; \ + -c -MF /dev/null -MQ /dev/null -MMD -MP \ + -x c /dev/null -o /dev/null 2>&1; \ echo $$?) ifeq ($(dep_check),0) COMPUTE_HEADER_DEPENDENCIES=3DYesPlease @@ -1912,7 +1913,7 @@ $(dep_dirs): =20 missing_dep_dirs :=3D $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs)= ) dep_file =3D $(dir $@).depend/$(notdir $@).d -dep_args =3D -MF $(dep_file) -MMD -MP +dep_args =3D -MF $(dep_file) -MQ $@ -MMD -MP ifdef CHECK_HEADER_DEPENDENCIES $(error cannot compute header dependencies outside a normal build. \ Please unset CHECK_HEADER_DEPENDENCIES and try again) --=20 1.7.8.rc3