|
| 1 | +# © Copyright IBM Corporation 2018 |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +############################################################################### |
| 16 | +# Conditional variables - you can override the values of these variables from |
| 17 | +# the command line |
| 18 | +############################################################################### |
| 19 | +# BASE_IMAGE is the MQ SDK base image to use |
| 20 | +BASE_IMAGE ?= mq-sdk:9.0.5.0-x86_64-ubuntu-16.04 |
| 21 | +# GO_IMAGE is the GOLANG image to use for building samples |
| 22 | +GO_IMAGE ?= golang:1.10 |
| 23 | +# DOCKER is the Docker command to run |
| 24 | +DOCKER ?= docker |
| 25 | +# BUILD_IMAGE is the name of the image that will be produced while building packages |
| 26 | +BUILD_IMAGE ?= mq-golang-build:9.0.5.0-x86_64-ubuntu-16.04 |
| 27 | +# SAMPLE_BUILD_IMAGE is the name of the image that will be produced while building samples |
| 28 | +SAMPLE_BUILD_IMAGE ?= mq-sample-build:9.0.5.0-x86_64-ubuntu-16.04 |
| 29 | + |
| 30 | +############################################################################### |
| 31 | +# Other variables |
| 32 | +############################################################################### |
| 33 | + |
| 34 | +ifneq (,$(findstring Microsoft,$(shell uname -r))) |
| 35 | + PLATFORM=WINDOWS |
| 36 | +else |
| 37 | + PLATFORM=UNIX |
| 38 | +endif |
| 39 | + |
| 40 | +############################################################################### |
| 41 | +# Build targets |
| 42 | +############################################################################### |
| 43 | + |
| 44 | +# Build all packages when on unix |
| 45 | +.PHONY: all |
| 46 | +ifeq ("$(PLATFORM)", "WINDOWS") |
| 47 | +all: unsupported-message |
| 48 | +else |
| 49 | +all: build-packages-unix build-samples-unix |
| 50 | +endif |
| 51 | + |
| 52 | +.PHONY: clean |
| 53 | +clean: |
| 54 | + $(DOCKER) rmi -f $(BUILD_IMAGE) |
| 55 | + $(DOCKER) rmi -f $(SAMPLE_BUILD_IMAGE) |
| 56 | + |
| 57 | +.PHONY: build-packages-unix |
| 58 | +build-packages-unix: |
| 59 | + $(info $(SPACER)$(shell printf $(TITLE)"Building packages in build container"$(END))) |
| 60 | + $(call docker-build,$(BUILD_IMAGE),Dockerfile-build-packages,$(BASE_IMAGE)) |
| 61 | + |
| 62 | +.PHONY: build-samples-unix |
| 63 | +build-samples-unix: build-packages-unix |
| 64 | + $(info $(SPACER)$(shell printf $(TITLE)"Building samples in build container"$(END))) |
| 65 | + $(call docker-build,$(SAMPLE_BUILD_IMAGE),Dockerfile-build-samples,$(BUILD_IMAGE)) |
| 66 | + |
| 67 | +.PHONY: unsupported-message |
| 68 | +unsupported-message: |
| 69 | + $(info $(SPACER)$(shell printf $(TITLE)"This makefile can only be ran on UNIX platforms"$(END))) |
| 70 | + |
| 71 | +define docker-build |
| 72 | + # Build the image first to compile the package/samples |
| 73 | + $(DOCKER) build -t $1 \ |
| 74 | + -f $2 \ |
| 75 | + --build-arg BASE_IMAGE=$3 \ |
| 76 | + . |
| 77 | +endef |
| 78 | + |
| 79 | +include formatting.mk |
0 commit comments