Changeset 73 for trunk/kBuild


Ignore:
Timestamp:
May 31, 2004, 3:11:52 AM (21 years ago)
Author:
bird
Message:

...

Location:
trunk/kBuild
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/kBuild/footer.kmk

    r72 r73  
    3030#
    3131# Variables.
     32# (Some of these need initialization before including definitions using them.)
    3233#
    3334
     
    4748endef
    4849$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
     50
     51# misc
     52type :=
     53
     54
     55#
     56# Basic macros
     57#
     58
     59## Figure out the tool for a source
     60# @param    $1      source file
     61# @param    $2      normalized main target
     62_SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) )
     63
     64## Figure out where to put object files.
     65# @param    $1      source file
     66# @param    $2      normalized main target
     67_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
     68
     69## Figure out where to put object files.
     70# @param    $1      real target name.
     71# @param    $2      normalized main target
     72_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
     73
    4974
    5075#
     
    154179#
    155180# Include SDKs
    156 #                       
     181#
    157182_SDKS := $(SDKS)
    158183define def_sdks_target_source
     
    175200$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
    176201
     202#
     203# Object processing.
     204#
     205
     206## Generic macro for processing C, C++ and Assembly sources.
     207# @param    $(target)     Normalized target name.
     208# @param    $(source)     Source file name.
     209# @param    $(type)       Source type. {C,CXX,AS}
     210#
     211# @remark   I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
     212define def_target_source_c_cpp_asm
     213#$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
     214
     215$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target)))
     216$(eval defs        :=\
     217        $($(target)_$(source)_$(type)DEFS)\
     218        $($(target)_$(source)_DEFS)\
     219        $($(source)_$(type)DEFS)\
     220        $($(source)_DEFS)\
     221        $($(target)_$(type)DEFS)\
     222        $($(target)_DEFS)\
     223        $(DEFS)\
     224        $(TOOL_$(tool)_$(type)DEFS)\
     225        )
     226$(eval incs        :=\
     227        $($(target)_$(source)_$(type)INCS)\
     228        $($(target)_$(source)_INCS)\
     229        $($(source)_$(type)INCS)\
     230        $($(source)_INCS)\
     231        $($(target)_$(type)INCS)\
     232        $($(target)_INCS)\
     233        $(INCS)\
     234        $(TOOL_$(tool)_$(type)INCS)\
     235        )
     236$(eval flags        :=\
     237        $(TOOL_$(tool)_$(type)FLAGS)\
     238        $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
     239        $($(type)FLAGS)\
     240        $($(type)FLAGS.$(BUILD_TYPE))\
     241        $($(target)_$(type)FLAGS)\
     242        $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
     243        $($(source)_$(type)FLAGS)\
     244        $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
     245        $($(target)_$(source)_$(type)FLAGS)\
     246        $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
     247        )
     248$(eval outbase     := $(call _OBJECT_BASE,$(source),$(target)))
     249$(eval dirdep      := $(dir $(outbase)).dir_created)
     250$(eval objsuff     := $(firstword $($(target)_$(source)_OBJSUFF) $($(source)_OBJSUFF) $($(target)_OBJSUFF) $(TOOL_$(tool)_$(type)OBJSUFF) $(SUFF_OBJ)))
     251$(eval obj         := $(outbase)$(objsuff))
     252$(eval depfile     := $(outbase)$(SUFF_DEP))
     253
     254#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
     255$(eval $(TOOL_$(tool)_COMPILE_$(type)))
     256
     257$(eval _OBJS_$(target) += $(obj))
     258$(eval _DEPFILES       += $(dep))
     259
     260endef
     261
     262## Generic macro for processing all target sources.
     263# @param    $target     Normalized target name.
     264define def_target_sources
     265#$ (warning def_target_sources)
     266# C sources
     267$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
     268        ,$(eval $(def_target_source_c_cpp_asm)) ))
     269
     270# C++ sources
     271$(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
     272        ,$(eval $(def_target_source_c_cpp_asm)) ))
     273
     274# ASM sources
     275$(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
     276        ,$(eval $(def_target_source_c_cpp_asm)) ))
     277endef
     278
    177279
    178280#
    179281# LIBRARIES
    180 #               
    181 
    182 ## Figure out the tool for a source
    183 # @param    $1      source file
    184 # @param    $2      normalized main target
    185 _SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL))
    186 ## Figure out where to put object files.
    187 # @param    $1      source file
    188 # @param    $2      normalized main target
    189 _OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $1)
    190        
     282#
     283
    191284## Library (one).
    192285# @param    $(lib)  Library name
    193286define def_lib
    194 #$ (warning dbg: Processing library $(target))
    195 
    196 # C++ sources
    197 #$(foreach o, $(filter %.cpp,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
    198 #$(foreach o, $(filter %.cxx,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
    199 #$(foreach o, $(filter %.cc, $($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
    200 
    201 # C sources
    202 $(foreach source, $(filter %.c, $($(target)_SOURCES)), \
    203         $(eval $(call TOOL_$(call _SOURCE_TOOL,$(source),$(target))_COMPILE_C,$(call _OBJECT_BASE,$(source),$(target)),$(source),$(target)) ) )
    204 
    205 ## ASM sources
    206 #$(foreach o, $(filter %.asm,$($1_SOURCES)), $(eval $(call def_lib_asm,$1,$o)))
    207                                                
     287# source -> object
     288$(eval $(def_target_sources))
     289
    208290# library
    209 #$$(PATH_TARGET)/$1$(SUFF_LIB): \
    210 #               $$(PATH_TARGET) \
    211 #               $$(_OBJS_$1)
    212 #       $$(AR) $($1_ARFLAGS) $(ARFLAGS) $(AROUT)$$(@:/=\) $$(_OBJS_$1)
    213 #
    214 _OBJS += $(_OBJS_$(target))             
    215 _LIBS += $(PATH_TARGET)/$1$(SUFF_LIB)
     291$(eval tool        := $(firstword $($(target)_TOOL) $(TOOL)))
     292$(eval flags       := $($(target)_ARFLAGS) $(ARFLAGS) $(TOOL_$(tool)_ARFLAGS))
     293$(eval libsuff     := $(firstword $($(target)_LIBSUFF) $($(target)_LIBSUFF) $(TOOL_$(tool)_ARLIBSUFF) $(SUFF_LIB)))
     294## @todo prefix
     295$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
     296$(eval lib         := $(outbase)$(libsuff))
     297$(eval objs         = $(_OBJS_$(target)))
     298$(eval dirdep      := $(dir $(lib)).dir_created)
     299## @todo fix dependencies
     300$(eval deps        := )
     301
     302$(eval $(TOOL_$(tool)_LINK_LIBRARY))
     303
     304_OBJS += $(_OBJS_$(target))
     305_LIBS += $(lib)
    216306endef
    217307
     
    257347define def_createdir
    258348$(dirfile):
     349        $(call MSG_L1,Creating directory $$(@D))
    259350        $(MKDIR) -p $$(@D)
    260         echo dir_created > $$@
     351        @echo dir_created > $$@
    261352endef
    262353
     
    270361
    271362objs: $(_OBJS)
     363        echo "dbg: _OBJS = $(_OBJS)"
     364
     365libs: $(_LIBS)
     366        echo "dbg: _LIBS = $(_LIBS)"
    272367
    273368
  • trunk/kBuild/header.kmk

    r72 r73  
    194194EXEC_X86_WIN32      :=
    195195HOSTSUFF_EXE        := .exe
     196endif
     197
     198#
     199# Build target setup.
     200#
     201ifeq ($(BUILD_TARGET),os2)
     202SUFF_OBJ            := .obj
     203SUFF_LIB            := .lib
     204SUFF_DLL            := .dll
     205SUFF_EXE            := .exe
     206SUFF_DRV            := .sys
     207SUFF_RES            := .res
     208endif
     209ifeq ($(BUILD_TARGET),win32)
     210SUFF_OBJ            := .obj
     211SUFF_LIB            := .lib
     212SUFF_DLL            := .dll
     213SUFF_EXE            := .exe
     214SUFF_DRV            := .sys
     215SUFF_RES            := .res
     216endif
     217ifeq ($(BUILD_TARGET),linux)
     218SUFF_OBJ            := .o
     219SUFF_LIB            := .a
     220SUFF_DLL            := .so
     221SUFF_EXE            :=
     222SUFF_DRV            := .a
     223SUFF_RES            :=
    196224endif
    197225
     
    215243
    216244#
     245# Message macros.
     246#                                       
     247ifndef BUILD_QUIET
     248MSG_L1          = @echo "kBuild: $1"
     249ifdef BUILD_VERBOSE
     250MSG_L2          = @echo "kBuild: $1"
     251else
     252MSG_L2          =
     253endif
     254ifdef BUILD_DEBUG
     255MSG_L3      = @echo "kBuild: $1"
     256else
     257MSG_L3      =
     258endif
     259else
     260MSG_L1          =
     261MSG_L2      =
     262MSG_L3      =
     263endif
     264
     265#
    217266# This is how we find the closest config.kmk.
    218267# It's a little hacky but I think it works fine.
  • trunk/kBuild/tools/GCC.kmk

    r72 r73  
    2727
    2828TOOL_GCC                := Generic GCC
     29
    2930TOOL_GCC_CC             := gcc$(HOSTSUFF_EXE)
     31TOOL_GCC_COBJSUFF       := .o
    3032TOOL_GCC_CFLAGS         := -g
    3133TOOL_GCC_CFLAGS.debug   := -O0
     
    3335TOOL_GCC_CFLAGS.profile := -pg
    3436TOOL_GCC_CINCS          :=
     37TOOL_GCC_CDEFS          :=
     38
     39TOOL_GCC_CC             := gcc$(HOSTSUFF_EXE)
     40TOOL_GCC_CXXOBJSUFF     := .o
     41
     42TOOL_GCC_AS             := as$(HOSTSUFF_EXE)
     43TOOL_GCC_ASOBJSUFF      := .o
     44
     45TOOL_GCC_AR             := ar$(HOSTSUFF_EXE)
     46TOOL_GCC_ARFLAGS        := cr
     47TOOL_GCC_ARLIBSUFF      := .a
    3548
    3649
    3750## Compile C source.
    38 # @param    $1  Output basename (full).
    39 # @param    $2  Source filename (relative).
    40 # @param    $3  Normalized main target name.
     51# @param    $(target)   Normalized main target name.
     52# @param    $(source)   Source filename (relative).
     53# @param        $(obj)      Object file name. This shall be (re)created by the compilation.
     54# @param    $(dep)          Dependcy file. This shall be (re)created by the compilation.
     55# @param    $(flags)    Flags.
     56# @param    $(defs)     Definitions. No -D or something.
     57# @param    $(incs)     Includes. No -I or something.
     58# @param        $(dirdep)   Directory creation dependency.
     59#
     60# @param    $(outbase)  Output basename (full). Use this for list files and such.
     61# @param        $(objsuff)  Object suffix.
    4162define TOOL_GCC_COMPILE_C
    42 #$ (warning dbg GCC: 1=$1 2=$2 3=$3 4=$4 5=$5)
    43 $1.o: $(PATH_CURRENT)/$2 $(dir $1).dir_created
    44         $(TOOL_GCC_CC) -c \
    45                 $($3_$2_CFLAGS) $($3_$2_CFLAGS.$(BUILD_TYPE)) \
    46                 $($2_CFLAGS) $($2_CFLAGS.$(BUILD_TYPE)) \
    47                 $($3_CFLAGS) $($3_CFLAGS.$(BUILD_TYPE)) \
    48                 $(TOOL_GCC_CFLAGS) $(TOOL_GCC_CFLAGS.$(BUILD_TYPE)) \
    49                 $(addprefix -I, $($3_$2_CINCS) $($3_$2_INCS) $($2_CINCS) $($2_INCS) $($3_CINCS) $($3_INCS) $(INCS) \
    50                                                 $(TOOL_GCC_CINCS)) \
    51                 $(addprefix -D, $($3_$2_CDEFS) $($3_$2_DEFS) $($2_CDEFS) $($2_DEFS) $($3_CDEFS) $($3_DEFS) $(DEFS) $(TOOL_GCC_CDEFS)) \
    52                 -o $$@ -Wp,-MT,$1$(SUFF_DEP) -Wp,-MD,$$@ \
    53         $(PATH_CURRENT)/$2             
    54 _OBJS_$(3) += $1.o
    55 _DEPFILES += $1$(SUFF_DEP)
     63#$ (warning dbg: GCC: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
     64$(obj): $(dirdep) $(PATH_CURRENT)/$(source)
     65        $(call MSG_L2,Compiling $$@ using GCC)
     66        $(TOOL_GCC_CC) -c\
     67                $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
     68                -Wp,-MT,$(dep) -Wp,-MD,$$@\
     69                -o $$@\
     70        $(PATH_CURRENT)/$(source)               
     71               
    5672endef
    5773
     74
     75## Link library
     76# @param    $(target)   Normalized main target name.
     77# @param    $(lib)              Library name.
     78# @param    $(objs)     Object files to put in the library.
     79# @param    $(flags)    Flags.
     80# @param        $(dirdep)   Directory creation dependency.
     81# @param        $(deps)         Other dependencies.
     82#
     83# @param    $(outbase)  Output basename (full). Use this for list files and such.
     84define TOOL_GCC_LINK_LIBRARY
     85#$ (warning dbg: GCC: target=$(target) lib=$(lib) objs=$(objs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) outbase=$(outbase))
     86$(lib): $(dirdep) $(objs) $(deps)
     87        $(call MSG_L1,Creating Library $$@)
     88        $(RM) -f $$@
     89        $(TOOL_GCC_AR) $(flags) $$@ $(objs)
     90       
     91endef
     92
Note: See TracChangeset for help on using the changeset viewer.