{"thread":{"id":"43385","subject":"[PATCH] Allow building GIT in a different directory from the source directory","startedAt":"2006-12-08T17:15:25Z","lastAt":"2006-12-09T01:16:39Z","messageCount":4,"participants":["Han-Wen Nienhuys","Alex Riesen","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"294578","messageId":"elc6j2$vej$1@sea.gmane.org","threadId":"43385","inReplyTo":null,"subject":"[PATCH] Allow building GIT in a different directory from the source directory","fromName":"Han-Wen Nienhuys","fromEmail":"hanwen@xs4all.nl","sentAt":"2006-12-08T17:15:25Z","receivedAt":"2006-12-08T17:15:25Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"\nFrom 105d331aee95c0cf3610ac0d2fd4aa7688bd5211 Mon Sep 17 00:00:00 2001\nFrom: Han-Wen Nienhuys <hanwen@xs4all.nl>\nDate: Fri, 8 Dec 2006 18:07:56 +0100\n\nGIT can now be built in a separate builddirectory. This is done as\nfollows:\n\n  mkdir build\n  cd build\n  $my_git_dir/configure\n  make\n\nIn this case, configure creates an empty directory tree based on the\nsource directory, and wraps Makefiles from source directory in the\nbuild directory.  The rest of the functionality is delivered with the\nVPATH feature of Make.\n\nTo make this work the Makefile should not mention ./ explicitly in\nrules, but rather use $< and $^ to automatically look in the source\ndir too.\n\nperl/Makefile and perl/Makefile.PL need special massaging because perl\nis not VPATH aware.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@xs4all.nl>\n---\n Makefile            |   21 ++++++++++++---------\n config.mak.in       |    9 ++++-----\n configure.ac        |   34 ++++++++++++++++++++++++++++++++++\n generate-cmdlist.sh |    2 +-\n perl/Makefile       |    4 ++++\n perl/Makefile.PL    |   16 +++++++++++++---\n 6 files changed, 68 insertions(+), 18 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex cb9b745..3ed57ec 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -97,7 +97,7 @@ all:\n #\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n-\t@$(SHELL_PATH) ./GIT-VERSION-GEN\n+\t@$(SHELL_PATH) $(srcdir)/GIT-VERSION-GEN\n -include GIT-VERSION-FILE\n \n uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n@@ -110,7 +110,7 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')\n \n CFLAGS = -g -O2 -Wall\n LDFLAGS =\n-ALL_CFLAGS = $(CFLAGS)\n+ALL_CFLAGS = $(CFLAGS) -I.\n ALL_LDFLAGS = $(LDFLAGS)\n STRIP ?= strip\n \n@@ -120,7 +120,10 @@ datadir = $(prefix)/share\n GIT_datadir = $(datadir)/git-core\n gitexecdir = $(bindir)\n template_dir = $(GIT_datadir)/templates/\n-# DESTDIR=\n+srcdir = .\n+\n+# this is usually set on the make command line.\n+DESTDIR=\n \n # default configuration for gitweb\n GITWEB_CONFIG = gitweb_config.perl\n@@ -598,8 +601,8 @@ git-merge-recur$X: git-merge-recursive$X\n $(BUILT_INS): git$X\n \trm -f $@ && ln git$X $@\n \n-common-cmds.h: Documentation/git-*.txt\n-\t./generate-cmdlist.sh > $@+\n+common-cmds.h: $(wildcard $(srcdir)/Documentation/git-*.txt)\n+\t$(srcdir)/generate-cmdlist.sh $(srcdir)/Documentation/ > $@+\n \tmv $@+ $@\n \n $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n@@ -609,7 +612,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    -e 's!@@GIT_datadir@@!$(GIT_datadir)!g' \\\n \t    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n-\t    $@.sh >$@+\n+\t    $^ >$@+\n \tchmod +x $@+\n \tmv $@+ $@\n \n@@ -630,7 +633,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n \t    -e '}' \\\n \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n-\t    $@.perl >$@+\n+\t    $^ >$@+\n \tchmod +x $@+\n \tmv $@+ $@\n \n@@ -674,7 +677,7 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n \t    -e '/@@GITWEB_CGI@@/d' \\\n \t    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \\\n \t    -e '/@@GITWEB_CSS@@/d' \\\n-\t    $@.sh > $@+\n+\t    $< > $@+\n \tchmod +x $@+\n \tmv $@+ $@\n \n@@ -821,7 +824,7 @@ install: all\n \tfi\n \t$(foreach p,$(BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)\n \t$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_datadir_SQ)'\n-\t$(INSTALL) -m755 git-sh-setup.sh '$(DESTDIR_SQ)$(GIT_datadir_SQ)'\n+\t$(INSTALL) -m755 $(srcdir)/git-sh-setup.sh '$(DESTDIR_SQ)$(GIT_datadir_SQ)'\n \n install-doc:\n \t$(MAKE) -C Documentation install\ndiff --git a/config.mak.in b/config.mak.in\nindex 9a57840..bfbbf46 100644\n--- a/config.mak.in\n+++ b/config.mak.in\n@@ -10,17 +10,16 @@ TAR = @TAR@\n prefix = @prefix@\n exec_prefix = @exec_prefix@\n bindir = @bindir@\n-#gitexecdir = @libexecdir@/git-core/\n+mandir=@mandir@\n+\n+## unused, but necessary for some autoconf versions (?)\n datarootdir = @datarootdir@\n-template_dir = @datadir@/git-core/templates/\n \n-mandir=@mandir@\n \n srcdir = @srcdir@\n-VPATH = @srcdir@\n \n export exec_prefix mandir\n-export srcdir VPATH\n+export srcdir \n \n NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@\n NO_OPENSSL=@NO_OPENSSL@\ndiff --git a/configure.ac b/configure.ac\nindex 34e3478..403c410 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -5,6 +5,7 @@ AC_PREREQ(2.59)\n AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org])\n \n AC_CONFIG_SRCDIR([git.c])\n+srcdir=`cd $srcdir && pwd`\n \n config_file=config.mak.autogen\n config_append=config.mak.append\n@@ -334,6 +335,39 @@ GIT_PARSE_WITH(iconv))\n AC_CONFIG_FILES([\"${config_file}\":\"${config_in}\":\"${config_append}\"])\n AC_OUTPUT\n \n+if test \"$srcdir\" != \".\"; then\n+\n+  ## if we're building in another directory\n+  ## we need to set it up like the sourcedir\n+  for d in `cd $srcdir &&  find . -type d -print | grep -v '\\.git'` ;\n+  do\n+    if test ! -d  $d ; then\n+      echo creating $d \n+      mkdir $d\n+    fi\n+\n+    if test -f $srcdir/$d/Makefile ; then\n+\n+      dnl [[]] is to keep m4 happy\n+      depth=`echo $d/ | sed -e 's!^\\./!!g' -e 's![[^/]]*/!../!g'`\n+      echo creating $d/Makefile\n+\n+      if test \"$depth\"  = \"\";  then\n+        INCLUDE_AUTOGEN=\"include config.mak.autogen\" ;\n+      else\n+        INCLUDE_AUTOGEN=\"srcdir=$srcdir\" \n+      fi\n+ \n+      cat << EOF > $d/Makefile\n+$INCLUDE_AUTOGEN\n+VPATH = $srcdir/$d\n+export VPATH\n+include $srcdir/$d/Makefile\n+EOF\n+\n+    fi \n+  done\n+fi\n \n ## Cleanup\n rm -f \"${config_append}\"\ndiff --git a/generate-cmdlist.sh b/generate-cmdlist.sh\nindex 5450918..e744fbb 100755\n--- a/generate-cmdlist.sh\n+++ b/generate-cmdlist.sh\n@@ -47,6 +47,6 @@ do\n             x\n             s/.*git-'\"$cmd\"' - \\(.*\\)/  {\"'\"$cmd\"'\", \"\\1\"},/\n \t    p\n-     }' \"Documentation/git-$cmd.txt\"\n+     }' \"$1/git-$cmd.txt\"\n done\n echo \"};\"\ndiff --git a/perl/Makefile b/perl/Makefile\nindex bd483b0..e912191 100644\n--- a/perl/Makefile\n+++ b/perl/Makefile\n@@ -28,6 +28,10 @@ $(makfile): ../GIT-CFLAGS Makefile\n \techo instlibdir: >> $@\n \techo '\techo $(instdir_SQ)' >> $@\n else\n+\n+PERL_SRCDIR=$(srcdir)/perl\n+export PERL_SRCDIR\n+\n $(makfile): Makefile.PL ../GIT-CFLAGS\n \t'$(PERL_PATH_SQ)' $< FIRST_MAKEFILE='$@' PREFIX='$(prefix_SQ)'\n endif\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nindex de73235..8a1251d 100644\n--- a/perl/Makefile.PL\n+++ b/perl/Makefile.PL\n@@ -8,21 +8,31 @@ instlibdir:\n MAKE_FRAG\n }\n \n-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');\n+\n+$src_prefix = '';\n+if (!($ENV{'PERL_SRCDIR'} eq \"\")) {\n+    $src_prefix = $ENV{'PERL_SRCDIR'} . \"/\"\n+}\n+\n+\n+my %pm = (\"$src_prefix/Git.pm\" => '$(INST_LIBDIR)/Git.pm');\n+\n+\n \n # We come with our own bundled Error.pm. It's not in the set of default\n # Perl modules so install it if it's not available on the system yet.\n eval { require Error };\n if ($@) {\n-\t$pm{'private-Error.pm'} = '$(INST_LIBDIR)/Error.pm';\n+\t$pm{\"$src_prefix/private-Error.pm\"} = '$(INST_LIBDIR)/Error.pm';\n }\n \n my %extra;\n $extra{DESTDIR} = $ENV{DESTDIR} if $ENV{DESTDIR};\n \n+\n WriteMakefile(\n \tNAME            => 'Git',\n-\tVERSION_FROM    => 'Git.pm',\n+\tVERSION_FROM    => \"$src_prefix/Git.pm\",\n \tPM\t\t=> \\%pm,\n \t%extra\n );\n-- \n1.4.4.1.gc9922-dirty\n\n\n-- \n Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"},{"id":"298488","messageId":"elc84p$4cs$1@sea.gmane.org","threadId":"43385","inReplyTo":"elc6j2$vej$1@sea.gmane.org","subject":"Re: [PATCH] Allow building GIT in a different directory from the source directory","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-08T17:44:03Z","receivedAt":"2006-12-08T17:44:03Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Han-Wen Nienhuys wrote:\n\n> From 105d331aee95c0cf3610ac0d2fd4aa7688bd5211 Mon Sep 17 00:00:00 2001\n\nThis line is not needed.\n\n> From: Han-Wen Nienhuys <hanwen@xs4all.nl>\n> Date: Fri, 8 Dec 2006 18:07:56 +0100\n> \n> GIT can now be built in a separate builddirectory. This is done as\n> follows:\n> \n>   mkdir build\n>   cd build\n>   $my_git_dir/configure\n>   make\n\nPerhaps we should add this to INSTALL file, or to comments in either\nMakefile, or configure.ac?\n\n> In this case, configure creates an empty directory tree based on the\n> source directory, and wraps Makefiles from source directory in the\n> build directory.  The rest of the functionality is delivered with the\n> VPATH feature of Make.\n> \n> To make this work the Makefile should not mention ./ explicitly in\n> rules, but rather use $< and $^ to automatically look in the source\n> dir too.\n> \n> perl/Makefile and perl/Makefile.PL need special massaging because perl\n> is not VPATH aware.\n>\n> Signed-off-by: Han-Wen Nienhuys <hanwen@xs4all.nl>\n\nVery nicely written commit message. Good work.\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"296560","messageId":"4579AB86.7060400@xs4all.nl","threadId":"43385","inReplyTo":"elc84p$4cs$1@sea.gmane.org","subject":"Re: [PATCH] Allow building GIT in a different directory from the source directory","fromName":"Han-Wen Nienhuys","fromEmail":"hanwen@xs4all.nl","sentAt":"2006-12-08T18:14:30Z","receivedAt":"2006-12-08T18:14:30Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"Jakub Narebski escreveu:\n\n> Perhaps we should add this to INSTALL file, or to comments in either\n> Makefile, or configure.ac?\n\nyes, will do. \n\n-- \n Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"},{"id":"297873","messageId":"20061209011639.GA8010@steel.home","threadId":"43385","inReplyTo":"elc6j2$vej$1@sea.gmane.org","subject":"Re: [PATCH] Allow building GIT in a different directory from the source directory","fromName":"Alex Riesen","fromEmail":"fork0@t-online.de","sentAt":"2006-12-09T01:16:39Z","receivedAt":"2006-12-09T01:16:39Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Han-Wen Nienhuys, Fri, Dec 08, 2006 18:15:25 +0100:\n> -my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');\n> +\n> +$src_prefix = '';\n> +if (!($ENV{'PERL_SRCDIR'} eq \"\")) {\n> +    $src_prefix = $ENV{'PERL_SRCDIR'} . \"/\"\n> +}\n\nHurts my eyes :)\n\n    $src_prefix = defined($ENV{PERL_SRCDIR}) ?  \"$ENV{PERL_SRCDIR}/\": '';\n\ncould be shorter, unless you want (you do) strict syntax check.\n"}]}