Ignore:
Timestamp:
Aug 1, 2011, 1:45:20 AM (14 years ago)
Author:
bird
Message:

kBuild: debug info installation support, core hacking + mac os x.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kBuild/footer-pass2-compiling-targets.kmk

    r2521 r2523  
    137137$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
    138138endif
    139 $(out) + $($(target)_2_OUTPUT) +| $($(target)_2_OUTPUT_MAYBE) : \
     139$(out) \
     140+ $($(target)_2_OUTPUT) \
     141+ $($(target)_2_OUTPUT_DEBUG_FILES) \
     142+ $($(target)_2_OUTPUT_DEBUG_DIRS) \
     143+| $($(target)_2_OUTPUT_MAYBE) : \
    140144                $$$$($(target)_2_DEPEND) \
    141145                $(value _DEP_LINK_CMDS) \
     
    143147                $$$$($(target)_2_DEPORD)
    144148        %$$(call MSG_LINK,$(target),$$@,$(tool_do))
    145         $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE)
     149        $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_DEBUG_FILES)
     150ifdef $(target)_2_OUTPUT_DEBUG_DIRS
     151        $$(QUIET)$$(RM) -Rf -- $($(target)_2_OUTPUT_DEBUG_DIRS)
     152endif
    146153
    147154$(cmds)
     
    281288#
    282289# @param   1            The property name.
     290# @param   2            The default property name, empty if none.
     291# @param   3            What to return if all variables are empty. (optional)
    283292# @note    Implicit parameters: target, bld_trg, bld_trg_arch, bld_trg_cpu, bld_type.
    284293# @returns Expanded property value.
    285294#
    286 ## @todo bld_trg_cpu is missing here.
    287295define def_fn_prop_get_first_defined
    288 ifdef $(target)_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type)
    289  local .RETURN := $($(target)_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type))
    290 else ifdef $(target)_$(1).$(bld_trg).$(bld_trg_arch)
    291  local .RETURN := $($(target)_$(1).$(bld_trg).$(bld_trg_arch))
    292 else ifdef $(target)_$(1).$(bld_trg).$(bld_type)
    293  local .RETURN := $($(target)_$(1).$(bld_trg).$(bld_type))
    294 else ifdef $(target)_$(1).$(bld_trg_arch)
    295  local .RETURN := $($(target)_$(1).$(bld_trg_arch))
    296 else ifdef $(target)_$(1).$(bld_trg)
    297  local .RETURN := $($(target)_$(1).$(bld_trg))
    298 else ifdef $(target)_$(1).$(bld_type)
    299  local .RETURN := $($(target)_$(1).$(bld_type))
    300 else ifdef $(target)_$(1)
    301  local .RETURN := $($(target)_$(1))
    302 else ifdef $(1).$(bld_trg).$(bld_trg_arch).$(bld_type)
    303  local .RETURN := $($(1).$(bld_trg).$(bld_trg_arch).$(bld_type))
    304 else ifdef $(1).$(bld_trg).$(bld_trg_arch)
    305  local .RETURN := $($(1).$(bld_trg).$(bld_trg_arch))
    306 else ifdef $(1).$(bld_trg).$(bld_type)
    307  local .RETURN := $($(1).$(bld_trg).$(bld_type))
    308 else ifdef $(1).$(bld_trg_arch)
    309  local .RETURN := $($(1).$(bld_trg_arch))
    310 else ifdef $(1).$(bld_trg)
    311  local .RETURN := $($(1).$(bld_trg))
    312 else ifdef $(1).$(bld_type)
    313  local .RETURN := $($(1).$(bld_type))
     296local .RETURN := $(firstdefined \
     297    $(target)_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type) \
     298    $(target)_$(1).$(bld_trg).$(bld_trg_arch) \
     299    $(target)_$(1).$(bld_trg).$(bld_type) \
     300    $(target)_$(1).$(bld_trg_cpu) \
     301    $(target)_$(1).$(bld_trg_arch) \
     302    $(target)_$(1).$(bld_trg) \
     303    $(target)_$(1).$(bld_type) \
     304    $(target)_$(1) \
     305)
     306ifeq ($(.RETURN),)
     307 ifneq ($(2),)
     308  local .RETURN := $(firstdefined \
     309    $(2).$(bld_trg).$(bld_trg_arch).$(bld_type) \
     310    $(2).$(bld_trg).$(bld_trg_arch) \
     311    $(2).$(bld_trg).$(bld_type) \
     312    $(2).$(bld_trg_cpu) \
     313    $(2).$(bld_trg_arch) \
     314    $(2).$(bld_trg) \
     315    $(2).$(bld_type) \
     316    $(2) \
     317    3 \
     318  )
     319 else
     320  local .RETURN := $(firstdefined \
     321    kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type) \
     322    kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_trg_arch) \
     323    kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_type) \
     324    kBuildGlobalDefaults_$(1).$(bld_trg_cpu) \
     325    kBuildGlobalDefaults_$(1).$(bld_trg_arch) \
     326    kBuildGlobalDefaults_$(1).$(bld_trg) \
     327    kBuildGlobalDefaults_$(1).$(bld_type) \
     328    kBuildGlobalDefaults_$(1) \
     329    3 \
     330  )
     331 endif
     332endif
     333local .RETURN := $(strip $($(.RETURN)))
     334endef # def_fn_prop_get_first_defined
     335
     336##
     337# Function for getting the first property value (ignoring empty defines).
     338#
     339# @param   1            The property name.
     340# @param   2            The default property name, empty if none.
     341# @param   3            What to return if all variables are empty. (optional)
     342# @note    Implicit parameters: target, bld_trg, bld_trg_arch, bld_trg_cpu, bld_type.
     343# @returns First word.
     344#
     345define def_fn_prop_get_first_word
     346local .RETURN := $(firstword \
     347    $($(target)_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type)) \
     348    $($(target)_$(1).$(bld_trg).$(bld_trg_arch)) \
     349    $($(target)_$(1).$(bld_trg).$(bld_type)) \
     350    $($(target)_$(1).$(bld_trg_cpu)) \
     351    $($(target)_$(1).$(bld_trg_arch)) \
     352    $($(target)_$(1).$(bld_trg)) \
     353    $($(target)_$(1).$(bld_type)) \
     354    $($(target)_$(1)) \
     355)
     356ifeq ($(.RETURN),)
     357 ifneq ($(2),)
     358  local .RETURN := $(firstword \
     359    $($(2).$(bld_trg).$(bld_trg_arch).$(bld_type)) \
     360    $($(2).$(bld_trg).$(bld_trg_arch)) \
     361    $($(2).$(bld_trg).$(bld_type)) \
     362    $($(2).$(bld_trg_cpu)) \
     363    $($(2).$(bld_trg_arch)) \
     364    $($(2).$(bld_trg)) \
     365    $($(2).$(bld_type)) \
     366    $($(2)) \
     367    $(3) \
     368  )
     369 else
     370  local .RETURN := $(firstword \
     371    $(kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_trg_arch).$(bld_type)) \
     372    $(kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_trg_arch)) \
     373    $(kBuildGlobalDefaults_$(1).$(bld_trg).$(bld_type)) \
     374    $(kBuildGlobalDefaults_$(1).$(bld_trg_cpu)) \
     375    $(kBuildGlobalDefaults_$(1).$(bld_trg_arch)) \
     376    $(kBuildGlobalDefaults_$(1).$(bld_trg)) \
     377    $(kBuildGlobalDefaults_$(1).$(bld_type)) \
     378    $(kBuildGlobalDefaults_$(1)) \
     379    $(3) \
     380  )
     381 endif
     382endif
     383endef # def_fn_prop_get_first_word
     384
     385##
     386# Install a debug directory.
     387# @param    debug_dir           The directory name.
     388define def_link_install_debug_dir_rule
     389local dir := $(debug_inst_path)/$(debug_inst)$(debug_dir)
     390$$(dir): | $$$$(dir $$$$(patsubst %/,%,$$$$@))
     391        %$$(call MSG_INST_DIR,$$@)
     392        $$(QUIET)$$(MKDIR) -p -- $$@
     393$(target)_2_DEBUG_$(debug_var)_TARGET_DIRS += $$(dir)
     394endef # def_link_install_debug_dir_rule
     395
     396##
     397# Install a debug file.
     398# @param    debug_file          Src=>Dst file pair.
     399define def_link_install_debug_file_rule
     400local dst := $(debug_inst_path)/$(debug_inst)$(word 2, $(subst =>,$(SP),$(debug_file)))
     401$$(dst): $(word 1, $(subst =>,$(SP),$(debug_file))) | $$$$(dir $$$$@)
     402        %$$(call MSG_INST_FILE,$$@,$$<)
     403        $$(QUIET)$(debug_install_cmd) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $$< $$@
     404$(target)_2_DEBUG_$(debug_var)_TARGET_FILES += $$(dst)
     405endef # def_link_install_debug_file_rule
     406
     407##
     408# Install debug info to $(debug_inst), where debug_inst can be a directory or
     409# file (just like $(inst) and $(stage).  Used for both staging and installing.
     410define def_target_install_only_debug
     411if "$(substr $(debug_inst),-1,1)" == "/"
     412 if "$(debug_inst)" == "./"
     413  local debug_inst :=
     414 endif
     415 local debug_dirs  := $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_DIRS))
     416 ifneq ($(strip $(root $(debug_dirs))),)
     417  $(error kBuild: Bad tool? debug_dirs='$(debug_dirs)', expected all to be under '$(outbase)')
     418 endif
     419 local debug_files := $(foreach file, $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_FILES)) \
     420                        ,$($(target)_0_OUTDIR)/$(file)=>$(file))
    314421else
    315  local .RETURN := $($(1))
    316 endif
    317 endef # def_fn_prop_get_first_defined
     422 local debug_files := $(call TOOL_$(tool)_$(tool_do)_DEBUG_INSTALL_FN,$(out),$(outbase),$(debug_inst))
     423 local debug_dirs  := $(filter     %/,$(debug_files))
     424 local debug_files := $(filter-out %/,$(debug_files))
     425endif
     426$(foreach debug_dir, $(debug_dirs), $(eval $(def_link_install_debug_dir_rule)))
     427$(foreach debug_file, $(debug_files), $(eval $(def_link_install_debug_file_rule)))
     428endef
    318429
    319430
     
    365476 $(typevar) += $(out)
    366477endif # INSTTYPE == none
     478
     479# Install debug info.
     480$(target)_2_DEBUG_STAGE_TARGET_DIRS :=
     481$(target)_2_DEBUG_STAGE_TARGET_FILES :=
     482$(target)_2_DEBUG_INSTALL_TARGET_DIRS :=
     483$(target)_2_DEBUG_INSTALL_TARGET_FILES :=
     484
     485if  (   defined($(target)_2_OUTPUT_DEBUG_DIRS) \
     486     || defined($(target)_2_OUTPUT_DEBUG_FILES) ) \
     487 && "$($(target)_1_DEBUG_INSTTYPE)" != "none"
     488 local mode := $(if $(mode),$(mode)$(COMMA)a-x,0644)
     489
     490 ifeq ($($(target)_1_DEBUG_INSTTYPE),both)
     491  local debug_inst_path   := $(PATH_INS)
     492  local debug_install_cmd := $(INSTALL)
     493  local debug_var         := INSTALL
     494  $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalval def_target_install_only_debug))
     495 endif
     496
     497 local debug_inst_path    := $(PATH_STAGE)
     498 local debug_install_cmd  := $(INSTALL_STAGING)
     499 local debug_var          := STAGE
     500 if1of ($($(target)_1_DEBUG_INSTTYPE), stage both)
     501  $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalval def_target_install_only_debug))
     502 endif
     503 if1of ($($(target)_1_INSTTYPE), stage both)
     504  ifndef debug_nostage
     505   $(foreach debug_inst,$($(target)_1_STAGE), $(evalval def_target_install_only_debug))
     506  endif
     507 endif
     508
     509 _DEBUG_STAGE_DIRS    += $($(target)_2_DEBUG_STAGE_TARGET_DIRS)
     510 _DEBUG_STAGE_FILES   += $($(target)_2_DEBUG_STAGE_TARGET_FILES)
     511 _DEBUG_INSTALL_DIRS  += $($(target)_2_DEBUG_INSTALL_TARGET_DIRS)
     512 _DEBUG_INSTALL_FILES += $($(target)_2_DEBUG_INSTALL_TARGET_FILES)
     513
     514 $(basename $(notdir $(out))):: $($(target)_2_DEBUG_STAGE_TARGET_DIRS) $($(target)_2_DEBUG_STAGE_TARGET_FILES)
     515endif
    367516
    368517endef # def_target_install_only
     
    534683
    535684# call the tool
    536 local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
     685local  cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
    537686ifneq ($(pre_cmds),)
    538687 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
    539688endif
    540689ifneq ($(post_cmds),)
    541  local cmds  := $(cmds)$(NL)$(TAB)$(post_cmds)
     690 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
    542691endif
    543692$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
     
    813962endif
    814963
     964# Debug info.
     965local ld_debug      := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
     966local debug_inst    := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
     967local debug_stage   := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
     968local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)
     969
    815970# Custom pre/post-link actions.
    816 local pre_cmds  := $(evalcall def_fn_prop_get_first_defined,PRE_CMDS)
    817 local post_cmds := $(evalcall def_fn_prop_get_first_defined,POST_CMDS)
     971local pre_cmds      := $(evalcall def_fn_prop_get_first_defined,PRE_CMDS)
     972local post_cmds     := $(evalcall def_fn_prop_get_first_defined,POST_CMDS)
    818973
    819974# eliminate this guy?
    820975local objs = $($(target)_2_OBJS)
    821 
    822 # installation targets
    823 local target_type_mode :=
    824 $(evalval def_target_install_only)
    825976
    826977# dependency file
     
    8611012 local cmds  := $(cmds)$(NL)$(TAB)$(post_cmds)
    8621013endif
    863 $(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
    864 $(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
    865 $(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
    866 $(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
     1014$(target)_2_OUTPUT              := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
     1015$(target)_2_OUTPUT_MAYBE        := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
     1016if1of ($(ld_debug), split)
     1017 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
     1018 $(target)_2_OUTPUT_DEBUG_DIRS  := $(filter     %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
     1019else
     1020 $(target)_2_OUTPUT_DEBUG_FILES :=
     1021 $(target)_2_OUTPUT_DEBUG_DIRS  :=
     1022endif
     1023$(target)_2_DEPEND              := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
     1024$(target)_2_DEPORD              := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
    8671025
    8681026# generate the link rule.
    8691027$(eval $(def_link_rule))
    8701028
     1029# installation targets
     1030local target_type_mode :=
     1031$(evalval def_target_install_only)
    8711032
    8721033# Update globals.
Note: See TracChangeset for help on using the changeset viewer.