{"thread":{"id":"6902","subject":"[PATCH] Makefile: Improve support for static linking.","startedAt":"2007-02-20T23:43:13Z","lastAt":"2007-02-20T23:43:13Z","messageCount":1,"participants":["Peter Simons"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35146","messageId":"87ps84v1im.fsf@write-only.cryp.to","threadId":"6902","inReplyTo":null,"subject":"[PATCH] Makefile: Improve support for static linking.","fromName":"Peter Simons","fromEmail":"simons@cryp.to","sentAt":"2007-02-20T23:43:13Z","receivedAt":"2007-02-20T23:43:13Z","isPatch":true,"sender":{"key":"simons@cryp.to","avatar":"https://gravatar.com/avatar/56227a0fffc05e2d0584aecce45f0f1fd2b2c0a464a266dff6c2a4aa9191241e?d=mp&s=160"},"body":"The naive approach to build a statically linked git toolset, \"make\nLDFLAGS=-static\", fails for two reasons:\n\n * Libraries git depends on might depend on other libraries this\n   Makefile can't know about. Curl, for example, can be compiled with or\n   without support for international domain names. If that capability is\n   compiled in, linking curl needs \"-lidn\". Also, static linking often\n   adds a dependency on dlopen() and friends, so \"-ldl\" must be\n   specified too.\n\n * Linking statically requires the libraries to be specified in top-down\n   order.\n\nGuessing how to build a static binary on any given platform is quite\ndifficult, but this patch gets us a littler closer to that goal. The\nchanges are:\n\n * Support \"make LIBS=-ldl\".\n\n * Use curl-config(1) to determine $CURL_LIBCURL defaults.\n\n * Reorder $LIB_4_CRYPTO to \"-lssl -lcrypto\" (if NEEDS_SSL_WITH_CRYPTO).\n\n * Always specify $BASIC_LIBS (formerly $LIBS) last.\n---\n Makefile |   22 ++++++++++++----------\n 1 files changed, 12 insertions(+), 10 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 289decd..b07b2b8 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -167,6 +167,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__\n # but it still might be nice to keep that distinction.)\n BASIC_CFLAGS =\n BASIC_LDFLAGS =\n+BASIC_LIBS =\n \n SCRIPT_SH = \\\n \tgit-bisect.sh git-checkout.sh \\\n@@ -454,7 +455,8 @@ ifndef NO_CURL\n \tifdef CURLDIR\n \t\t# Try \"-Wl,-rpath=$(CURLDIR)/lib\" in such a case.\n \t\tBASIC_CFLAGS += -I$(CURLDIR)/include\n-\t\tCURL_LIBCURL = -L$(CURLDIR)/lib $(CC_LD_DYNPATH)$(CURLDIR)/lib -lcurl\n+\t\tCURL_LIBCURL  = $(shell curl-config --libs)\n+\t\tCURL_LIBCURL += -L$(CURLDIR)/lib $(CC_LD_DYNPATH)$(CURLDIR)/lib -lcurl\n \telse\n \t\tCURL_LIBCURL = -lcurl\n \tendif\n@@ -484,7 +486,7 @@ else\n \tOPENSSL_LIBSSL =\n endif\n ifdef NEEDS_SSL_WITH_CRYPTO\n-\tLIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto -lssl\n+\tLIB_4_CRYPTO = $(OPENSSL_LINK) -lssl -lcrypto\n else\n \tLIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto\n endif\n@@ -607,7 +609,7 @@ prefix_SQ = $(subst ','\\'',$(prefix))\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n \n-LIBS = $(GITLIBS) $(EXTLIBS)\n+BASIC_LIBS += $(GITLIBS) $(EXTLIBS) $(LIBS)\n \n BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n@@ -636,7 +638,7 @@ strip: $(PROGRAMS) git$X\n git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS\n \t$(CC) -DGIT_VERSION='\"$(GIT_VERSION)\"' \\\n \t\t$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \\\n-\t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)\n+\t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(BASIC_LIBS)\n \n help.o: common-cmds.h\n \n@@ -754,7 +756,7 @@ http-fetch.o: http-fetch.c http.h GIT-CFLAGS\n endif\n \n git-%$X: %.o $(GITLIBS)\n-\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(BASIC_LIBS)\n \n ssh-pull.o: ssh-fetch.c\n ssh-push.o: ssh-upload.c\n@@ -769,11 +771,11 @@ git-imap-send$X: imap-send.o $(LIB_FILE)\n http.o http-fetch.o http-push.o: http.h\n git-http-fetch$X: fetch.o http.o http-fetch.o $(GITLIBS)\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \\\n-\t\t$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)\n+\t\t$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(BASIC_LIBS)\n \n git-http-push$X: revision.o http.o http-push.o $(GITLIBS)\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \\\n-\t\t$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)\n+\t\t$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(BASIC_LIBS)\n \n $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)\n $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)\n@@ -832,13 +834,13 @@ test-date$X: test-date.c date.o ctype.o\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o\n \n test-delta$X: test-delta.o diff-delta.o patch-delta.o $(GITLIBS)\n-\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(BASIC_LIBS)\n \n test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)\n-\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(BASIC_LIBS)\n \n test-sha1$X: test-sha1.o $(GITLIBS)\n-\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(BASIC_LIBS)\n \n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n-- \n1.5.0\n"}]}