github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/Makefile (about)

     1  #
     2  # Copyright (c) 2019 Intel Corporation
     3  #
     4  # SPDX-License-Identifier: Apache-2.0
     5  #
     6  
     7  PREFIX := /usr
     8  BIN_DIR := $(PREFIX)/bin
     9  VC_BIN_DIR := $(BIN_DIR)/virtcontainers/bin
    10  TEST_BIN_DIR := $(VC_BIN_DIR)/test
    11  HOOK_DIR := hook/mock
    12  HOOK_BIN := hook
    13  KATA_SHIM_DIR := shim/mock/kata-shim
    14  KATA_SHIM_BIN := kata-shim
    15  MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
    16  
    17  #
    18  # Pretty printing
    19  #
    20  
    21  V	      = @
    22  Q	      = $(V:1=)
    23  QUIET_GOBUILD = $(Q:@=@echo    '     GOBUILD  '$@;)
    24  
    25  #
    26  # Build
    27  #
    28  
    29  all: build binaries
    30  
    31  build:
    32  	$(QUIET_GOBUILD)go build $(go list ./... | grep -v /vendor/)
    33  
    34  hook:
    35  	$(QUIET_GOBUILD)go build -o $(HOOK_DIR)/$@ $(HOOK_DIR)/*.go
    36  
    37  kata-shim:
    38  	$(QUIET_GOBUILD)go build -o $(KATA_SHIM_DIR)/$@ $(KATA_SHIM_DIR)/*.go
    39  
    40  binaries: hook kata-shim
    41  
    42  #
    43  # Tests
    44  #
    45  
    46  check: check-go-static check-go-test
    47  
    48  check-go-static:
    49  	bash $(MK_DIR)/../.ci/static-checks.sh
    50  
    51  check-go-test:
    52  	bash $(MK_DIR)/../.ci/go-test.sh \
    53  		$(TEST_BIN_DIR)/$(KATA_SHIM_BIN) \
    54  		$(TEST_BIN_DIR)/$(HOOK_BIN)
    55  
    56  #
    57  # Install
    58  #
    59  
    60  define INSTALL_EXEC
    61  	install -D $1 $(VC_BIN_DIR)/ || exit 1;
    62  endef
    63  
    64  define INSTALL_TEST_EXEC
    65  	install -D $1 $(TEST_BIN_DIR)/ || exit 1;
    66  endef
    67  
    68  install:
    69  	@mkdir -p $(VC_BIN_DIR)
    70  	@mkdir -p $(TEST_BIN_DIR)
    71  	$(call INSTALL_TEST_EXEC,$(HOOK_DIR)/$(HOOK_BIN))
    72  	$(call INSTALL_TEST_EXEC,$(KATA_SHIM_DIR)/$(KATA_SHIM_BIN))
    73  
    74  #
    75  # Uninstall
    76  #
    77  
    78  define UNINSTALL_EXEC
    79  	rm -f $(call FILE_SAFE_TO_REMOVE,$(VC_BIN_DIR)/$1) || exit 1;
    80  endef
    81  
    82  define UNINSTALL_TEST_EXEC
    83  	rm -f $(call FILE_SAFE_TO_REMOVE,$(TEST_BIN_DIR)/$1) || exit 1;
    84  endef
    85  
    86  uninstall:
    87  	$(call UNINSTALL_TEST_EXEC,$(HOOK_BIN))
    88  	$(call UNINSTALL_TEST_EXEC,$(KATA_SHIM_BIN))
    89  
    90  #
    91  # Clean
    92  #
    93  
    94  # Input: filename to check.
    95  # Output: filename, assuming the file exists and is safe to delete.
    96  define FILE_SAFE_TO_REMOVE =
    97  $(shell test -e "$(1)" && test "$(1)" != "/" && echo "$(1)")
    98  endef
    99  
   100  CLEAN_FILES += $(HOOK_DIR)/$(HOOK_BIN)
   101  CLEAN_FILES += $(SHIM_DIR)/$(KATA_SHIM_BIN)
   102  
   103  clean:
   104  	rm -f $(foreach f,$(CLEAN_FILES),$(call FILE_SAFE_TO_REMOVE,$(f)))
   105  
   106  .PHONY: \
   107  	all \
   108  	build \
   109  	hook \
   110  	shim \
   111  	binaries \
   112  	check \
   113  	check-go-static \
   114  	check-go-test \
   115  	install \
   116  	uninstall \
   117  	clean