build.sh 43.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
#
#set -vx # shell debug options
set -e

# strategy:
# get all sources from svn
# copy and build from non-clean sources
# copy build from clean sources (with distribution)
# build distribution step 1
# test
# copy build from clean sources (with new build)
# test

# TODO
#   ... reduce number of C compilers
#   ... build *everything* from svn 
#   ... also for other platforms, mac should be easiest
#   ... test bootstrap

BUILDSCRIPT=`cygpath --unix --absolute "$0"`
BUILDDIR=`dirname "$BUILDSCRIPT"`

#
# Configure section
#

# Where to build
ROOT="$BUILDDIR"

# dos command shell
COMMAND=`cygpath --unix $COMSPEC`

Bas Lijnse's avatar
Bas Lijnse committed
34
SVN=svn
35
36

# Clean System
37
CLEANROOT="`pwd`/Clean_3.0_32"
38
39

# MS Visual .NET
Bas Lijnse's avatar
Bas Lijnse committed
40
41
if test -e "C:\Program Files\Microsoft Visual Studio 14.0"; then
	VSROOT="C:\Program Files\Microsoft Visual Studio 14.0"
42
43
44
	VSDEVENV=`cygpath --unix "$VSROOT\Common7\IDE\devenv.exe"`
	VSVARS="$VSROOT\VC\bin\vcvars32.bat"
	VSCC="$VSROOT\VC\bin\cl.exe"
45
	VSCC_INLINE=""
46
47
48
49
50
51
else
	if test -e "C:\Program Files\Microsoft Visual Studio .NET 2003"; then
		VSROOT="C:\Program Files\Microsoft Visual Studio .NET 2003"
		VSDEVENV=`cygpath --unix "$VSROOT\Common7\IDE\devenv.exe"`
		VSVARS="$VSROOT\Common7\Tools\vsvars32.bat"
		VSCC="$VSROOT\VC7\BIN\cl.exe"
52
		VSCC_INLINE=""
53
	else
Bas Lijnse's avatar
Bas Lijnse committed
54
		VSROOT="C:\Program Files\Microsoft Visual Studio"
55
56
57
		VSDEVENV=`cygpath --unix "$VSROOT\Common\MSDev98\Bin\msdev.exe"`
		VSVARS="$VSROOT\VC98\Bin\vcvars32.bat"
		VSCC="$VSROOT\VC98\Bin\cl.exe"
58
		VSCC_INLINE="/Dinline=__forceinline"
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	fi
fi

STDENV_SYSTEM_MODULES="StdBool StdChar StdFile StdInt StdMisc StdReal StdString"


log ()
	# $1: message
{
	echo "$1"
}

fatal ()
	# $1: message
{
	log "$1"
	exit 1
}

checkreturncodeoptionallyfail ()
	# $1: where
	# $2: error message
	# $3: return code
	# $4: 0: don't fail, otherwise: fail
{
	if test $3 -ne 0; then
		if test $4 -eq 0; then
			log "$1: warning ($3) $2"
		else
			fatal "$1: error ($3) $2"
		fi
	fi
}

checkreturncode ()
	# $1: where
	# $2: error message
	# $3: return code
{
	checkreturncodeoptionallyfail "$1" "$2" $3 1
}

checkcleanreturncode ()
	# $1: clean system dir
	# $2: where
	# $3: error message
	# $4: return code
{
	if test "$1" = "$CLEANROOT" ; then
		checkcleanreturncode_fail=0
	else
		checkcleanreturncode_fail=1
	fi

	checkreturncodeoptionallyfail "$2" "$3" $4 $checkcleanreturncode_fail
}

svn_get ()
	# $1 $2 $3
{
	w1=`cygpath --absolute --windows "$1"`
	log "svn '$2' '$3'"
	$SVN export -q "https://svn.cs.ru.nl/repos/$2" "$w1/$3"
}

124
125
126
127
128
129
130
131
git_get ()
	# $1 $2 $3
{
	w1=`cygpath --absolute --windows "$1"`
	log "git '$2' '$3'"
	"/c/Program Files/Git/cmd/git.exe" clone --depth 1 "https://gitlab.science.ru.nl/$2" "$w1/$3"
}

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
makedir ()
	# $1: directory path
{
	if test -e "$1"; then
		fatal "makedir: directory '$1' already exists"
	fi

	mkdir -p "$1"
	checkreturncode "makedir" "creating '$1'" $?
}

move ()
	# $1: source path
	# $2: destination path
{
	if test ! -e "$1"; then
		fatal "move source '$1' does not exist"
	fi
	if test -e "$2"; then
		fatal "move destination '$2' already exists"
	fi

	mv "$1" "$2"
	checkreturncode "move" "moving '$1' to '$2'" $?
}

remove ()
	# $1: directory or file path
{
	if test ! -e "$1"; then
		fatal "remove '$1' does not exist"
	fi
	rm -r "$1"
	checkreturncode "remove" "removing '$1'" $?
}

duplicate ()
	# $1: source path
	# $2: destination path
{
	log "duplicating '$1' -> '$2'"

	if test ! -e "$1"; then
		fatal "duplicate: source '$1' does not exist"
	fi
	if test -e "$2"; then
		fatal "duplicate: destination '$2' already exists"
	fi

	cp -r "$1" "$2"
	checkreturncode "duplicate" "copying '$1' to '$2'" $?
}

vscc ()
	# $1: C .c file path
{
	vscc_file=`cygpath --absolute --windows "$1"`
	vscc_dir=`dirname "$1"`
	vscc_object_file=`basename $vscc_file .c`.o
191
	# here documents
192
	(cd "$vscc_dir"
193
	"$COMMAND" <<EOBATCH
194
@"$VSVARS"
195
196
@cl /nologo /c /GS- /O "$vscc_file" /Fo"$vscc_object_file"
@if %errorlevel% neq 0 exit %errorlevel%
197
198
199
200
201
EOBATCH
	checkreturncode "vscc" "compiling '$1'" $?
	)
}

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
vscc_with_inline ()
	# $1: C .c file path
{
	vscc_file=`cygpath --absolute --windows "$1"`
	vscc_dir=`dirname "$1"`
	vscc_object_file=`basename $vscc_file .c`.o
	# here documents
	(cd "$vscc_dir"
	"$COMMAND" <<EOBATCH
@"$VSVARS"
@cl /nologo /c /GS- /O "$vscc_file" /Fo"$vscc_object_file" "$VSCC_INLINE"
@if %errorlevel% neq 0 exit %errorlevel%
EOBATCH
	checkreturncode "vscc" "compiling '$1'" $?
	)
}

219
220
221
222
223
224
vscc_O2 ()
	# $1: C .c file path
{
	vscc_file=`cygpath --absolute --windows "$1"`
	vscc_dir=`dirname "$1"`
	vscc_object_file=`basename $vscc_file .c`.o
225
	# here documents
226
	(cd "$vscc_dir"
227
	"$COMMAND" <<EOBATCH
228
@"$VSVARS"
229
230
@cl /nologo /c /GS- /O2 "$vscc_file" /Fo"$vscc_object_file"
@if %errorlevel% neq 0 exit %errorlevel%
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
EOBATCH
	checkreturncode "vscc" "compiling '$1'" $?
	)
}

vsbuild ()
	# $1: project file path
	# $2: target name
{
	vsbuild_project=`cygpath --absolute --windows "$1"`

	log "vsbuild '$1' '$2'"
	"$VSDEVENV" "$vsbuild_project" /build "$2"

	checkreturncode "vsbuild" "building '$1' '$2'" $?
}

