|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2024 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 git: |
| 22 | +DEPS_CHECK_GIT ?= $(TOOLS_DIR)/scripts/check_git |
| 23 | + |
| 24 | +# Define the download URL: |
| 25 | +DEPS_WASI_LIBC_URL ?= https://github.com/WebAssembly/wasi-libc |
| 26 | + |
| 27 | +# Determine the basename for the download: |
| 28 | +deps_wasi_libc_basename := wasi_libc |
| 29 | + |
| 30 | +# Define the path to the file containing a checksum to verify a download: |
| 31 | +DEPS_WASI_LIBC_CHECKSUM ?= $(shell $(CAT) $(DEPS_CHECKSUMS_DIR)/$(subst .,_,$(deps_wasi_libc_basename))/sha256) |
| 32 | + |
| 33 | +# Define the output path when downloading: |
| 34 | +DEPS_WASI_LIBC_DOWNLOAD_OUT ?= $(DEPS_TMP_DIR)/$(deps_wasi_libc_basename) |
| 35 | + |
| 36 | +# Define the output path after extracting: |
| 37 | +deps_wasi_libc_extract_out := $(DEPS_BUILD_DIR)/wasi_libc_extracted |
| 38 | + |
| 39 | + |
| 40 | +# RULES # |
| 41 | + |
| 42 | +#/ |
| 43 | +# Downloads WASI libc. |
| 44 | +# |
| 45 | +# @private |
| 46 | +#/ |
| 47 | +$(DEPS_WASI_LIBC_DOWNLOAD_OUT): | $(DEPS_TMP_DIR) |
| 48 | + $(QUIET) echo 'Downloading WASI libc...' >&2 |
| 49 | + $(QUIET) $(GIT) clone --depth=1 $(DEPS_WASI_LIBC_URL) $(DEPS_WASI_LIBC_DOWNLOAD_OUT) |
| 50 | + |
| 51 | +#/ |
| 52 | +# Extracts a WASI libc download. |
| 53 | +# |
| 54 | +# @private |
| 55 | +#/ |
| 56 | +$(DEPS_WASI_LIBC_BUILD_OUT): | $(DEPS_BUILD_DIR) $(DEPS_WASI_LIBC_DOWNLOAD_OUT) |
| 57 | + $(QUIET) echo 'Extracting WASI libc...' >&2 |
| 58 | + $(QUIET) $(CP) -a $(DEPS_WASI_LIBC_DOWNLOAD_OUT) $(deps_wasi_libc_extract_out) |
| 59 | + $(QUIET) mv $(deps_wasi_libc_extract_out) $(DEPS_WASI_LIBC_BUILD_OUT) |
| 60 | + |
| 61 | +#/ |
| 62 | +# Compiles a WASI libc sysroot. |
| 63 | +# |
| 64 | +# @private |
| 65 | +#/ |
| 66 | +$(DEPS_WASI_LIBC_SYSROOT): $(DEPS_LLVM_CLANG) $(DEPS_LLVM_AR) $(DEPS_LLVM_NM) $(DEPS_WASI_LIBC_BUILD_OUT) |
| 67 | + $(QUIET) cd $(DEPS_WASI_LIBC_BUILD_OUT) && \ |
| 68 | + $(MAKE) CC="$(DEPS_LLVM_CLANG)" AR="$(DEPS_LLVM_AR)" NM="$(DEPS_LLVM_NM)" |
| 69 | + |
| 70 | +#/ |
| 71 | +# Downloads WASI libc. |
| 72 | +# |
| 73 | +# @private |
| 74 | +# |
| 75 | +# @example |
| 76 | +# make deps-download-wasi-libc |
| 77 | +#/ |
| 78 | +deps-download-wasi-libc: $(DEPS_WASI_LIBC_DOWNLOAD_OUT) |
| 79 | + |
| 80 | +.PHONY: deps-download-wasi-libc |
| 81 | + |
| 82 | +#/ |
| 83 | +# Verifies a WASI libc download. |
| 84 | +# |
| 85 | +# @private |
| 86 | +# |
| 87 | +# @example |
| 88 | +# make deps-verify-wasi-libc |
| 89 | +#/ |
| 90 | +deps-verify-wasi-libc: deps-download-wasi-libc |
| 91 | + $(QUIET) echo 'Verifying download...' >&2 |
| 92 | + $(QUIET) echo 'Nothing to verify.' >&2 |
| 93 | + |
| 94 | +.PHONY: deps-verify-wasi-libc |
| 95 | + |
| 96 | +#/ |
| 97 | +# Extracts a WASI libc download. |
| 98 | +# |
| 99 | +# @private |
| 100 | +# |
| 101 | +# @example |
| 102 | +# make deps-extract-wasi-libc |
| 103 | +#/ |
| 104 | +deps-extract-wasi-libc: $(DEPS_WASI_LIBC_BUILD_OUT) |
| 105 | + |
| 106 | +.PHONY: deps-extract-wasi-libc |
| 107 | + |
| 108 | +#/ |
| 109 | +# Checks a host system for WASI libc installation prerequisites. |
| 110 | +# |
| 111 | +# @private |
| 112 | +# |
| 113 | +# @example |
| 114 | +# make deps-prerequisites-wasi-libc |
| 115 | +#/ |
| 116 | +deps-prerequisites-wasi-libc: |
| 117 | + $(QUIET) $(DEPS_CHECK_GIT) |
| 118 | + |
| 119 | +.PHONY: deps-prerequisites-wasi-libc |
| 120 | + |
| 121 | +#/ |
| 122 | +# Installs WASI libc. |
| 123 | +# |
| 124 | +# @private |
| 125 | +# |
| 126 | +# @example |
| 127 | +# make deps-install-wasi-libc |
| 128 | +#/ |
| 129 | +deps-install-wasi-libc: deps-prerequisites-wasi-libc $(DEPS_WASI_LIBC_BUILD_OUT) $(DEPS_WASI_LIBC_SYSROOT) |
| 130 | + |
| 131 | +.PHONY: deps-install-wasi-libc |
| 132 | + |
| 133 | +#/ |
| 134 | +# Updates WASI libc. |
| 135 | +# |
| 136 | +# @private |
| 137 | +# |
| 138 | +# @example |
| 139 | +# make deps-update-wasi-libc |
| 140 | +#/ |
| 141 | +deps-update-wasi-libc: deps-install-wasi-libc |
| 142 | + |
| 143 | +.PHONY: deps-update-wasi-libc |
| 144 | + |
| 145 | +#/ |
| 146 | +# Tests a WASI libc installation. |
| 147 | +# |
| 148 | +# @private |
| 149 | +# |
| 150 | +# @example |
| 151 | +# make deps-test-wasi-libc |
| 152 | +#/ |
| 153 | +deps-test-wasi-libc: |
| 154 | + $(QUIET) echo '' >&2 |
| 155 | + $(QUIET) test -d $(DEPS_WASI_LIBC_SYSROOT) >&2 |
| 156 | + $(QUIET) echo '' >&2 |
| 157 | + $(QUIET) echo 'Success.' >&2 |
| 158 | + |
| 159 | +.PHONY: deps-test-wasi-libc |
| 160 | + |
| 161 | +#/ |
| 162 | +# Installs WASI libc. |
| 163 | +# |
| 164 | +# @example |
| 165 | +# make install-deps-wasi-libc |
| 166 | +#/ |
| 167 | +install-deps-wasi-libc: deps-download-wasi-libc deps-verify-wasi-libc deps-extract-wasi-libc deps-install-wasi-libc deps-test-wasi-libc |
| 168 | + |
| 169 | +.PHONY: install-deps-wasi-libc |
| 170 | + |
| 171 | +#/ |
| 172 | +# Removes a WASI libc install (but does not remove a download if one exists). |
| 173 | +# |
| 174 | +# @example |
| 175 | +# make clean-deps-wasi-libc |
| 176 | +#/ |
| 177 | +clean-deps-wasi-libc: clean-deps-wasi-libc-tests |
| 178 | + $(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_WASI_LIBC_BUILD_OUT) |
| 179 | + |
| 180 | +.PHONY: clean-deps-wasi-libc |
| 181 | + |
| 182 | +#/ |
| 183 | +# Removes WASI libc installation tests. |
| 184 | +# |
| 185 | +# @example |
| 186 | +# make clean-deps-wasi-libc-tests |
| 187 | +#/ |
| 188 | +clean-deps-wasi-libc-tests: |
| 189 | + $(QUIET) echo '' >&2 |
| 190 | + |
| 191 | +.PHONY: clean-deps-wasi-libc-tests |
0 commit comments