common.mk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright 2016 The Rook Authors. All rights reserved.
  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. # remove default suffixes as we dont use them
  15. .SUFFIXES:
  16. SHELL := /usr/bin/env bash
  17. ifneq (, $(shell command -v shasum))
  18. SHA256CMD := shasum -a 256
  19. else ifneq (, $(shell command -v sha256sum))
  20. SHA256CMD := sha256sum
  21. else
  22. $(error "please install 'shasum' or 'sha256sum'")
  23. endif
  24. ifeq ($(origin DOCKERCMD),undefined)
  25. DOCKERCMD?=$(shell docker version >/dev/null 2>&1 && echo docker)
  26. ifeq ($(DOCKERCMD),)
  27. DOCKERCMD=$(shell podman version >/dev/null 2>&1 && echo podman)
  28. endif
  29. endif
  30. ifeq ($(origin PLATFORM), undefined)
  31. ifeq ($(origin GOOS), undefined)
  32. GOOS := $(shell go env GOOS)
  33. endif
  34. ifeq ($(origin GOARCH), undefined)
  35. GOARCH := $(shell go env GOARCH)
  36. endif
  37. PLATFORM := $(GOOS)_$(GOARCH)
  38. else
  39. GOOS := $(word 1, $(subst _, ,$(PLATFORM)))
  40. GOARCH := $(word 2, $(subst _, ,$(PLATFORM)))
  41. export GOOS GOARCH
  42. endif
  43. ALL_PLATFORMS ?= darwin_amd64 darwin_arm64 windows_amd64 linux_amd64 linux_arm64
  44. export GOARM
  45. # force the build of a linux binary when running on MacOS
  46. GOHOSTOS=linux
  47. GOHOSTARCH := $(shell go env GOHOSTARCH)
  48. HOST_PLATFORM := $(GOHOSTOS)_$(GOHOSTARCH)
  49. # REAL_HOST_PLATFORM is used to determine the correct url to download the various binary tools from and it does not use
  50. # HOST_PLATFORM which is used to build the program.
  51. REAL_HOST_PLATFORM=$(shell go env GOHOSTOS)_$(GOHOSTARCH)
  52. # set the version number. you should not need to do this
  53. # for the majority of scenarios.
  54. ifeq ($(origin VERSION), undefined)
  55. VERSION := $(shell git describe --dirty --always --tags | sed 's/-/./2' | sed 's/-/./2' )
  56. endif
  57. export VERSION
  58. # include the common make file
  59. COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
  60. ifeq ($(origin ROOT_DIR),undefined)
  61. ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/../.. && pwd -P))
  62. endif
  63. ifeq ($(origin OUTPUT_DIR),undefined)
  64. OUTPUT_DIR := $(ROOT_DIR)/_output
  65. endif
  66. ifeq ($(origin WORK_DIR), undefined)
  67. WORK_DIR := $(ROOT_DIR)/.work
  68. endif
  69. ifeq ($(origin CACHE_DIR), undefined)
  70. CACHE_DIR := $(ROOT_DIR)/.cache
  71. endif
  72. TOOLS_DIR := $(CACHE_DIR)/tools
  73. TOOLS_HOST_DIR := $(TOOLS_DIR)/$(HOST_PLATFORM)
  74. ifeq ($(origin HOSTNAME), undefined)
  75. HOSTNAME := $(shell hostname)
  76. endif
  77. # a registry that is scoped to the current build tree on this host
  78. ifeq ($(origin BUILD_REGISTRY), undefined)
  79. BUILD_REGISTRY := build-$(shell echo "$(HOSTNAME)-$(ROOT_DIR)" | $(SHA256CMD) | cut -c1-8)
  80. endif
  81. ifeq ($(BUILD_REGISTRY),build-)
  82. $(error Failed to get unique ID for host+dir. Check that '$(SHA256CMD)' functions or override SHA256CMD)
  83. endif
  84. SED_IN_PLACE = $(ROOT_DIR)/build/sed-in-place
  85. export SED_IN_PLACE
  86. # This is a neat little target that prints any variable value from the Makefile
  87. # Usage: make echo.IMAGES echo.PLATFORM
  88. echo.%: ; @echo $* = $($*)
  89. # Select which images (backends) to make; default to all possible images
  90. IMAGES ?= ceph
  91. COMMA := ,
  92. SPACE :=
  93. SPACE +=
  94. # define a newline
  95. define \n
  96. endef