cleancocl ()
	# $1: clean system dir
	# $2: clean icl module path
	# $3: dynamic option
{
	TMP=/tmp # +++
	cleancocl_error=`cygpath --windows "$TMP/cocl.error"`
	cleancocl_out=`cygpath --windows "$TMP/cocl.out"`

	cleancocl_moduledir=`dirname "$2"`
#	cleancocl_moduledir=`cygpath --windows --absolute "$cleancocl_moduledir"`
	cleancocl_module=`basename "$2"`
	cleancocl_sytemdir=`cygpath --windows --absolute "$1"`

	if test "$3"x = "-dynamic"x; then
		cleancocl_paths="."
		cleancocl_paths="$cleancocl_paths"\;"$cleancocl_sytemdir"\\Libraries\\Dynamics
		cleancocl_paths="$cleancocl_paths"\;"$cleancocl_sytemdir"\\Libraries\\Dynamics\\general
		cleancocl_paths="$cleancocl_paths"\;"$cleancocl_sytemdir"\\Libraries\\Dynamics\\implementation
		cleancocl_paths="$cleancocl_paths"\;"$cleancocl_sytemdir"\\Libraries\\Dynamics\\implementation\\windows
268
		cleancocl_dynamics="-dynamics"
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
	else
		cleancocl_paths="."
		cleancocl_dynamics=
	fi
	
	(cd "$cleancocl_moduledir"

	echo "$1/Tools/Clean System"/CleanCompiler \
		-P "$cleancocl_paths" \
		-RE "$cleancocl_error" -RO "$cleancocl_out" \
		-ou -pm -pt -wmt $cleancocl_dynamics \
		"$cleancocl_module" 
	"$1/Tools/Clean System"/CleanCompiler \
		-P "$cleancocl_paths" \
		-RE "$cleancocl_error" -RO "$cleancocl_out" \
		-ou -pm -pt -wmt $cleancocl_dynamics \
		"$cleancocl_module" 
		# -RO: redirect error/out
		# -ou: reuse unique nodes / -pm: memory profile / -pt: time profile
	)

	checkcleanreturncode "$1" "cleancocl" "compiling '$2'" $?
}

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
newcleancocl ()
	# $1: clean system dir
	# $2: clean icl module path
	# $3: compiler dir
	# $4: dynamic lib dir
	# $5: dynamic option
{
	TMP=/tmp # +++
	cleancocl_error=`cygpath --windows "$TMP/cocl.error"`
	cleancocl_out=`cygpath --windows "$TMP/cocl.out"`

	cleancocl_moduledir=`dirname "$2"`
	cleancocl_module=`basename "$2"`
	std_dynamic_env_dir=`cygpath --windows --absolute "$4"`

	if test "$5"x = "-dynamic"x; then
		cleancocl_paths="."
		cleancocl_paths="$cleancocl_paths"\;"$std_dynamic_env_dir"
		cleancocl_paths="$cleancocl_paths"\;"$std_dynamic_env_dir"\\general
		cleancocl_paths="$cleancocl_paths"\;"$std_dynamic_env_dir"\\implementation
		cleancocl_paths="$cleancocl_paths"\;"$std_dynamic_env_dir"\\implementation\\windows
314
		cleancocl_dynamics="-tcl -dynamics"
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
	else
		cleancocl_paths="."
		cleancocl_dynamics=
	fi

	(cd "$cleancocl_moduledir"

	echo "$3"/cocl \
		-P "$cleancocl_paths" \
		-RE "$cleancocl_error" -RO "$cleancocl_out" \
		-ou -pm -pt -wmt $cleancocl_dynamics \
		"$cleancocl_module"
	"$3"/cocl \
		-P "$cleancocl_paths" \
		-RE "$cleancocl_error" -RO "$cleancocl_out" \
		-ou -pm -pt -wmt $cleancocl_dynamics \
		"$cleancocl_module"
		# -RO: redirect error/out
		# -ou: reuse unique nodes / -pm: memory profile / -pt: time profile
	)

	checkcleanreturncode "$1" "cleancocl" "compiling '$2'" $?
}

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
cleanbuild ()
	# $1: clean system dir
	# $2: clean project file path
{
	cleanbuild_project=`cygpath --windows --absolute "$2"`

	log "compiling $cleanbuild_project"

	"$1/CleanIDE" --batch-build "$cleanbuild_project"

	checkcleanreturncode "$1" "cleanbuild" "building '$2'" $?
}

htoclean ()
	# $1: htoclean path
	# $2: C .h file path
{
	"$1" "$2"

	checkreturncode "htoclean" "converting '$2'" $?
}

