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

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

assembler.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1# $Id: MINGW32.kmk 470 2006-07-15 04:33:03Z 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
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)gcc$(_TOOL_MINGW32_SUFF_EXE)
78TOOL_MINGW32_ASFLAGS := -g -x assembler-with-cpp
79TOOL_MINGW32_ASOBJSUFF := .o
80
81TOOL_MINGW32_AR := $(_TOOL_MINGW32_PREFIX)ar$(_TOOL_MINGW32_SUFF_EXE)
82TOOL_MINGW32_ARFLAGS := cr
83TOOL_MINGW32_ARLIBSUFF := .a
84
85# The linux cross compiler ebuild haven't got g++, this is a hack for that.
86ifndef _TOOL_MINGW32_XCOMPILE
87TOOL_MINGW32_LD := $(_TOOL_MINGW32_PREFIX)g++$(_TOOL_MINGW32_SUFF_EXE)
88else
89TOOL_MINGW32_LD := $(_TOOL_MINGW32_PREFIX)gcc$(_TOOL_MINGW32_SUFF_EXE)
90endif
91TOOL_MINGW32_LDFLAGS :=
92TOOL_MINGW32_LDFLAGS.debug := -g
93TOOL_MINGW32_LDFLAGS.release := -s
94TOOL_MINGW32_LD_MAP = -Wl,-Map -Wl,$(1) -Wl,--cref
95TOOL_MINGW32_LD_SYSMOD_MAP = -Map $(1) --cref
96
97TOOL_MINGW32_DLLWRAP := $(_TOOL_MINGW32_PREFIX)dllwrap$(_TOOL_MINGW32_SUFF_EXE)
98TOOL_MINGW32_DLLTOOL := $(_TOOL_MINGW32_PREFIX)dlltool$(_TOOL_MINGW32_SUFF_EXE)
99
100
101## Compile C source.
102# @param $(target) Normalized main target name.
103# @param $(source) Source filename (relative).
104# @param $(obj) Object file name. This shall be (re)created by the compilation.
105# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
106# @param $(flags) Flags.
107# @param $(defs) Definitions. No -D or something.
108# @param $(incs) Includes. No -I or something.
109# @param $(dirdep) Directory creation dependency.
110# @param $(deps) Other dependencies.
111# @param $(outbase) Output basename (full). Use this for list files and such.
112# @param $(objsuff) Object suffix.
113TOOL_MINGW32_COMPILE_C_OUTPUT =
114TOOL_MINGW32_COMPILE_C_DEPEND =
115TOOL_MINGW32_COMPILE_C_DEPORD =
116define TOOL_MINGW32_COMPILE_C_CMDS
117 $(TOOL_MINGW32_CC) -c\
118 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
119 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
120 -o $(obj)\
121 $(call ABSPATH,$(source))
122endef
123
124
125## Compile C++ source.
126# @param $(target) Normalized main target name.
127# @param $(source) Source filename (relative).
128# @param $(obj) Object file name. This shall be (re)created by the compilation.
129# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
130# @param $(flags) Flags.
131# @param $(defs) Definitions. No -D or something.
132# @param $(incs) Includes. No -I or something.
133# @param $(dirdep) Directory creation dependency.
134# @param $(deps) Other dependencies.
135# @param $(outbase) Output basename (full). Use this for list files and such.
136# @param $(objsuff) Object suffix.
137TOOL_MINGW32_COMPILE_CXX_OUTPUT =
138TOOL_MINGW32_COMPILE_CXX_DEPEND =
139TOOL_MINGW32_COMPILE_CXX_DEPORD =
140define TOOL_MINGW32_COMPILE_CXX_CMDS
141 $(TOOL_MINGW32_CXX) -c\
142 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
143 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
144 -o $(obj)\
145 $(call ABSPATH,$(source))
146endef
147
148
149## Compile Assembly source.
150# @param $(target) Normalized main target name.
151# @param $(source) Source filename (relative).
152# @param $(obj) Object file name. This shall be (re)created by the compilation.
153# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
154# @param $(flags) Flags.
155# @param $(defs) Definitions. No -D or something.
156# @param $(incs) Includes. No -I or something.
157# @param $(dirdep) Directory creation dependency.
158# @param $(deps) Other dependencies.
159# @param $(outbase) Output basename (full). Use this for list files and such.
160# @param $(objsuff) Object suffix.
161#
162TOOL_MINGW32_COMPILE_AS_OUTPUT =
163TOOL_MINGW32_COMPILE_AS_DEPEND =
164TOOL_MINGW32_COMPILE_AS_DEPORD =
165define TOOL_MINGW32_COMPILE_AS_CMDS
166 $(TOOL_MINGW32_AS) -c\
167 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
168 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
169 -o $(obj)\
170 $(call ABSPATH,$(source))
171endef
172
173
174## Link library
175# @param $(target) Normalized main target name.
176# @param $(lib) Library name.
177# @param $(objs) Object files to put in the library.
178# @param $(flags) Flags.
179# @param $(dirdep) Directory creation dependency.
180# @param $(deps) Other dependencies.
181#
182# @param $(outbase) Output basename (full). Use this for list files and such.
183TOOL_MINGW32_LINK_LIBRARY_OUTPUT = $(lib).ar-script
184TOOL_MINGW32_LINK_LIBRARY_DEPEND = $(filter %.a %.lib,$(othersrc))
185TOOL_MINGW32_LINK_LIBRARY_DEPORD =
186define TOOL_MINGW32_LINK_LIBRARY_CMDS
187 $(APPEND) $(lib).ar-script "CREATE $(out)"
188 $(foreach o, $(objs)\
189 ,$(NL)$(TAB)$(APPEND) $(lib).ar-script "ADDMOD $(o)")
190 $(foreach srclib, $(filter %.a %.lib,$(othersrc))\
191 ,$(NL)$(TAB)$(APPEND) $(lib).ar-script "ADDLIB $(srclib)")
192 $(APPEND) $(lib).ar-script "SAVE"
193 $(APPEND) $(lib).ar-script "END"
194 $(TOOL_MINGW32_AR) -M < $(lib).ar-script
195endef
196
197
198## Link program
199# @param $(target) Normalized main target name.
200# @param $(out) Program name.
201# @param $(objs) Object files to link together.
202# @param $(libs) Libraries to search.
203# @param $(libpath) Library search paths.
204# @param $(flags) Flags.
205# @param $(dirdep) Directory creation dependency.
206# @param $(deps) Other dependencies.
207# @param $(othersrc) Unhandled sources.
208# @param $(custom_pre) Custom step invoked before linking.
209# @param $(custom_post) Custom step invoked after linking.
210#
211# @param $(outbase) Output basename (full). Use this for list files and such.
212TOOL_MINGW32_LINK_PROGRAM_OUTPUT =
213TOOL_MINGW32_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
214TOOL_MINGW32_LINK_PROGRAM_DEPORD =
215define TOOL_MINGW32_LINK_PROGRAM_CMDS
216 $(TOOL_MINGW32_LD) $(flags) -o $(out) $(objs)\
217 $(foreach p,$(libpath), -L$(p))\
218 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
219 $(call TOOL_MINGW32_LD_MAP,$(outbase).map)
220endef
221
222
223## Link DLL.
224# @param $(target) Normalized main target name.
225# @param $(out) DLL name.
226# @param $(objs) Object files to link together.
227# @param $(libs) Libraries to search.
228# @param $(libpath) Library search paths.
229# @param $(flags) Flags.
230# @param $(dirdep) Directory creation dependency.
231# @param $(deps) Other dependencies.
232# @param $(othersrc) Unhandled sources.
233# @param $(custom_pre) Custom step invoked before linking.
234# @param $(custom_post) Custom step invoked after linking.
235# @param $(outbase) Output basename (full). Use this for list files and such.
236TOOL_MINGW32_LINK_DLL_OUTPUT = $(outbase).a $(outbase).exp
237TOOL_MINGW32_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
238 $(filter %.def %.res,$(othersrc))
239TOOL_MINGW32_LINK_DLL_DEPORD = $(call DIRDEP,$(PATH_LIB))
240define TOOL_MINGW32_LINK_DLL_CMDS
241 $(TOOL_MINGW32_DLLWRAP) $(flags)\
242 --dllname=$(out)\
243 --output-exp=$(outbase).exp\
244 --output-lib=$(outbase).a\
245 $(foreach def,$(filter %.def,$(othersrc)), --def $(def))\
246 $(filter %.res,$(othersrc))\
247 $(objs)\
248 $(foreach p,$(libpath), -L$(p))\
249 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))\
250 $(call TOOL_MINGW32_LD_MAP,$(outbase).map)
251 $(CP) $(outbase).exp $(outbase).a $(PATH_LIB)/
252endef
253## @todo seperate install stuff!
Note: See TracBrowser for help on using the repository browser.