|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2017 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 path to an executable for checking CMake: |
| 22 | +DEPS_CHECK_CMAKE ?= $(TOOLS_DIR)/scripts/check_cmake |
| 23 | + |
| 24 | +# Define the path to an executable for checking git: |
| 25 | +DEPS_CHECK_GIT ?= $(TOOLS_DIR)/scripts/check_git |
| 26 | + |
| 27 | +# Define the path to an executable for checking Python: |
| 28 | +DEPS_CHECK_PYTHON ?= $(TOOLS_DIR)/scripts/check_python |
| 29 | + |
| 30 | +# Define the download URL: |
| 31 | +DEPS_LLVM_URL ?= https://github.com/llvm/llvm-project.git |
| 32 | + |
| 33 | +# Determine the basename for the download: |
| 34 | +deps_llvm_basename := llvm |
| 35 | + |
| 36 | +# Define the path to the file containing a checksum to verify a download: |
| 37 | +DEPS_LLVM_CHECKSUM ?= $(shell $(CAT) $(DEPS_CHECKSUMS_DIR)/$(subst .,_,$(deps_llvm_basename))/sha256) |
| 38 | + |
| 39 | +# Define the output path when downloading: |
| 40 | +DEPS_LLVM_DOWNLOAD_OUT ?= $(DEPS_TMP_DIR)/$(deps_llvm_basename) |
| 41 | + |
| 42 | +# Define the output path after extracting: |
| 43 | +deps_llvm_extract_out := $(DEPS_BUILD_DIR)/llvm_extracted |
| 44 | + |
| 45 | +# Define the path to the directory containing tests: |
| 46 | +DEPS_LLVM_TEST_DIR ?= $(DEPS_DIR)/test/llvm |
| 47 | + |
| 48 | +# Define the output directory path for compiled tests: |
| 49 | +DEPS_LLVM_TEST_OUT ?= $(DEPS_LLVM_TEST_DIR)/build |
| 50 | + |
| 51 | +# Define the path to a test file for checking an installation: |
| 52 | +DEPS_LLVM_TEST_INSTALL ?= $(DEPS_LLVM_TEST_DIR)/test_install.c |
| 53 | + |
| 54 | +# Define output paths for a compiled test file: |
| 55 | +DEPS_LLVM_TEST_INSTALL_WASM_OUT ?= $(DEPS_LLVM_TEST_OUT)/test.wasm |
| 56 | + |
| 57 | + |
| 58 | +# RULES # |
| 59 | + |
| 60 | +#/ |
| 61 | +# Downloads LLVM. |
| 62 | +# |
| 63 | +# @private |
| 64 | +#/ |
| 65 | +$(DEPS_LLVM_DOWNLOAD_OUT): | $(DEPS_TMP_DIR) |
| 66 | + $(QUIET) echo 'Downloading LLVM...' >&2 |
| 67 | + $(QUIET) $(GIT) clone --depth=1 $(DEPS_LLVM_URL) $(DEPS_LLVM_DOWNLOAD_OUT) |
| 68 | + |
| 69 | +#/ |
| 70 | +# Extracts an LLVM download. |
| 71 | +# |
| 72 | +# @private |
| 73 | +#/ |
| 74 | +$(DEPS_LLVM_BUILD_OUT): | $(DEPS_BUILD_DIR) $(DEPS_LLVM_DOWNLOAD_OUT) |
| 75 | + $(QUIET) echo 'Extracting LLVM...' >&2 |
| 76 | + $(QUIET) $(CP) -a $(DEPS_LLVM_DOWNLOAD_OUT) $(deps_llvm_extract_out) |
| 77 | + $(QUIET) mv $(deps_llvm_extract_out) $(DEPS_LLVM_BUILD_OUT) |
| 78 | + |
| 79 | +#/ |
| 80 | +# Creates a directory for storing compiled LLVM tests. |
| 81 | +# |
| 82 | +# @private |
| 83 | +#/ |
| 84 | +$(DEPS_LLVM_TEST_OUT): |
| 85 | + $(QUIET) $(MKDIR_RECURSIVE) $(DEPS_LLVM_TEST_OUT) |
| 86 | + |
| 87 | +#/ |
| 88 | +# Compiles a WebAssembly test file for testing an LLVM installation. |
| 89 | +# |
| 90 | +# @private |
| 91 | +#/ |
| 92 | +$(DEPS_LLVM_TEST_INSTALL_WASM_OUT): $(DEPS_LLVM_BUILD_OUT) $(DEPS_LLVM_TEST_OUT) |
| 93 | + $(QUIET) $(DEPS_LLVM_CLANG) $(DEPS_LLVM_TEST_INSTALL) \ |
| 94 | + --target=wasm32 \ |
| 95 | + --no-standard-libraries \ |
| 96 | + -Wl,--export-all \ |
| 97 | + -Wl,--no-entry \ |
| 98 | + -o $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) |
| 99 | + |
| 100 | +#/ |
| 101 | +# Downloads LLVM. |
| 102 | +# |
| 103 | +# @private |
| 104 | +# |
| 105 | +# @example |
| 106 | +# make deps-download-llvm |
| 107 | +#/ |
| 108 | +deps-download-llvm: $(DEPS_LLVM_DOWNLOAD_OUT) |
| 109 | + |
| 110 | +.PHONY: deps-download-llvm |
| 111 | + |
| 112 | +#/ |
| 113 | +# Verifies an LLVM download. |
| 114 | +# |
| 115 | +# @private |
| 116 | +# |
| 117 | +# @example |
| 118 | +# make deps-verify-llvm |
| 119 | +#/ |
| 120 | +deps-verify-llvm: deps-download-llvm |
| 121 | + $(QUIET) echo 'Verifying download...' >&2 |
| 122 | + $(QUIET) echo 'Nothing to verify.' >&2 |
| 123 | + |
| 124 | +.PHONY: deps-verify-llvm |
| 125 | + |
| 126 | +#/ |
| 127 | +# Extracts an LLVM download. |
| 128 | +# |
| 129 | +# @private |
| 130 | +# |
| 131 | +# @example |
| 132 | +# make deps-extract-llvm |
| 133 | +#/ |
| 134 | +deps-extract-llvm: $(DEPS_LLVM_BUILD_OUT) |
| 135 | + |
| 136 | +.PHONY: deps-extract-llvm |
| 137 | + |
| 138 | +#/ |
| 139 | +# Checks a host system for LLVM installation prerequisites. |
| 140 | +# |
| 141 | +# @private |
| 142 | +# |
| 143 | +# @example |
| 144 | +# make deps-prerequisites-llvm |
| 145 | +#/ |
| 146 | +deps-prerequisites-llvm: |
| 147 | + $(QUIET) $(DEPS_CHECK_CMAKE) |
| 148 | + $(QUIET) $(DEPS_CHECK_GIT) |
| 149 | + $(QUIET) $(DEPS_CHECK_PYTHON) |
| 150 | + |
| 151 | +.PHONY: deps-prerequisites-llvm |
| 152 | + |
| 153 | +#/ |
| 154 | +# Installs LLVM. |
| 155 | +# |
| 156 | +# @private |
| 157 | +# |
| 158 | +# @example |
| 159 | +# make deps-install-llvm |
| 160 | +#/ |
| 161 | +deps-install-llvm: $(DEPS_LLVM_BUILD_OUT) deps-prerequisites-llvm |
| 162 | + $(QUIET) cd $(DEPS_LLVM_BUILD_OUT) && $(MKDIR_RECURSIVE) build |
| 163 | + $(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(CMAKE) -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm |
| 164 | + $(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(MAKE) |
| 165 | + |
| 166 | +.PHONY: deps-install-llvm |
| 167 | + |
| 168 | +#/ |
| 169 | +# Updates an installed LLVM. |
| 170 | +# |
| 171 | +# @private |
| 172 | +# |
| 173 | +# @example |
| 174 | +# make deps-update-llvm |
| 175 | +#/ |
| 176 | +deps-update-llvm: deps-install-llvm deps-test-llvm |
| 177 | + |
| 178 | +.PHONY: deps-update-llvm |
| 179 | + |
| 180 | +# |
| 181 | +# Tests an LLVM installation. |
| 182 | +# |
| 183 | +# @private |
| 184 | +# |
| 185 | +# @example |
| 186 | +# make deps-test-llvm |
| 187 | +#/ |
| 188 | +deps-test-llvm: $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) deps-test-llvm-wasm |
| 189 | + $(QUIET) echo '' >&2 |
| 190 | + $(QUIET) echo 'LLVM info...' >&2 |
| 191 | + $(QUIET) echo '' >&2 |
| 192 | + $(QUIET) $(DEPS_LLVM_CLANG) --help >&2 |
| 193 | + $(QUIET) echo '' >&2 |
| 194 | + $(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(MAKE) check-clang |
| 195 | + $(QUIET) echo 'Success.' >&2 |
| 196 | + |
| 197 | +.PHONY: deps-test-llvm |
| 198 | + |
| 199 | +#/ |
| 200 | +# Tests an LLVM installation for generating WebAssembly. |
| 201 | +# |
| 202 | +# @private |
| 203 | +# |
| 204 | +# @example |
| 205 | +# make deps-test-llvm-wasm |
| 206 | +#/ |
| 207 | +deps-test-llvm-wasm: $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) |
| 208 | + $(QUIET) echo 'Running wasm tests...' >&2 |
| 209 | + $(QUIET) echo '' >&2 |
| 210 | + $(QUIET) echo 'TODO: make test more robust' >&2 |
| 211 | + $(QUIET) test -f $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) >&2 |
| 212 | + $(QUIET) echo '' >&2 |
| 213 | + $(QUIET) echo 'Success.' >&2 |
| 214 | + |
| 215 | +.PHONY: deps-test-llvm-wasm |
| 216 | + |
| 217 | +#/ |
| 218 | +# Installs LLVM. |
| 219 | +# |
| 220 | +# @example |
| 221 | +# make install-deps-llvm |
| 222 | +#/ |
| 223 | +install-deps-llvm: deps-download-llvm deps-verify-llvm deps-extract-llvm deps-install-llvm deps-test-llvm |
| 224 | + |
| 225 | +.PHONY: install-deps-llvm |
| 226 | + |
| 227 | +#/ |
| 228 | +# Removes an LLVM installation (but does not remove an LLVM download if one exists). |
| 229 | +# |
| 230 | +# @example |
| 231 | +# make clean-deps-llvm |
| 232 | +#/ |
| 233 | +clean-deps-llvm: clean-deps-llvm-tests |
| 234 | + $(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_LLVM_BUILD_OUT) |
| 235 | + |
| 236 | +.PHONY: clean-deps-llvm |
| 237 | + |
| 238 | +#/ |
| 239 | +# Removes LLVM installation tests. |
| 240 | +# |
| 241 | +# @example |
| 242 | +# make clean-deps-llvm-tests |
| 243 | +#/ |
| 244 | +clean-deps-llvm-tests: |
| 245 | + $(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_LLVM_TEST_OUT) |
| 246 | + |
| 247 | +.PHONY: clean-deps-llvm-tests |
0 commit comments