source: trunk/kBuild/tools/MINGW32.kmk@ 655

Last change on this file since 655 was 655, checked in by bird, 19 years ago

use ?= everywhere.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1# $Id: MINGW32.kmk 655 2006-12-04 15:34:29Z bird $
2## @file
3#
4# kBuild Tool Config - MINGW32 GCC.
5#
6# Copyright (c) 2004-2006 knut st. osmundsen <bird-srcspam@anduin.net>
7#
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
27TOOL_MINGW32 := MinGW32 GCC v3.3+
28
29# find latest installed version
30ifndef PATH_TOOL_MINGW32
31 PATH_DEV_BLD ?= $(PATH_DEV)/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)
32 PATH_TOOL_MINGW32 := $(sort $(wildcard $(PATH_DEV)/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)/mingw32/v*.*))
33 ifeq ($(PATH_TOOL_MINGW32),)
34 PATH_TOOL_MINGW32 := $(sort $(wildcard $(PATH_DEV)/x86.win32/mingw32/v*.*))
35 endif
36 ifneq ($(PATH_TOOL_MINGW32),)
37 PATH_TOOL_MINGW32 := $(call lastword,$(PATH_TOOL_MINGW32))
38 endif
39endif
40
41# figure out if it's native or needs a win32 launcher
42_TOOL_MINGW32_PREFIX ?=
43ifneq ($(PATH_TOOL_MINGW32),)
44_TOOL_MINGW32_PREFIX ?= $(PATH_TOOL_MINGW32)/bin/
45endif
46_TOOL_MINGW32_SUFF_EXE ?= $(HOSTSUFF_EXE)
47ifneq ($(BUILD_PLATFORM),win32)
48# we're cross compiling either using wine/odin or a cross compiler.
49ifneq ($(PATH_TOOL_MINGW32),$(subst x86.win32,,$(PATH_TOOL_MINGW32)))
50_TOOL_MINGW32_PREFIX ?= $(EXEC_X86_WIN32) $(_TOOL_MINGW32_PREFIX)
51_TOOL_MINGW32_SUFF_EXE ?= .exe
52else
53_TOOL_MINGW32_PREFIX ?= $(_TOOL_MINGW32_PREFIX)i386-mingw32msvc-
54_TOOL_MINGW32_SUFF_EXE ?=
55_TOOL_MINGW32_XCOMPILE ?= 1
56endif
57endif
58
59TOOL_MINGW32_CC ?= $(_TOOL_MINGW32_PREFIX)gcc$(_TOOL_MINGW32_SUFF_EXE)
60TOOL_MINGW32_COBJSUFF ?= .o
61TOOL_MINGW32_CFLAGS ?= -g
62TOOL_MINGW32_CFLAGS.debug ?= -O0
63TOOL_MINGW32_CFLAGS.release ?= -O2
64TOOL_MINGW32_CFLAGS.profile ?= -O2 #-pg
65TOOL_MINGW32_CINCS ?=
66TOOL_MINGW32_CDEFS ?=
67
68TOOL_MINGW32_CXX ?= $(_TOOL_MINGW32_PREFIX)g++$(_TOOL_MINGW32_SUFF_EXE)
69TOOL_MINGW32_CXXOBJSUFF ?= .o
70TOOL_MINGW32_CXXOBJSUFF ?= .o
71TOOL_MINGW32_CXXFLAGS ?= -g
72TOOL_MINGW32_CXXFLAGS.debug ?= -O0
73TOOL_MINGW32_CXXFLAGS.release ?= -O2
74TOOL_MINGW32_CXXFLAGS.profile ?= -O2 #-pg
75TOOL_MINGW32_CXXINCS ?=
76TOOL_MINGW32_CXXDEFS ?=
77
78TOOL_MINGW32_AS ?= $(_TOOL_MINGW32_PREFIX)gcc$(_TOOL_MINGW32_SUFF_EXE)
79TOOL_MINGW32_ASFLAGS ?= -g -x assembler-with-cpp
80TOOL_MINGW32_ASOBJSUFF ?= .o
81
82TOOL_MINGW32_AR ?= $(_TOOL_MINGW32_PREFIX)ar$(_TOOL_MINGW32_SUFF_EXE)
83TOOL_MINGW32_ARFLAGS ?= cr
84TOOL_MINGW32_ARLIBSUFF ?= .a
85
86# The linux cross compiler ebuild haven't got g++, this is a hack for that.
87ifndef _TOOL_MINGW32_XCOMPILE
88TOOL_MINGW32_LD ?= $(_TOOL_MINGW32_PREFIX)g++$(_TOOL_MINGW32_SUFF_EXE)
89else
90TOOL_MINGW32_LD ?= $(_TOOL_MINGW32_PREFIX)gcc$(_TOOL_MINGW32_SUFF_EXE)
91endif
92TOOL_MINGW32_LDFLAGS ?=
93TOOL_MINGW32_LDFLAGS.debug ?= -g
94TOOL_MINGW32_LDFLAGS.release ?= -s
95TOOL_MINGW32_LD_MAP ?= -Wl,-Map -Wl,$(1) -Wl,--cref
96TOOL_MINGW32_LD_SYSMOD_MAP ?= -Map $(1) --cref
97
98TOOL_MINGW32_DLLWRAP ?= $(_TOOL_MINGW32_PREFIX)dllwrap$(_TOOL_MINGW32_SUFF_EXE)
99TOOL_MINGW32_DLLTOOL ?= $(_TOOL_MINGW32_PREFIX)dlltool$(_TOOL_MINGW32_SUFF_EXE)
100
101
102## Compile C source.
103# @param $(target) Normalized main target name.
104# @param $(source) Source filename (relative).
105# @param $(obj) Object file name. This shall be (re)created by the compilation.
106# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
107# @param $(flags) Flags.
108# @param $(defs) Definitions. No -D or something.
109# @param $(incs) Includes. No -I or something.
110# @param $(dirdep) Directory creation dependency.
111# @param $(deps) Other dependencies.
112# @param $(outbase) Output basename (full). Use this for list files and such.
113# @param $(objsuff) Object suffix.
114TOOL_MINGW32_COMPILE_C_OUTPUT =
115TOOL_MINGW32_COMPILE_C_DEPEND =
116TOOL_MINGW32_COMPILE_C_DEPORD =
117define TOOL_MINGW32_COMPILE_C_CMDS
118 $(TOOL_MINGW32_CC) -c\
119 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
120 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
121 -o $(obj)\
122 $(call ABSPATH,$(source))
123endef
124
125
126## Compile C++ source.
127# @param $(target) Normalized main target name.
128# @param $(source) Source filename (relative).
129# @param $(obj) Object file name. This shall be (re)created by the compilation.
130# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
131# @param $(flags) Flags.
132# @param $(defs) Definitions. No -D or something.
133# @param $(incs) Includes. No -I or something.
134# @param $(dirdep) Directory creation dependency.
135# @param $(deps) Other dependencies.
136# @param $(outbase) Output basename (full). Use this for list files and such.
137# @param $(objsuff) Object suffix.
138TOOL_MINGW32_COMPILE_CXX_OUTPUT =
139TOOL_MINGW32_COMPILE_CXX_DEPEND =
140TOOL_MINGW32_COMPILE_CXX_DEPORD =
141define TOOL_MINGW32_COMPILE_CXX_CMDS
142 $(TOOL_MINGW32_CXX) -c\
143 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
144 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
145 -o $(obj)\
146 $(call ABSPATH,$(source))
147endef
148
149
150## Compile Assembly source.
151# @param $(target) Normalized main target name.
152# @param $(source) Source filename (relative).
153# @param $(obj) Object file name. This shall be (re)created by the compilation.
154# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
155# @param $(flags) Flags.
156# @param $(defs) Definitions. No -D or something.
157# @param $(incs) Includes. No -I or something.
158# @param $(dirdep) Directory creation dependency.
159# @param $(deps) Other dependencies.
160# @param $(outbase) Output basename (full). Use this for list files and such.
161# @param $(objsuff) Object suffix.
162#
163TOOL_MINGW32_COMPILE_AS_OUTPUT =
164TOOL_MINGW32_COMPILE_AS_DEPEND =
165TOOL_MINGW32_COMPILE_AS_DEPORD =
166define TOOL_MINGW32_COMPILE_AS_CMDS
167 $(TOOL_MINGW32_AS) -c\
168 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
169 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
170 -o $(obj)\
171 $(call ABSPATH,$(source))
172endef
173
174
175## Link library
176# @param $(target) Normalized main target name.
177# @param $(lib) Library name.
178# @param $(objs) Object files to put in the library.
179# @param $(flags) Flags.
180# @param $(dirdep) Directory creation dependency.
181# @param $(deps) Other dependencies.
182#
183# @param $(outbase) Output basename (full). Use this for list files and such.
184TOOL_MINGW32_LINK_LIBRARY_OUTPUT = $(lib).ar-script
185TOOL_MINGW32_LINK_LIBRARY_DEPEND = $(filter %.a %.lib,$(othersrc))
186TOOL_MINGW32_LINK_LIBRARY_DEPORD =
187define TOOL_MINGW32_LINK_LIBRARY_CMDS
188 $(APPEND) $(lib).ar-script "CREATE $(out)"
189 $(foreach o, $(objs)\
190 ,$(NL)$(TAB)$(APPEND) $(lib).ar-script "ADDMOD $(o)")
191 $(foreach srclib, $(filter %.a %.lib,$(othersrc))\
192 ,$(NL)$(TAB)$(APPEND) $(lib).ar-script "ADDLIB $(srclib)")
193 $(APPEND) $(lib).ar-script "SAVE"
194 $(APPEND) $(lib).ar-script "END"
195 $(TOOL_MINGW32_AR) -M < $(lib).ar-script
196endef
197
198
199## Link program
200# @param $(target) Normalized main target name.
201# @param $(out) Program name.
202# @param $(objs) Object files to link together.
203# @param $(libs) Libraries to search.
204# @param $(libpath) Library search paths.
205# @param $(flags) Flags.
206# @param $(dirdep) Directory creation dependency.
207# @param $(deps) Other dependencies.
208# @param $(othersrc) Unhandled sources.
209# @param $(custom_pre) Custom step invoked before linking.
210# @param $(custom_post) Custom step invoked after linking.
211#
212# @param $(outbase) Output basename (full). Use this for list files and such.
213TOOL_MINGW32_LINK_PROGRAM_OUTPUT =
214TOOL_MINGW32_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
215TOOL_MINGW32_LINK_PROGRAM_DEPORD =
216define TOOL_MINGW32_LINK_PROGRAM_CMDS
217 $(TOOL_MINGW32_LD) $(flags) -o $(out) $(objs)\
218 $(foreach p,$(libpath), -L$(p))\
219 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
220 $(call TOOL_MINGW32_LD_MAP,$(outbase).map)
221endef
222
223
224## Link DLL.
225# @param $(target) Normalized main target name.
226# @param $(out) DLL name.
227# @param $(objs) Object files to link together.
228# @param $(libs) Libraries to search.
229# @param $(libpath) Library search paths.
230# @param $(flags) Flags.
231# @param $(dirdep) Directory creation dependency.
232# @param $(deps) Other dependencies.
233# @param $(othersrc) Unhandled sources.
234# @param $(custom_pre) Custom step invoked before linking.
235# @param $(custom_post) Custom step invoked after linking.
236# @param $(outbase) Output basename (full). Use this for list files and such.
237TOOL_MINGW32_LINK_DLL_OUTPUT = $(outbase).a $(outbase).exp
238TOOL_MINGW32_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
239 $(filter %.def %.res,$(othersrc))
240TOOL_MINGW32_LINK_DLL_DEPORD = $(call DIRDEP,$(PATH_LIB))
241define TOOL_MINGW32_LINK_DLL_CMDS
242 $(TOOL_MINGW32_DLLWRAP) $(flags)\
243 --dllname=$(out)\
244 --output-exp=$(outbase).exp\
245 --output-lib=$(outbase).a\
246 $(foreach def,$(filter %.def,$(othersrc)), --def $(def))\
247 $(filter %.res,$(othersrc))\
248 $(objs)\
249 $(foreach p,$(libpath), -L$(p))\
250 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
251 $(call TOOL_MINGW32_LD_MAP,$(outbase).map)
252 $(CP) $(outbase).exp $(outbase).a $(PATH_LIB)/
253endef
254## @todo seperate install stuff!
Note: See TracBrowser for help on using the repository browser.