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

Last change on this file since 2010 was 1786, checked in by bird, 17 years ago

MINGW32.kmk: Handle a defined TOOL_MINGW32_PREFIX correctly. Also check that we're not included more than once.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1# $Id: MINGW32.kmk 1786 2008-09-14 22:19:14Z bird $
2## @file
3# kBuild Tool Config - MinGW32 GCC v3.3+.
4#
5
6#
7# Copyright (c) 2004-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net>
8#
9#
10# This file is part of kBuild.
11#
12# kBuild is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# kBuild is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with kBuild; if not, write to the Free Software
24# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25#
26#
27# As a special exception you are granted permission to include this file, via
28# the kmk include directive, as you wish without this in itself causing the
29# resulting makefile, program or whatever to be covered by the GPL license.
30# This exception does not however invalidate any other reasons why the makefile,
31# program, whatever should not be covered the GPL.
32#
33#
34
35ifdef TOOL_MINGW32
36$(error Already included (TOOL_MINGW32=$(TOOL_MINGW32)))
37endif
38TOOL_MINGW32 := MinGW32 GCC v3.3+.
39
40# Tool Specific Properties
41ifndef PATH_TOOL_MINGW32
42 PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS_BLD)/mingw32/v*.*)
43 ifeq ($(PATH_TOOL_MINGW32),)
44 PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS)/win.x86/mingw32/v*.*)
45 endif
46 ifeq ($(PATH_TOOL_MINGW32),)
47 PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/mingw32/v*.*)
48 endif
49 ifneq ($(PATH_TOOL_MINGW32),)
50 PATH_TOOL_MINGW32 := $(lastword $(sort $(PATH_TOOL_MINGW32)))
51 endif
52else
53 # Resolve any fancy stuff once and for all.
54 PATH_TOOL_MINGW32 := $(PATH_TOOL_MINGW32)
55endif
56
57# figure out if it's native or needs a win32 launcher
58TOOL_MINGW32_HOSTSUFF_EXE ?= $(HOSTSUFF_EXE)
59ifndef TOOL_MINGW32_PREFIX
60 ifneq ($(PATH_TOOL_MINGW32),)
61 TOOL_MINGW32_PREFIX := $(PATH_TOOL_MINGW32)/bin/
62 else
63 TOOL_MINGW32_PREFIX :=
64 endif
65 ifneq ($(KBUILD_HOST),win)
66 # we're cross compiling either using an emulator (wine/odin) or a cross compiler.
67 ifneq ($(PATH_TOOL_MINGW32),$(subst /win.x86,,$(subst /x86.win,,$(PATH_TOOL_MINGW32))))
68 TOOL_MINGW32_PREFIX := $(EXEC_X86_WIN32) $(TOOL_MINGW32_PREFIX)
69 TOOL_MINGW32_HOSTSUFF_EXE := .exe
70 else
71 TOOL_MINGW32_PREFIX := $(TOOL_MINGW32_PREFIX)i386-mingw32msvc-
72 TOOL_MINGW32_HOSTSUFF_EXE :=
73 TOOL_MINGW32_XCOMPILE := 1
74 endif
75 endif
76else
77 # Resolve any fancy stuff once and for all.
78 TOOL_MINGW32_PREFIX := $(TOOL_MINGW32_PREFIX)
79endif
80
81TOOL_MINGW32_CC ?= $(TOOL_MINGW32_PREFIX)gcc$(TOOL_MINGW32_HOSTSUFF_EXE)
82TOOL_MINGW32_CXX ?= $(TOOL_MINGW32_PREFIX)g++$(TOOL_MINGW32_HOSTSUFF_EXE)
83TOOL_MINGW32_AS ?= $(TOOL_MINGW32_PREFIX)gcc$(TOOL_MINGW32_HOSTSUFF_EXE)
84TOOL_MINGW32_AR ?= $(TOOL_MINGW32_PREFIX)ar$(TOOL_MINGW32_HOSTSUFF_EXE)
85ifndef TOOL_MINGW32_XCOMPILE# The gentoo package doesn't have g++.
86TOOL_MINGW32_LD ?= $(TOOL_MINGW32_PREFIX)g++$(TOOL_MINGW32_HOSTSUFF_EXE)
87else
88TOOL_MINGW32_LD ?= $(TOOL_MINGW32_PREFIX)gcc$(TOOL_MINGW32_HOSTSUFF_EXE)
89endif
90TOOL_MINGW32_DLLWRAP ?= $(TOOL_MINGW32_PREFIX)dllwrap$(TOOL_MINGW32_HOSTSUFF_EXE)
91TOOL_MINGW32_DLLTOOL ?= $(TOOL_MINGW32_PREFIX)dlltool$(TOOL_MINGW32_HOSTSUFF_EXE)
92
93# General Properties used by kBuild
94TOOL_MINGW32_COBJSUFF ?= .o
95TOOL_MINGW32_CFLAGS ?= -g
96TOOL_MINGW32_CFLAGS.debug ?= -O0
97TOOL_MINGW32_CFLAGS.release ?= -O2
98TOOL_MINGW32_CFLAGS.profile ?= -O2 #-pg
99TOOL_MINGW32_CINCS ?=
100TOOL_MINGW32_CDEFS ?=
101
102TOOL_MINGW32_CXXOBJSUFF ?= .o
103TOOL_MINGW32_CXXOBJSUFF ?= .o
104TOOL_MINGW32_CXXFLAGS ?= -g
105TOOL_MINGW32_CXXFLAGS.debug ?= -O0
106TOOL_MINGW32_CXXFLAGS.release ?= -O2
107TOOL_MINGW32_CXXFLAGS.profile ?= -O2 #-pg
108TOOL_MINGW32_CXXINCS ?=
109TOOL_MINGW32_CXXDEFS ?=
110
111TOOL_MINGW32_ASFLAGS ?= -g -x assembler-with-cpp
112TOOL_MINGW32_ASOBJSUFF ?= .o
113
114TOOL_MINGW32_ARFLAGS ?= cr
115TOOL_MINGW32_ARLIBSUFF ?= .a
116
117TOOL_MINGW32_LDFLAGS ?=
118TOOL_MINGW32_LDFLAGS.debug ?= -g
119TOOL_MINGW32_LDFLAGS.release ?= -s
120
121
122## Compile C source.
123# @param $(target) Normalized main target name.
124# @param $(source) Source filename (relative).
125# @param $(obj) Object file name. This shall be (re)created by the compilation.
126# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
127# @param $(flags) Flags.
128# @param $(defs) Definitions. No -D or something.
129# @param $(incs) Includes. No -I or something.
130# @param $(dirdep) Directory creation dependency.
131# @param $(deps) Other dependencies.
132# @param $(outbase) Output basename (full). Use this for list files and such.
133# @param $(objsuff) Object suffix.
134TOOL_MINGW32_COMPILE_C_OUTPUT =
135TOOL_MINGW32_COMPILE_C_DEPEND =
136TOOL_MINGW32_COMPILE_C_DEPORD =
137define TOOL_MINGW32_COMPILE_C_CMDS
138 $(QUIET)$(TOOL_MINGW32_CC) -c\
139 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
140 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
141 -o $(obj)\
142 $(abspath $(source))
143endef
144
145
146## Compile C++ source.
147# @param $(target) Normalized main target name.
148# @param $(source) Source filename (relative).
149# @param $(obj) Object file name. This shall be (re)created by the compilation.
150# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
151# @param $(flags) Flags.
152# @param $(defs) Definitions. No -D or something.
153# @param $(incs) Includes. No -I or something.
154# @param $(dirdep) Directory creation dependency.
155# @param $(deps) Other dependencies.
156# @param $(outbase) Output basename (full). Use this for list files and such.
157# @param $(objsuff) Object suffix.
158TOOL_MINGW32_COMPILE_CXX_OUTPUT =
159TOOL_MINGW32_COMPILE_CXX_DEPEND =
160TOOL_MINGW32_COMPILE_CXX_DEPORD =
161define TOOL_MINGW32_COMPILE_CXX_CMDS
162 $(QUIET)$(TOOL_MINGW32_CXX) -c\
163 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
164 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
165 -o $(obj)\
166 $(abspath $(source))
167endef
168
169
170## Compile Assembly source.
171# @param $(target) Normalized main target name.
172# @param $(source) Source filename (relative).
173# @param $(obj) Object file name. This shall be (re)created by the compilation.
174# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
175# @param $(flags) Flags.
176# @param $(defs) Definitions. No -D or something.
177# @param $(incs) Includes. No -I or something.
178# @param $(dirdep) Directory creation dependency.
179# @param $(deps) Other dependencies.
180# @param $(outbase) Output basename (full). Use this for list files and such.
181# @param $(objsuff) Object suffix.
182#
183TOOL_MINGW32_COMPILE_AS_OUTPUT =
184TOOL_MINGW32_COMPILE_AS_DEPEND =
185TOOL_MINGW32_COMPILE_AS_DEPORD =
186define TOOL_MINGW32_COMPILE_AS_CMDS
187 $(QUIET)$(TOOL_MINGW32_AS) -c\
188 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
189 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
190 -o $(obj)\
191 $(abspath $(source))
192endef
193
194
195## Link library
196# @param $(target) Normalized main target name.
197# @param $(out) Library name.
198# @param $(objs) Object files to put in the library.
199# @param $(flags) Flags.
200# @param $(dirdep) Directory creation dependency.
201# @param $(deps) Other dependencies.
202#
203# @param $(outbase) Output basename (full). Use this for list files and such.
204TOOL_MINGW32_LINK_LIBRARY_OUTPUT = $(out).ar-script
205TOOL_MINGW32_LINK_LIBRARY_DEPEND = $(othersrc)
206TOOL_MINGW32_LINK_LIBRARY_DEPORD =
207define TOOL_MINGW32_LINK_LIBRARY_CMDS
208 $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
209 $(QUIET)$(APPEND) -n $(out).ar-script \
210 $(foreach o,$(objs), 'ADDMOD $(o)') \
211 $(foreach o,$(othersrc), 'ADDLIB $(o)')
212 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
213 $(QUIET)$(APPEND) $(out).ar-script 'END'
214 $(QUIET)$(TOOL_MINGW32_AR) -M < $(out).ar-script
215endef
216
217
218
219## Link program
220# @param $(target) Normalized main target name.
221# @param $(out) Program name.
222# @param $(objs) Object files to link together.
223# @param $(libs) Libraries to search.
224# @param $(libpath) Library search paths.
225# @param $(flags) Flags.
226# @param $(dirdep) Directory creation dependency.
227# @param $(deps) Other dependencies.
228# @param $(othersrc) Unhandled sources.
229# @param $(custom_pre) Custom step invoked before linking.
230# @param $(custom_post) Custom step invoked after linking.
231#
232# @param $(outbase) Output basename (full). Use this for list files and such.
233TOOL_MINGW32_LINK_PROGRAM_OUTPUT =
234TOOL_MINGW32_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
235TOOL_MINGW32_LINK_PROGRAM_DEPORD =
236define TOOL_MINGW32_LINK_PROGRAM_CMDS
237 $(QUIET)$(TOOL_MINGW32_LD) $(flags) -o $(out) $(objs)\
238 $(foreach p,$(libpath), -L$(p))\
239 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
240endef
241
242
243## Link DLL.
244# @param $(target) Normalized main target name.
245# @param $(out) DLL name.
246# @param $(objs) Object files to link together.
247# @param $(libs) Libraries to search.
248# @param $(libpath) Library search paths.
249# @param $(flags) Flags.
250# @param $(dirdep) Directory creation dependency.
251# @param $(deps) Other dependencies.
252# @param $(othersrc) Unhandled sources.
253# @param $(custom_pre) Custom step invoked before linking.
254# @param $(custom_post) Custom step invoked after linking.
255# @param $(outbase) Output basename (full). Use this for list files and such.
256TOOL_MINGW32_LINK_DLL_OUTPUT =
257TOOL_MINGW32_LINK_DLL_OUTPUT_MAYBE = $(outbase).a $(outbase).exp $(PATH_LIB)/$(notdir $(outbase)).exp $(PATH_LIB)/$(notdir $(outbase)).a
258## @todo Find a better solution for installing the extra files (.a, .exp, .pdb, etc).
259TOOL_MINGW32_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
260 $(filter %.def %.res,$(othersrc))
261TOOL_MINGW32_LINK_DLL_DEPORD = $(call DIRDEP,$(PATH_LIB))
262define TOOL_MINGW32_LINK_DLL_CMDS
263 $(QUIET)$(TOOL_MINGW32_DLLWRAP) $(flags)\
264 --dllname=$(out)\
265 --output-exp=$(outbase).exp\
266 --output-lib=$(outbase).a\
267 $(foreach def,$(filter %.def,$(othersrc)), --def $(def))\
268 $(filter %.res,$(othersrc))\
269 $(objs)\
270 $(foreach p,$(libpath), -L$(p))\
271 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
272 $(QUIET)$(CP) $(outbase).exp $(outbase).a $(PATH_LIB)/
273endef
274## @todo separate install stuff!
Note: See TracBrowser for help on using the repository browser.