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

Last change on this file since 300 was 300, checked in by bird, 20 years ago

Do dependencies first.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1# $Id: MINGW32.kmk 300 2005-06-23 18:36:41Z bird $
2## @file
3#
4# kBuild Tool Config - MINGW32 GCC.
5#
6# Copyright (c) 2004 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
93
94TOOL_MINGW32_DLLWRAP := $(_TOOL_MINGW32_PREFIX)dllwrap$(_TOOL_MINGW32_SUFF_EXE)
95TOOL_MINGW32_DLLTOOL := $(_TOOL_MINGW32_PREFIX)dlltool$(_TOOL_MINGW32_SUFF_EXE)
96
97
98## Compile C source.
99# @param $(target) Normalized main target name.
100# @param $(source) Source filename (relative).
101# @param $(obj) Object file name. This shall be (re)created by the compilation.
102# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
103# @param $(flags) Flags.
104# @param $(defs) Definitions. No -D or something.
105# @param $(incs) Includes. No -I or something.
106# @param $(dirdep) Directory creation dependency.
107# @param $(deps) Other dependencies.
108#
109# @param $(outbase) Output basename (full). Use this for list files and such.
110# @param $(objsuff) Object suffix.
111define TOOL_MINGW32_COMPILE_C
112#$ (warning dbg: TOOL_MINGW32_COMPILE_C: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
113$(obj): $(deps) $(source) | $(dirdep)
114 $(call MSG_L2,Compiling $$@ using MINGW32)
115 $(TOOL_MINGW32_CC) -c\
116 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
117 -Wp,-MD,$(dep) -Wp,-MT,$$@ \
118 -o $$@\
119 $(call ABSPATH,$(source))
120
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#
135# @param $(outbase) Output basename (full). Use this for list files and such.
136# @param $(objsuff) Object suffix.
137define TOOL_MINGW32_COMPILE_CXX
138#$ (warning dbg: TOOL_MINGW32_COMPILE_CXX: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
139$(obj): $(deps) $(source) | $(dirdep)
140 $(call MSG_L2,Compiling $$@ using MINGW32)
141 $(TOOL_MINGW32_CXX) -c\
142 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
143 -Wp,-MD,$(dep) -Wp,-MT,$$@ \
144 -o $$@\
145 $(call ABSPATH,$(source))
146
147endef
148
149
150## Link library
151# @param $(target) Normalized main target name.
152# @param $(lib) Library name.
153# @param $(objs) Object files to put in the library.
154# @param $(flags) Flags.
155# @param $(dirdep) Directory creation dependency.
156# @param $(deps) Other dependencies.
157#
158# @param $(outbase) Output basename (full). Use this for list files and such.
159define TOOL_MINGW32_LINK_LIBRARY
160#$ (warning dbg: TOOL_MINGW32_LINK_LIBRARY: target=$(target) lib=$(lib) objs=$(objs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) outbase=$(outbase))
161$(lib): $(deps) $(objs) | $(dirdep)
162 $(call MSG_L1,Creating Library $$@)
163 $(RM) -f $$@
164 $(TOOL_MINGW32_AR) $(flags) $$@ $(objs)
165
166endef
167
168
169## Link program
170# @param $(target) Normalized main target name.
171# @param $(exe) Program name.
172# @param $(objs) Object files to link together.
173# @param $(libs) Libraries to search.
174# @param $(libpath) Library search paths.
175# @param $(flags) Flags.
176# @param $(dirdep) Directory creation dependency.
177# @param $(deps) Other dependencies.
178# @param $(othersrc) Unhandled sources.
179# @param $(custom_pre) Custom step invoked before linking.
180# @param $(custom_post) Custom step invoked after linking.
181#
182# @param $(outbase) Output basename (full). Use this for list files and such.
183define TOOL_MINGW32_LINK_PROGRAM
184#$ (warning dbg: TOOL_MINGW32_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
185$(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
186 $(call MSG_L1,Creating Program $$@)
187ifneq ($(custom_pre),)
188 $(eval $(custom_pre))
189endif
190 $(TOOL_MINGW32_LD) $(flags) -o $$@ $(objs) \
191 $(foreach p,$(libpath), -L$(p)) \
192 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
193ifneq ($(custom_post),)
194 $(eval $(custom_post))
195endif
196
197endef
198
199
200## Link system module (windows aka driver, linux aka kernel module)
201# @param $(target) Normalized main target name.
202# @param $(dll) System module name.
203# @param $(objs) Object files to link together.
204# @param $(libs) Libraries to search.
205# @param $(libpath) Library search paths.
206# @param $(flags) Flags.
207# @param $(dirdep) Directory creation dependency.
208# @param $(deps) Other dependencies.
209# @param $(othersrc) Unhandled sources.
210# @param $(custom_pre) Custom step invoked before linking.
211# @param $(custom_post) Custom step invoked after linking.
212#
213# @param $(outbase) Output basename (full). Use this for list files and such.
214define TOOL_MINGW32_LINK_DLL
215#$ (warning dbg: TOOL_MINGW32_LINK_DLL: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
216$(dll): $(deps) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
217 $(call MSG_L1,Creating Program $$@)
218ifneq ($(custom_pre),)
219 $(eval $(custom_pre))
220endif
221 $(TOOL_MINGW32_DLLWRAP) $(flags) \
222 --dllname=$(dll) \
223 --output-exp=$(outbase).exp \
224 --output-lib=$(outbase).a \
225 $(foreach def,$(filter %.def,$(othersrc)), --def $(def)) \
226 $(filter %.res,$(othersrc)) \
227 $(objs) \
228 $(foreach p,$(libpath), -L$(p)) \
229 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
230ifeq ($(filter %.exp .def,$(othersrc)),)
231 $(CP) $(outbase).exp $(outbase).a $(PATH_LIB)/
232endif
233ifneq ($(custom_post),)
234 $(eval $(custom_post))
235endif
236_OUT_FILES += $(outbase).map $(outbase).a $(outbase).exp
237
238endef
239
Note: See TracBrowser for help on using the repository browser.