forked from fluxcd/source-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: fluxcd#515 (comment) Signed-off-by: Sanskar Jaiswal <[email protected]> Signed-off-by: pa250194 <[email protected]>
- Loading branch information
Showing
1 changed file
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,12 @@ endif | |
|
||
ifeq ($(shell uname -s),Darwin) | ||
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.$(LIBGIT2_VERSION).dylib | ||
HAS_BREW := $(shell brew --version 2>/dev/null) | ||
ifdef HAS_BREW | ||
HAS_OPENSSL := $(shell brew --prefix [email protected]) | ||
endif | ||
endif | ||
|
||
|
||
# API (doc) generation utilities | ||
CONTROLLER_GEN_VERSION ?= v0.5.0 | ||
|
@@ -52,23 +57,53 @@ else | |
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
ifeq ($(strip ${PKG_CONFIG_PATH}),) | ||
MAKE_PKG_CONFIG_PATH = $(LIBGIT2_LIB_PATH)/pkgconfig | ||
else | ||
MAKE_PKG_CONFIG_PATH = ${PKG_CONFIG_PATH}:$(LIBGIT2_LIB_PATH)/pkgconfig | ||
endif | ||
|
||
ifdef HAS_OPENSSL | ||
MAKE_PKG_CONFIG_PATH := $(MAKE_PKG_CONFIG_PATH):$(HAS_OPENSSL)/lib/pkgconfig | ||
endif | ||
|
||
all: build | ||
|
||
build: $(LIBGIT2) ## Build manager binary | ||
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \ | ||
ifeq ($(shell uname -s),Darwin) | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go build -o bin/manager main.go | ||
else | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
go build -o bin/manager main.go | ||
endif | ||
|
||
test: $(LIBGIT2) test-api ## Run tests | ||
ifeq ($(shell uname -s),Darwin) | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \ | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go test ./... -coverprofile cover.out | ||
else | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
go test ./... -coverprofile cover.out | ||
endif | ||
|
||
test-api: ## Run api tests | ||
cd api; go test ./... -coverprofile cover.out | ||
|
||
run: $(LIBGIT2) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config | ||
ifeq ($(shell uname -s),Darwin) | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go run ./main.go | ||
else | ||
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \ | ||
go run ./main.go | ||
endif | ||
|
||
|
||
install: manifests ## Install CRDs into a cluster | ||
kustomize build config/crd | kubectl apply -f - | ||
|
@@ -102,9 +137,16 @@ fmt: ## Run go fmt against code | |
cd api; go fmt ./... | ||
|
||
vet: $(LIBGIT2) ## Run go vet against code | ||
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig \ | ||
ifeq ($(shell uname -s),Darwin) | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
CGO_LDFLAGS="-Wl,-rpath,$(LIBGIT2_LIB_PATH)" \ | ||
go vet ./... | ||
cd api; go vet ./... | ||
else | ||
PKG_CONFIG_PATH=$(MAKE_PKG_CONFIG_PATH) \ | ||
go vet ./... | ||
cd api; go vet ./... | ||
endif | ||
|
||
generate: controller-gen ## Generate API code | ||
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..." | ||
|