[72] | 1 | # $Id: GXX.kmk 3566 2022-06-13 15:37:08Z bird $
|
---|
| 2 | ## @file
|
---|
[971] | 3 | # kBuild Tool Config - Generic GCC using the system GCC, for building C++ code.
|
---|
[72] | 4 | #
|
---|
[1547] | 5 |
|
---|
| 6 | #
|
---|
[3121] | 7 | # Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
|
---|
[72] | 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 | #
|
---|
[1547] | 26 | # As a special exception you are granted permission to include this file, via
|
---|
[2243] | 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.
|
---|
[1547] | 29 | # This exception does not however invalidate any other reasons why the makefile,
|
---|
| 30 | # program, whatever should not be covered the GPL.
|
---|
| 31 | #
|
---|
| 32 | #
|
---|
[72] | 33 |
|
---|
[971] | 34 | TOOL_GXX := Generic GCC using the system GCC, for building C++ code.
|
---|
[72] | 35 |
|
---|
[667] | 36 | # Tool Specific Properties
|
---|
[3391] | 37 | ifndef TOOL_GXX_PREFIX
|
---|
[3393] | 38 | TOOL_GXX_PREFIX :=
|
---|
[3391] | 39 | endif
|
---|
| 40 | ifndef TOOL_GXX_SUFFIX
|
---|
[3393] | 41 | TOOL_GXX_SUFFIX := $(HOSTSUFF_EXE)
|
---|
[3391] | 42 | endif
|
---|
[3393] | 43 | if1of ($(KBUILD_HOST), solaris)
|
---|
| 44 | TOOL_GXX_PREFIX2 ?= g
|
---|
| 45 | else
|
---|
| 46 | TOOL_GXX_PREFIX2 ?=
|
---|
| 47 | endif
|
---|
| 48 | TOOL_GXX_SUFFIX2 ?= $(HOSTSUFF_EXE)
|
---|
| 49 | TOOL_GXX_PREFIX3 ?=
|
---|
| 50 | TOOL_GXX_SUFFIX3 ?= $(HOSTSUFF_EXE)
|
---|
| 51 | TOOL_GXX_CC ?= $(TOOL_GXX_PREFIX)gcc$(TOOL_GXX_SUFFIX)
|
---|
| 52 | TOOL_GXX_CXX ?= $(TOOL_GXX_PREFIX)g++$(TOOL_GXX_SUFFIX)
|
---|
| 53 | TOOL_GXX_PCH ?= $(TOOL_GXX_CXX)
|
---|
| 54 | TOOL_GXX_AS ?= $(TOOL_GXX_PREFIX)gcc$(TOOL_GXX_SUFFIX)
|
---|
| 55 | TOOL_GXX_AR ?= $(TOOL_GXX_PREFIX2)ar$(TOOL_GXX_SUFFIX2)
|
---|
| 56 | TOOL_GXX_RANLIB ?= $(TOOL_GXX_PREFIX2)ranlib$(TOOL_GXX_SUFFIX2)
|
---|
| 57 | TOOL_GXX_LD ?= $(TOOL_GXX_PREFIX)g++$(TOOL_GXX_SUFFIX)
|
---|
[3391] | 58 | TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll
|
---|
[971] | 59 | TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib
|
---|
[1504] | 60 | ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)
|
---|
[3391] | 61 | TOOL_GXX_LDFLAGS.dll ?= -shared
|
---|
[667] | 62 | else
|
---|
[3391] | 63 | TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET))
|
---|
[667] | 64 | endif
|
---|
[73] | 65 |
|
---|
[667] | 66 | # General Properties used by kBuild
|
---|
[971] | 67 | TOOL_GXX_COBJSUFF ?= .o
|
---|
| 68 | TOOL_GXX_CFLAGS ?=
|
---|
| 69 | TOOL_GXX_CFLAGS.debug ?= -g
|
---|
| 70 | TOOL_GXX_CFLAGS.profile ?= -g -O2 #-pg
|
---|
| 71 | TOOL_GXX_CFLAGS.release ?= -O2
|
---|
| 72 | TOOL_GXX_CINCS ?=
|
---|
| 73 | TOOL_GXX_CDEFS ?=
|
---|
[72] | 74 |
|
---|
[971] | 75 | TOOL_GXX_CXXOBJSUFF ?= .o
|
---|
| 76 | TOOL_GXX_CXXOBJSUFF ?= .o
|
---|
| 77 | TOOL_GXX_CXXFLAGS ?=
|
---|
| 78 | TOOL_GXX_CXXFLAGS.debug ?= -g -O0
|
---|
| 79 | TOOL_GXX_CXXFLAGS.profile ?= -g -O2 #-pg
|
---|
| 80 | TOOL_GXX_CXXFLAGS.release ?= -O2
|
---|
| 81 | TOOL_GXX_CXXINCS ?=
|
---|
| 82 | TOOL_GXX_CXXDEFS ?=
|
---|
[72] | 83 |
|
---|
[3257] | 84 | TOOL_GXX_PCHOBJSUFF ?= .h.gch
|
---|
| 85 | TOOL_GXX_PCHFLAGS ?= $(TOOL_GXX_CXXFLAGS)
|
---|
| 86 | TOOL_GXX_PCHFLAGS.debug ?= $(TOOL_GXX_CXXFLAGS.debug)
|
---|
| 87 | TOOL_GXX_PCHFLAGS.profile ?= $(TOOL_GXX_CXXFLAGS.profile)
|
---|
| 88 | TOOL_GXX_PCHFLAGS.release ?= $(TOOL_GXX_CXXFLAGS.release)
|
---|
| 89 | TOOL_GXX_PCHINCS ?= $(TOOL_GXX_CXXINCS)
|
---|
| 90 | TOOL_GXX_PCHDEFS ?= $(TOOL_GXX_CXXDEFS)
|
---|
| 91 |
|
---|
[971] | 92 | TOOL_GXX_ASFLAGS ?= -x assembler-with-cpp
|
---|
| 93 | TOOL_GXX_ASFLAGS.debug ?= -g
|
---|
| 94 | TOOL_GXX_ASFLAGS.profile ?= -g
|
---|
| 95 | TOOL_GXX_ASOBJSUFF ?= .o
|
---|
[73] | 96 |
|
---|
[971] | 97 | TOOL_GXX_ARFLAGS ?= cr
|
---|
| 98 | TOOL_GXX_ARLIBSUFF ?= .a
|
---|
[73] | 99 |
|
---|
[971] | 100 | TOOL_GXX_LDFLAGS ?=
|
---|
| 101 | TOOL_GXX_LDFLAGS.debug ?= -g
|
---|
| 102 | TOOL_GXX_LDFLAGS.profile ?= -g
|
---|
[73] | 103 |
|
---|
[74] | 104 |
|
---|
[72] | 105 | ## Compile C source.
|
---|
[73] | 106 | # @param $(target) Normalized main target name.
|
---|
| 107 | # @param $(source) Source filename (relative).
|
---|
[235] | 108 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
[73] | 109 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
| 110 | # @param $(flags) Flags.
|
---|
| 111 | # @param $(defs) Definitions. No -D or something.
|
---|
| 112 | # @param $(incs) Includes. No -I or something.
|
---|
[235] | 113 | # @param $(dirdep) Directory creation dependency.
|
---|
| 114 | # @param $(deps) Other dependencies.
|
---|
[73] | 115 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[235] | 116 | # @param $(objsuff) Object suffix.
|
---|
[380] | 117 | #
|
---|
[971] | 118 | TOOL_GXX_COMPILE_C_OUTPUT =
|
---|
| 119 | TOOL_GXX_COMPILE_C_DEPEND =
|
---|
| 120 | TOOL_GXX_COMPILE_C_DEPORD =
|
---|
| 121 | define TOOL_GXX_COMPILE_C_CMDS
|
---|
| 122 | $(QUIET)$(TOOL_GXX_CC) -c\
|
---|
[3566] | 123 | $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
|
---|
[846] | 124 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
|
---|
| 125 | -o $(obj)\
|
---|
[697] | 126 | $(abspath $(source))
|
---|
[2431] | 127 | $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
|
---|
[72] | 128 | endef
|
---|
| 129 |
|
---|
[73] | 130 |
|
---|
[77] | 131 | ## Compile C++ source.
|
---|
| 132 | # @param $(target) Normalized main target name.
|
---|
| 133 | # @param $(source) Source filename (relative).
|
---|
[235] | 134 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
[3257] | 135 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
[77] | 136 | # @param $(flags) Flags.
|
---|
| 137 | # @param $(defs) Definitions. No -D or something.
|
---|
| 138 | # @param $(incs) Includes. No -I or something.
|
---|
[235] | 139 | # @param $(dirdep) Directory creation dependency.
|
---|
[3257] | 140 | # @param $(deps) Other dependencies.
|
---|
[77] | 141 | #
|
---|
| 142 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[235] | 143 | # @param $(objsuff) Object suffix.
|
---|
[971] | 144 | TOOL_GXX_COMPILE_CXX_OUTPUT =
|
---|
[3257] | 145 | TOOL_GXX_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
|
---|
[971] | 146 | TOOL_GXX_COMPILE_CXX_DEPORD =
|
---|
| 147 | define TOOL_GXX_COMPILE_CXX_CMDS
|
---|
| 148 | $(QUIET)$(TOOL_GXX_CXX) -c\
|
---|
[3566] | 149 | $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
|
---|
[3257] | 150 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
|
---|
| 151 | -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
|
---|
| 152 | ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
|
---|
| 153 | $(abspath $(source))
|
---|
| 154 | $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
|
---|
| 155 | endef
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | ## Precompile C++ header.
|
---|
| 159 | # @param $(target) Normalized main target name.
|
---|
| 160 | # @param $(source) Source filename (relative).
|
---|
| 161 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
| 162 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
| 163 | # @param $(flags) Flags.
|
---|
| 164 | # @param $(defs) Definitions. No -D or something.
|
---|
| 165 | # @param $(incs) Includes. No -I or something.
|
---|
| 166 | # @param $(dirdep) Directory creation dependency.
|
---|
| 167 | # @param $(deps) Other dependencies.
|
---|
| 168 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
| 169 | # @param $(objsuff) Object suffix.
|
---|
| 170 | TOOL_GXX_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
|
---|
| 171 | TOOL_GXX_COMPILE_PCH_DEPEND =
|
---|
| 172 | TOOL_GXX_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
|
---|
| 173 | define TOOL_GXX_COMPILE_PCH_CMDS
|
---|
| 174 | $(QUIET)$(TOOL_GXX_PCH) -c\
|
---|
[3566] | 175 | $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
|
---|
[3257] | 176 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
|
---|
[846] | 177 | -o $(obj)\
|
---|
[697] | 178 | $(abspath $(source))
|
---|
[3257] | 179 | $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
|
---|
[2431] | 180 | $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
|
---|
[77] | 181 | endef
|
---|
| 182 |
|
---|
| 183 |
|
---|
[465] | 184 | ## Compile Assembly source.
|
---|
| 185 | # @param $(target) Normalized main target name.
|
---|
| 186 | # @param $(source) Source filename (relative).
|
---|
| 187 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
| 188 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
| 189 | # @param $(flags) Flags.
|
---|
| 190 | # @param $(defs) Definitions. No -D or something.
|
---|
| 191 | # @param $(incs) Includes. No -I or something.
|
---|
| 192 | # @param $(dirdep) Directory creation dependency.
|
---|
| 193 | # @param $(deps) Other dependencies.
|
---|
| 194 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
| 195 | # @param $(objsuff) Object suffix.
|
---|
| 196 | #
|
---|
[971] | 197 | TOOL_GXX_COMPILE_AS_OUTPUT =
|
---|
| 198 | TOOL_GXX_COMPILE_AS_DEPEND =
|
---|
| 199 | TOOL_GXX_COMPILE_AS_DEPORD =
|
---|
| 200 | define TOOL_GXX_COMPILE_AS_CMDS
|
---|
| 201 | $(QUIET)$(TOOL_GXX_AS) -c\
|
---|
[3566] | 202 | $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
|
---|
[846] | 203 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
|
---|
| 204 | -o $(obj)\
|
---|
[697] | 205 | $(abspath $(source))
|
---|
[2431] | 206 | $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
|
---|
[465] | 207 | endef
|
---|
| 208 |
|
---|
| 209 |
|
---|
[73] | 210 | ## Link library
|
---|
| 211 | # @param $(target) Normalized main target name.
|
---|
[380] | 212 | # @param $(out) Library name.
|
---|
[73] | 213 | # @param $(objs) Object files to put in the library.
|
---|
| 214 | # @param $(flags) Flags.
|
---|
[235] | 215 | # @param $(dirdep) Directory creation dependency.
|
---|
| 216 | # @param $(deps) Other dependencies.
|
---|
[73] | 217 | #
|
---|
| 218 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[971] | 219 | TOOL_GXX_LINK_LIBRARY_OUTPUT =
|
---|
| 220 | TOOL_GXX_LINK_LIBRARY_DEPEND =
|
---|
| 221 | TOOL_GXX_LINK_LIBRARY_DEPORD =
|
---|
| 222 | define TOOL_GXX_LINK_LIBRARY_CMDS
|
---|
[3257] | 223 | $(QUIET)$(TOOL_GXX_AR) $(flags) $(out) $(filter-out %.h.gch,$(objs))
|
---|
| 224 | $(call xargs,$(QUIET)$(TOOL_GXX_AR) $(flags) $(out),$(filter-out %.h.gch,$(objs)))
|
---|
[846] | 225 | $(foreach lib,$(othersrc)\
|
---|
| 226 | ,$(NL)$(TAB)$(call MSG_AR_MERGE,$(target),$(out),$(lib)) \
|
---|
| 227 | $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))ar.tmp.dir/* \
|
---|
| 228 | $(NL)$(TAB)$(QUIET)$(MKDIR) -p $(dir $(outbase))/ar.tmp.dir/ \
|
---|
| 229 | $(NL)$(TAB)$(QUIET)(cd $(dir $(outbase))ar.tmp.dir/ \
|
---|
[971] | 230 | && $(TOOL_GXX_AR) x $(abspath $(lib)) \
|
---|
| 231 | && $(TOOL_GXX_AR) $(flags) $(out) *) \
|
---|
[846] | 232 | $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))/ar.tmp.dir/* \
|
---|
| 233 | $(NL)$(TAB)$(QUIET)$(RMDIR) $(dir $(outbase))ar.tmp.dir/)
|
---|
[971] | 234 | $(QUIET)$(TOOL_GXX_RANLIB) $(out)
|
---|
[73] | 235 | endef
|
---|
| 236 |
|
---|
[74] | 237 |
|
---|
| 238 | ## Link program
|
---|
| 239 | # @param $(target) Normalized main target name.
|
---|
[353] | 240 | # @param $(out) Program name.
|
---|
[74] | 241 | # @param $(objs) Object files to link together.
|
---|
| 242 | # @param $(libs) Libraries to search.
|
---|
| 243 | # @param $(libpath) Library search paths.
|
---|
| 244 | # @param $(flags) Flags.
|
---|
[235] | 245 | # @param $(dirdep) Directory creation dependency.
|
---|
| 246 | # @param $(deps) Other dependencies.
|
---|
| 247 | # @param $(othersrc) Unhandled sources.
|
---|
| 248 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
| 249 | # @param $(custom_post) Custom step invoked after linking.
|
---|
[74] | 250 | #
|
---|
| 251 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[971] | 252 | TOOL_GXX_LINK_PROGRAM_OUTPUT =
|
---|
| 253 | TOOL_GXX_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
|
---|
| 254 | TOOL_GXX_LINK_PROGRAM_DEPORD =
|
---|
| 255 | define TOOL_GXX_LINK_PROGRAM_CMDS
|
---|
[3257] | 256 | $(QUIET)$(TOOL_GXX_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
|
---|
[1259] | 257 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
|
---|
[74] | 258 | endef
|
---|
| 259 |
|
---|
[130] | 260 |
|
---|
[353] | 261 | ## Link DLL
|
---|
[130] | 262 | # @param $(target) Normalized main target name.
|
---|
[353] | 263 | # @param $(out) Program name.
|
---|
[130] | 264 | # @param $(objs) Object files to link together.
|
---|
| 265 | # @param $(libs) Libraries to search.
|
---|
| 266 | # @param $(libpath) Library search paths.
|
---|
| 267 | # @param $(flags) Flags.
|
---|
[235] | 268 | # @param $(dirdep) Directory creation dependency.
|
---|
| 269 | # @param $(deps) Other dependencies.
|
---|
| 270 | # @param $(othersrc) Unhandled sources.
|
---|
| 271 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
| 272 | # @param $(custom_post) Custom step invoked after linking.
|
---|
[380] | 273 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[971] | 274 | TOOL_GXX_LINK_DLL_OUTPUT =
|
---|
| 275 | TOOL_GXX_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
|
---|
| 276 | TOOL_GXX_LINK_DLL_DEPORD =
|
---|
| 277 | define TOOL_GXX_LINK_DLL_CMDS
|
---|
[3257] | 278 | $(QUIET)$(TOOL_GXX_LD) $(TOOL_GXX_LDFLAGS.dll) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
|
---|
[1259] | 279 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
|
---|
[130] | 280 | endef
|
---|
| 281 |
|
---|