Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright 2016 The Kubernetes Authors.
  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. .PHONY: all push container clean orphan all-push push-manifest
  15. include ../../hack/make-rules/Makefile.manifest
  16. REGISTRY ?= staging-k8s.gcr.io
  17. IMAGE = $(REGISTRY)/pause
  18. IMAGE_WITH_ARCH = $(IMAGE)-$(ARCH)
  19. TAG = 3.1
  20. REV = $(shell git describe --contains --always --match='v*')
  21. # Architectures supported: amd64, arm, arm64, ppc64le and s390x
  22. ARCH ?= amd64
  23. ALL_ARCH = amd64 arm arm64 ppc64le s390x
  24. CFLAGS = -Os -Wall -Werror -static -DVERSION=v$(TAG)-$(REV)
  25. KUBE_CROSS_IMAGE ?= k8s.gcr.io/kube-cross
  26. KUBE_CROSS_VERSION ?= $(shell cat ../build-image/cross/VERSION)
  27. BIN = pause
  28. SRCS = pause.c
  29. ifeq ($(ARCH),amd64)
  30. TRIPLE ?= x86_64-linux-gnu
  31. endif
  32. ifeq ($(ARCH),arm)
  33. TRIPLE ?= arm-linux-gnueabihf
  34. endif
  35. ifeq ($(ARCH),arm64)
  36. TRIPLE ?= aarch64-linux-gnu
  37. endif
  38. ifeq ($(ARCH),ppc64le)
  39. TRIPLE ?= powerpc64le-linux-gnu
  40. endif
  41. ifeq ($(ARCH),s390x)
  42. TRIPLE ?= s390x-linux-gnu
  43. endif
  44. # If you want to build AND push all containers, see the 'all-push' rule.
  45. all: all-container
  46. all-push: all-push-images push-manifest
  47. push-manifest: manifest-tool
  48. manifest-tool push from-args --platforms $(call join_platforms,$(ALL_ARCH)) --template $(IMAGE)-ARCH:$(TAG) --target $(IMAGE):$(TAG)
  49. sub-container-%:
  50. $(MAKE) ARCH=$* container
  51. sub-push-%:
  52. $(MAKE) ARCH=$* push
  53. all-container: $(addprefix sub-container-,$(ALL_ARCH))
  54. all-push-images: $(addprefix sub-push-,$(ALL_ARCH))
  55. build: bin/$(BIN)-$(ARCH)
  56. bin/$(BIN)-$(ARCH): $(SRCS)
  57. mkdir -p bin
  58. docker run --rm -u $$(id -u):$$(id -g) -v $$(pwd):/build \
  59. $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \
  60. /bin/bash -c "\
  61. cd /build && \
  62. $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \
  63. $(TRIPLE)-strip $@"
  64. container: .container-$(ARCH)
  65. .container-$(ARCH): bin/$(BIN)-$(ARCH)
  66. docker build --pull -t $(IMAGE_WITH_ARCH):$(TAG) --build-arg ARCH=$(ARCH) .
  67. touch $@
  68. push: .push-$(ARCH)
  69. .push-$(ARCH): .container-$(ARCH)
  70. docker push $(IMAGE_WITH_ARCH):$(TAG)
  71. touch $@
  72. # Useful for testing, not automatically included in container image
  73. orphan: bin/orphan-$(ARCH)
  74. bin/orphan-$(ARCH): orphan.c
  75. mkdir -p bin
  76. docker run -u $$(id -u):$$(id -g) -v $$(pwd):/build \
  77. $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \
  78. /bin/bash -c "\
  79. cd /build && \
  80. $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \
  81. $(TRIPLE)-strip $@"
  82. clean:
  83. rm -rf .container-* .push-* bin/