|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2021 The Stdlib Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +#/ |
| 18 | + |
| 19 | +# VARIABLES # |
| 20 | + |
| 21 | +# Define the download URL... |
| 22 | +ifeq ($(OS), WINNT) |
| 23 | + DEPS_CPPCHECK_URL ?= https://github.com/danmar/cppcheck/archive/$(DEPS_CPPCHECK_VERSION).zip |
| 24 | +else |
| 25 | + DEPS_CPPCHECK_URL ?= https://github.com/danmar/cppcheck/archive/$(DEPS_CPPCHECK_VERSION).tar.gz |
| 26 | +endif |
| 27 | + |
| 28 | +# Determine the basename for the download: |
| 29 | +deps_cppcheck_basename := $(notdir $(DEPS_CPPCHECK_URL)) |
| 30 | + |
| 31 | +# Define the path to the file containing a checksum to verify a download: |
| 32 | +DEPS_CPPCHECK_CHECKSUM ?= $(shell $(CAT) $(DEPS_CHECKSUMS_DIR)/cppcheck_v$(subst .,_,$(subst -,_,$(deps_cppcheck_basename)))/sha256) |
| 33 | + |
| 34 | +# Define the output path when downloading: |
| 35 | +DEPS_CPPCHECK_DOWNLOAD_OUT ?= $(DEPS_TMP_DIR)/cppcheck-v$(deps_cppcheck_basename) |
| 36 | + |
| 37 | +# Define the output path after extracting: |
| 38 | +deps_cppcheck_extract_out := $(DEPS_BUILD_DIR)/cppcheck-$(DEPS_CPPCHECK_VERSION) |
| 39 | + |
| 40 | +# Define the path to the `cppcheck` executable... |
| 41 | +ifeq ($(DEPS_CPPCHECK_PLATFORM), win32) |
| 42 | + CPPCHECK ?= $(DEPS_CPPCHECK_BUILD_OUT)/cppcheck.exe |
| 43 | +else |
| 44 | + CPPCHECK ?= $(DEPS_CPPCHECK_BUILD_OUT)/cppcheck |
| 45 | +endif |
| 46 | + |
| 47 | +# Define rule prerequisites... |
| 48 | +deps_cppcheck_test_prereqs := $(DEPS_CPPCHECK_BUILD_OUT) |
| 49 | +deps_cppcheck_install_prereqs := deps-download-cppcheck deps-verify-cppcheck deps-extract-cppcheck deps-install-cppcheck deps-test-cppcheck |
| 50 | + |
| 51 | + |
| 52 | +# RULES # |
| 53 | + |
| 54 | +#/ |
| 55 | +# Downloads a `cppcheck` distribution. |
| 56 | +# |
| 57 | +# @private |
| 58 | +#/ |
| 59 | +$(DEPS_CPPCHECK_DOWNLOAD_OUT): | $(DEPS_TMP_DIR) |
| 60 | + $(QUIET) echo 'Downloading cppcheck...' >&2 |
| 61 | + $(QUIET) $(DEPS_DOWNLOAD_BIN) $(DEPS_CPPCHECK_URL) $(DEPS_CPPCHECK_DOWNLOAD_OUT) |
| 62 | + |
| 63 | +#/ |
| 64 | +# Extracts a `cppcheck` archive. |
| 65 | +# |
| 66 | +# @private |
| 67 | +#/ |
| 68 | +$(DEPS_CPPCHECK_BUILD_OUT): $(DEPS_CPPCHECK_DOWNLOAD_OUT) | $(DEPS_BUILD_DIR) |
| 69 | +ifeq ($(OS), WINNT) |
| 70 | + $(QUIET) echo 'Extracting cppcheck...' >&2 |
| 71 | + $(QUIET) $(UNZIP) -q $(DEPS_CPPCHECK_DOWNLOAD_OUT) -d $@ |
| 72 | +else |
| 73 | + $(QUIET) echo 'Extracting cppcheck...' >&2 |
| 74 | + $(QUIET) $(TAR) --xz -xvf $(DEPS_CPPCHECK_DOWNLOAD_OUT) -C $(DEPS_BUILD_DIR) |
| 75 | + $(QUIET) mv $(deps_cppcheck_extract_out) $(DEPS_CPPCHECK_BUILD_OUT) |
| 76 | +endif |
| 77 | + |
| 78 | +#/ |
| 79 | +# Downloads cppcheck. |
| 80 | +# |
| 81 | +# @private |
| 82 | +# |
| 83 | +# @example |
| 84 | +# make deps-download-cppcheck |
| 85 | +#/ |
| 86 | +deps-download-cppcheck: $(DEPS_CPPCHECK_DOWNLOAD_OUT) |
| 87 | + |
| 88 | +.PHONY: deps-download-cppcheck |
| 89 | + |
| 90 | +#/ |
| 91 | +# Verifies a `cppcheck` download. |
| 92 | +# |
| 93 | +# @private |
| 94 | +# |
| 95 | +# @example |
| 96 | +# make deps-verify-cppcheck |
| 97 | +#/ |
| 98 | +deps-verify-cppcheck: deps-download-cppcheck |
| 99 | + $(QUIET) echo 'Verifying download...' >&2 |
| 100 | + $(QUIET) $(DEPS_CHECKSUM_BIN) $(DEPS_CPPCHECK_DOWNLOAD_OUT) $(DEPS_CPPCHECK_CHECKSUM) >&2 |
| 101 | + |
| 102 | +.PHONY: deps-verify-cppcheck |
| 103 | + |
| 104 | +#/ |
| 105 | +# Extracts a `cppcheck` download. |
| 106 | +# |
| 107 | +# @private |
| 108 | +# |
| 109 | +# @example |
| 110 | +# make deps-extract-cppcheck |
| 111 | +#/ |
| 112 | +deps-extract-cppcheck: $(DEPS_CPPCHECK_BUILD_OUT) |
| 113 | + |
| 114 | +.PHONY: deps-extract-cppcheck |
| 115 | + |
| 116 | +#/ |
| 117 | +# Installs `cppcheck`. |
| 118 | +# |
| 119 | +# @private |
| 120 | +# |
| 121 | +# @example |
| 122 | +# make deps-install-cppcheck |
| 123 | +#/ |
| 124 | +deps-install-cppcheck: $(DEPS_CPPCHECK_BUILD_OUT) |
| 125 | + $(QUIET) $(MAKE) --directory="$(DEPS_CPPCHECK_BUILD_OUT)" |
| 126 | + |
| 127 | +.PHONY: deps-install-cppcheck |
| 128 | + |
| 129 | +#/ |
| 130 | +# Tests a `cppcheck` installation. |
| 131 | +# |
| 132 | +# @private |
| 133 | +# |
| 134 | +# @example |
| 135 | +# make deps-test-cppcheck |
| 136 | +#/ |
| 137 | +deps-test-cppcheck: $(deps_cppcheck_test_prereqs) |
| 138 | + $(QUIET) echo 'Running tests...' >&2 |
| 139 | + $(QUIET) $(CPPCHECK) --version >&2 |
| 140 | + $(QUIET) echo '' >&2 |
| 141 | + $(QUIET) echo 'Success.' >&2 |
| 142 | + |
| 143 | +.PHONY: deps-test-cppcheck |
| 144 | + |
| 145 | +#/ |
| 146 | +# Installs `cppcheck`. |
| 147 | +# |
| 148 | +# @example |
| 149 | +# make install-deps-cppcheck |
| 150 | +#/ |
| 151 | +install-deps-cppcheck: $(deps_cppcheck_install_prereqs) |
| 152 | + |
| 153 | +.PHONY: install-deps-cppcheck |
| 154 | + |
| 155 | +#/ |
| 156 | +# Removes a `cppcheck` distribution (but does not remove a `cppcheck` download if one exists). |
| 157 | +# |
| 158 | +# @example |
| 159 | +# make clean-deps-cppcheck |
| 160 | +#/ |
| 161 | +clean-deps-cppcheck: |
| 162 | + $(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_CPPCHECK_BUILD_OUT) |
| 163 | + |
| 164 | +.PHONY: clean-deps-cppcheck |
0 commit comments