| 1 | # $Id: GXX.kmk 1547 2008-04-22 02:02:09Z bird $ | 
|---|
| 2 | ## @file | 
|---|
| 3 | # kBuild Tool Config - Generic GCC using the system GCC, for building C++ code. | 
|---|
| 4 | # | 
|---|
| 5 |  | 
|---|
| 6 | # | 
|---|
| 7 | # Copyright (c) 2004-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net> | 
|---|
| 8 | # | 
|---|
| 9 | # This file is part of kBuild. | 
|---|
| 10 | # | 
|---|
| 11 | # kBuild is free software; you can redistribute it and/or modify | 
|---|
| 12 | # it under the terms of the GNU General Public License as published by | 
|---|
| 13 | # the Free Software Foundation; either version 2 of the License, or | 
|---|
| 14 | # (at your option) any later version. | 
|---|
| 15 | # | 
|---|
| 16 | # kBuild is distributed in the hope that it will be useful, | 
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | # GNU General Public License for more details. | 
|---|
| 20 | # | 
|---|
| 21 | # You should have received a copy of the GNU General Public License | 
|---|
| 22 | # along with kBuild; if not, write to the Free Software | 
|---|
| 23 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|---|
| 24 | # | 
|---|
| 25 | # | 
|---|
| 26 | # As a special exception you are granted permission to include this file, via | 
|---|
| 27 | # the kmk include directive, as you wish without this in itself causing the | 
|---|
| 28 | # resulting makefile, program or whatever to be covered by the GPL license. | 
|---|
| 29 | # This exception does not however invalidate any other reasons why the makefile, | 
|---|
| 30 | # program, whatever should not be covered the GPL. | 
|---|
| 31 | # | 
|---|
| 32 | # | 
|---|
| 33 |  | 
|---|
| 34 | TOOL_GXX := Generic GCC using the system GCC, for building C++ code. | 
|---|
| 35 |  | 
|---|
| 36 | # Tool Specific Properties | 
|---|
| 37 | TOOL_GXX_CC  ?= gcc$(HOSTSUFF_EXE) | 
|---|
| 38 | TOOL_GXX_CXX ?= g++$(HOSTSUFF_EXE) | 
|---|
| 39 | TOOL_GXX_AS  ?= gcc$(HOSTSUFF_EXE) | 
|---|
| 40 | TOOL_GXX_AR  ?= ar$(HOSTSUFF_EXE) | 
|---|
| 41 | TOOL_GXX_RANLIB ?= ranlib$(HOSTSUFF_EXE) | 
|---|
| 42 | TOOL_GXX_LD  ?= g++$(HOSTSUFF_EXE) | 
|---|
| 43 | TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll | 
|---|
| 44 | TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib | 
|---|
| 45 | ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET) | 
|---|
| 46 | TOOL_GXX_LDFLAGS.dll ?= -shared | 
|---|
| 47 | else | 
|---|
| 48 | TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)) | 
|---|
| 49 | endif | 
|---|
| 50 |  | 
|---|
| 51 | # General Properties used by kBuild | 
|---|
| 52 | TOOL_GXX_COBJSUFF         ?= .o | 
|---|
| 53 | TOOL_GXX_CFLAGS           ?= | 
|---|
| 54 | TOOL_GXX_CFLAGS.debug     ?= -g | 
|---|
| 55 | TOOL_GXX_CFLAGS.profile   ?= -g -O2 #-pg | 
|---|
| 56 | TOOL_GXX_CFLAGS.release   ?= -O2 | 
|---|
| 57 | TOOL_GXX_CINCS            ?= | 
|---|
| 58 | TOOL_GXX_CDEFS            ?= | 
|---|
| 59 |  | 
|---|
| 60 | TOOL_GXX_CXXOBJSUFF       ?= .o | 
|---|
| 61 | TOOL_GXX_CXXOBJSUFF       ?= .o | 
|---|
| 62 | TOOL_GXX_CXXFLAGS         ?= | 
|---|
| 63 | TOOL_GXX_CXXFLAGS.debug   ?= -g -O0 | 
|---|
| 64 | TOOL_GXX_CXXFLAGS.profile ?= -g -O2 #-pg | 
|---|
| 65 | TOOL_GXX_CXXFLAGS.release ?= -O2 | 
|---|
| 66 | TOOL_GXX_CXXINCS          ?= | 
|---|
| 67 | TOOL_GXX_CXXDEFS          ?= | 
|---|
| 68 |  | 
|---|
| 69 | TOOL_GXX_ASFLAGS          ?= -x assembler-with-cpp | 
|---|
| 70 | TOOL_GXX_ASFLAGS.debug    ?= -g | 
|---|
| 71 | TOOL_GXX_ASFLAGS.profile  ?= -g | 
|---|
| 72 | TOOL_GXX_ASOBJSUFF        ?= .o | 
|---|
| 73 |  | 
|---|
| 74 | TOOL_GXX_ARFLAGS          ?= cr | 
|---|
| 75 | TOOL_GXX_ARLIBSUFF        ?= .a | 
|---|
| 76 |  | 
|---|
| 77 | TOOL_GXX_LDFLAGS          ?= | 
|---|
| 78 | TOOL_GXX_LDFLAGS.debug    ?= -g | 
|---|
| 79 | TOOL_GXX_LDFLAGS.profile  ?= -g | 
|---|
| 80 |  | 
|---|
| 81 |  | 
|---|
| 82 | ## Compile C source. | 
|---|
| 83 | # @param    $(target)   Normalized main target name. | 
|---|
| 84 | # @param    $(source)   Source filename (relative). | 
|---|
| 85 | # @param    $(obj)      Object file name. This shall be (re)created by the compilation. | 
|---|
| 86 | # @param    $(dep)          Dependcy file. This shall be (re)created by the compilation. | 
|---|
| 87 | # @param    $(flags)    Flags. | 
|---|
| 88 | # @param    $(defs)     Definitions. No -D or something. | 
|---|
| 89 | # @param    $(incs)     Includes. No -I or something. | 
|---|
| 90 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 91 | # @param    $(deps)             Other dependencies. | 
|---|
| 92 | # @param    $(outbase)  Output basename (full). Use this for list files and such. | 
|---|
| 93 | # @param    $(objsuff)  Object suffix. | 
|---|
| 94 | # | 
|---|
| 95 | TOOL_GXX_COMPILE_C_OUTPUT = | 
|---|
| 96 | TOOL_GXX_COMPILE_C_DEPEND = | 
|---|
| 97 | TOOL_GXX_COMPILE_C_DEPORD = | 
|---|
| 98 | define TOOL_GXX_COMPILE_C_CMDS | 
|---|
| 99 | $(QUIET)$(TOOL_GXX_CC) -c\ | 
|---|
| 100 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\ | 
|---|
| 101 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) \ | 
|---|
| 102 | -o $(obj)\ | 
|---|
| 103 | $(abspath $(source)) | 
|---|
| 104 | endef | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | ## Compile C++ source. | 
|---|
| 108 | # @param    $(target)   Normalized main target name. | 
|---|
| 109 | # @param    $(source)   Source filename (relative). | 
|---|
| 110 | # @param    $(obj)      Object file name. This shall be (re)created by the compilation. | 
|---|
| 111 | # @param    $(dep)          Dependcy file. This shall be (re)created by the compilation. | 
|---|
| 112 | # @param    $(flags)    Flags. | 
|---|
| 113 | # @param    $(defs)     Definitions. No -D or something. | 
|---|
| 114 | # @param    $(incs)     Includes. No -I or something. | 
|---|
| 115 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 116 | # @param    $(deps)             Other dependencies. | 
|---|
| 117 | # | 
|---|
| 118 | # @param    $(outbase)  Output basename (full). Use this for list files and such. | 
|---|
| 119 | # @param    $(objsuff)  Object suffix. | 
|---|
| 120 | TOOL_GXX_COMPILE_CXX_OUTPUT = | 
|---|
| 121 | TOOL_GXX_COMPILE_CXX_DEPEND = | 
|---|
| 122 | TOOL_GXX_COMPILE_CXX_DEPORD = | 
|---|
| 123 | define TOOL_GXX_COMPILE_CXX_CMDS | 
|---|
| 124 | $(QUIET)$(TOOL_GXX_CXX) -c\ | 
|---|
| 125 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\ | 
|---|
| 126 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) \ | 
|---|
| 127 | -o $(obj)\ | 
|---|
| 128 | $(abspath $(source)) | 
|---|
| 129 | endef | 
|---|
| 130 |  | 
|---|
| 131 |  | 
|---|
| 132 | ## Compile Assembly source. | 
|---|
| 133 | # @param    $(target)   Normalized main target name. | 
|---|
| 134 | # @param    $(source)   Source filename (relative). | 
|---|
| 135 | # @param    $(obj)      Object file name. This shall be (re)created by the compilation. | 
|---|
| 136 | # @param    $(dep)      Dependcy file. This shall be (re)created by the compilation. | 
|---|
| 137 | # @param    $(flags)    Flags. | 
|---|
| 138 | # @param    $(defs)     Definitions. No -D or something. | 
|---|
| 139 | # @param    $(incs)     Includes. No -I or something. | 
|---|
| 140 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 141 | # @param    $(deps)     Other dependencies. | 
|---|
| 142 | # @param    $(outbase)  Output basename (full). Use this for list files and such. | 
|---|
| 143 | # @param    $(objsuff)  Object suffix. | 
|---|
| 144 | # | 
|---|
| 145 | TOOL_GXX_COMPILE_AS_OUTPUT = | 
|---|
| 146 | TOOL_GXX_COMPILE_AS_DEPEND = | 
|---|
| 147 | TOOL_GXX_COMPILE_AS_DEPORD = | 
|---|
| 148 | define TOOL_GXX_COMPILE_AS_CMDS | 
|---|
| 149 | $(QUIET)$(TOOL_GXX_AS) -c\ | 
|---|
| 150 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\ | 
|---|
| 151 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) \ | 
|---|
| 152 | -o $(obj)\ | 
|---|
| 153 | $(abspath $(source)) | 
|---|
| 154 | endef | 
|---|
| 155 |  | 
|---|
| 156 |  | 
|---|
| 157 | ## Link library | 
|---|
| 158 | # @param    $(target)   Normalized main target name. | 
|---|
| 159 | # @param    $(out)      Library name. | 
|---|
| 160 | # @param    $(objs)     Object files to put in the library. | 
|---|
| 161 | # @param    $(flags)    Flags. | 
|---|
| 162 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 163 | # @param    $(deps)             Other dependencies. | 
|---|
| 164 | # | 
|---|
| 165 | # @param    $(outbase)  Output basename (full). Use this for list files and such. | 
|---|
| 166 | TOOL_GXX_LINK_LIBRARY_OUTPUT = | 
|---|
| 167 | TOOL_GXX_LINK_LIBRARY_DEPEND = | 
|---|
| 168 | TOOL_GXX_LINK_LIBRARY_DEPORD = | 
|---|
| 169 | define TOOL_GXX_LINK_LIBRARY_CMDS | 
|---|
| 170 | $(QUIET)$(TOOL_GXX_AR) $(flags) $(out) $(objs) | 
|---|
| 171 | $(call xargs,$(QUIET)$(TOOL_GXX_AR) $(flags) $(out),$(objs)) | 
|---|
| 172 | $(foreach lib,$(othersrc)\ | 
|---|
| 173 | ,$(NL)$(TAB)$(call MSG_AR_MERGE,$(target),$(out),$(lib)) \ | 
|---|
| 174 | $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))ar.tmp.dir/* \ | 
|---|
| 175 | $(NL)$(TAB)$(QUIET)$(MKDIR) -p $(dir $(outbase))/ar.tmp.dir/ \ | 
|---|
| 176 | $(NL)$(TAB)$(QUIET)(cd $(dir $(outbase))ar.tmp.dir/ \ | 
|---|
| 177 | && $(TOOL_GXX_AR) x $(abspath $(lib)) \ | 
|---|
| 178 | && $(TOOL_GXX_AR) $(flags) $(out) *) \ | 
|---|
| 179 | $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))/ar.tmp.dir/* \ | 
|---|
| 180 | $(NL)$(TAB)$(QUIET)$(RMDIR) $(dir $(outbase))ar.tmp.dir/) | 
|---|
| 181 | $(QUIET)$(TOOL_GXX_RANLIB) $(out) | 
|---|
| 182 | endef | 
|---|
| 183 |  | 
|---|
| 184 |  | 
|---|
| 185 | ## Link program | 
|---|
| 186 | # @param    $(target)   Normalized main target name. | 
|---|
| 187 | # @param    $(out)              Program name. | 
|---|
| 188 | # @param    $(objs)     Object files to link together. | 
|---|
| 189 | # @param    $(libs)     Libraries to search. | 
|---|
| 190 | # @param    $(libpath)  Library search paths. | 
|---|
| 191 | # @param    $(flags)    Flags. | 
|---|
| 192 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 193 | # @param    $(deps)             Other dependencies. | 
|---|
| 194 | # @param    $(othersrc) Unhandled sources. | 
|---|
| 195 | # @param    $(custom_pre)   Custom step invoked before linking. | 
|---|
| 196 | # @param    $(custom_post)  Custom step invoked after linking. | 
|---|
| 197 | # | 
|---|
| 198 | # @param    $(outbase)  Output basename (full). Use this for list files and such. | 
|---|
| 199 | TOOL_GXX_LINK_PROGRAM_OUTPUT = | 
|---|
| 200 | TOOL_GXX_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | 
|---|
| 201 | TOOL_GXX_LINK_PROGRAM_DEPORD = | 
|---|
| 202 | define TOOL_GXX_LINK_PROGRAM_CMDS | 
|---|
| 203 | $(QUIET)$(TOOL_GXX_LD) $(flags) -o $(out) $(objs) \ | 
|---|
| 204 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib))) | 
|---|
| 205 | endef | 
|---|
| 206 |  | 
|---|
| 207 |  | 
|---|
| 208 | ## Link DLL | 
|---|
| 209 | # @param    $(target)   Normalized main target name. | 
|---|
| 210 | # @param    $(out)              Program name. | 
|---|
| 211 | # @param    $(objs)     Object files to link together. | 
|---|
| 212 | # @param    $(libs)     Libraries to search. | 
|---|
| 213 | # @param    $(libpath)  Library search paths. | 
|---|
| 214 | # @param    $(flags)    Flags. | 
|---|
| 215 | # @param    $(dirdep)   Directory creation dependency. | 
|---|
| 216 | # @param    $(deps)             Other dependencies. | 
|---|
| 217 | # @param    $(othersrc) Unhandled sources. | 
|---|
| 218 | # @param    $(custom_pre)   Custom step invoked before linking. | 
|---|
| 219 | # @param    $(custom_post)  Custom step invoked after linking. | 
|---|
| 220 | # @param    $(outbase)      Output basename (full). Use this for list files and such. | 
|---|
| 221 | TOOL_GXX_LINK_DLL_OUTPUT = | 
|---|
| 222 | TOOL_GXX_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | 
|---|
| 223 | TOOL_GXX_LINK_DLL_DEPORD = | 
|---|
| 224 | define TOOL_GXX_LINK_DLL_CMDS | 
|---|
| 225 | $(QUIET)$(TOOL_GXX_LD) $(TOOL_GXX_LDFLAGS.dll) $(flags) -o $(out) $(objs) \ | 
|---|
| 226 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib))) | 
|---|
| 227 | endef | 
|---|
| 228 |  | 
|---|