This repository was archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
137 lines (126 loc) · 4.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This determines if we are building while making use of xx. Ensuring
# the package directives target the right manager and inject (OS) vendor
# specific configurations.
IS_XX := $(shell command -v xx-info 2> /dev/null)
ifdef IS_XX
XX_VENDOR ?= $(shell xx-info vendor)
endif
# Libgit2 build configuration flags.
INSTALL_PREFIX ?= /usr
ifndef IS_XX
INSTALL_LIBDIR ?= $(INSTALL_PREFIX)/lib
else
INSTALL_LIBDIR ?= $(INSTALL_PREFIX)/lib/$(shell xx-info triple)
endif
BUILD_TYPE ?= "RelWithDebInfo"
FLAGS ?=
USE_HTTPS ?= OpenSSL
USE_SSH ?= ON
USE_BUNDLED_ZLIB ?= OFF
BUILD_SHARED_LIBS ?= ON
# Cmake version to be installed.
CMAKE_VERSION ?= 3.21.3
# Libgit2 version to be compiled and installed.
LIBGIT2_VERSION ?= 1.1.1
# In some scenarios libgit2 needs to be checked out to a specific commit.
# This takes presidence over LIBGIT_VERSION if defined.
# Ref: https://github.com/libgit2/git2go/issues/834
LIBGIT2_REVISION ?=
# Set the download URL based on the above information.
ifeq (,$(LIBGIT2_REVISION))
LIBGIT2_DOWNLOAD_URL ?= https://github.com/libgit2/libgit2/archive/refs/tags/v$(LIBGIT2_VERSION).tar.gz
else
LIBGIT2_DOWNLOAD_URL ?= https://github.com/libgit2/libgit2/archive/$(LIBGIT2_REVISION).tar.gz
endif
# OS specific expected lib output.
LIBGIT2 := $(INSTALL_LIBDIR)/libgit2.so.$(LIBGIT2_VERSION)
ifeq (Darwin,$(shell uname -s))
LIBGIT2 := $(INSTALL_LIBDIR)/libgit2.$(LIBGIT2_VERSION).dylib
HAS_BREW := $(shell brew --version 2>/dev/null)
endif
cmake:
ifeq (debian,$(XX_VENDOR))
cmake:
apt-get update && apt-get install --no-install-recommends -y clang cmake
endif
.PHONY: cmake
base:
ifeq (debian,$(XX_VENDOR))
base:
xx-apt update && xx-apt install --no-install-recommends -y binutils gcc libc6-dev dpkg-dev
endif
.PHONY: base
dependencies: base
ifeq (debian,$(XX_VENDOR))
# Install libssh2 for $TARGETPLATFORM from "sid", as the version in "bullseye"
# has been linked against gcrypt, which causes issues with PKCS* formats.
# We pull (sub)dependencies from there as well, to ensure all versions are aligned,
# and not accidentially linked to e.g. mbedTLS (which has limited support for
# certain key formats).
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
# Ref: https://github.com/ARMmbed/mbedtls/issues/2452#issuecomment-802683144
DEPENDENCIES =
ifneq ("OFF",$(USE_BUNDLED_ZLIB))
DEPENDENCIES += zlib1g-dev
endif
ifneq ("OFF",$(USE_HTTPS))
DEPENDENCIES += libssl-dev
endif
ifneq ("OFF",$(USE_SSH))
DEPENDENCIES += libssh2-1-dev
endif
dependencies:
ifneq ("",$(DEPENDENCIES))
set -e; \
echo "deb http://deb.debian.org/debian sid main" > /etc/apt/sources.list.d/sid.list \
&& echo "deb-src http://deb.debian.org/debian sid main" /etc/apt/sources.list.d/sid.list \
&& xx-apt update \
&& xx-apt -t sid install --no-install-recommends -y $(DEPENDENCIES)
endif
endif
.PHONY: dependencies
libgit2: $(LIBGIT2)
.PHONY: libgit2
ifdef HAS_BREW
ifneq ("OFF",$(USE_HTTPS))
HAS_OPENSSL := $(shell brew --prefix [email protected])
# NB: the OPENSSL_LDFLAGS ensures the path is included in the libgit2.pc
# file. As a standard brew installation doesn't appear to be system wide
# on most macOS instances, and we thus have to explicitly tell where
# it can be found.
ifdef HAS_OPENSSL
PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(HAS_OPENSSL)/lib/pkgconfig
FLAGS += -DOPENSSL_LDFLAGS:STRING='-L $(HAS_OPENSSL)/lib'
endif
endif
ifneq ("OFF",$(USE_SSH))
HAS_LIBSSH2 := $(shell brew --prefix libssh2)
ifdef HAS_LIBSSH2
PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(HAS_LIBSSH2)/lib/pkgconfig
endif
endif
endif
$(LIBGIT2):
set -e; \
SETUP_LIBGIT2_TMP_DIR=$$(mktemp -d) \
&& curl -L $(LIBGIT2_DOWNLOAD_URL) -o $$SETUP_LIBGIT2_TMP_DIR/archive.tar.gz \
&& mkdir -p $$SETUP_LIBGIT2_TMP_DIR/src \
&& tar xzf $$SETUP_LIBGIT2_TMP_DIR/archive.tar.gz --strip 1 -C $$SETUP_LIBGIT2_TMP_DIR/src \
&& PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) cmake -S $$SETUP_LIBGIT2_TMP_DIR/src -B $$SETUP_LIBGIT2_TMP_DIR/build \
-DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE)\
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
-DCMAKE_C_FLAGS=-fPIC \
-DDEPRECATE_HARD=ON \
-DCMAKE_INSTALL_PREFIX:PATH=$(INSTALL_PREFIX) \
-DCMAKE_INSTALL_LIBDIR:PATH=$(INSTALL_LIBDIR) \
-DBUILD_CLAR:BOOL:BOOL=OFF \
-DTHREADSAFE:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=$(BUILD_SHARED_LIBS) \
-DUSE_BUNDLED_ZLIB:BOOL=$(USE_BUNDLED_ZLIB) \
-DUSE_HTTP_PARSER:STRING=builtin \
-DREGEX_BACKEND:STRING=builtin \
-DUSE_HTTPS:STRING=$(USE_HTTPS) \
-DUSE_SSH:BOOL=$(USE_SSH) \
$(FLAGS) \
&& cmake --build $$SETUP_LIBGIT2_TMP_DIR/build --target install \
&& rm -rf $$SETUP_LIBGIT2_TMP_DIR