1Trusty userspace build system 2============================= 3 4The userspace build system is built on top of the lk build system, along with 5the xbin extension for building multiple independent modules. Libraries are 6built independently into static library archives and their build flags are 7cached for use by future modules. When a library or app depends on another 8library, its cached flags are added to the current module flags and re-exported 9in the case of a library. 10 11The top-level entry point for building a userspace app is the 12`trusty-build-rule` function in user-tasks.mk. This helper function kicks off 13generation of the necessary build rules using the new module system. See the doc 14comment on the function's definition for more details on usage. 15 16Library rules files must include `make/library.mk` after the appropriate 17variables have been configured, and similarly, apps must include 18`make/trusted_app.mk`. These makefiles handle the generation of the appropriate 19build rules for the app or library. See the comments at the beginning of these 20makefiles for a full list of the relevant variables that can be set in 21library/app rules files to control the build. 22 23`library.mk` includes `userspace_recurse.mk` to handle isolation of libraries 24from each other and the main app, along with proper dependency chains and 25propagation of flags up from dependencies. Users writing rules for libraries 26should never need to interact with this makefile directly. 27 28 29Example Library Rules 30--------------------- 31 32Note the use of `library.mk` rather than `module.mk`. Apps rules are structured 33the same, but must include `make/trusted_app.mk` instead of `library.mk`. 34 35Libraries and apps must use the MODULE_MODULE_LIBRARY_DEPS variable to add other 36libraries as dependencies. See `library.mk` for a full list of input variables 37available for use in library `rules.mk` files. 38 39 LOCAL_DIR := $(GET_LOCAL_DIR) 40 MODULE := $(LOCAL_DIR) 41 42 MODULE_SRCS := $(LOCAL_DIR)/source_file.c 43 44 MODULE_LIBRARY_DEPS := trusty/user/base/lib/tipc 45 46 include make/library.mk 47 48Include Diagram 49--------------- 50 51user-tasks.mk is included by lk make/build.mk as an extra build rule. 52 53 user-tasks.mk 54 | 55 |--> arch/$(ARCH)/toolchain.mk 56 | 57 |--> For each SDK library $(LIB) in $(TRUSTY_SDK_MODULES): 58 | | MODULE := $(LIB) 59 | | 60 | | /-------------------------------------------------\ 61 | | | | 62 | | v | 63 | make/userspace_recurse.mk | 64 | | | 65 | | Reset all GLOBAL_ and MODULE_ variables to get | 66 | | a clean state. | 67 | | | 68 | |--> $(LIB)/rules.mk | 69 | | | | 70 | | |--> make/library.mk | 71 | | | | | 72 | | | | Cache flags for this module in | 73 | | | | _MODULES_$(MODULE)_$(FLAG) variables. | 74 | | | | | 75 | | | | For each DEPENDENCY_MODULE in | 76 | | | | $(MODULE_LIBRARY_DEPS) | 77 | | | |---------------------------------------/ 78 | | | | 79 | | | | Cache library and ldflags for this module in 80 | | | | _MODULES_$(MODULE)_$(FLAG) variables. 81 | | | | 82 | | | \--> make/module.mk --> make/compile.mk 83 | | | 84 | | | Restore GLOBAL_ and MODULE_ variables to saved values 85 | | | 86 | | | Add dependency's flags to current module's 87 | | | private flags. 88 | | 89 | | 90 | | Restore GLOBAL_ and MODULE_ variables to saved values. 91 | 92 | 93 \--> For each user task $TASK in $(ALL_USER_TASKS): 94 | MODULE := $(TASK) 95 | 96 make/userspace_recurse.mk 97 | 98 | Reset all GLOBAL_ and MODULE_ variables to get 99 | a clean state. 100 | 101 |--> $(TASK)/rules.mk 102 | | 103 | \--> make/trusted_app.mk 104 | | TRUSTY_APP = true 105 | | 106 | | /---------------------------------------------------------------\ 107 | | | | 108 | | v | 109 | |--> make/library.mk | 110 | | | | 111 | | | Cache flags for this module in _MODULES_$(MODULE)_$(FLAG) | 112 | | | variables. | 113 | | | | 114 | | | For each DEPENDENCY_MODULE in | 115 | | | $(MODULE_LIBRARY_DEPS): | 116 | | |--> make/userspace_recurse.mk | 117 | | | | | 118 | | | | Reset all GLOBAL_ and MODULE_ variables to get | 119 | | | | a clean state. | 120 | | | | | 121 | | | | TRUSTY_APP = false | 122 | | | | | 123 | | | |--> $(DEP)/rules.mk | 124 | | | | | | 125 | | | | \______________________________________________/ 126 | | | | 127 | | | | 128 | | | | Restore GLOBAL_ and MODULE_ variables to saved values 129 | | | | 130 | | | | Add dependency's flags to current module's 131 | | | | private flags. 132 | | | 133 | | | Cache library and ldflags for this module in 134 | | | _MODULES_$(MODULE)_$(FLAG) variables. 135 | | | 136 | | \--> make/module.mk --> make/compile.mk 137 | | 138 | | 139 | | Build app ELF binary from objects and all dependency libraries 140 | | (formerly done by xbin.mk). 141 | 142 | 143 | Restore GLOBAL_ and MODULE_ variables to saved values. 144