[123] | 1 | # $Id: MINGWW64.kmk 3121 2017-10-31 10:58:59Z bird $
|
---|
| 2 | ## @file
|
---|
[2623] | 3 | # kBuild Tool Config - MinGW-W64.
|
---|
[123] | 4 | #
|
---|
[1547] | 5 |
|
---|
| 6 | #
|
---|
[3121] | 7 | # Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
|
---|
[123] | 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
|
---|
[1612] | 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 | #
|
---|
[123] | 33 |
|
---|
[2623] | 34 | ifdef TOOL_MINGWW64
|
---|
| 35 | $(error Already included (TOOL_MINGWW64=$(TOOL_MINGWW64)))
|
---|
[1786] | 36 | endif
|
---|
[2623] | 37 | TOOL_MINGWW64 := MinGW-W64 - The incomprehensible 64-bit GCC port to Windows.
|
---|
[123] | 38 |
|
---|
[667] | 39 | # Tool Specific Properties
|
---|
[2623] | 40 | ifndef PATH_TOOL_MINGWW64
|
---|
[2750] | 41 | PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS_HST)/mingw-w64/r*)
|
---|
[2623] | 42 | ifeq ($(PATH_TOOL_MINGWW64),)
|
---|
[2726] | 43 | PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/mingw-w64/r*)
|
---|
[655] | 44 | endif
|
---|
[2623] | 45 | ifeq ($(PATH_TOOL_MINGWW64),)
|
---|
[2726] | 46 | PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/mingw-w64/r*)
|
---|
[667] | 47 | endif
|
---|
[2623] | 48 | ifneq ($(PATH_TOOL_MINGWW64),)
|
---|
| 49 | PATH_TOOL_MINGWW64 := $(lastword $(sort $(PATH_TOOL_MINGWW64)))
|
---|
[655] | 50 | endif
|
---|
[667] | 51 | else
|
---|
| 52 | # Resolve any fancy stuff once and for all.
|
---|
[2623] | 53 | PATH_TOOL_MINGWW64 := $(PATH_TOOL_MINGWW64)
|
---|
[123] | 54 | endif
|
---|
| 55 |
|
---|
| 56 | # figure out if it's native or needs a win32 launcher
|
---|
[2623] | 57 | TOOL_MINGWW64_HOSTSUFF_EXE ?= $(HOSTSUFF_EXE)
|
---|
| 58 | ifndef TOOL_MINGWW64_PREFIX
|
---|
| 59 | ifneq ($(PATH_TOOL_MINGWW64),)
|
---|
| 60 | TOOL_MINGWW64_PREFIX := $(PATH_TOOL_MINGWW64)/bin/
|
---|
[657] | 61 | else
|
---|
[2623] | 62 | TOOL_MINGWW64_PREFIX :=
|
---|
[657] | 63 | endif
|
---|
[1504] | 64 | ifneq ($(KBUILD_HOST),win)
|
---|
[2623] | 65 | # # we're cross compiling either using an emulator (wine/odin) or a cross compiler.
|
---|
| 66 | # ifneq ($(PATH_TOOL_MINGWW64),$(subst /win.x86,,$(subst /x86.win,,$(PATH_TOOL_MINGWW64))))
|
---|
| 67 | TOOL_MINGWW64_PREFIX := $(EXEC_X86_WIN32) $(TOOL_MINGWW64_PREFIX)
|
---|
| 68 | TOOL_MINGWW64_HOSTSUFF_EXE := .exe
|
---|
| 69 | # else
|
---|
| 70 | # TOOL_MINGWW64_PREFIX := $(TOOL_MINGWW64_PREFIX)i386-mingw32msvc-
|
---|
| 71 | # TOOL_MINGWW64_HOSTSUFF_EXE :=
|
---|
| 72 | # TOOL_MINGWW64_XCOMPILE := 1
|
---|
| 73 | # endif
|
---|
[667] | 74 | endif
|
---|
| 75 | else
|
---|
| 76 | # Resolve any fancy stuff once and for all.
|
---|
[2623] | 77 | TOOL_MINGWW64_PREFIX := $(TOOL_MINGWW64_PREFIX)
|
---|
[123] | 78 | endif
|
---|
[184] | 79 |
|
---|
[2623] | 80 | TOOL_MINGWW64_CC ?= $(TOOL_MINGWW64_PREFIX)gcc$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
| 81 | TOOL_MINGWW64_CXX ?= $(TOOL_MINGWW64_PREFIX)g++$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
| 82 | TOOL_MINGWW64_AS ?= $(TOOL_MINGWW64_PREFIX)gcc$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
| 83 | TOOL_MINGWW64_AR ?= $(TOOL_MINGWW64_PREFIX)ar$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
| 84 | ifndef TOOL_MINGWW64_XCOMPILE# The gentoo package doesn't have g++.
|
---|
| 85 | TOOL_MINGWW64_LD ?= $(TOOL_MINGWW64_PREFIX)g++$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
[667] | 86 | else
|
---|
[2623] | 87 | TOOL_MINGWW64_LD ?= $(TOOL_MINGWW64_PREFIX)gcc$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
[667] | 88 | endif
|
---|
[2623] | 89 | TOOL_MINGWW64_DLLWRAP ?= $(TOOL_MINGWW64_PREFIX)dllwrap$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
| 90 | TOOL_MINGWW64_DLLTOOL ?= $(TOOL_MINGWW64_PREFIX)dlltool$(TOOL_MINGWW64_HOSTSUFF_EXE)
|
---|
[667] | 91 |
|
---|
| 92 | # General Properties used by kBuild
|
---|
[2623] | 93 | TOOL_MINGWW64_COBJSUFF ?= .o
|
---|
| 94 | TOOL_MINGWW64_CFLAGS ?= -g
|
---|
| 95 | TOOL_MINGWW64_CFLAGS.debug ?= -O0
|
---|
| 96 | TOOL_MINGWW64_CFLAGS.release ?= -O2
|
---|
| 97 | TOOL_MINGWW64_CFLAGS.profile ?= -O2 #-pg
|
---|
| 98 | TOOL_MINGWW64_CINCS ?=
|
---|
| 99 | TOOL_MINGWW64_CDEFS ?=
|
---|
[123] | 100 |
|
---|
[2623] | 101 | TOOL_MINGWW64_CXXOBJSUFF ?= .o
|
---|
| 102 | TOOL_MINGWW64_CXXOBJSUFF ?= .o
|
---|
| 103 | TOOL_MINGWW64_CXXFLAGS ?= -g
|
---|
| 104 | TOOL_MINGWW64_CXXFLAGS.debug ?= -O0
|
---|
| 105 | TOOL_MINGWW64_CXXFLAGS.release ?= -O2
|
---|
| 106 | TOOL_MINGWW64_CXXFLAGS.profile ?= -O2 #-pg
|
---|
| 107 | TOOL_MINGWW64_CXXINCS ?=
|
---|
| 108 | TOOL_MINGWW64_CXXDEFS ?=
|
---|
[123] | 109 |
|
---|
[2623] | 110 | TOOL_MINGWW64_ASFLAGS ?= -g -x assembler-with-cpp
|
---|
| 111 | TOOL_MINGWW64_ASOBJSUFF ?= .o
|
---|
[123] | 112 |
|
---|
[2623] | 113 | TOOL_MINGWW64_ARFLAGS ?= cr
|
---|
| 114 | TOOL_MINGWW64_ARLIBSUFF ?= .a
|
---|
[123] | 115 |
|
---|
[2623] | 116 | TOOL_MINGWW64_LDFLAGS ?=
|
---|
| 117 | TOOL_MINGWW64_LDFLAGS.debug ?= -g
|
---|
| 118 | TOOL_MINGWW64_LDFLAGS.release ?= -s
|
---|
[123] | 119 |
|
---|
| 120 |
|
---|
| 121 | ## Compile C source.
|
---|
| 122 | # @param $(target) Normalized main target name.
|
---|
| 123 | # @param $(source) Source filename (relative).
|
---|
[235] | 124 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
[123] | 125 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
| 126 | # @param $(flags) Flags.
|
---|
| 127 | # @param $(defs) Definitions. No -D or something.
|
---|
| 128 | # @param $(incs) Includes. No -I or something.
|
---|
[235] | 129 | # @param $(dirdep) Directory creation dependency.
|
---|
| 130 | # @param $(deps) Other dependencies.
|
---|
[123] | 131 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[235] | 132 | # @param $(objsuff) Object suffix.
|
---|
[2623] | 133 | TOOL_MINGWW64_COMPILE_C_OUTPUT =
|
---|
| 134 | TOOL_MINGWW64_COMPILE_C_DEPEND =
|
---|
| 135 | TOOL_MINGWW64_COMPILE_C_DEPORD =
|
---|
| 136 | define TOOL_MINGWW64_COMPILE_C_CMDS
|
---|
| 137 | $(QUIET)$(TOOL_MINGWW64_CC) -c\
|
---|
[123] | 138 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
|
---|
[422] | 139 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
|
---|
[380] | 140 | -o $(obj)\
|
---|
[697] | 141 | $(abspath $(source))
|
---|
[123] | 142 | endef
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | ## Compile C++ source.
|
---|
| 146 | # @param $(target) Normalized main target name.
|
---|
| 147 | # @param $(source) Source filename (relative).
|
---|
[235] | 148 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
| 149 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
[123] | 150 | # @param $(flags) Flags.
|
---|
| 151 | # @param $(defs) Definitions. No -D or something.
|
---|
| 152 | # @param $(incs) Includes. No -I or something.
|
---|
[235] | 153 | # @param $(dirdep) Directory creation dependency.
|
---|
| 154 | # @param $(deps) Other dependencies.
|
---|
[123] | 155 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[235] | 156 | # @param $(objsuff) Object suffix.
|
---|
[2623] | 157 | TOOL_MINGWW64_COMPILE_CXX_OUTPUT =
|
---|
| 158 | TOOL_MINGWW64_COMPILE_CXX_DEPEND =
|
---|
| 159 | TOOL_MINGWW64_COMPILE_CXX_DEPORD =
|
---|
| 160 | define TOOL_MINGWW64_COMPILE_CXX_CMDS
|
---|
| 161 | $(QUIET)$(TOOL_MINGWW64_CXX) -c\
|
---|
[123] | 162 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
|
---|
[422] | 163 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
|
---|
[380] | 164 | -o $(obj)\
|
---|
[697] | 165 | $(abspath $(source))
|
---|
[123] | 166 | endef
|
---|
| 167 |
|
---|
| 168 |
|
---|
[470] | 169 | ## Compile Assembly source.
|
---|
| 170 | # @param $(target) Normalized main target name.
|
---|
| 171 | # @param $(source) Source filename (relative).
|
---|
| 172 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
| 173 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
| 174 | # @param $(flags) Flags.
|
---|
| 175 | # @param $(defs) Definitions. No -D or something.
|
---|
| 176 | # @param $(incs) Includes. No -I or something.
|
---|
| 177 | # @param $(dirdep) Directory creation dependency.
|
---|
| 178 | # @param $(deps) Other dependencies.
|
---|
| 179 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
| 180 | # @param $(objsuff) Object suffix.
|
---|
| 181 | #
|
---|
[2623] | 182 | TOOL_MINGWW64_COMPILE_AS_OUTPUT =
|
---|
| 183 | TOOL_MINGWW64_COMPILE_AS_DEPEND =
|
---|
| 184 | TOOL_MINGWW64_COMPILE_AS_DEPORD =
|
---|
| 185 | define TOOL_MINGWW64_COMPILE_AS_CMDS
|
---|
| 186 | $(QUIET)$(TOOL_MINGWW64_AS) -c\
|
---|
[470] | 187 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
|
---|
| 188 | -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
|
---|
| 189 | -o $(obj)\
|
---|
[697] | 190 | $(abspath $(source))
|
---|
[470] | 191 | endef
|
---|
| 192 |
|
---|
| 193 |
|
---|
[123] | 194 | ## Link library
|
---|
| 195 | # @param $(target) Normalized main target name.
|
---|
[752] | 196 | # @param $(out) Library name.
|
---|
[123] | 197 | # @param $(objs) Object files to put in the library.
|
---|
| 198 | # @param $(flags) Flags.
|
---|
[235] | 199 | # @param $(dirdep) Directory creation dependency.
|
---|
[353] | 200 | # @param $(deps) Other dependencies.
|
---|
[123] | 201 | #
|
---|
| 202 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[2623] | 203 | TOOL_MINGWW64_LINK_LIBRARY_OUTPUT = $(out).ar-script
|
---|
| 204 | TOOL_MINGWW64_LINK_LIBRARY_DEPEND = $(othersrc)
|
---|
| 205 | TOOL_MINGWW64_LINK_LIBRARY_DEPORD =
|
---|
| 206 | define TOOL_MINGWW64_LINK_LIBRARY_CMDS
|
---|
[772] | 207 | $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
|
---|
[771] | 208 | $(QUIET)$(APPEND) -n $(out).ar-script \
|
---|
| 209 | $(foreach o,$(objs), 'ADDMOD $(o)') \
|
---|
| 210 | $(foreach o,$(othersrc), 'ADDLIB $(o)')
|
---|
| 211 | $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
|
---|
| 212 | $(QUIET)$(APPEND) $(out).ar-script 'END'
|
---|
[2623] | 213 | $(QUIET)$(TOOL_MINGWW64_AR) -M < $(out).ar-script
|
---|
[771] | 214 | endef
|
---|
[123] | 215 |
|
---|
| 216 |
|
---|
[1034] | 217 |
|
---|
[123] | 218 | ## Link program
|
---|
| 219 | # @param $(target) Normalized main target name.
|
---|
[353] | 220 | # @param $(out) Program name.
|
---|
[123] | 221 | # @param $(objs) Object files to link together.
|
---|
| 222 | # @param $(libs) Libraries to search.
|
---|
| 223 | # @param $(libpath) Library search paths.
|
---|
| 224 | # @param $(flags) Flags.
|
---|
[235] | 225 | # @param $(dirdep) Directory creation dependency.
|
---|
[353] | 226 | # @param $(deps) Other dependencies.
|
---|
| 227 | # @param $(othersrc) Unhandled sources.
|
---|
[235] | 228 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
| 229 | # @param $(custom_post) Custom step invoked after linking.
|
---|
[123] | 230 | #
|
---|
| 231 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[2623] | 232 | TOOL_MINGWW64_LINK_PROGRAM_OUTPUT =
|
---|
| 233 | TOOL_MINGWW64_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
|
---|
| 234 | TOOL_MINGWW64_LINK_PROGRAM_DEPORD =
|
---|
| 235 | define TOOL_MINGWW64_LINK_PROGRAM_CMDS
|
---|
| 236 | $(QUIET)$(TOOL_MINGWW64_LD) $(flags) -o $(out) $(objs)\
|
---|
[380] | 237 | $(foreach p,$(libpath), -L$(p))\
|
---|
[1612] | 238 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
|
---|
[123] | 239 | endef
|
---|
| 240 |
|
---|
[141] | 241 |
|
---|
[353] | 242 | ## Link DLL.
|
---|
[141] | 243 | # @param $(target) Normalized main target name.
|
---|
[353] | 244 | # @param $(out) DLL name.
|
---|
[141] | 245 | # @param $(objs) Object files to link together.
|
---|
| 246 | # @param $(libs) Libraries to search.
|
---|
| 247 | # @param $(libpath) Library search paths.
|
---|
| 248 | # @param $(flags) Flags.
|
---|
[235] | 249 | # @param $(dirdep) Directory creation dependency.
|
---|
[353] | 250 | # @param $(deps) Other dependencies.
|
---|
| 251 | # @param $(othersrc) Unhandled sources.
|
---|
[235] | 252 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
| 253 | # @param $(custom_post) Custom step invoked after linking.
|
---|
[141] | 254 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
[2623] | 255 | TOOL_MINGWW64_LINK_DLL_OUTPUT =
|
---|
| 256 | TOOL_MINGWW64_LINK_DLL_OUTPUT_MAYBE = $(outbase).a $(outbase).exp $(PATH_STAGE_LIB)/$(notdir $(outbase)).exp $(PATH_STAGE_LIB)/$(notdir $(outbase)).a
|
---|
[1612] | 257 | ## @todo Find a better solution for installing the extra files (.a, .exp, .pdb, etc).
|
---|
[2623] | 258 | TOOL_MINGWW64_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
|
---|
[380] | 259 | $(filter %.def %.res,$(othersrc))
|
---|
[2623] | 260 | TOOL_MINGWW64_LINK_DLL_DEPORD = $(call DIRDEP,$(PATH_STAGE_LIB))
|
---|
| 261 | define TOOL_MINGWW64_LINK_DLL_CMDS
|
---|
[2695] | 262 | $(QUIET)$(REDIRECT) -C "$(dir $(out))" -- $(TOOL_MINGWW64_DLLWRAP) $(flags)\
|
---|
| 263 | --dllname=$(notdir $(out))\
|
---|
[380] | 264 | --output-exp=$(outbase).exp\
|
---|
| 265 | --output-lib=$(outbase).a\
|
---|
| 266 | $(foreach def,$(filter %.def,$(othersrc)), --def $(def))\
|
---|
| 267 | $(filter %.res,$(othersrc))\
|
---|
| 268 | $(objs)\
|
---|
| 269 | $(foreach p,$(libpath), -L$(p))\
|
---|
[1612] | 270 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
|
---|
[2487] | 271 | $(QUIET)$(CP) $(outbase).exp $(outbase).a $(PATH_STAGE_LIB)/
|
---|
[141] | 272 | endef
|
---|
[1612] | 273 | ## @todo separate install stuff!
|
---|