1- BUILD_TYPE ?= "RelWithDebInfo"
2- FLAGS ?=
1+ # This determines if we are building while making use of xx. Ensuring
2+ # the package directives target the right manager and inject (OS) vendor
3+ # specific configurations.
4+ IS_XX := $(shell command -v xx-info 2> /dev/null)
5+ ifdef IS_XX
6+ XX_VENDOR ?= $(shell xx-info vendor)
7+ endif
38
9+ # Libgit2 build configuration flags.
410INSTALL_PREFIX ?= /usr
11+ ifndef IS_XX
512INSTALL_LIBDIR ?= $(INSTALL_PREFIX ) /lib
13+ else
14+ INSTALL_LIBDIR ?= $(INSTALL_PREFIX ) /lib/$(shell xx-info triple)
15+ endif
16+ BUILD_TYPE ?= "RelWithDebInfo"
17+ FLAGS ?=
618USE_HTTPS ?= OpenSSL
719USE_SSH ?= ON
820
21+ # Cmake version to be installed.
22+ CMAKE_VERSION ?= 3.21.3
23+
24+ # Libgit2 version to be compiled and installed.
925LIBGIT2_VERSION ?= 1.1.1
10- # Overwritten to a specific version by default for git2go support
26+ # In some scenarios libgit2 needs to be checked out to a specific commit.
27+ # This takes presidence over LIBGIT_VERSION if defined.
1128# Ref: https://github.com/libgit2/git2go/issues/834
1229LIBGIT2_REVISION ?=
1330
14- ifeq ($(LIBGIT2_REVISION ) ,)
31+ # Set the download URL based on the above information.
32+ ifeq (,$(LIBGIT2_REVISION ) )
1533LIBGIT2_DOWNLOAD_URL ?= https://github.com/libgit2/libgit2/archive/refs/tags/v$(LIBGIT2_VERSION ) .tar.gz
1634else
1735LIBGIT2_DOWNLOAD_URL ?= https://github.com/libgit2/libgit2/archive/$(LIBGIT2_REVISION ) .tar.gz
1836endif
1937
20- LIBGIT2_LIB := $(INSTALL_LIBDIR ) /libgit2.so.$(LIBGIT2_VERSION )
21-
22- PKG_CONFIG_PATH ?=
23- # Detect Darwin (MacOS) to help the user a bit configuring OpenSSL,
24- # or at least in pointing out what steps should be taken if it can't
25- # magically figure it out by itself. Because we too, are nice people.
26- ifeq ($(shell uname -s) ,Darwin)
27- LIBGIT2_LIB := $(INSTALL_LIBDIR)/libgit2.$(LIBGIT2_VERSION).dylib
38+ # OS specific expected lib output.
39+ LIBGIT2 := $(INSTALL_LIBDIR ) /libgit2.so.$(LIBGIT2_VERSION )
40+ ifeq (Darwin,$(shell uname -s) )
41+ LIBGIT2 := $(INSTALL_LIBDIR)/libgit2.$(LIBGIT2_VERSION).dylib
2842 HAS_BREW := $(shell brew --version 2>/dev/null)
43+ endif
44+
45+ cmake :
46+ ifeq (debian,$(XX_VENDOR ) )
47+ cmake :
48+ apt-get update && apt-get install --no-install-recommends -y clang cmake
49+ endif
50+ .PHONY : cmake
51+
52+ base :
53+ ifeq (debian,$(XX_VENDOR ) )
54+ base :
55+ xx-apt update && xx-apt install --no-install-recommends -y binutils gcc libc6-dev dpkg-dev
56+ endif
57+ .PHONY : base
58+
59+ dependencies : base
60+ ifeq (debian,$(XX_VENDOR ) )
61+ # Install libssh2 for $TARGETPLATFORM from "sid", as the version in "bullseye"
62+ # has been linked against gcrypt, which causes issues with PKCS* formats.
63+ # We pull (sub)dependencies from there as well, to ensure all versions are aligned,
64+ # and not accidentially linked to e.g. mbedTLS (which has limited support for
65+ # certain key formats).
66+ # Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
67+ # Ref: https://github.com/ARMmbed/mbedtls/issues/2452#issuecomment-802683144
68+ dependencies :
69+ set -e; \
70+ echo " deb http://deb.debian.org/debian sid main" > /etc/apt/sources.list.d/sid.list \
71+ && echo " deb-src http://deb.debian.org/debian sid main" /etc/apt/sources.list.d/sid.list \
72+ && xx-apt update \
73+ && xx-apt -t sid install --no-install-recommends -y zlib1g-dev libssl-dev libssh2-1-dev
74+ endif
75+ .PHONY : dependencies
76+
77+ libgit2 : $(LIBGIT2 )
78+ .PHONY : libgit2
79+
2980ifdef HAS_BREW
3081HAS_OPENSSL := $(shell brew --prefix openssl@1.1)
3182# NB: the OPENSSL_LDFLAGS ensures the path is included in the libgit2.pc
32- # file. As standard brew installation doesn't appear to be system wide
33- # on most macOS instances, and you thus have to tell explicitly where
83+ # file. As a standard brew installation doesn't appear to be system wide
84+ # on most macOS instances, and we thus have to explicitly tell where
3485# it can be found.
3586ifdef HAS_OPENSSL
3687 PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(HAS_OPENSSL)/lib/pkgconfig
37- OS_FLAGS += -DOPENSSL_LDFLAGS:STRING=-L $(HAS_OPENSSL)/lib
38- else
39- $(warning "Failed to detect openssl@1.1 installation with brew. It can be installed with 'brew install openssl@1.1',")
40- $(warning "or an alternative location can be provided using the PKG_CONFIG_PATH flag, for example:")
41- $(warning "'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig make'.")
88+ FLAGS += -DOPENSSL_LDFLAGS:STRING=-L $(HAS_OPENSSL)/lib
4289endif
4390HAS_LIBSSH2 := $(shell brew --prefix libssh2)
4491ifdef HAS_LIBSSH2
4592 PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(HAS_LIBSSH2)/lib/pkgconfig
46- else
47- $(warning "Failed to detect libssh2 installation with brew. It can be installed with 'brew install libssh2',")
48- $(warning "or an alternative location can be provided using the PKG_CONFIG_PATH flag, for example:")
49- $(warning "'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig make'.")
50- endif
51- else
52- $(warning "Failed to detect brew installation, and therefore unable to automatically determine lib paths.")
53- $(warning "The location of openssl and libssh2 can be provided using the PKG_CONFIG_PATH flag, for example:")
54- $(warning "'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig make'.")
5593endif
5694endif
5795
58- $(LIBGIT2_LIB ) :
96+ $(LIBGIT2 ) :
5997 set -e; \
6098 SETUP_LIBGIT2_TMP_DIR=$$(mktemp -d ) \
6199 && curl -L $(LIBGIT2_DOWNLOAD_URL ) -o $$ SETUP_LIBGIT2_TMP_DIR/archive.tar.gz \
@@ -76,25 +114,6 @@ $(LIBGIT2_LIB):
76114 -DREGEX_BACKEND:STRING=builtin \
77115 -DUSE_HTTPS:STRING=$(USE_HTTPS ) \
78116 -DUSE_SSH:BOOL=$(USE_SSH ) \
79- $(OS_FLAGS ) \
80117 $(FLAGS ) \
81118 && cmake --build $$ SETUP_LIBGIT2_TMP_DIR/build --target install \
82119 && rm -rf $$ SETUP_LIBGIT2_TMP_DIR
83-
84- # \ && cmake -S $tmp/src -B $tmp/build $(xx-clang --print-cmake-defines) \
85- # -DCMAKE_BUILD_TYPE:STRING=$LIBGIT2_BUILD_TYPE \
86- # -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
87- # -DCMAKE_C_FLAGS=-fPIC \
88- # -DCMAKE_CXX_FLAGS=-fPIC \
89- # -DDEPRECATE_HARD=ON \
90- # -DCMAKE_INSTALL_PREFIX:PATH=/usr \
91- # -DCMAKE_INSTALL_LIBDIR:PATH=/usr/lib/$(xx-info triple) \
92- # -DBUILD_CLAR:BOOL:BOOL=OFF \
93- # -DTHREADSAFE:BOOL=ON \
94- # -DBUILD_SHARED_LIBS=OFF \
95- # -DUSE_BUNDLED_ZLIB:BOOL=OFF \
96- # -DUSE_HTTP_PARSER:STRING=builtin \
97- # -DREGEX_BACKEND:STRING=builtin \
98- # -DUSE_HTTPS:STRING=OpenSSL \
99- # -DUSE_SSH:BOOL=ON \
100- # && cmake --build $tmp/build --target install \
0 commit comments