buildallcleanprojectfiles ()
	# $1: clean system dir
	# $2: directory with projects to build
{
    for prj in "$2"/*.prj; do
        if test -f "$prj"; then
            cleanbuild "$1" "$prj"
        fi
    done

    # recurse in dirs
    for dir in "$2"/*; do
        if test -d "$dir"; then
			buildallcleanprojectfiles "$1" "$dir"
        fi
    done
}

#CLEAN_LIBRARIES="Directory ExtendedArith MersenneTwister Parsers StdEnv StdLib WrapDebug ExceptionsWindows TCPIP"
380
381
#CLEAN_LIBRARIES="Directory MersenneTwister Parsers StdEnv StdLib WrapDebug ExceptionsWindows TCPIP"
CLEAN_LIBRARIES="Directory MersenneTwister Parsers StdLib WrapDebug ExceptionsWindows TCPIP"
382
383
384
385
386
387
388
389
390
391
392
393
394

xmakedir ()
	# $1: directory path
{
	mkdir -p "$1"
	checkreturncode "makedir" "creating '$1'" $?
}

cvscleansystem ()
	# $1: destination directory
{
	xmakedir "$1"

395
396
397
398
399
400
401
402
	git_get "$1" clean-compiler-and-rts/stdenv.git libraries/StdEnv

	w1=`cygpath --absolute --windows "$1"`
	rm -rf "$w1/libraries/StdEnv/.git"

	git_get "$1" clean-and-itasks/clean-libraries.git clean-libraries-git
	xmakedir "$1/libraries"
	xmakedir "$1/CleanExamples"
403
404
	for cvscleansystem_lib in $CLEAN_LIBRARIES; do
#		cvsget "$1" "libraries/$cvscleansystem_lib"
405
406
#		svn_get "$1" "clean-libraries/trunk/Libraries/$cvscleansystem_lib" "libraries/$cvscleansystem_lib"
		mv "$1/clean-libraries-git/Libraries/$cvscleansystem_lib" "$1/libraries/$cvscleansystem_lib"
407
	done
408
409
#	svn_get "$1" clean-libraries/trunk/Libraries/ArgEnvWindows libraries/ArgEnvWindows
	mv "$1/clean-libraries-git/Libraries/ArgEnvWindows" "$1/libraries/ArgEnvWindows"
410
411
#	svn_get "$1" gast libraries/Gast
	git_get "$1" clean-and-itasks/gast.git libraries/Gast
412
413
414
415
416
417
#	svn_get "$1" clean-code-generator/trunk CodeGenerator
	git_get "$1" clean-compiler-and-rts/code-generator.git CodeGenerator
#	svn_get "$1" clean-run-time-system/trunk RuntimeSystem
	git_get "$1" clean-compiler-and-rts/run-time-system.git RuntimeSystem
#	svn_get "$1" clean-compiler/trunk compiler
	git_get "$1" clean-compiler-and-rts/compiler.git compiler
418
	svn_get "$1" clean-dynamic-system/trunk dynamic
419
420
#	svn_get "$1" clean-ide/trunk tools/CleanIDE
	git_get "$1" clean-and-itasks/clean-ide.git tools/CleanIDE
421
#	svn_get "$1" clean-language-report/trunk LanguageReport
422
423
	git_get "$1" clean-compiler-and-rts/language-report.git LanguageReport
	svn_get "$1" sparkle/trunk tools/Sparkle
424
	svn_get "$1" clean-tools/trunk/htoclean tools/htoclean
425
426
427
428
429
430
431
432
433
434
#	svn_get "$1" clean-libraries/trunk/Libraries/GenLib libraries/GenLib
	mv "$1/clean-libraries-git/Libraries/GenLib" "$1/libraries/GenLib"
#	svn_get "$1" clean-libraries/trunk/Examples/GenLib CleanExamples/Generics
	mv "$1/clean-libraries-git/Examples/GenLib" "$1/CleanExamples/Generics"
#	svn_get "$1" clean-libraries/trunk/Libraries/ObjectIO libraries/ObjectIO
	mv "$1/clean-libraries-git/Libraries/ObjectIO" "$1/libraries/ObjectIO"
#	svn_get "$1" clean-libraries/trunk/Examples/ObjectIO CleanExamples/ObjectIO
	mv "$1/clean-libraries-git/Examples/ObjectIO" "$1/CleanExamples/ObjectIO"
#	svn_get "$1" clean-libraries/trunk/Examples/TCPIP CleanExamples/TCPIP
	mv "$1/clean-libraries-git/Examples/TCPIP" "$1/CleanExamples/TCPIP"
435
#	svn_get "$1" clean-examples/trunk CleanExamples/Small\ Examples
436
437
#	svn_get "$1" clean-libraries/trunk/Examples/Small\ Examples CleanExamples/Small\ Examples
	mv "$1/clean-libraries-git/Examples/Small Examples" "$1/CleanExamples/Small Examples"
438
	git_get "$1" clean-and-itasks/clean-platform.git libraries/Platform
439
440
441
442
443
444
445
446
447

	xmakedir "$1/fonts"
	curl "http://git.ghostscript.com/?p=urw-core35-fonts.git;a=blob_plain;f=NimbusMonoPS-Regular.ttf;hb=refs/heads/master" -H "Host: git.ghostscript.com" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "DNT: 1" -H "Connection: keep-alive" -H "Upgrade-Insecure-Requests: 1" > "$1/fonts/NimbusMonoPS-Regular.ttf"
	curl "http://git.ghostscript.com/?p=urw-core35-fonts.git;a=blob_plain;f=NimbusMonoPS-Bold.ttf;hb=refs/heads/master"    -H "Host: git.ghostscript.com" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "DNT: 1" -H "Connection: keep-alive" -H "Upgrade-Insecure-Requests: 1" > "$1/fonts/NimbusMonoPS-Bold.ttf"
	(cd "$1/fonts"; wget "https://get.fontspace.co/download/family/8j4z/36725246f64c4594a48441c88f803e0b/liberation-sans-font.zip")
	(cd "$1/fonts"; unzip liberation-sans-font.zip LiberationSansBold-1adM.ttf LiberationSansItalic-RJre.ttf LiberationSans-BaDn.ttf)
	mv "$1/fonts/LiberationSans-BaDn.ttf" "$1/fonts/LiberationSans-Regular.ttf"
	mv "$1/fonts/LiberationSansBold-1adM.ttf" "$1/fonts/LiberationSans-Bold.ttf"
	mv "$1/fonts/LiberationSansItalic-RJre.ttf" "$1/fonts/LiberationSans-Italic.ttf"
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
}

xduplicate ()
	# $1: source path
	# $2: destination path
{
	log "duplicating '$1' -> '$2'"

	if test ! -e "$1"; then
		fatal "xduplicate: source '$1' does not exist"
	fi
	if test ! -e "$2"; then
		cp -r "$1" "$2"
		checkreturncode "xduplicate" "copying '$1' to '$2'" $?
	fi
}

xduplicate2 ()
	# $1: source path
	# $2: destination dir
{
	log "duplicating '$1' -> '$2'"

	if test ! -e "$1"; then
472
		fatal "xduplicate2: source '$1' does not exist"
473
474
	fi
	if test ! -e "$2"; then
475
		fatal "xduplicate2: destination '$2' does not exist"
476
477
478
479
480
481
	fi

	xduplicate2_file=`basename "$1"`
	xduplicate "$1" "$2/$xduplicate2_file"
}

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
xduplicate3 ()
	# $1: source path
	# $2: destination path
{
	log "duplicating '$1' -> '$2'"

	if test ! -e "$1"; then
		fatal "xduplicate3: source '$1' does not exist"
	fi
	if test ! -e "$2"; then
		fatal "xduplicate3: destination '$2' does not exist"
	fi
	cp -r -t "$2" "$1"/*
	checkreturncode "xduplicate3" "copying '$1' to '$2'" $?
}

498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
xduplicatefiles ()
	# $1: source path
	# $2: destination path
{
	log "duplicating files '$1' -> '$2'"

	if test ! -e "$1"; then
		fatal "xduplicate: source '$1' does not exist"
	fi
	if test ! -e "$2"; then
		fatal "xduplicate: destination '$2' does not exist"
	fi

	for xduplicatefiles_source in "$1"/*; do
		xduplicatefiles_file=`basename "$xduplicatefiles_source"`
		xduplicate "$xduplicatefiles_source" "$2/$xduplicatefiles_file"
	done
}

xmove ()
	# $1: source path
	# $2: destination path
{
	if test ! -e "$2"; then
		if test ! -e "$1"; then
			fatal "xmove source '$1' does not exist"
		fi
		mv "$1" "$2"
		checkreturncode "xmove" "moving '$1' to '$2'" $?
	fi
}


xremove ()
	# $1: directory or file path
{
	if test -e "$1"; then
		rm -r "$1"
		checkreturncode "xremove" "removing '$1'" $?
	fi
}


NONCLEAN_COMPONENTS="runtimesystem backend dynamicchannel dynamicgraphconversion 
542
						idersrc ioobjects tcpip codegen stdenvobj gast platform"
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

runtimesystem_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/RuntimeSystem" "$2/runtimesystem"
	chmod +x "$2/runtimesystem/build_windows_object_files.sh"

	(cd "$2/runtimesystem"
	./build_windows_object_files.sh
	)
}

runtimesystem_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	for objectfile in _startup1.o _startup1Profile.o _startup1Trace.o _startup2.o ; do
		xduplicate2 "$1/RuntimeSystem/$objectfile" "$2/Libraries/StdEnv/Clean System Files"
562
		xduplicate2 "$1/RuntimeSystem/$objectfile" "$2/Libraries/StdEnv Sparkle/Clean System Files"
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
	done
}

backend_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/compiler/backendC" "$2/backend"	
	(
		cd "$2/backend/CleanCompilerSources"
		PATH="/cygdrive/c/MinGW/bin":$PATH
		make -f Makefile.windows_mingw
	)
}

backend_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate "$1/backend/backend.dll" "$2/Tools/Clean System/backend.dll"
}

dynamicchannel_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/dynamic/dynamics/Channel" "$2/dynamicchannel"

	(cd "$2/dynamicchannel"
	cat <<EOBATCH | "$COMMAND"
@		"$VSVARS"
@		call build_dlls_and_exes.bat
EOBATCH
	)

#	vsbuild "$2/dynamicchannel/Dynamics.sln" debug # +++ release
#	vsbuild "$2/dynamicchannel/DynamicLinker Workspace 2.dsw"
}

dynamicchannel_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate "$1/dynamicchannel/ClientChannel/ClientChannel.dll" \
					"$2/Tools/Dynamics/ClientChannel.dll"
	xduplicate "$1/dynamicchannel/ClientChannel/ClientChannel.dll" \
					"$2/Tools/Dynamics/utilities/ClientChannel.dll"
	xduplicate "$1/dynamicchannel/DynamicLink/DynamicLink.dll" \
					"$2/Tools/Dynamics/DynamicLink.dll"
	xduplicate "$1/dynamicchannel/dyn_link_app.o" \
					"$2/Tools/Dynamics/dyn_link_app.o"
	xduplicate "$1/stdenvobj/_startup0.o" \
					"$2/Tools/Dynamics/_startup0.o"
	xduplicate "$1/dynamicchannel/ClientChannel_library" \
					"$2/Tools/Dynamics/ClientChannel_library"
#	xduplicate "$1/dynamicchannel/StaticClientChannel/StaticClientChannel.dll" \
#					"$2/Tools/Dynamics/StaticClientChannel.dll"
#	xduplicate "$1/dynamicchannel/StaticClientChannel/StaticClientChannel.dll" \
#					"$2/Tools/Dynamics/utilities/StaticClientChannel.dll"
#	xduplicate "$1/dynamicchannel/ServerChannel/ServerChannel.dll" \
#					"$2/Tools/Dynamics/ServerChannel.dll"
#	xduplicate "$1/dynamicchannel/ConsoleClient/ConsoleClient.exe" \
#					"$2/Tools/Dynamics/utilities/ConsoleClient.exe"
#	xduplicate "$1/dynamicchannel/GuiClient/GuiClient.exe" \
#					"$2/Tools/Dynamics/utilities/GuiClient.exe"
}

dynamicgraphconversion_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/dynamic/dynamics/Graph conversion" "$2/dynamicgraphconversion"

	xremove "$2/dynamicgraphconversion/as.exe"
	xremove "$2/dynamicgraphconversion/sed.exe"
	xremove "$2/dynamicgraphconversion/cygwin.dll"

	(cd "$2/dynamicgraphconversion"
	cat <<EOBATCH | "$COMMAND"
@		"$VSVARS"
@		call z.bat
EOBATCH
	)
}

dynamicgraphconversion_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate "$1/dynamicgraphconversion/copy_graph_to_string_0x00010101.obj" \
				"$2/Tools/Dynamics/conversion/copy_graph_to_string_0x00010101.obj"
	xduplicate "$1/dynamicgraphconversion/copy_string_to_graph_0x00010101.obj" \
				"$2/Tools/Dynamics/conversion/copy_string_to_graph_0x00010101.obj"
}

idersrc_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/tools/CleanIDE/WinSupport" "$2/idersrc"

	xremove "$1/tools/CleanIDE/WinSupport/winIde.rsrc"

	(cd "$2/idersrc"
	cat <<EOBATCH | "$COMMAND"
@		"$VSVARS"
@		call makeresource.bat
EOBATCH
	)

	xduplicate "$2/idersrc/winIde.rsrc"  "$1/tools/CleanIDE/WinSupport/winIde.rsrc"
}

idersrc_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
680
	echo "NOP"
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
}

ioobjects_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/libraries/ObjectIO/ObjectIO/OS Windows/Windows_C_12" "$2/ioobjects"

	for c in "$2"/ioobjects/*.c; do
		if test "$c_file" = "cGameLib_121.c" -o "$c_file" = "cOSGameLib_121.c" -o "$c_file" = "cCrossCallGame_121.c"; then
			vscc_O2 "$c"
		else
			vscc "$c"
		fi
    done
}

ioobjects_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	for ioobjects_dist_ioobj in "$1"/ioobjects/*.o; do \
		if test "$ioobjects_dist_ioobj" = "$1/ioobjects/cTCP_121.o" -o "$ioobjects_dist_ioobj" = "$1/ioobjects/cCrossCallTCP_121.o"; then
			xduplicate2 "$ioobjects_dist_ioobj" "$2/Libraries/Tcp/Clean System Files/"			
		else
			if test "$ioobjects_dist_ioobj" = "$1/ioobjects/cGameLib_121.o" -o "$ioobjects_dist_ioobj" = "$1/ioobjects/cOSGameLib_121.o" -o "$ioobjects_dist_ioobj" = "$1/ioobjects/cCrossCallGame_121.o"; then
				xduplicate2 "$ioobjects_dist_ioobj" "$2/Libraries/GameLib/Clean System Files/"
			else
				xduplicate2 "$ioobjects_dist_ioobj" "$2/Libraries/ObjectIO/OS Windows/Clean System Files/"
			fi
		fi
	done
}

tcpip_build ()
	# $1: cvs dir
	# $2: build dir
{
	mkdir -p "$2/tcpip"
	for h_path in "$1/libraries/ObjectIO/ObjectIO/OS Windows/Windows_C_12"/*.h; do
		h_file=`basename "$h_path"`
		if test "$h_file" != "cTCP_121.h" -a "$h_file" != "cCrossCallTCP_121.h"; then
			xduplicate "$1/libraries/ObjectIO/ObjectIO/OS Windows/Windows_C_12/$h_file" "$2/tcpip/$h_file"
		fi
	done
	for c_or_h_path in "$1/libraries/TCPIP/Windows_C"/*.[ch]; do
		c_or_h_file=`basename "$c_or_h_path"`
		xduplicate "$1/libraries/TCPIP/Windows_C/$c_or_h_file" "$2/tcpip/$c_or_h_file"
	done

	for c in "$2"/tcpip/*.c; do
		c_file=`basename "$c"`
		vscc "$c"
    done
}

tcpip_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xremove "$2/Libraries/TCPIP/Clean System Files/cTCP_121.o"
	cp "$1"/tcpip/cTCP_121.o "$2/Libraries/TCPIP/Clean System Files/cTCP_121.o"			
	xremove "$2/Libraries/TCPIP/ObjectIO/Clean System Files/cCrossCallTCP_121.o"
	cp "$1"/tcpip/cCrossCallTCP_121.o "$2/Libraries/TCPIP/ObjectIO/Clean System Files/cCrossCallTCP_121.o"			
}

747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
gast_build ()
	# $1: cvs dir
	# $2: build dir
{
	:
}

gast_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	(cd "$2/Examples/Gast"; $2/cpm.exe project char.prj create; $2/cpm.exe project char.prj target Gast; $2/cpm.exe project char.prj set -b)
	(cd "$2/Examples/Gast"; $2/cpm.exe project bool.prj create; $2/cpm.exe project bool.prj target Gast; $2/cpm.exe project bool.prj set -b)
	(cd "$2/Examples/Gast"; $2/cpm.exe project int.prj create; $2/cpm.exe project int.prj target Gast; $2/cpm.exe project int.prj set -b)
	(cd "$2/Examples/Gast"; $2/cpm.exe project tree.prj create; $2/cpm.exe project tree.prj target Gast; $2/cpm.exe project tree.prj set -b)
	(cd "$2/Examples/Gast"; $2/cpm.exe project with_options.prj create; $2/cpm.exe project with_options.prj target Gast; $2/cpm.exe project with_options.prj set -b)

	(cd "$2/Examples/Gast"; $2/cpm.exe project char.prj path add {Application}\\Libraries\\Platform; $2/cpm.exe project char.prj path move 0 down)
	(cd "$2/Examples/Gast"; $2/cpm.exe project bool.prj path add {Application}\\Libraries\\Platform; $2/cpm.exe project bool.prj path move 0 down)
	(cd "$2/Examples/Gast"; $2/cpm.exe project int.prj path add {Application}\\Libraries\\Platform; $2/cpm.exe project int.prj path move 0 down)
	(cd "$2/Examples/Gast"; $2/cpm.exe project tree.prj path add {Application}\\Libraries\\Platform; $2/cpm.exe project tree.prj path move 0 down)
	(cd "$2/Examples/Gast"; $2/cpm.exe project with_options.prj path add {Application}\\Libraries\\Platform; $2/cpm.exe project with_options.prj path move 0 down)
}

771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
platform_build ()
	# $1: cvs dir
	# $2: build dir
{
	mkdir -p "$2/platform"

	for c_or_h_path in "$1/libraries/Platform/src/cdeps"/*.[ch]; do
		c_or_h_file=`basename "$c_or_h_path"`
		xduplicate "$1/libraries/Platform/src/cdeps/$c_or_h_file" "$2/platform/$c_or_h_file"
	done

	for c in "$2"/platform/*.c; do
		c_file=`basename "$c"`
		if test "$c_file" != "WCsubst.c"; then
			vscc "$c"
		else
			vscc_with_inline "$c"
		fi
    done
}

platform_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	for c in "$1"/platform/*.c; do
		base_name=`basename "$c" .c`
		xremove "$2/Libraries/Platform/Clean System Files/$base_name.o"
		cp "$1/platform/$base_name.o" "$2/Libraries/Platform/Clean System Files/$base_name.o"
    done
801
802
803
804
805
806
807
808

	(cd "$2/Examples/Platform Examples"; $2/cpm.exe project IPLookup.prj create;    $2/cpm.exe project IPLookup.prj target Platform)
	(cd "$2/Examples/Platform Examples"; $2/cpm.exe project MapDemo.prj create;     $2/cpm.exe project MapDemo.prj target Platform)
	(cd "$2/Examples/Platform Examples"; $2/cpm.exe project ProcessDemo.prj create; $2/cpm.exe project ProcessDemo.prj target Platform)
	(cd "$2/Examples/Platform Examples"; $2/cpm.exe project SQLDbDemo.prj create;   $2/cpm.exe project SQLDbDemo.prj target Platform)
	(cd "$2/Examples/Platform Examples"; $2/cpm.exe project WebDemo.prj create;     $2/cpm.exe project WebDemo.prj target Platform;\
	 $2/cpm.exe project WebDemo.prj path add {Application}\\Libraries\\TCPIP; $2/cpm.exe project WebDemo.prj path move 0 down)

809
810
	(cd "$2/Examples/Platform Examples/socket"; $2/cpm.exe project client.prj create; $2/cpm.exe project client.prj target Platform)
	(cd "$2/Examples/Platform Examples/socket"; $2/cpm.exe project server.prj create; $2/cpm.exe project server.prj target Platform)
811
812
813

	(cd "$2/Examples/Platform Examples/WebPM"; $2/cpm.exe project PM.prj create; $2/cpm.exe project PM.prj target Platform;\
	 $2/cpm.exe project PM.prj path add {Application}\\Libraries\\TCPIP; $2/cpm.exe project PM.prj path move 0 down)
814
815
}

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
codegen_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/CodeGenerator" "$2/codegen"

	(	cd "$2/codegen"
		PATH="/cygdrive/c/MinGW/bin":$PATH
		make -f Makefile.windows_mingw
		checkreturncode "codegen_build" "making cg.exe" $?
	)
}

codegen_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate "$1/codegen/cg.exe" "$2/Tools/Clean System/CodeGenerator.exe"
}

stdenvobj_build ()
	# $1: cvs dir
	# $2: build dir
{
	xduplicate "$1/libraries/StdEnv/Object Files Windows 32" "$2/stdenvobj"
}

stdenvobj_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate2 "$1"/stdenvobj/_startup0.o "$2/Libraries/StdEnv/Clean System Files"
	for stdenvobj_dist_object in "$1"/stdenvobj/*_library; do
		xduplicate2 "$stdenvobj_dist_object" "$2/Libraries/StdEnv/Clean System Files"
	done
}

hildeobjects_build ()
	# $1: cvs dir
	# $2: build dir
{
	mkdir -p "$2/hildeobjects"
	xduplicate "$1/libraries/Hilde/OS Windows/Foreign/windowsTcpIp.c" "$2/hildeobjects/windowsTcpIp.c"
	(
		cd "$2/hildeobjects"
		gcc -o windowsTcpIp.obj -O2 -Wall -Werror -c windowsTcpIp.c
	)
}

hildeobjects_dist ()
	# $1: non-Clean build dir
	# $2: dist dir
{
	xduplicate "$1"/hildeobjects/windowsTcpIp.obj "$2/Libraries/Hilde/OS Windows/Clean System Files/windowsTcpIp.obj"
}

872
CLEAN_COMPONENTS="compiler dynamic_lib stdenv ide dynamic sparkle htoclean language_report"
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889

cleanduplicate ()
	# $1: source path
	# $2: alternative source path
	# $3: destination path
{
	if test -e "$1"; then
		xduplicate "$1" "$3"
	else
		xduplicate "$2" "$3"
	fi
}

compiler_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
890
	# $4: nonclean dir
891
892
893
894
895
896
897
898
{
	xduplicate "$2/compiler" "$3/compiler"

	xduplicate "$3/compiler/backendC/CleanCompilerSources/backend.h" \
				 "$3/compiler/backend/backend.h"

	compiler_build_htoclean="$1/Tools/htoclean/htoclean.exe"

899
	"$1/Tools/htoclean"/htoclean.exe `cygpath --windows --absolute "$3/compiler/backend/backend.h"`
900
901
902
903

	xmove "$3/compiler/coclmaindll/cocl.prj" "$3/compiler/cocl.prj"
	xmakedir "$3/compiler/Clean System Files"
	cleanbuild "$1" "$3/compiler/cocl.prj"
904
905

	xduplicate "$4/backend/backend.dll" "$3/compiler/backend.dll"
906
907
908
909
910
911
912
}

compiler_dist ()
	# $1: Clean build dir
	# $2: non-Clean build dir
	# $3: dist dir
{
913
	cleanduplicate "$1/compiler/cocl.exe" "$CLEANROOT/Tools/Clean System"/CleanCompiler.exe \
914
915
916
917
918
919
920
921
922
923
924
925
						"$3/Tools/Clean System/CleanCompiler.exe"
}

stdenv_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/libraries/StdEnv" "$3/stdenv"

	# compile twice to inline abc code between system modules
	for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
926
#		cleancocl "$1" "$3/stdenv/$stdenv_build_m" -dynamic;
927
		newcleancocl "$1" "$3/stdenv/$stdenv_build_m" "$3/compiler" "$3/std_dynamic_env" -dynamic
928
929
	done
	for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
930
#		cleancocl "$1" "$3/stdenv/$stdenv_build_m";
931
		newcleancocl "$1" "$3/stdenv/$stdenv_build_m" "$3/compiler" "$3/std_dynamic_env"
932
933
934
935
936
937
938
939
940
941
942
	done
}

stdenv_dist ()
	# $1: Clean build dir
	# $2: non-Clean build dir
	# $3: dist dir
{
	for stdenv_dist_m in $STDENV_SYSTEM_MODULES; do
		xduplicate "$1/stdenv/Clean System Files/$stdenv_dist_m.abc" \
			"$3/Libraries/StdEnv/Clean System Files/$stdenv_dist_m.abc"
943
944
		xduplicate "$1/stdenv/Clean System Files/$stdenv_dist_m.tcl" \
			"$3/Libraries/StdEnv/Clean System Files/$stdenv_dist_m.tcl"
945
	done
946
947
948
949
950
951
}

ide_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
952
	# $4: nonclean dir
953
954
955
{
	xduplicate "$2/tools/CleanIDE" "$3/ide"

956
	for ide_build_prj in WinIde WinHeapProfile WinTimeProfile BatchBuild CpmWin; do
957
958
959
960
961
962
963
964
965
966
967
		cleanbuild "$1" "$3/ide/$ide_build_prj.prj"
	done
}

ide_dist ()
	# $1: Clean build dir
	# $2: non-Clean build dir
	# $3: dist dir
{
	cleanduplicate "$1/ide/CleanIDE.exe" "$CLEANROOT/CleanIDE.exe" \
						"$3/CleanIDE.exe"
968
969
970
971
	cleanduplicate "$1/ide/BatchBuild.exe" "$CLEANROOT/BatchBuild.exe" \
						"$3/BatchBuild.exe"
	cleanduplicate "$1/ide/cpm/cpm.exe" "$CLEANROOT/cpm/cpm.exe" \
						"$3/cpm.exe"
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
	if test -e "$CLEANROOT"/Tools/Heap\ Profiler/ShowHeapProfile.exe; then
		cleanduplicate "$1/ide/ShowHeapProfile.exe" "$CLEANROOT"/Tools/Heap\ Profiler/ShowHeapProfile.exe \
						"$3/Tools/Heap Profiler/ShowHeapProfile.exe"
	else
		cleanduplicate "$1/ide/ShowHeapProfile.exe" "$CLEANROOT"/Tools/Heap\ Profiler*/ShowHeapProfile*.exe \
						"$3/Tools/Heap Profiler/ShowHeapProfile.exe"
	fi
	cleanduplicate "$1/ide/ShowTimeProfile.exe" "$CLEANROOT"/Tools/Time\ Profiler*/ShowTimeProfile*.exe \
						"$3/Tools/Time Profiler/ShowTimeProfile.exe"
}

