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

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

map files.

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