Merge pull request #1991 from dmp42/01-carry-on-build-tweaks

Add simpler make targets and fix Windows build
This commit is contained in:
Nathan LeClaire 2015-10-15 16:43:01 -07:00
commit a63f26f438
5 changed files with 38 additions and 18 deletions

View File

@ -95,19 +95,23 @@ This will generate and open the report file:
make test
make validate
### Build targets
### Advanced build targets
Just build the machine binary itself:
Just build the machine binary itself (native):
make `pwd`/bin/docker-machine
make machine
Just build the plugins (native):
make plugins
Build for all supported oses and architectures (binaries will be in the `bin` project subfolder):
make build-x
make cross
Build for a specific list of oses and architectures:
TARGET_OS=linux TARGET_ARCH="amd64 arm" make build-x
TARGET_OS=linux TARGET_ARCH="amd64 arm" make cross
You can further control build options through the following environment variables:

View File

@ -31,6 +31,6 @@ test: build
make $@
@test ! -d bin || rm -Rf bin
@test -z "$(findstring build,$@)" || docker cp $(DOCKER_CONTAINER_NAME):/go/src/github.com/docker/machine/bin bin
@test -z "$(findstring build,$(patsubst cross,build,$@))" || docker cp $(DOCKER_CONTAINER_NAME):/go/src/github.com/docker/machine/bin bin
endif

View File

@ -29,7 +29,7 @@ dependencies:
test:
pre:
- gvm use stable && go version
- gvm use stable && make build-simple:
- gvm use stable && make build:
pwd: $BASE_STABLE
override:

View File

@ -1,23 +1,31 @@
build-clean:
@rm -Rf $(PREFIX)/bin/*
extension = $(patsubst windows,.exe,$(filter windows,$(1)))
# Cross builder helper
define gocross
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/bin/$(1)-$(2)/docker-$(patsubst cmd/%.go,%,$3) \
-a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) \
-extldflags -static" $(GO_GCFLAGS) $(3);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \
-o $(PREFIX)/bin/$(1)-$(2)/docker-$(patsubst cmd/%.go,%,$3)$(call extension,$(GOOS)) \
-a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo \
-ldflags "$(GO_LDFLAGS) -extldflags -static" $(GO_GCFLAGS) $(3);
endef
# XXX building with -a fails in debug (with -N -l) ????
# Independent targets for every bin
$(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
$(GO) build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<
$(GO) build -o $@$(call extension,$(GOOS)) $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<
# Native build
build-simple: $(patsubst ./cmd/%.go,$(PREFIX)/bin/docker-%,$(filter-out %_test.go, $(wildcard ./cmd/*.go)))
# Cross compilation targets
# Cross-compilation targets
build-x-%: ./cmd/%.go $(shell find . -type f -name '*.go')
@$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GOOS),$(GOARCH),$<)))
# Cross-build
# Build just machine
build-machine: $(PREFIX)/bin/docker-machine
# Build all plugins
build-plugins: $(patsubst ./cmd/%.go,$(PREFIX)/bin/docker-%,$(filter-out %_test.go, $(wildcard ./cmd/machine-driver-*.go)))
# Overall cross-build
build-x: $(patsubst ./cmd/%.go,build-x-%,$(filter-out %_test.go, $(wildcard ./cmd/*.go)))

View File

@ -44,15 +44,23 @@ include mk/release.mk
include mk/test.mk
include mk/validate.mk
.all_build: build build-clean build-x
.all_build: build build-clean build-x build-machine build-plugins
.all_coverage: coverage-generate coverage-html coverage-send coverage-serve coverage-clean
.all_release: release-checksum release
.all_test: test-short test-long test-integration
.all_validate: dco fmt vet lint
default: build
# Build native machine and all drivers
build: build-machine build-plugins
# Just build native machine itself
machine: build-machine
# Just build the native plugins
plugins: build-plugins
# Build all, cross platform
cross: build-x
clean: coverage-clean build-clean
build: build-simple
test: dco fmt vet test-short
validate: dco fmt vet lint test-short test-long