sparkle_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/tools/Sparkle" "$3/sparkle"
	xduplicate "$2/compiler/frontend" "$3/sparkle/Libraries/frontend"
990
991
992
993
	xduplicate "$2/compiler/main/Windows/DirectorySeparator.dcl" "$3/sparkle/Libraries/frontend/DirectorySeparator.dcl"
	xduplicate "$2/compiler/main/Windows/DirectorySeparator.icl" "$3/sparkle/Libraries/frontend/DirectorySeparator.icl"
#	xduplicate "$2/compiler/main/Windows/thread_message.dcl" "$3/sparkle/Libraries/frontend/thread_message.dcl"
#	xduplicate "$2/compiler/main/Windows/thread_message.icl" "$3/sparkle/Libraries/frontend/thread_message.icl"
994
	mkdir -p "$3/sparkle/Libraries/frontend/Clean System Files"
995
996
997
#	xduplicate "$2/compiler/main/Windows/Clean System Files/c_thread_message.o" "$3/sparkle/Libraries/frontend/Clean System Files/c_thread_message.o"
#	xduplicate "$2/compiler/main/filesystem.dcl" "$3/sparkle/Libraries/frontend/filesystem.dcl"
#	xduplicate "$2/compiler/main/filesystem.icl" "$3/sparkle/Libraries/frontend/filesystem.icl"
998
999
1000
1001
1002

	cleanbuild "$1" "$3/sparkle/Sparkle.prj"

	# compile twice to inline abc code between system modules
	for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
