Ben Vanik | 7d2c17a | 2022-11-27 09:10:41 -0800 | [diff] [blame] | 1 | # Copyright 2022 The IREE Authors |
| 2 | # |
| 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | |
| 7 | # This is an example showing a basic makefile that links in the IREE runtime by |
| 8 | # way of the unified static library. It's recommended that IREE is added as a |
| 9 | # subproject and cmake is used to add the dependencies (as in the CMakeLists.txt |
| 10 | # in this directory) but when using other build systems this is easier to adapt. |
| 11 | # |
| 12 | # Configure the runtime: |
| 13 | # cmake -GNinja -B ../iree-build-runtime/ . \ |
| 14 | # -DCMAKE_BUILD_TYPE=MinSizeRel \ |
| 15 | # -DIREE_SIZE_OPTIMIZED=ON |
| 16 | # Build the runtime: |
| 17 | # cmake --build ../iree-build-runtime/ --target iree_runtime_unified |
| 18 | # Make this binary: |
| 19 | # make custom-module-run-min RUNTIME_BUILD_DIR=../iree-build-runtime/ |
| 20 | # |
| 21 | # Note that if IREE_SIZE_OPTIMIZED is used to build the runtime then the |
| 22 | # -DNDEBUG and -DIREE_STATUS_MODE=0 are required on any binaries using it. |
| 23 | |
| 24 | RUNTIME_SRC_DIR ?= ../../runtime/src/ |
| 25 | RUNTIME_BUILD_DIR ?= ../../../iree-build/ |
| 26 | |
| 27 | SRC_FILES := module.h module.cc main.c |
| 28 | INCLUDE_DIRS := ${RUNTIME_SRC_DIR} |
| 29 | INCLUDE_FLAGS := $(addprefix -I,${INCLUDE_DIRS}) |
| 30 | LIBRARY_DIRS := \ |
| 31 | ${RUNTIME_BUILD_DIR}/build_tools/third_party/flatcc/ \ |
| 32 | ${RUNTIME_BUILD_DIR}/runtime/src/iree/runtime/ |
| 33 | LINK_LIBRARIES := \ |
| 34 | iree_runtime_unified \ |
| 35 | flatcc_parsing |
| 36 | LIBRARY_FLAGS := $(addprefix -L,${LIBRARY_DIRS}) $(addprefix -l,${LINK_LIBRARIES}) |
| 37 | CXX_FLAGS := -flto ${INCLUDE_FLAGS} ${LIBRARY_FLAGS} |
| 38 | MIN_FLAGS := \ |
| 39 | -s \ |
| 40 | -Os \ |
| 41 | -DNDEBUG \ |
| 42 | -DIREE_STATUS_MODE=0 |
| 43 | |
| 44 | all: custom-module-run custom-module-run-min |
| 45 | clean: |
| 46 | rm -f custom-module-run custom-module-run-min |
| 47 | |
| 48 | custom-module-run: ${SRC_FILES} |
| 49 | ${CXX} ${SRC_FILES} ${CXX_FLAGS} -o $@ |
| 50 | custom-module-run-min: ${SRC_FILES} |
| 51 | ${CXX} ${SRC_FILES} ${CXX_FLAGS} ${MIN_FLAGS} -o $@ |