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

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

use append -n for creating the ar-script if available.

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