1003
		cleancocl "$1" "$3/sparkle/libraries/StdEnv Sparkle 0.0.4a/$stdenv_build_m"
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
	done
	for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
		cleancocl "$1" "$3/sparkle/libraries/StdEnv Sparkle 0.0.4a/$stdenv_build_m";
	done
}

sparkle_dist ()
	# $1: Clean build dir
	# $2: non-Clean build dir
	# $3: dist dir
{
	cleanduplicate "$1/sparkle/Tools/Sparkle.exe" "$CLEANROOT"/Tools/Sparkle*/Sparkle.exe \
						"$3/Tools/Sparkle/Sparkle.exe"

	mkdir -p "$3/Libraries/StdEnv Sparkle/Clean System Files"

	for stdenv_dist_m in $STDENV_SYSTEM_MODULES; do
		xduplicate "$1/sparkle/libraries/StdEnv Sparkle 0.0.4a/Clean System Files/$stdenv_dist_m.abc" \
			"$3/Libraries/StdEnv Sparkle/Clean System Files/$stdenv_dist_m.abc"
	done	

	xduplicate2 "$3/Libraries/StdEnv/Clean System Files/_system.abc" "$3/Libraries/StdEnv Sparkle/Clean System Files"

	xduplicate2 "$2"/stdenvobj/_startup0.o "$3/Libraries/StdEnv Sparkle/Clean System Files"
	for stdenvobj_dist_object in "$2"/stdenvobj/*_library; do
		xduplicate2 "$stdenvobj_dist_object" "$3/Libraries/StdEnv Sparkle/Clean System Files"
	done
}

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
dynamic_lib_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/dynamic/dynamics/StdDynamicEnv" "$3/std_dynamic_env"
}

dynamic_lib_dist ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	echo
}

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
dynamic_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/dynamic" "$3/dynamic"

	for dynamic_build_prj in  checkdynamics dumpDynamic dynGarbCollector \
									StaticLinker DynamicLinker; do
		cleanbuild "$1" "$3/dynamic/$dynamic_build_prj.prj"
	done
}

dynamic_dist ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	cleanduplicate "$1/dynamic/checkdynamics.exe" "$CLEANROOT"/Tools/Dynamics*/utilities/checkdynamics*.exe \
						"$3"/Tools/Dynamics/utilities/checkdynamics.exe
	cleanduplicate "$1/dynamic/dumpDynamic.exe" "$CLEANROOT"/Tools/Dynamics*/utilities/dumpDynamic*.exe \
						"$3"/Tools/Dynamics/utilities/dumpDynamic.exe
	cleanduplicate "$1/dynamic/dynGarbCollector.exe" "$CLEANROOT"/Tools/Dynamics*/utilities/dynGarbCollector*.exe \
						"$3"/Tools/Dynamics/utilities/dynGarbCollector.exe

1074
	cleanduplicate "$1/dynamic/StaticLinker.exe" "$CLEANROOT"/Tools/Clean\ System/StaticLinker.exe \
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
						"$3"/Tools/Clean\ System/StaticLinker.exe

	cleanduplicate "$1/dynamic/DynamicLinker.exe" "$CLEANROOT"/Tools/Dynamics*/DynamicLinker*.exe \
						"$3"/Tools/Dynamics/DynamicLinker.exe
}

