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

Last change on this file since 2434 was 2413, checked in by bird, 15 years ago

copyright year update.

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