source: branches/swt/testapp/apitest/toolchains.gmi@ 22129

Last change on this file since 22129 was 22129, checked in by rousseau, 10 years ago

The 'canned recipes' to build various targets [apitest]

These form the abstraction of toolchains and platforms.
Needs more tuning but is functional.

File size: 16.7 KB
Line 
1###############################################################################
2# toolchains.gmi :: Compile and Link wrappers for various toolchains #
3# --------------------------------------------------------------------------- #
4# From the perspective of ApiTest we have a multitude of angles which include #
5# different toolchains as well as several platforms and subsystems. #
6# This file contains wrappers for several toolchains and platforms to unify #
7# compiling and linking. This enables the Master Makefile to be more easy to #
8# modify and extend. #
9###############################################################################
10
11#
12# Note that these macros are executed in the target recipe context, so you
13# cannot comment-out lines with a '#' because that would be interpreted by the
14# shell in use. To disable or change a toolchain macro, you can redefine it at
15# the target-specific level, after the toolchain has been selected. Because
16# such a redefinition is target-specific, it only affects the $(call <tool>,...)
17# recipes of that particular target.
18#
19
20# Only load the whole shebang if not already loaded
21ifndef __TOOLCHAINS_GMI__
22define __TOOLCHAINS_GMI__
23@@@ toolchain wrappers loaded @@@
24endef
25
26# Abort if some required tools or toolchains cannot be found
27#~ ifndef WATCOM
28#~ $(error Open Watcom toolchain not available)
29#~ endif
30#~ ifeq ($(shell sh which gcc),)
31#~ $(error gcc unavailable)
32#~ endif
33
34# Convert a space or ';' separated list of include dirs to a list of -I flags for gcc
35define incdirs2flags.gcc
36$(foreach idir,$(subst ;, ,$(1)),-I$(idir))
37endef
38
39# Convert a space or ';' separated list of library dirs to a list of -L flags for gcc
40define libdirs2flags.gcc
41$(foreach ldir,$(subst ;, ,$(1)),-L$(ldir))
42endef
43
44# Convert a space or ';' separated list of library names to a list of -l flags for gcc
45define libnames2flags.gcc
46$(foreach lname,$(subst ;, ,$(1)),-l$(lname))
47endef
48
49###############################################################################
50# Platform Macros :: some quick-n-dirty hacks for platform differences #
51# --------------------------------------------------------------------------- #
52# As long as the stuff here works for Make (and Kmk) v3.81 on OS/2, Linux and #
53# Win(e)dows it will be used. So a platform independent directory-separator #
54# is '$/' and an independent path-separator is '$;'. (among the others) #
55###############################################################################
56os.name=$(shell uname)
57ifeq ($(os.name),Linux)
58watcom.bindir=binl
59watcom.hdir=lh
60watcom.hdir.os=linux
61/=/
62"="
63;=:
64nl=@echo
65md=mkdir -p
66export WATCOM?=/shared/opt/owc19
67else
68watcom.bindir=binp
69watcom.hdir=h
70watcom.hdir.os=os2
71/=\$
72;=;
73nl=@echo.
74md=md 2>nul
75ifeq ($(os.name),WindowsNT)
76watcom.bindir=binnt
77watcom.hdir.os=nt
78endif
79ODIN32SDK=m:$/work$/odin32-swt
80endif
81
82###############################################################################
83# Inspection Tools :: common tools for inspection of objects and executables #
84# --------------------------------------------------------------------------- #
85# The $(1) holds the toolchain suffix, which is a custom definition in the #
86# toolchain macros below. It is not the same as the compiler prefix which #
87# mainly distinguishes between MinGW variants. #
88###############################################################################
89define tools.common
90$(eval exehdr=@echo $"exehdr: tool-wrapper not yet available, params: $$(1), toolchain:$(1)$")
91endef
92
93###############################################################################
94# ToolChain Wrappers :: encapsulate the toolchain beasts in common commands #
95# --------------------------------------------------------------------------- #
96# The $(1) holds the toolchain suffix, which is a custom definition in the #
97# toolchain macros below. It is not the same as the compiler prefix which #
98# mainly distinguishes between MinGW variants. #
99###############################################################################
100define toolchain.map
101$(eval $(call tools.common,$(1)))
102$(eval cc = $(value cc$(1)))
103$(eval ccl = $(value ccl$(1)))
104$(eval lnk = $(value lnk$(1)))
105$(eval cc++ = $(value cc++$(1)))
106$(eval ccl++ = $(value ccl++$(1)))
107$(eval lnk++ = $(value lnk++$(1)))
108$(eval asm = $(value asm$(1)))
109$(eval rc = $$(value rc$(1)))
110$(eval rc.bind = $(value rc.bind$(1)))
111$(eval objdump = $(value objdump$(1)))
112endef
113
114###############################################################################
115# OpenWatcom toolchain :: cross-platform hosted and cross-compilation #
116# --------------------------------------------------------------------------- #
117# Here the 'owcc' compiler front-end is wrapped. #
118# Note the '$/'-hacks for compiler and linker (v1.9 bug) #
119###############################################################################
120define toolchain.openwatcom
121$(eval toolchain.suffix = .openwatcom)
122
123$(eval cc.defines=-Done -Dtwo -Dthree)
124
125$(eval $(if $(filter os2v2,$(platform)),export INCLUDE=$(WATCOM)$/h$;$(WATCOM)$/h$/os2,))
126$(eval $(if $(filter os2v2,$(platform)),cc.flags.pre=-b os2v2))
127$(eval $(if $(filter os2v2,$(platform)),rc.flags.pre=-bt=os2 -zm))
128$(eval $(if $(filter os2v2,$(platform)),lnk.flags.pre=-b os2v2 -fm=$(basename $@).map -fd=$(basename $@).wlk))
129
130$(eval $(if $(filter win32,$(platform)),export INCLUDE=$(WATCOM)$/h$;$(WATCOM)$/h$/nt,))
131$(eval $(if $(filter win32,$(platform)),cc.flags.pre=-b nt))
132$(eval $(if $(filter win32,$(platform)),rc.flags.pre=-bt=nt -zm))
133$(eval $(if $(filter win32,$(platform)),lnk.flags.pre=-b nt -fm=$(basename $@).map -fd=$(basename $@).wlk))
134
135$(eval $(if $(filter tux32,$(platform)),export INCLUDE=$(WATCOM)$/lh,))
136$(eval $(if $(filter tux32,$(platform)),cc.flags.pre=-b linux))
137$(eval $(if $(filter tux32,$(platform)),lnk.flags.pre=-b linux -fm=$(basename $@).map -fd=$(basename $@).wlk))
138
139$(eval export PATH=$(WATCOM)$/$(watcom.bindir)$;$(PATH))
140$(eval cc.prefix = )
141$(eval cc.openwatcom = $(cc.prefix)owcc -c $(cc.flags.pre) $$(subst /,$/,$$(1)) $$(cc.defines) $(1))
142$(eval ccl.openwatcom = $(cc.prefix)owcc $(cc.flags.pre) $$(lnk.flags.pre) $$(lnk.libpaths) $$(lnk.libs) $$(subst /,$/,$$(1)) $$(cc.defines) $(1) -o $@)
143$(eval lnk.openwatcom = $(cc.prefix)owcc $$(lnk.flags.pre) $$(lnk.libpaths) $$(lnk.libs) $$(subst /,$/,$$(1)) -o $@)
144$(eval cc++.openwatcom = $(cc.prefix)owcc -c $(cc.flags.pre) $$(subst /,$/,$$(1)) $$(cc.defines) $(1))
145$(eval ccl++.openwatcom = $(cc.prefix)owcc $(cc.flags.pre) $$(lnk.flags.pre) $$(lnk.libpaths) $$(link.libs) $$(subst /,$/,$$(1)) $$(cc.defines) $(1) -o $@)
146$(eval lnk++.openwatcom = $(cc.prefix)owcc $$(lnk.flags.pre) $$(lnk.libpaths) $$(lnk.libs) $$(subst /,$/,$$(1)) -o $@)
147$(eval asm.openwatcom = $(cc.prefix)wasm $$(1) $(1))
148$(eval rc.openwatcom = $(if $(module.rc),$(cc.prefix)wrc $(rc.flags.pre) -q -r $(module.rc) -fo=$(basename $@).res $(1)))
149$(eval rc.bind.openwatcom = $(if $(and $(module.rc),$(filter-out odin32,$(gui))),$(cc.prefix)wrc $(rc.flags.pre) -q $$(1) $(basename $@).res $@ $(1)))
150$(eval objdump.openwatcom = )
151$(eval $(call toolchain.map,$(toolchain.suffix)))
152endef
153
154###############################################################################
155# Standard OS/2 GCC toolchain :: OS/2 hosted and OS/2 specific capabilities #
156# --------------------------------------------------------------------------- #
157# Works by producing 'a.out' which is converted to 'OMF'. #
158# Has OS/2 specific -Z* option flags. #
159###############################################################################
160define toolchain.gcc.os2
161$(eval toolchain.suffix = .os2)
162$(eval export EMXOMFLD_TYPE=wlink)
163$(eval export EMXOMFLD_LINKER=wl.exe)
164
165$(eval lnk.flags.pre=-Zomf)
166
167$(eval cc.prefix = )
168$(eval cc.os2 = $(cc.prefix)gcc -c $(cc.flags.pre) $$(1) $$(cc.includes) $$(cc.defines) $(1))
169$(eval ccl.os2 = $(cc.prefix)gcc $(cc.flags.pre) $(lnk.flags.pre) $(lnk.libpaths) $(link.libs) $$(1) $$(cc.defines) $(1) -o $@)
170$(eval lnk.os2 = $(cc.prefix)gcc $(lnk.flags.pre) $(lnk.libpaths) $(link.libs) $$(1) $(1) -o $@)
171$(eval cc++.os2 = $(cc.prefix)g++ -c $(cc.flags.pre) $$(1) $$(cc.includes) $$(cc.defines) $(1))
172$(eval ccl++.os2 = $(cc.prefix)g++ $(cc.flags.pre) $(lnk.flags.pre) $(lnk.libpaths) $(link.libs) $$(1) $$(cc.defines) $(1) -o $@)
173$(eval lnk++.os2 = $(cc.prefix)g++ $(lnk.flags.pre) $(lnk.libpaths) $(link.libs) $$(1) $(1) -o $@)
174$(eval asm.os2 = $(cc.prefix)as $$(1) $(1))
175$(eval rc.os2 = $(if $(module.rc),$(cc.prefix)wrc $(rc.flags.pre) -q -r $$(1) $(module.rc) -fo=$(basename $@).res $(1)))
176$(eval rc.bind.os2 = $(if $(module.rc),$(cc.prefix)wrc $(rc.flags.pre) -q $$(1) $(basename $@).res $@ $(1)))
177$(eval objdump.os2 = $(cc.prefix)objdump $$(1))
178$(eval $(call toolchain.map,$(toolchain.suffix)))
179endef
180
181###############################################################################
182# Standard Linux toolchain :: Linux hosted and cross-compilation capable #
183# --------------------------------------------------------------------------- #
184# Produces ELF32/64 but can be convinced to produce PE-COFF32/64. #
185# Has no Win32 or Win64 libs. #
186###############################################################################
187define toolchain.gcc.linux
188$(eval toolchain.suffix = .linux)
189$(eval cc.prefix = )
190$(eval cc.linux = $(cc.prefix)gcc -c $(cc.flags.pre) $$(1) $(1))
191$(eval ccl.linux = $(cc.prefix)gcc $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(1))
192$(eval lnk.linux = $(cc.prefix)gcc $(lnk.flags.pre) $$(1) $(1))
193$(eval cc++.linux = $(cc.prefix)g++ -c $(cc.flags.pre) $$(1) $(1))
194$(eval ccl++.linux = $(cc.prefix)g++ $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(1))
195$(eval lnk++.linux = $(cc.prefix)g++ $(lnk.flags.pre) $$(1) $(1))
196$(eval asm.linux = $(cc.prefix)as $$(1) $(1))
197$(eval rc.linux = )
198$(eval objdump.linux = $(cc.prefix)objdump $$(1))
199$(eval $(call toolchain.map,$(toolchain.suffix)))
200endef
201
202###############################################################################
203# MinGW32 MSVC compatible toolchain :: Linux hosted and semi MSVC compatibe #
204# --------------------------------------------------------------------------- #
205# This is the 'old' MinGW32 toolchain and it produces PE-COFF32. #
206# No gdb debugger available. #
207###############################################################################
208define toolchain.mingw32msvc
209$(eval toolchain.suffix = .mingw32msvc)
210
211$(eval lnk.flags.pre=-mwindows)
212
213$(eval cc.prefix = i586-mingw32msvc-)
214$(eval cc.mingw32msvc = $(cc.prefix)gcc -c $(cc.flags.pre) $$(1) $(1))
215$(eval ccl.mingw32msvc = $(cc.prefix)gcc $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
216$(eval lnk.mingw32msvc = $(cc.prefix)gcc $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
217$(eval cc++.mingw32msvc = $(cc.prefix)g++ -c $(cc.flags.pre) $$(1) $(1))
218$(eval ccl++.mingw32msvc = $(cc.prefix)g++ $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
219$(eval lnk++.mingw32msvc = $(cc.prefix)g++ $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
220$(eval asm.mingw32msvc = $(cc.prefix)as $$(1) $(1))
221
222$(eval rc.mingw32msvc = $(if $(module.rc),$(cc.prefix)windres -O coff $$(1) $(module.rc) -o $(basename $@).ors $(1)))
223$(eval rc.bind.mingw32msvc =)
224
225$(eval objdump.mingw32msvc = $(cc.prefix)objdump $$(1))
226$(eval $(call toolchain.map,$(toolchain.suffix)))
227endef
228
229###############################################################################
230# MinGW32-w64 toolchain (32-bit) :: Linux hosted #
231# --------------------------------------------------------------------------- #
232# This is the 'new' MinGW32 toolchain and it produces PE-COFF32. #
233# A gdb debugger is available. #
234###############################################################################
235define toolchain.mingw32
236$(eval toolchain.suffix = .mingw32)
237
238$(eval lnk.flags.pre=-mwindows)
239
240$(eval cc.prefix = i686-w64-mingw32-)
241$(eval cc.mingw32 = $(cc.prefix)gcc -c $(cc.flags.pre) $$(1) $(1))
242$(eval ccl.mingw32 = $(cc.prefix)gcc $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
243$(eval lnk.mingw32 = $(cc.prefix)gcc $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
244$(eval cc++.mingw32 = $(cc.prefix)g++ -c $(cc.flags.pre) $$(1) $(1))
245$(eval ccl++.mingw32 = $(cc.prefix)g++ $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
246$(eval lnk++.mingw32 = $(cc.prefix)g++ $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
247$(eval asm.mingw32 = $(cc.prefix)as $$(1) $(1))
248$(eval rc.mingw32 = $(if $(module.rc),$(cc.prefix)windres -O coff $$(1) $(module.rc) -o $(basename $@).ors $(1)))
249$(eval rc.bind.mingw32 =)
250$(eval objdump.mingw32 = $(cc.prefix)objdump $$(1))
251$(eval $(call toolchain.map,$(toolchain.suffix)))
252endef
253
254###############################################################################
255# MinGW32-w64 toolchain (32-bit & 64-bit) :: Linux hosted #
256# --------------------------------------------------------------------------- #
257# This is the 'new' MinGW32 toolchain and it produces PE-COFF32 and PE-COFF64.#
258# A gdb debugger is available. #
259# The default is 64-bit, -m32 selects 32-bit. #
260# Does not compile Win32 because only 64-bit Win32 libs available. #
261###############################################################################
262define toolchain.mingw64
263$(eval toolchain.suffix = .mingw64)
264
265$(eval lnk.flags.pre=-mwindows)
266
267$(eval cc.prefix = x86_64-w64-mingw32-)
268$(eval cc.mingw64 = $(cc.prefix)gcc -c $(cc.flags.pre) $$(1) $(1))
269$(eval ccl.mingw64 = $(cc.prefix)gcc $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
270$(eval lnk.mingw64 = $(cc.prefix)gcc $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
271$(eval cc++.mingw64 = $(cc.prefix)g++ -c $(cc.flags.pre) $$(1) $(1))
272$(eval ccl++.mingw64 = $(cc.prefix)g++ $(cc.flags.pre) $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
273$(eval lnk++.mingw64 = $(cc.prefix)g++ $(lnk.flags.pre) $$(1) $(if $(module.rc),$(basename $@).ors) $(1) -o $@)
274$(eval asm.mingw64 = $(cc.prefix)as $$(1) $(1))
275$(eval rc.mingw64 = $(if $(module.rc),$(cc.prefix)windres -O coff $$(1) $(module.rc) -o $(basename $@).ors $(1)))
276$(eval objdump.mingw64 = $(cc.prefix)objdump $$(1))
277$(eval $(call toolchain.map,$(toolchain.suffix)))
278endef
279
280
281
282define odin32sdk
283$(eval ODIN32SDK_INCDIRS:=$)
284$(eval ODIN32SDK_INCDIRS+=$(1)$/include)
285$(eval ODIN32SDK_INCDIRS+=$(1)$/include$/win)
286$(eval ODIN32SDK_INCDIRS+=$(1)$/include/win/wine)
287$(eval ODIN32SDK_INCDIRS:=$(strip $(ODIN32SDK_INCDIRS)))
288$(eval ODIN32SDK_INCPATH:=$(subst $ ,$;,$(ODIN32SDK_INCDIRS)))
289
290$(eval ODIN32SDK_LIBDIRS:=$)
291$(eval ODIN32SDK_LIBDIRS+=$(1)$/$(2)$/os2.x86$/$(3)$/stage$/lib)
292$(eval ODIN32SDK_LIBDIRS:=$(strip $(ODIN32SDK_LIBDIRS)))
293$(eval ODIN32SDK_LIBPATH:=$(subst $ ,;,$(ODIN32SDK_LIBDIRS)))
294
295$(eval ODIN32SDK_LIBS:=$)
296$(eval ODIN32SDK_LIBS+=kernel32.lib)
297$(eval ODIN32SDK_LIBS+=user32.lib)
298$(eval ODIN32SDK_LIBS+=gdi32.lib)
299$(eval ODIN32SDK_LIBS:=$(strip $(ODIN32SDK_LIBS)))
300
301$(eval cc.defines+=-D__WIN32OS2__ -D__i386__)
302$(eval cc.includes+=$(call incdirs2flags.gcc,$(ODIN32SDK_INCDIRS)))
303$(eval lnk.flags.pre+=-Wl,"lib {$(ODIN32SDK_LIBS)}")
304$(eval lnk.flags.pre+=-Wl,"file {$(basename $@).ors}")
305
306$(eval export LIB:=$(ODIN32SDK_LIBPATH))
307@echo LIB:$(LIB)
308@echo lnk.flags.pre:$(lnk.flags.pre)
309@echo module.rc:$(module.rc)
310$(eval rc.openwatcom=$(if $(module.rc),winerc -D__WIN32OS2__ -s -I$(inc) -I$(src) $(module.rc) -o $(basename $@).s&as -Zomf $(basename $@).s -o $(basename $@).ors))
311$(eval rc.os2=$(if $(module.rc),winerc -D__WIN32OS2__ -s -I$(inc) -I$(src) $(module.rc) -o $(basename $@).s&as -Zomf $(basename $@).s -o $(basename $@).ors))
312endef
313
314# $(rc.flags.pre) -q -r $$(1) $(module.rc) -fo=$(basename $@).res $(1)))
315
316$(info $(__TOOLCHAINS_GMI__))
317endif
318# winerc -D__WIN32OS2__ -s $(cc.flags.incdirs) -I$(src) $< -o $(basename $@).s
319# as -Zomf $(basename $@).s -o $@
Note: See TracBrowser for help on using the repository browser.