htoclean_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/tools/htoclean/htoclean source code" "$3/htoclean"

	cleanbuild "$1" "$3/htoclean/htoclean.prj"
}

htoclean_dist ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	cleanduplicate "$1/htoclean/htoclean.exe" "$CLEANROOT"/Tools/htoclean*/htoclean*.exe \
						"$3/Tools/htoclean/htoclean.exe"	
}

1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
language_report_build ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$2/LanguageReport/write_clean_manual" "$3/write_clean_manual"

	xduplicate2 "$2/fonts/NimbusMonoPS-Regular.ttf" "$3/write_clean_manual"
	xduplicate2 "$2/fonts/NimbusMonoPS-Bold.ttf" "$3/write_clean_manual"
	xduplicate2 "$2/fonts/LiberationSans-Regular.ttf" "$3/write_clean_manual"
	xduplicate2 "$2/fonts/LiberationSans-Bold.ttf" "$3/write_clean_manual"
	xduplicate2 "$2/fonts/LiberationSans-Italic.ttf" "$3/write_clean_manual"

	cleanbuild "$1" "$3/write_clean_manual/write_clean_manual.prj"

	(cd "$3/write_clean_manual"; "./write_clean_manual.exe")
}

language_report_dist ()
	# $1: clean system dir
	# $2: cvs dir
	# $3: build dir
{
	xduplicate "$1"/write_clean_manual/CleanLanguageReport.pdf "$3/Help/CleanLanguageReport.pdf"
	xmakedir "$3/Help/CleanLanguageReportHtml"
	for html_path in "$1"/write_clean_manual/*.html ; do
		html_file=`basename "$html_path"`
		if test "$html_file" != "CleanLanguageReport.html"; then
			if test "$html_file" != "CleanLanguageReportT.html"; then
				xduplicate "$1/write_clean_manual/$html_file" "$3/Help/CleanLanguageReportHtml/$html_file"
			else
				xduplicate "$1/write_clean_manual/$html_file" "$3/Help/CleanLanguageReportHtml/CleanLanguageReport.html"
			fi
		fi
	done
}

1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
buildnonclean ()
	# $1: directory with sources from cvs
	# $2: directory to build components that are not written in Clean
{
	xmakedir "$2"

	for buildnonclean_component in $NONCLEAN_COMPONENTS; do
		${buildnonclean_component}_build "$1" "$2" $buildnonclean_component
	done
}

buildclean ()
	# $1: clean system dir
	# $2: directory with sources from cvs
1151
1152
	# $3: nonclean dir
	# $4: directory to build components that are written in Clean
1153
{
1154
	xmakedir "$4"
1155
1156

	for buildclean_component in $CLEAN_COMPONENTS; do
1157
		${buildclean_component}_build "$1" "$2" "$4" "$3" $buildclean_component
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
	done
}

distcreatedirs ()
	# $1: directory to put distribution in
{
	xmakedir "$1"
	xmakedir "$1/Libraries"
	xmakedir "$1/Examples"
	xmakedir "$1/Temp"
	xmakedir "$1/Tools"
	xmakedir "$1/Tools/Clean System"
	xmakedir "$1/Tools/Dynamics"
	xmakedir "$1/Tools/Dynamics/conversion"
	xmakedir "$1/Tools/Dynamics/utilities"
	xmakedir "$1/Tools/Dynamics/system dynamics"
	xmakedir "$1/Tools/Heap Profiler"
	xmakedir "$1/Tools/Time Profiler"
1176
	xmakedir "$1/Tools/Sparkle"
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
}

distduplicate ()
	# $1: directory with sources from cvs
	# $2: directory to put distribution in
{
	# Root
	xduplicate "$1/tools/CleanIDE/CleanLicenseConditions.txt" "$2/CleanLicenseConditions.txt"

	# Config
	xduplicate "$1"/tools/CleanIDE/Config "$2"/Config
	xremove "$2"/Config/Macintosh
	xremove "$2"/Config/"Windows 64"
	xduplicate "$2"/Config/windows.km "$2"/Config/default.km

	# Tools
	xduplicate "$1/tools/htoclean" "$2/Tools/htoclean"
	xduplicate "$1/tools/CleanIDE/HeapProfile/ShowHeapProfileHelp" "$2/Tools/Heap Profiler/ShowHeapProfileHelp"
	xduplicate "$1/tools/CleanIDE/TimeProfile/ShowTimeProfileHelp" "$2/Tools/Time Profiler/ShowTimeProfileHelp"
1196
1197
1198
1199
	xduplicate "$1/tools/Sparkle/Tools/Changes.txt" "$2/Tools/Sparkle/Changes.txt"
	xduplicate "$1/tools/Sparkle/Tools/options" "$2/Tools/Sparkle/options"
	xduplicate "$1/tools/Sparkle/Tools/Images" "$2/Tools/Sparkle/Images"
	xduplicate "$1/tools/Sparkle/Tools/Sections" "$2/Tools/Sparkle/Sections"
1200
1201
1202
1203
1204

	# Libraries
	for distduplicate_library in $CLEAN_LIBRARIES; do
		xduplicate "$1/libraries/$distduplicate_library" "$2/Libraries/$distduplicate_library"
	done
1205
	xduplicate "$1/libraries/StdEnv" "$2/Libraries/StdEnv"
1206
	xduplicate "$1/libraries/ArgEnvWindows" "$2/Libraries/ArgEnv"
1207
1208
1209
1210
1211
#	xduplicate "$1/libraries/Gast" "$2/Libraries/Gast"
	xmakedir "$2/Libraries/Gast"
	xduplicate "$1/libraries/Gast/Libraries/Gast.icl" "$2/Libraries/Gast/Gast.icl"
	xduplicate "$1/libraries/Gast/Libraries/Gast.dcl" "$2/Libraries/Gast/Gast.dcl"
	xduplicate "$1/libraries/Gast/Libraries/Gast" "$2/Libraries/Gast/Gast"
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
	xmove "$2/Libraries/Directory/Clean System Files Windows" \
			"$2/Libraries/Directory/Clean System Files"
#	xmove "$2/Libraries/ExtendedArith/ExtendedArith/Clean System Files Windows" \
#			"$2/Libraries/ExtendedArith/ExtendedArith/Clean System Files"
	xduplicate "$1/libraries/ObjectIO/ObjectIO" "$2/Libraries/ObjectIO"
	xduplicate "$1/libraries/ObjectIO/GameLib" "$2/Libraries/GameLib"
	xduplicate "$1/libraries/ObjectIO/Tcp" "$2/Libraries/Tcp"
	xremove "$2/Libraries/Tcp/Macintosh"
	xduplicate "$1"/libraries/GenLib "$2/Libraries/Generics"

	# xduplicate "$1"/dynamic/dynamics/StdDynamicEnv "$2/Libraries/Dynamics"
	xduplicate "$1"/dynamic/dynamics/StdDynamicEnv/extension "$2/Libraries/Dynamics"
	xduplicate "$1"/dynamic/dynamics/StdDynamicEnv/general "$2/Libraries/Dynamics/general"
	xduplicate "$1"/dynamic/dynamics/StdDynamicEnv/implementation "$2/Libraries/Dynamics/implementation"

1227
1228
1229
1230
1231
	xduplicate "$1/libraries/Platform/src/libraries/OS-Independent" "$2/Libraries/Platform"
	xduplicate3 "$1/libraries/Platform/src/libraries/OS-Windows" "$2/Libraries/Platform"
	xduplicate3 "$1/libraries/Platform/src/libraries/OS-Windows-32" "$2/Libraries/Platform"
	xduplicate3 "$1/libraries/Platform/src/libraries/Platform-x86" "$2/Libraries/Platform"

1232
	xduplicate "$1/tools/Sparkle/Libraries/StdEnv Sparkle 0.0.4a" "$2/Libraries/StdEnv Sparkle"
1233
1234
1235
	xremove "$2/Libraries/Directory/Clean System Files Macintosh"
	xremove "$2/Libraries/Directory/Clean System Files Unix"
#	xremove "$2/Libraries/ExtendedArith/ExtendedArith/Clean System Files Macintosh"
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
	xremove "$2/Libraries/StdEnv/StdEnv 64 Changed Files"
	xremove "$2/Libraries/StdEnv/Library Files Windows 64"
	xremove "$2/Libraries/StdEnv/LICENSE"
	xremove "$2/Libraries/StdEnv/Makefile.linux"
	xremove "$2/Libraries/StdEnv/Makefile_no_profile.linux"
	xremove "$2/Libraries/StdEnv/Makefile_no_trace.linux"
	xremove "$2/Libraries/StdEnv/Makefile.solaris"
	xremove "$2/Libraries/StdEnv/Makefile.macos"
	xremove "$2/Libraries/StdEnv/install.sh"
	xremove "$2/Libraries/StdEnv/install_no_profile.sh"
	xremove "$2/Libraries/StdEnv/make.sh"
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
	xremove "$2/Libraries/StdEnv/StdFile_solaris.icl"
	xremove "$2/Libraries/StdEnv/StdFile_solaris.dcl"
	xremove "$2/Libraries/StdEnv/Object Files Windows 32"
	xremove "$3/Libraries/StdEnv/Library Files Windows 64"
	xremove "$2/Libraries/StdEnv/Library Files Macintosh"
	xremove "$2/Libraries/StdEnv/Makefile.linux"
	xremove "$2/Libraries/StdEnv/Makefile.solaris"
	xremove "$2/Libraries/ObjectIO/OS Linux"
	xremove "$2/Libraries/ObjectIO/OS Mac Carbon"

#	xmakedir "$2/Libraries/Hilde/OS Windows/Clean System Files"
#	xduplicate "$1/Libraries/Hilde/OS Windows/Foreign/windowsKERNEL32_library" "$2/Libraries/Hilde/OS Windows/Clean System Files/windowsKERNEL32_library"
#	xduplicate "$1/Libraries/Hilde/OS Windows/Foreign/windowsWS2_32_library" "$2/Libraries/Hilde/OS Windows/Clean System Files/windowsWS2_32_library"

#	xremove "$2/Libraries/Hilde/WrapDebugClosures"
	for distduplicate_ioobj in \
		"$2/LibrariesObjectIO/OS Windows/Clean System Files"/*.obj; do
		xremove "$distduplicate_ioobj"
	done
1266
1267
1268
#	xremove "$2/Libraries/Gast/trunk"
#	xremove "$2/Libraries/Gast/branches"
#	xremove "$2/Libraries/Gast/tags"
1269
1270
1271
1272
1273

	# Examples
	xduplicate "$1"/CleanExamples/Generics "$2"/Examples/Generics
	xduplicate "$1"/CleanExamples/Small\ Examples "$2"/Examples/Small\ Examples
	xremove "$2"/Examples/Small\ Examples/Macintosh
1274
1275
	xremove "$2"/Examples/Small\ Examples/Makefile
	xremove "$2"/Examples/Small\ Examples/run_all_programs
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
#	xduplicate "$1/libraries/ObjectIO/ObjectIO Examples" "$2/Examples/ObjectIO Examples"
	xduplicate "$1/CleanExamples/ObjectIO/ObjectIO Examples" "$2/Examples/ObjectIO Examples"
	for a in "$2/Examples/ObjectIO Examples/"*; do
		xremove "$a/Macintosh"
	done
#	xduplicate "$1/libraries/ObjectIO/Game Examples" "$2/Examples/Game Examples"
	xduplicate "$1/CleanExamples/ObjectIO/Game Examples" "$2/Examples/Game Examples"
#	xduplicate "$1/libraries/ObjectIO/Tcp Examples" "$2/Examples/Tcp Examples"
	xduplicate "$1/CleanExamples/TCPIP" "$2/Examples/Tcp Examples"
	for a in "$2/Examples/Tcp Examples/"*; do
		xremove "$a/Macintosh"
	done
	xduplicate "$1/dynamic/dynamics/Examples/User examples" "$2/Examples/Dynamics"

	xmakedir "$2/Examples/Parsers"
	xmove "$2/Libraries/Parsers/ParsersTestware.icl" "$2/Examples/Parsers/ParsersTestware.icl"
	xmove "$2/Libraries/Parsers/ParsersTestware.prj" "$2/Examples/Parsers/ParsersTestware.prj"
	xmove "$2/Libraries/Parsers/MetarDemo" "$2/Examples/Parsers/MetarDemo"

1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
#	xmove "$2/Libraries/Gast/examples" "$2/Examples/Gast"
	xmakedir "$2/Examples/Gast"
	xduplicate2 "$1/libraries/Gast/Tests/char.icl" "$2/Examples/Gast"
	xduplicate2 "$1/libraries/Gast/Tests/bool.icl" "$2/Examples/Gast"
	xduplicate2 "$1/libraries/Gast/Tests/int.icl" "$2/Examples/Gast"
	xduplicate2 "$1/libraries/Gast/Tests/tree.icl" "$2/Examples/Gast"
	xduplicate2 "$1/libraries/Gast/Tests/with_options.icl" "$2/Examples/Gast"
#	xremove "$2/Examples/Gast/testFixed.icl"
#	xremove "$2/Examples/Gast/testFixed.prj"
#	xremove "$2/Examples/Gast/fixed.icl"
#	xremove "$2/Examples/Gast/fixed.dcl"
1306

1307
1308
1309
	xduplicate "$1/libraries/Platform/src/examples" "$2/Examples/Platform Examples"
	find "$2/Examples/Platform Examples" -name .gitignore -delete

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
	# Help
	xduplicate "$1"/tools/CleanIDE/Help "$2"/Help

	xmove "$2/Tools/htoclean/CallingCFromClean.html" "$2/Help/CallingCFromClean.html"
	xmove "$2/Libraries/Parsers/Parsers Manual.doc" "$2/Help/Library Documents/Parsers Manual.doc"
}

dist ()
	# $1: directory with sources from cvs
	# $2: directory with built nonclean components
	# $3: directory with built clean components
	# $4: directory to put distribution in
{
	distcreatedirs "$4"
	distduplicate "$1" "$4"

	for dist_component in $CLEAN_COMPONENTS; do
		${dist_component}_dist  "$3" "$2" "$4"
	done

	for dist_component in $NONCLEAN_COMPONENTS; do
		${dist_component}_dist "$2" "$4"
	done
}

# main

cvscleansystem "$ROOT/cvssource"

1339
1340
1341
1342
1343
1344
1345
1346
1347
if grep -q SystemTimeToTzSpecificLocalTime@12 "./Clean_3.0_32/Libraries/StdEnv/Clean System Files/kernel_library"; then
	:
else
	if [[ $(tail -c 1 "./Clean_3.0_32/Libraries/StdEnv/Clean System Files/kernel_library" | wc -l) -eq 0 ]]; then
		echo "" >> "./Clean_3.0_32/Libraries/StdEnv/Clean System Files/kernel_library"
	fi
	echo "SystemTimeToTzSpecificLocalTime@12" >> "./Clean_3.0_32/Libraries/StdEnv/Clean System Files/kernel_library"
fi

1348
#dos2unix cvssource/RuntimeSystem/build_windows_object_files.sh
1349
1350
tr -d "\r" < "$ROOT/cvssource/RuntimeSystem/build_windows_object_files.sh" > "$ROOT/cvssource/RuntimeSystem/build_windows_object_files.sh_"
mv "$ROOT/cvssource/RuntimeSystem/build_windows_object_files.sh_" "$ROOT/cvssource/RuntimeSystem/build_windows_object_files.sh"
1351
1352
1353

buildnonclean "$ROOT/cvssource" "$ROOT/nonclean"

1354
buildclean "$CLEANROOT" "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step0/clean"
1355
1356
dist "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step0/clean" "$ROOT/step0/dist"

1357
buildclean "$ROOT/step0/dist" "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step1/clean"
1358
1359
dist "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step1/clean" "$ROOT/step1/dist"

1360
buildclean "$ROOT/step1/dist" "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step2/clean"
1361
1362
1363
1364
1365
dist "$ROOT/cvssource" "$ROOT/nonclean" "$ROOT/step2/clean" "$ROOT/step2/dist"

buildallcleanprojectfiles "$ROOT/step1/dist"  "$ROOT/step1/dist/Examples"

log "Build successful!!!"
1366
1367

mkdir -p target/clean-classic
1368
mv "$ROOT/step2/dist"/* target/clean-classic/