source: trunk/tools/os2/setaboot/Makefile

Last change on this file was 225, checked in by Ben Rietbroek, 8 years ago

Work around a weird code-generation issue [v1.1.3-testing]

Using the 'wcc386' '-ol' flag can result in the generation of different
code, depending on the length of the source-path.

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.2-manual.pdf

File size: 11.3 KB
Line 
1###############################################################################
2# Makefile :: Builds the 'set(a)boot' 'setboot' replacement for OS/2 [WMake] #
3# --------------------------------------------------------------------------- #
4# #
5# This Makefile builds the 'set(a)boot' 'setboot' replacement for OS/2. #
6# #
7###############################################################################
8
9
10#
11# Include a Master Makefile with several cross-platform definitions and macros.
12# This is used to compensate for the differences between the target platforms.
13#
14!include ../../../include/makefile.mif
15
16
17
18#
19# Specifies the level of debugging.
20# Level 0 is no debugging (release) and each higher level may use other
21# assembler / compiler / linker flags and define jammed-in constants
22# to influence source assembly / compilation.
23#
24DEBUG_LEVEL=0
25MAX_DEBUG_LEVEL=2
26
27#
28# Protect against missing or invalid debug-levels.
29#
30!ifndef DEBUG_LEVEL
31!error DEBUG_LEVEL not defined !
32!elseifndef MAX_DEBUG_LEVEL
33!error MAX_DEBUG_LEVEL not defined !
34!elseif $(DEBUG_LEVEL) > $(MAX_DEBUG_LEVEL)
35!error DEBUG_LEVEL cannot exceed $(MAX_DEBUG_LEVEL) !
36!elseif $(DEBUG_LEVEL) < 0
37!error DEBUG_LEVEL cannot be negative !
38!endif
39
40#
41# Base Name of Source Program to compile.
42#
43BASENAME=setaboot
44
45#
46# Base Name of Executable Module to build.
47# A letter is appended for each platform version:
48# D=DOS, W=Windows, 2=OS2, L=Linux.
49#
50MODULE=$(BASENAME)
51
52#
53# This is a list of the Targets to be built.
54#
55#TARGETS=$(MODULE)d.exe $(MODULE)w.exe $(MODULE)2.exe $(MODULE)l.elf
56TARGETS=$(MODULE).exe
57
58#
59# Assembler Tools.
60#
61#ASM=alp
62#ASM=tasm
63#ASM=wasm
64ASM=jwasm
65
66#
67# There are no masm or alp for Linux and the yasm tasm-mode is incompatible.
68# So we override to jwasm when a non-jwasm assembler is specified and
69# we are building on Linux.
70#
71!ifdef __LINUX__
72!if "$(ASM)"=="masm" | "$(ASM)"=="tasm" | "$(ASM)"=="alp"
73ASM=jwasm
74!endif
75!endif
76
77!if "$(ASM)"=="jwasm"
78# -Cp = case sensitive symbols
79# -zcw = no _ prefix on symbols (C model)
80ASM_FLAGS_D0=-DDEBUG_LEVEL=$(DEBUG_LEVEL) -DASSEMBLER=JWASM -q -Cp -Fo$^. -Fl=$^&.lst -Fw$^&.err
81ASM_FLAGS_D1=-DDEBUG_LEVEL=$(DEBUG_LEVEL) -DASSEMBLER=JWASM -q -Cp -Zd -Zi -Fo$^. -Sa -Fl=$^&.lst -Fw$^&.err
82ASM_FLAGS_D2=-DDEBUG_LEVEL=$(DEBUG_LEVEL) -DASSEMBLER=JWASM -q -Cp -Zd -Zi -Fo$^. -Sa -Fl=$^&.lst -Fw$^&.err
83!elseif "$(ASM)"=="wasm"
84ASM_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -zq -fo=$^. -fr=$^&.err
85ASM_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -zq -d1 -fo=$^. -fr=$^&.err
86ASM_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -zq -d1 -fo=$^. -fr=$^&.err
87!elseif "$(ASM)"=="tasm"
88# -ml = case sensitive symbols
89ASM_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -t -ml -l
90ASM_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -t -ml -z -zi -c -la
91ASM_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) -dASSEMBLER=TASM -t -ml -z -zi -c -la
92!elseif "$(ASM)"=="alp"
93ASM_FLAGS_D0=-D:DEBUG_LEVEL=$(DEBUG_LEVEL) -D:ASSEMBLER=ALP -Mb +Feo:obj +Fl +Fel:lst +Fm +Fem:err
94ASM_FLAGS_D1=-D:DEBUG_LEVEL=$(DEBUG_LEVEL) -D:ASSEMBLER=ALP -Mb +Od:MS16 +Feo:obj +Fl +Fel:lst +Fm +Fem:err
95ASM_FLAGS_D2=-D:DEBUG_LEVEL=$(DEBUG_LEVEL) -D:ASSEMBLER=ALP
96!else
97!error Unknown Assembler specified !
98!endif
99ASM_FLAGS=$(ASM_FLAGS_D$(DEBUG_LEVEL))
100
101#
102# 16-bits C Compiler
103#
104MM16=-ml
105CC16=wcc
106CC16_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) $(%CC_DEFINES) -w4 -e25 -zq -otebmieran -fo=$^. -fr=$^&.err
107#~ CC16_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) $(%CC_DEFINES) -w4 -e25 -zq -otexan -fo=$^. -fr=$^&.err
108CC16_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) $(%CC_DEFINES) -d2 -w4 -e25 -zq -od -fo=$^. -fr=$^&.err
109CC16_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM16) $(%CC_DEFINES) -d3 -w4 -e25 -zq -od -fo=$^. -fr=$^&.err
110CC16_FLAGS=$(CC16_FLAGS_D$(DEBUG_LEVEL))
111
112#
113# 32-bits C Compiler
114#
115MM32=-mf
116CC32=wcc386
117# rousseau.comment.201711092035 :: -ol optimization generates inconsistent code
118# It was already observed that building on Linux could generate different code
119# as when building on OS/2, so releases were always built on OS/2.
120# Lately, however, different code generation was also observed between building
121# on a local drive and on a network drive, both under OS/2. But is was not the
122# local or remote nature of the drive, but it seemed like the length of the
123# path to the sources played a role. Doing two builds on a local drive on OS/2,
124# one with a short path and one with a longer path generated substantially
125# different (prolog / indexing) code at specific locations. The one used a
126# combination of 'mov' and 'add' while the other used 'lea'.
127#
128# This has been tracked down to the wcc386 -ol (enable loop optimizations)
129# flag, which is part of -ox, which is short for -obmiler -s.
130# So the new flags replace -ox with -obmier and since we actually do want
131# stack overflow checking (-s), this flag is not re-added.
132#
133# Now MD5SUMS are the same again, even when building on Linux.
134# This requires further investigation and a cross-check against v1.9+ versions
135# of Open Watcom.
136CC32_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) $(%CC_DEFINES) -w4 -e25 -zq -otebmieran -6r -fo=$^. -fr=$^&.err
137#~ CC32_FLAGS_D0=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) $(%CC_DEFINES) -w4 -e25 -zq -otexan -6r -fo=$^. -fr=$^&.err
138CC32_FLAGS_D1=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) $(%CC_DEFINES) -d2 -w4 -e25 -zq -od -6r -fo=$^. -fr=$^&.err
139CC32_FLAGS_D2=-dDEBUG_LEVEL=$(DEBUG_LEVEL) $(MM32) $(%CC_DEFINES) -d3 -w4 -e25 -zq -od -6r -fo=$^. -fr=$^&.err
140CC32_FLAGS=$(CC32_FLAGS_D$(DEBUG_LEVEL))
141
142#
143# Linker
144#
145LNK=wlink
146#
147# DESCRIPTION does not work under WLink/Linux
148# @ Cannot be escaped like with \x40 and it is still processed in quotes.
149# WLink/2 can use the '\x40' variant.
150#
151#~ LNK_FLAGS_D0=op q op v op map=$^&.map op de '\x40\x23KIEWITZ:1.18\x23\x40\x41iR-BOOT Installer by Kiewitz'
152LNK_FLAGS_D0=op q op v op map=$^&.map
153#~ LNK_FLAGS_D1=op q op v d all &
154 #~ order clname CODE clname FAR_CONST clname FAR_DATA clnam BEGDATA clname DATA clname BSS clname STACK clname BLAP NOE &
155 #~ op map=$^&.map
156LNK_FLAGS_D1=op q op v d all op map=$^&.map
157LNK_FLAGS_D2=op q op v d all op map=$^&.map
158LNK_FLAGS=$(LNK_FLAGS_D$(DEBUG_LEVEL))
159
160
161#
162# This is executed before Makefile processing.
163#
164.BEFORE
165# @echo == BEFORE ==
166
167#
168# This is executed after Makefile processing.
169#
170.AFTER
171# @echo == AFTER ==
172!ifdef __MSDOS__
173 @echo $(WARN_DOS_BLD_ENV)
174!endif
175
176
177#
178# This builds all targets by using normal dependency rules.
179# If this Makefile was modified, all targets are forcefully rebuilt.
180#
181all: .SYMBOLIC Makefile.bu header $(TARGETS) footer
182
183
184#
185# Alternative ways to build all targets.
186# The first method builds all targets by recursively
187# invoking WMake for each target.
188# If concatenation is used, like adding include-directories to the environment,
189# this may result in multiple identical concatenations.
190# The second method uses the procedure method, no concatenation problem.
191#
192#all: .SYMBOLIC
193# Recursive method (concatenation problem)
194# @for %%i in (header $(TARGETS) footer) do @$(MAKE) -h %%i
195# Procedure method (no concatenation problem, no re-invocation)
196# @for %%i in (header $(TARGETS) footer) do @%MAKE %%i
197
198
199
200#
201# Show the header.
202#
203header: .SYMBOLIC
204 @echo.
205 @echo =====================================================================
206 @echo = PROGRAM: 'setaboot', setboot replacement for OS/2 [OS/2] =
207 @echo =====================================================================
208# @echo.
209
210
211#
212# Show the footer.
213#
214footer: .SYMBOLIC
215 @echo All targets up to date !
216 @echo.
217
218
219#
220# Create a backup of the Makefile when it is modified.
221# This also forces a rebuild of all targets.
222# So, when changing i.e. the DEBUG_LEVEL, all targets are rebuilt
223# using the new level.
224#
225Makefile.bu: Makefile
226 @echo.
227 @echo Makefile modified, forcing rebuild of all targets !
228 @echo.
229 @%MAKE clean
230 $(CP) Makefile Makefile.bu
231
232
233#
234# DOS WMake has a bug in that it expands $^& and $^. to lowercase,
235# even though the definition is in uppercase.
236# This gives problems when building in an OS/2 DOS-Box on a network
237# share where also a Linux build-environment is active.
238# The Linux build-environment is case sensitive and will not
239# find the lowercase files.
240# For example, a clean from Linux will not work properly in that case.
241# This does not influence building DOS targets on Linux.
242#
243
244#
245# While the DOS build-environment has been kept alive in this version,
246# it has several drawbacks:
247# - No support for long filenames
248# - Very limited memory
249# - JWasmR does not work because of memory limitations
250# - JWasmD does not work at all
251# - Batch scripting is very rudimentairy
252#
253# Therefore, the DOS build-environment will most probably disappear
254# in future versions.
255# This does not influence the building of DOS targets, which can be done
256# on OS/2, Windows or Linux.
257#
258
259
260
261
262#
263# MAIN TARGET
264#
265
266###############################################################################
267# OS/2 32-bits (LX)
268###############################################################################
269$(MODULE).exe: $(MODULE).obj
270 $(LNK) $(LNK_FLAGS) file $^&.obj name $^. sys os2v2
271 @if exist $^. @echo $^. $(MSG_SUCCESS)
272 @echo.
273 #~ wstrip $^.
274
275$(MODULE).obj: $(BASENAME).c $(BASENAME).h
276# @echo.
277 @echo TARGET: $^&.exe [OS/2 32-bits Executable]
278 $(CC32) $(CC32_FLAGS) -I$(%WATCOM)$(DS)h$(DS)os2 -bt=os2 $(BASENAME).c
279 @wdis -fi $^. > $^&.wda
280
281
282
283#
284# MAIN ACTIONS
285#
286
287#
288# Rebuild all targets.
289#
290rebuild: .SYMBOLIC
291 @%MAKE clean
292 @%MAKE all
293
294#
295# Remove all generated files.
296#
297clean: .SYMBOLIC
298 @for %%i in ($(TARGETS)) do @if exist %%i $(RM) %%i
299 @if exist *.obj $(RM) *.obj
300 @if exist *.wda $(RM) *.wda
301 @if exist *.nda $(RM) *.nda
302 @if exist *.map $(RM) *.map
303 @if exist *.lst $(RM) *.lst
304 @if exist *.err $(RM) *.err
305 @if exist *.o $(RM) *.o
306
307# -----------------------------------------------------------------------------
308# DISTRIBUTE TO RELEASE SPACE
309# -----------------------------------------------------------------------------
310# This distributes 'setaboot' 'release'.
311# -----------------------------------------------------------------------------
312dist: .SYMBOLIC
313 @if exist *.exe $(CP) *.exe ..$(DS)..$(DS)..$(DS)release$(DS)os2
314#
315# Help on using this Makefile.
316#
317help: .SYMBOLIC
318 @echo.
319 @echo The following actions are available:
320 @echo wmake to build all targets
321 @echo wmake show to show the list of buildable targets
322 @echo wmake clean to remove all generated files
323 @echo wmake rebuild to rebuild all targets
324 @echo wmake help to show this information
325 @echo.
326
327#
328# Show the list of buildable targets.
329#
330show: .SYMBOLIC
331 @echo.
332 @echo The following [case sensitive] targets can be built:
333 @for %%i in ($(TARGETS)) do @echo %%i
334 @echo.
335# Alias for show
336list: .SYMBOLIC
337 @%MAKE show
338
339#
340# Inform user that a rebuild might help if the build process fails.
341#
342.ERROR
343 @echo.
344 @echo Oops!
345 @echo Some error occured in this build session.
346 @echo If it's a linker problem, it could be
347 @echo the result of out-of-sync object files.
348 @echo Doing a wmake rebuild might resolve the problem.
349 @%MAKE help
350 @echo.
Note: See TracBrowser for help on using the repository browser.