driver_srcs.mk (5229B)
1 # mk/driver_srcs.mk 2 # =========================================================================== 3 # Driver source selection -> DRIVER_OBJS / DRIVER_DEPS. 4 # 5 # The tool set is gated by the KIT_TOOL_*_ENABLED flags (mk/config.mk), the 6 # same flags main.c keys its dispatch table on. DRIVER_ENV_SRCS (the hosted 7 # OS/libc adapter set) comes from mk/env.mk. 8 9 # A subcommand TU: include driver/cmd/$(2).c when KIT_TOOL_$(1)_ENABLED is set. 10 tool-cmd = $(if $(filter 1,$(KIT_TOOL_$(1)_ENABLED)),driver/cmd/$(2).c) 11 # A shared driver/lib TU: include $(2) if ANY of the named tools is enabled. 12 need-any = $(if $(filter 1,$(foreach f,$(1),$(KIT_TOOL_$(f)_ENABLED))),$(2)) 13 14 DRIVER_ENV_SRCS_EFFECTIVE = $(DRIVER_ENV_SRCS) 15 DRIVER_NEED_POSIX_DBG = $(filter 1,$(KIT_TOOL_DBG_ENABLED) $(KIT_TOOL_RUN_ENABLED)) 16 ifneq ($(HOST_OS),windows) 17 ifeq ($(DRIVER_NEED_POSIX_DBG),) 18 DRIVER_ENV_SRCS_EFFECTIVE := $(filter-out driver/env/posix_dbg.c $(DRIVER_ENV_UCTX_SRC),$(DRIVER_ENV_SRCS_EFFECTIVE)) \ 19 driver/env/posix_dbg_stubs.c 20 endif 21 endif 22 23 DRIVER_SRCS = driver/main.c driver/version.c driver/lib/target.c \ 24 $(DRIVER_ENV_SRCS_EFFECTIVE) 25 26 # One entry per subcommand. cc.c serves both `cc` and `check`; the final 27 # $(sort) below dedupes it. The cas/pkg tools additionally pull in 28 # driver/lib/dist_host.c (handled with the shared-lib group below). 29 DRIVER_TOOL_SRCS = \ 30 $(call tool-cmd,CC,cc) \ 31 $(call tool-cmd,CHECK,cc) \ 32 $(call tool-cmd,BUILD_EXE,build) \ 33 $(call tool-cmd,BUILD_LIB,build) \ 34 $(call tool-cmd,BUILD_OBJ,build) \ 35 $(call tool-cmd,BUILD,build_coord) \ 36 $(call tool-cmd,MAKE,make) \ 37 $(call tool-cmd,INSTALL,install) \ 38 $(call tool-cmd,CPP,cpp) \ 39 $(call tool-cmd,AS,as) \ 40 $(call tool-cmd,LD,ld) \ 41 $(call tool-cmd,AR,ar) \ 42 $(call tool-cmd,CPIO,cpio) \ 43 $(call tool-cmd,RANLIB,ranlib) \ 44 $(call tool-cmd,STRIP,strip) \ 45 $(call tool-cmd,OBJCOPY,objcopy) \ 46 $(call tool-cmd,IMAGE,image) \ 47 $(call tool-cmd,OBJDUMP,objdump) \ 48 $(call tool-cmd,DBG,dbg) \ 49 $(call tool-cmd,RUN,run) \ 50 $(call tool-cmd,EMU,emu) \ 51 $(call tool-cmd,NM,nm) \ 52 $(call tool-cmd,SIZE,size) \ 53 $(call tool-cmd,ADDR2LINE,addr2line) \ 54 $(call tool-cmd,SYMBOLIZE,symbolize) \ 55 $(call tool-cmd,STRINGS,strings) \ 56 $(call tool-cmd,CAS,cas) \ 57 $(call tool-cmd,PKG,pkg) \ 58 $(call tool-cmd,XXD,xxd) \ 59 $(call tool-cmd,CMP,cmp) \ 60 $(call tool-cmd,HASH,hash) \ 61 $(call tool-cmd,COMPRESS,compress) \ 62 $(call tool-cmd,DISAS,disas) \ 63 $(call tool-cmd,MC,mc) \ 64 $(call tool-cmd,GRAM,gram) \ 65 $(call tool-cmd,TARGETS,targets) \ 66 $(call tool-cmd,UPDATE,update) 67 DRIVER_SRCS += $(sort $(DRIVER_TOOL_SRCS)) 68 69 # Shared driver/lib support, each compiled in when any of its consumer tools 70 # is enabled. The cas/pkg tools link libkit's public cas/package APIs (gated 71 # by KIT_CAS_ENABLED / KIT_PKG_ENABLED, asserted by config_assert.c); the dist 72 # implementation and vendored primitives live in the library now. 73 # build.c is one shared TU compiled whenever ANY of BUILD_EXE/LIB/OBJ is on, and 74 # it references kit_build_link (the public build tier in libkit), driver_archive_emit, 75 # and driver_lib_resolve_for_os unconditionally (the call sites are gated at 76 # runtime, not by #if). So archive_engine/lib_resolve — and inputs, which 77 # archive_engine pulls in — must be present for every BUILD_* subset, not just 78 # the tools that exercise each path. Hence the full BUILD_EXE BUILD_LIB BUILD_OBJ 79 # union below. 80 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ CPP AS DBG RUN,driver/lib/cflags.c) 81 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ LD RUN,driver/lib/lib_resolve.c) 82 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ RUN,driver/lib/hosted.c) 83 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ LD,driver/lib/runtime.c) 84 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/link_flags.c) 85 DRIVER_SRCS += $(call need-any,BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/archive_engine.c) 86 DRIVER_SRCS += $(call need-any,CC CHECK AR RANLIB STRIP DBG RUN BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/inputs.c) 87 DRIVER_SRCS += $(call need-any,STRIP OBJCOPY,driver/lib/objedit.c) 88 DRIVER_SRCS += $(call need-any,RUN,driver/lib/wasm_run.c) 89 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/link_inputs.c) 90 DRIVER_SRCS += $(call need-any,CAS PKG BUILD UPDATE,driver/lib/dist_host.c) 91 ifeq ($(HOST_OS),windows) 92 DRIVER_SRCS += $(call need-any,BUILD,driver/env/build_host_windows.c) 93 DRIVER_SRCS += $(call need-any,BUILD MAKE,driver/env/exec_windows.c) 94 else 95 DRIVER_SRCS += $(call need-any,BUILD,driver/env/build_host_posix.c) 96 DRIVER_SRCS += $(call need-any,BUILD MAKE,driver/env/exec_posix.c) 97 endif 98 DRIVER_SRCS += $(call need-any,INSTALL UPDATE,driver/lib/install_links.c) 99 DRIVER_SRCS += $(call need-any,UPDATE,driver/release_key.c) 100 DRIVER_SRCS += $(call need-any,ADDR2LINE SYMBOLIZE,driver/lib/dwarfsym.c) 101 DRIVER_SRCS += $(call need-any,DBG RUN,driver/lib/backtrace.c) 102 103 DRIVER_SRCS := $(sort $(DRIVER_SRCS)) 104 DRIVER_OBJS = $(patsubst driver/%.c,$(BUILD_DIR)/driver/%.o,$(DRIVER_SRCS)) 105 DRIVER_DEPS = $(DRIVER_OBJS:.o=.d)