| # Copyright 2024 Google LLC | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # https://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # TODO: might need sail for reference (e.g. for testrig) | |
| TOOLCHAIN_CHERIOT_SRC_DIR := $(OUT)/tmp/toolchain/cheriot-llvm-project | |
| TOOLCHAIN_CHERIOT_BUILD_DIR := $(OUT)/tmp/toolchain/build_toolchain_cheriot | |
| TOOLCHAIN_CHERIOT_OUT_DIR := $(CACHE)/cheriot-tools | |
| TOOLCHAIN_CHERIOT_BIN := $(TOOLCHAIN_CHERIOT_OUT_DIR)/bin/llvm-objdump | |
| TOOLCHAIN_BUILD_DATE := $(shell date +%Y-%m-%d) | |
| toolchain_cheriot_src: | |
| if [[ -f "${TOOLCHAIN_CHERIOT_BIN}" ]]; then \ | |
| echo "Toolchain exists, run 'm toolchain_cheriot_clean' if you really want to rebuild"; \ | |
| else \ | |
| "$(ROOTDIR)/scripts/download-toolchain.sh" "$(TOOLCHAIN_CHERIOT_SRC_DIR)" CHERIOT; \ | |
| fi | |
| $(TOOLCHAIN_CHERIOT_BUILD_DIR): | |
| mkdir -p $(TOOLCHAIN_CHERIOT_BUILD_DIR) | |
| $(TOOLCHAIN_CHERIOT_BIN): | toolchain_cheriot_src $(TOOLCHAIN_CHERIOT_BUILD_DIR) | |
| cmake -B $(TOOLCHAIN_CHERIOT_BUILD_DIR) \ | |
| -DCMAKE_INSTALL_PREFIX=$(TOOLCHAIN_CHERIOT_OUT_DIR) \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \ | |
| -DLLVM_ENABLE_UNWIND_TABLES=NO \ | |
| -DLLVM_TARGETS_TO_BUILD=RISCV \ | |
| -DLLVM_DISTRIBUTION_COMPONENTS="clang;clangd;lld;llvm-objdump" \ | |
| -G Ninja \ | |
| $(TOOLCHAIN_CHERIOT_SRC_DIR)/llvm | |
| cmake --build $(TOOLCHAIN_CHERIOT_BUILD_DIR) --target install-distribution | |
| cmake --build $(TOOLCHAIN_CHERIOT_BUILD_DIR) --target clean | |
| $(OUT)/toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz: $(TOOLCHAIN_CHERIOT_BIN) | |
| tar -C $(CACHE) -czf \ | |
| "$(OUT)/toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz" cheriot-tools | |
| cd $(OUT) && sha256sum "toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz" > \ | |
| "toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz.sha256sum" | |
| @echo "===========================================================" | |
| @echo "CHERIoT Toolchain tarball ready at $(OUT)/toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz" | |
| @echo "===========================================================" | |
| ## Builds CHERIoT LLVM toolchain. | |
| # | |
| # Note: this actually builds from source, rather than fetching a release | |
| # tarball, and is most likely not the target you actually want. | |
| # | |
| # This target can take hours to build, and results in a tarball and sha256sum | |
| # called `out/toolchain_cheriot_<timestamp>.tar.gz` and | |
| # `out/toolchain_cheriot_<timestamp>.tar.gz.sha256sum`, ready for | |
| # upload. In the process of generating this tarball, this target also builds the | |
| # actual tools in `cache/toolchain_cheriot`, so untarring this tarball is | |
| # unneccessary. | |
| toolchain_cheriot: $(OUT)/toolchain_cheriot_$(TOOLCHAIN_BUILD_DATE).tar.gz | |
| ## Removes the CHERIoT toolchain from cache/, forcing a re-fetch if needed. | |
| toolchain_cheriot_clean: | |
| rm -rf "$(TOOLCHAIN_CHERIOT_OUT_DIR)" "$(TOOLCHAIN_CHERIOT_SRC_DIR)" "$(TOOLCHAIN_CHERIOT_BUILD_DIR)" | |
| .PHONY:: toolchain_cheriot toolchain_cheriot_src toolchain_cheriot_clean |