Skip to content

Commit d174bc9

Browse files
author
Sanskar Jaiswal
committed
fix potentially broken support for macos
macOS support is broken for users who rely on the Makefile to install libgit2 for them. libgit2.1.1.dylib could not be dynamically linked at runtime because it couldn't be found. This patch makes the following changes to the Makefile: 1) Respects the user's PKG_CONFIG_PATH present in the env so that both libgit2.pc and openssl.pc are discoverable. 2) Embeds the required rpath in the binary at compile time, so that libgit2.1.1.dylib can be found at runtime. For more info see: #515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 3f5da11 commit d174bc9

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

Makefile

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ endif
3939

4040
ifeq ($(shell uname -s),Darwin)
4141
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.$(LIBGIT2_VERSION).dylib
42+
HAS_BREW := $(shell brew --version 2>/dev/null)
43+
ifdef HAS_BREW
44+
HAS_OPENSSL := $(shell brew --prefix [email protected])
4245
endif
46+
endif
47+
4348

4449
# API (doc) generation utilities
4550
CONTROLLER_GEN_VERSION ?= v0.5.0
@@ -52,23 +57,53 @@ else
5257
GOBIN=$(shell go env GOBIN)
5358
endif
5459

60+
ifeq ($(strip ${PKG_CONFIG_PATH}),)
61+
MAKE_PKG_CONFIG_PATH = $(LIBGIT2_LIB_PATH)/pkgconfig
62+
else
63+
MAKE_PKG_CONFIG_PATH = ${PKG_CONFIG_PATH}:$(LIBGIT2_LIB_PATH)/pkgconfig
64+
endif
65+
66+
ifdef HAS_OPENSSL
67+
MAKE_PKG_CONFIG_PATH := $(MAKE_PKG_CONFIG_PATH):$(HAS_OPENSSL)/lib/pkgconfig
68+
endif
69+
5570
all: build
5671

5772
build: $(LIBGIT2) ## Build manager binary
58-
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \
73+
ifeq ($(shell uname -s),Darwin)
74+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
75+
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
76+
go build -o bin/manager main.go
77+
else
78+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
5979
go build -o bin/manager main.go
80+
endif
6081

6182
test: $(LIBGIT2) test-api ## Run tests
83+
ifeq ($(shell uname -s),Darwin)
6284
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
63-
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \
85+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
86+
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
6487
go test ./... -coverprofile cover.out
88+
else
89+
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
90+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
91+
go test ./... -coverprofile cover.out
92+
endif
6593

6694
test-api: ## Run api tests
6795
cd api; go test ./... -coverprofile cover.out
6896

6997
run: $(LIBGIT2) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
98+
ifeq ($(shell uname -s),Darwin)
7099
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
100+
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
71101
go run ./main.go
102+
else
103+
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
104+
go run ./main.go
105+
endif
106+
72107

73108
install: manifests ## Install CRDs into a cluster
74109
kustomize build config/crd | kubectl apply -f -
@@ -102,9 +137,16 @@ fmt: ## Run go fmt against code
102137
cd api; go fmt ./...
103138

104139
vet: $(LIBGIT2) ## Run go vet against code
105-
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig \
140+
ifeq ($(shell uname -s),Darwin)
141+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
142+
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \
143+
go vet ./...
144+
cd api; go vet ./...
145+
else
146+
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \
106147
go vet ./...
107148
cd api; go vet ./...
149+
endif
108150

109151
generate: controller-gen ## Generate API code
110152
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..."

0 commit comments

Comments
 (0)