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

Last change on this file since 143 was 142, checked in by bird, 21 years ago

Ooops /LIBPATH!

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