{"thread":{"id":"8792","subject":"[PATCH] Add USE_SHARED_LIBGIT flag to build and use libgit.so rather than libgit.a","startedAt":"2007-07-01T08:28:02Z","lastAt":"2007-07-01T08:28:02Z","messageCount":1,"participants":["Josh Triplett"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46156","messageId":"46876592.4060600@freedesktop.org","threadId":"8792","inReplyTo":null,"subject":"[PATCH] Add USE_SHARED_LIBGIT flag to build and use libgit.so rather than libgit.a","fromName":"Josh Triplett","fromEmail":"josh@freedesktop.org","sentAt":"2007-07-01T08:28:02Z","receivedAt":"2007-07-01T08:28:02Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Git builds a static libgit.a, and many commands which link to libgit.a,\nresulting in many duplicate copies of the code in libgit.a.  Add a\nUSE_SHARED_LIBGIT flag to the Makefile (off by default), which builds and uses\na shared library libgit.so instead.\n\nThe existing objects in libgit.a reference the symbols git_version_string and\ngit_usage_string, defined in git.c, but libgit does not include git.o, making\nthe library not self-contained, and leading to linking errors when trying to\nuse a shared library.  Move those two symbols to help.c, where the references\nfrom libgit occur.\n\nThis change does not install header files, versioned libraries, or anything\nelse that would support actually using libgit.so from anything other than the\ninstalled git binaries.  The built libgit.so exists solely for the benefit of\nthe installed git binaries that link to it.\n\nMotivated by trying to install Git on a machine for which this makes the\ndifference between remaining under quota and not.\n\nSigned-off-by: Josh Triplett <josh@freedesktop.org>\n---\n Makefile |   31 ++++++++++++++++++++++++++-----\n git.c    |    5 -----\n help.c   |    5 +++++\n 3 files changed, 31 insertions(+), 10 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex a98e27a..db35b3b 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -124,6 +124,8 @@ all::\n # If not set it defaults to the bare 'wish'. If it is set to the empty\n # string then NO_TCLTK will be forced (this is used by configure script).\n #\n+# Define USE_SHARED_LIBGIT to create and use a shared library libgit.so rather\n+# than a static library libgit.a.\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -146,6 +148,7 @@ STRIP ?= strip\n prefix = $(HOME)\n bindir = $(prefix)/bin\n gitexecdir = $(bindir)\n+libdir = $(prefix)/lib\n sharedir = $(prefix)/share\n template_dir = $(sharedir)/git-core/templates\n ifeq ($(prefix),/usr)\n@@ -290,7 +293,13 @@ endif\n \n export PERL_PATH\n \n+ifdef USE_SHARED_LIBGIT\n+LIB_FILE=libgit.so\n+LIBGIT=-L. -lgit\n+else\n LIB_FILE=libgit.a\n+LIBGIT=$(LIB_FILE)\n+endif\n XDIFF_LIB=xdiff/lib.a\n \n LIB_H = \\\n@@ -704,6 +713,7 @@ ETC_GITCONFIG_SQ = $(subst ','\\'',$(ETC_GITCONFIG))\n DESTDIR_SQ = $(subst ','\\'',$(DESTDIR))\n bindir_SQ = $(subst ','\\'',$(bindir))\n gitexecdir_SQ = $(subst ','\\'',$(gitexecdir))\n+libdir_SQ = $(subst ','\\'',$(libdir))\n template_dir_SQ = $(subst ','\\'',$(template_dir))\n prefix_SQ = $(subst ','\\'',$(prefix))\n \n@@ -712,7 +722,7 @@ PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n PYTHON_PATH_SQ = $(subst ','\\'',$(PYTHON_PATH))\n TCLTK_PATH_SQ = $(subst ','\\'',$(TCLTK_PATH))\n \n-LIBS = $(GITLIBS) $(EXTLIBS)\n+LIBS = $(LIBGIT) $(XDIFF_LIB) $(EXTLIBS)\n \n BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \\\n \t-DETC_GITCONFIG='\"$(ETC_GITCONFIG_SQ)\"' $(COMPAT_CFLAGS)\n@@ -721,6 +731,10 @@ LIB_OBJS += $(COMPAT_OBJS)\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \n+ifdef USE_SHARED_LIBGIT\n+ALL_CFLAGS += -fpic\n+endif\n+\n export TAR INSTALL DESTDIR SHELL_PATH\n \n \n@@ -747,16 +761,15 @@ gitk-wish: gitk GIT-GUI-VARS\n \tchmod +x $@+ && \\\n \tmv -f $@+ $@\n \n-git.o: git.c common-cmds.h GIT-CFLAGS\n-\t$(QUIET_CC)$(CC) -DGIT_VERSION='\"$(GIT_VERSION)\"' \\\n-\t\t$(ALL_CFLAGS) -c $(filter %.c,$^)\n+git.o: common-cmds.h\n \n git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)\n \t$(QUIET_LINK)$(CC) -DGIT_VERSION='\"$(GIT_VERSION)\"' \\\n \t\t$(ALL_CFLAGS) -o $@ $(filter %.c,$^) git.o \\\n \t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)\n \n-help.o: common-cmds.h\n+help.o: help.c common-cmds.h GIT-CFLAGS\n+\t$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DGIT_VERSION='\"$(GIT_VERSION)\"' $<\n \n git-merge-subtree$X: git-merge-recursive$X\n \t$(QUIET_BUILT_IN)rm -f $@ && ln git-merge-recursive$X $@\n@@ -908,7 +921,11 @@ $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)\n $(DIFF_OBJS): diffcore.h\n \n $(LIB_FILE): $(LIB_OBJS)\n+ifdef USE_SHARED_LIBGIT\n+\t$(QUIET_LINK)$(CC) -shared -o $@ $(LIB_OBJS)\n+else\n \t$(QUIET_AR)rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)\n+endif\n \n XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \\\n \txdiff/xmerge.o\n@@ -996,6 +1013,10 @@ install: all\n \t$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'\n \t$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'\n \t$(INSTALL) git$X '$(DESTDIR_SQ)$(bindir_SQ)'\n+ifdef USE_SHARED_LIBGIT\n+\t$(INSTALL) -d -m755 $(DESTDIR_SQ)$(libdir_SQ)\n+\t$(INSTALL) $(LIB_FILE) $(DESTDIR_SQ)$(libdir_SQ)\n+endif\n \t$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install\n \t$(MAKE) -C perl prefix='$(prefix_SQ)' install\n ifndef NO_TCLTK\ndiff --git a/git.c b/git.c\nindex 29b55a1..1e24903 100644\n--- a/git.c\n+++ b/git.c\n@@ -3,9 +3,6 @@\n #include \"cache.h\"\n #include \"quote.h\"\n \n-const char git_usage_string[] =\n-\t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]\";\n-\n static void prepend_to_path(const char *dir, int len)\n {\n \tconst char *old_path = getenv(\"PATH\");\n@@ -206,8 +203,6 @@ static int handle_alias(int *argcp, const char ***argv)\n \treturn ret;\n }\n \n-const char git_version_string[] = GIT_VERSION;\n-\n #define RUN_SETUP\t(1<<0)\n #define USE_PAGER\t(1<<1)\n /*\ndiff --git a/help.c b/help.c\nindex 1cd33ec..3f3ceeb 100644\n--- a/help.c\n+++ b/help.c\n@@ -9,6 +9,11 @@\n #include \"common-cmds.h\"\n #include <sys/ioctl.h>\n \n+const char git_usage_string[] =\n+\t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]\";\n+\n+const char git_version_string[] = GIT_VERSION;\n+\n /* most GUI terminals set COLUMNS (although some don't export it) */\n static int term_columns(void)\n {\n-- \n1.5.2.2\n\n\n"}]}