Makefile 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15 16 17
# Use the native vendor/ dependency system
export GO15VENDOREXPERIMENT=1

18 19 20
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
BUILD_DIR ?= ./out
21 22
REPOPATH ?= k8s.io/minikube
BUILD_IMAGE ?= gcr.io/google_containers/kube-cross:v1.6.2-1
D
Dan Lorenc 已提交
23 24 25 26

ifeq ($(IN_DOCKER),1)
	GOPATH := /go
else
27
	GOPATH := $(shell pwd)/_gopath
D
Dan Lorenc 已提交
28 29
endif

30 31 32

# Use system python if it exists, otherwise use Docker.
PYTHON := $(shell command -v python || docker run --rm -it -v $(shell pwd):/minikube -w /minikube python python)
33
# Set the version information for the Kubernetes servers, and build localkube statically
34
VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py)
35
LDFLAGS := "$(VERSION_LDFLAGS) -s -w -extldflags '-static'"
36

37 38 39
clean:
	rm -rf $(GOPATH)
	rm -rf $(BUILD_DIR)
D
Dan Lorenc 已提交
40
	rm pkg/minikube/cluster/localkubecontents.go
41

42 43 44
MKGOPATH := mkdir -p $(shell dirname $(GOPATH)/src/$(REPOPATH)) && ln -s -f $(shell pwd) $(GOPATH)/src/$(REPOPATH)
LOCALKUBEFILES := $(shell find pkg/localkube -name '*.go') $(shell find cmd/localkube -name '*.go') $(shell find vendor -name '*.go')
MINIKUBEFILES := $(shell find pkg/minikube -name '*.go') $(shell find cmd/minikube -name '*.go') $(shell find vendor -name '*.go')
45

46
out/minikube: out/minikube-$(GOOS)-$(GOARCH)
47 48
	cp $(BUILD_DIR)/minikube-$(GOOS)-$(GOARCH) $(BUILD_DIR)/minikube

49 50
out/localkube: $(LOCALKUBEFILES)
	$(MKGOPATH)
51
ifeq ($(GOOS),linux)
52
	CGO_ENABLED=1 go build -ldflags=$(LDFLAGS) -o $(BUILD_DIR)/localkube ./cmd/localkube
53
else
54
	docker run -w /go/src/$(REPOPATH) -e IN_DOCKER=1 -v $(shell pwd):/go/src/$(REPOPATH) $(BUILD_IMAGE) make out/localkube
55
endif
56

57 58
out/minikube-$(GOOS)-$(GOARCH): $(MINIKUBEFILES) pkg/minikube/cluster/localkubecontents.go
	$(MKGOPATH)
59
	CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build --installsuffix cgo -a -o $(BUILD_DIR)/minikube-$(GOOS)-$(GOARCH) ./cmd/minikube
60

D
dlorenc 已提交
61
.PHONY: integration
62
integration: out/minikube
63
	go test -v ./test/integration --tags=integration
64 65

.PHONY: test
66 67
test: pkg/minikube/cluster/localkubecontents.go
	$(MKGOPATH)
D
dlorenc 已提交
68
	./test.sh
69

D
Dan Lorenc 已提交
70
pkg/minikube/cluster/localkubecontents.go: out/localkube $(GOPATH)/bin/go-bindata
D
Dan Lorenc 已提交
71 72
	$(GOPATH)/bin/go-bindata -nomemcopy -o pkg/minikube/cluster/localkubecontents.go -pkg cluster ./out/localkube

73 74
$(GOPATH)/bin/go-bindata:
	$(MKGOPATH)
D
Dan Lorenc 已提交
75
	go get github.com/jteeuwen/go-bindata/...