kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

driver_srcs.mk (4460B)


      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_SRCS = driver/main.c driver/lib/target.c $(DRIVER_ENV_SRCS)
     15 
     16 # One entry per subcommand. cc.c serves both `cc` and `check`; the final
     17 # $(sort) below dedupes it. The cas/pkg tools additionally pull in
     18 # driver/lib/dist_host.c (handled with the shared-lib group below).
     19 DRIVER_TOOL_SRCS = \
     20     $(call tool-cmd,CC,cc) \
     21     $(call tool-cmd,CHECK,cc) \
     22     $(call tool-cmd,BUILD_EXE,build) \
     23     $(call tool-cmd,BUILD_LIB,build) \
     24     $(call tool-cmd,BUILD_OBJ,build) \
     25     $(call tool-cmd,INSTALL,install) \
     26     $(call tool-cmd,CPP,cpp) \
     27     $(call tool-cmd,AS,as) \
     28     $(call tool-cmd,LD,ld) \
     29     $(call tool-cmd,AR,ar) \
     30     $(call tool-cmd,RANLIB,ranlib) \
     31     $(call tool-cmd,STRIP,strip) \
     32     $(call tool-cmd,OBJCOPY,objcopy) \
     33     $(call tool-cmd,OBJDUMP,objdump) \
     34     $(call tool-cmd,DBG,dbg) \
     35     $(call tool-cmd,RUN,run) \
     36     $(call tool-cmd,EMU,emu) \
     37     $(call tool-cmd,NM,nm) \
     38     $(call tool-cmd,SIZE,size) \
     39     $(call tool-cmd,ADDR2LINE,addr2line) \
     40     $(call tool-cmd,SYMBOLIZE,symbolize) \
     41     $(call tool-cmd,STRINGS,strings) \
     42     $(call tool-cmd,CAS,cas) \
     43     $(call tool-cmd,PKG,pkg) \
     44     $(call tool-cmd,XXD,xxd) \
     45     $(call tool-cmd,CMP,cmp) \
     46     $(call tool-cmd,HASH,hash) \
     47     $(call tool-cmd,COMPRESS,compress) \
     48     $(call tool-cmd,DISAS,disas) \
     49     $(call tool-cmd,MC,mc)
     50 DRIVER_SRCS += $(sort $(DRIVER_TOOL_SRCS))
     51 
     52 # Shared driver/lib support, each compiled in when any of its consumer tools
     53 # is enabled. The cas/pkg tools link libkit's public cas/package APIs (gated
     54 # by KIT_CAS_ENABLED / KIT_PKG_ENABLED, asserted by config_assert.c); the dist
     55 # implementation and vendored primitives live in the library now.
     56 # build.c is one shared TU compiled whenever ANY of BUILD_EXE/LIB/OBJ is on, and
     57 # it references driver_link_engine_emit, driver_archive_emit, and
     58 # driver_lib_resolve_for_os unconditionally (the call sites are gated at runtime,
     59 # not by #if). So link_engine/archive_engine/lib_resolve — and inputs, which
     60 # archive_engine pulls in — must be present for every BUILD_* subset, not just
     61 # the tools that exercise each path. Hence the full BUILD_EXE BUILD_LIB BUILD_OBJ
     62 # union below.
     63 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ CPP AS DBG RUN,driver/lib/cflags.c)
     64 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ LD RUN,driver/lib/lib_resolve.c)
     65 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ RUN,driver/lib/hosted.c)
     66 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ LD,driver/lib/runtime.c)
     67 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/link_engine.c)
     68 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/link_flags.c)
     69 DRIVER_SRCS += $(call need-any,BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/archive_engine.c)
     70 DRIVER_SRCS += $(call need-any,AR RANLIB STRIP DBG RUN BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/inputs.c)
     71 DRIVER_SRCS += $(call need-any,RUN,driver/lib/wasm_run.c)
     72 DRIVER_SRCS += $(call need-any,CC CHECK BUILD_EXE BUILD_LIB BUILD_OBJ,driver/lib/compile_engine.c)
     73 DRIVER_SRCS += $(call need-any,CAS PKG,driver/lib/dist_host.c)
     74 DRIVER_SRCS += $(call need-any,ADDR2LINE SYMBOLIZE,driver/lib/dwarfsym.c)
     75 # backtrace.c (FP-walk kernel + symbolized printer) is consumed by the dbg/run
     76 # tools AND by posix_dbg.c's run crash guard, which is part of DRIVER_ENV_SRCS
     77 # and so links into every POSIX build regardless of tool selection. Compile it
     78 # unconditionally so a tools-trimmed build (DBG/RUN off) still resolves the
     79 # driver_bt_* references without relying on linker dead-stripping.
     80 DRIVER_SRCS += driver/lib/backtrace.c
     81 
     82 DRIVER_SRCS := $(sort $(DRIVER_SRCS))
     83 DRIVER_OBJS = $(patsubst driver/%.c,$(BUILD_DIR)/driver/%.o,$(DRIVER_SRCS))
     84 DRIVER_DEPS = $(DRIVER_OBJS:.o=.d)