Skip to content

Commit

Permalink
Merge pull request docker#1991 from dmp42/01-carry-on-build-tweaks
Browse files Browse the repository at this point in the history
Add simpler make targets and fix Windows build
  • Loading branch information
nathanleclaire committed Oct 15, 2015
2 parents 600ffb7 + 3e2e3d0 commit a63f26f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
14 changes: 9 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 17 additions & 9 deletions mk/build.mk
Original file line number Diff line number Diff line change
@@ -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) ????
$(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
$(GO) build -o $@ $(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)))
# Independent targets for every bin
$(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
$(GO) build -o $@$(call extension,$(GOOS)) $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<

# 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)))
12 changes: 10 additions & 2 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a63f26f

Please sign in to comment.