build.sh 15.9 KB
Newer Older
1
2
3
4
5
#!/bin/sh
set -e
export CUR_CLEAN_HOME=$CLEAN_HOME
export CUR_PATH=$PATH

6
7
8
9
PACKAGE=$1
OS=$2
ARCH=$3

10
11
12
13
14
15
16
17
18
19
20
21
22
#Visual studio compiler 
VSROOT="C:\Program Files (x86)\Microsoft Visual Studio 14.0"
#VSDEVENV=`cygpath --unix "$VSROOT\Common7\IDE\devenv.exe"`
#VSVARS="$VSROOT\VC\bin\vcvars32.bat"
#VSCC="$VSROOT\VC\bin\cl.exe"
VSSETENV="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"

COMMAND=`cygpath --unix $COMSPEC`

#### Component build functions ####

build_codegenerator () { # $1:target 
    mkdir -p build
23
    cp -r src/code-generator-master build/codegenerator
24
25
26
27
28
29
30
31
32
33
34
35
    cd build/codegenerator
	cat <<EOBATCH | "$COMMAND"
@call "$VSSETENV" amd64
@nmake -f Makefile.windows64
EOBATCH
    cd ../..

    mkdir -p "$1/Tools/Clean System 64"
    cp build/codegenerator/cg.exe "$1/Tools/Clean System 64/CodeGenerator64.exe"
}
build_compiler_backend () { # $1: target
    mkdir -p build
36
    cp -r src/compiler-itask/backendC build/backend
37
38
39
40
41
42
43
44
45
46
47
48
49
    cd build/backend/CleanCompilerSources
    	cat <<EOBATCH | "$COMMAND"
@call "$VSSETENV" amd64
@nmake -f Makefile.windows64
EOBATCH
    cd ../../..

    mkdir -p "$1/Tools/Clean System 64"
    cp build/backend/backend.dll "$1/Tools/Clean System 64/backend.dll"
}

build_runtimesystem_c () { # $1:target
    mkdir -p build
50
    cp -r src/run-time-system-master build/runtimesystem
51
52
53
54
55
56
57
58
59
60

    cd build/runtimesystem
    	./build_windows_object_files_ml64.bat
    cd ../..

    mkdir -p $1/Libraries/StdEnv/Clean\ System\ Files

    #touch $1/Libraries/StdEnv/_startupProfile.dcl
    #touch $1/Libraries/StdEnv/_startupTrace.dcl

61
    for objectfile in _startup0.o _startup1.o _startup1Profile.o _startup1ProfileGraph.o _startup1ProfileGraphB.o _startup1Trace.o _startup2.o _startup3.o _startup4.o ; do
62
63
64
65
66
67
68
69
70
        cp build/runtimesystem/$objectfile "$1/Libraries/StdEnv/Clean System Files/"
    done
}
build_runtimesystem_clean () { # $1:target
    #Generate the 'clean part' of the runtime system
    mkdir -p $1/Libraries/StdEnv/Clean\ System\ Files


    #Copy abc and library files
71
72
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/_system.abc $1/Libraries/StdEnv/Clean\ System\ Files/_system.abc
    cp src/stdenv-master/Library\ Files\ Windows\ 64/*_library $1/Libraries/StdEnv/Clean\ System\ Files/
73
74
75
76
77
78
79

    #Use the new code generator
    target/clean-c-components/Tools/Clean\ System\ 64/CodeGenerator64.exe $1/Libraries/StdEnv/Clean\ System\ Files/_system
}

build_linker () { # $1:target $2: clean system
    mkdir -p build/linker
80
    cp -r src/clean-dynamic-system-trunk/* build/linker/
81
82

    #Patched project file for the linker
83
    cp $PACKAGE/$OS-$ARCH/txt/StaticLinker64.prj build/linker/StaticLinker64.prj
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

    cd build/linker
	LINKER_PRJ=`cygpath --windows --absolute "StaticLinker64.prj"`
	#Try cpm first, otherwise try the clean ide
	if test -f ../clean/cpm.exe; then
           ../clean/cpm.exe StaticLinker64.prj
	else
           ../clean/CleanIDE.exe --batch-build $LINKER_PRJ
	fi
    cd ../..

    mkdir -p "$1/Tools/Clean System 64"
    cp build/linker/StaticLinker.exe "$1/Tools/Clean System 64/StaticLinker.exe"
}

build_clm () { # $1:target
100
101
	mkdir -p build
	cp -r src/clm-master build/clm
102

103
	make -C build/clm -f Makefile.windows-x64 clm
104

105
106
	mkdir -p $1
	cp build/clm/clm.exe $1/clm.exe
107
108
109
110
111
112
}
build_cpm_intermediate () {
    #Copy the clean system for building
    mkdir -p build/cpm/clean-build
    mkdir -p build/cpm/clean-target

113
    cp -r build/clean/* build/cpm/clean-build/
114
115
    cp -r target/clean-intermediate/* build/cpm/clean-target/

116
    #Get batchbuild source code
117
    mkdir -p build/cpm/CleanIDE
118
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
119
    #Add dependencies
120
    cp -r src/clean-libraries-master/Libraries/StdLib/* build/cpm/CleanIDE/Util/
121
122

    #Patch project file
123
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
124
125
126
127
128
129
130
131

    #Create BatchBuild to bootstrap
	
    # Use 16M heap for batchbuild instead of 4M
    sed s/HeapSize:\\t4194304/HeapSize:\\t16777216/ < build/cpm/CleanIDE/BatchBuild.prj > build/cpm/CleanIDE/BatchBuild_.prj
    BATCHBUILD_PRJ=`cygpath --windows --absolute "build/cpm/CleanIDE/BatchBuild_.prj"`

    build/cpm/clean-build/CleanIDE.exe --batch-build $BATCHBUILD_PRJ
132
133
134
135

    #Create a fresh copy of the intermediate clean system + batch-build
    rm -rf build/cpm/clean-target/*
    cp -r target/clean-intermediate/* build/cpm/clean-target/
136
137
    cp build/cpm/CleanIDE/BatchBuild.exe build/cpm/clean-target/

138
139
    #Create a fresh copy of the IDE source for cpm
    rm -rf build/cpm/CleanIDE/*
140
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
141
    #Add dependencies
142
    cp -r src/clean-libraries-master/Libraries/StdLib/* build/cpm/CleanIDE/Util/
143
    #Patch project file
144
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
145
146

    # Patch IDEEnvs for batchbuild
147
    mkdir -p build/cpm/clean-target/Config
148
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs build/cpm/clean-target/Config/IDEEnvs
149
150
151
152
153
154
155
156
157

    #Use batchbuild to create cpm
    CPM_PRJ=`cygpath --windows --absolute "build/cpm/CleanIDE/CpmWin.prj"`
    build/cpm/clean-target/BatchBuild.exe $CPM_PRJ

    #mkdir -p $1/Tools/Temp
    cp build/cpm/CleanIDE/cpm/cpm.exe target/clean-intermediate/cpm.exe

    mkdir -p target/clean-intermediate/Config
158
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs target/clean-intermediate/Config/IDEEnvs
159
160
161
162
163
164
165
166
167
168
169
170
}

build_cpm_base() {
    echo "CPM BASE"

    #Copy the clean system for building
    mkdir -p build/cpm/clean-build

    cp -r target/clean-intermediate/* build/cpm/clean-build/

    #Get cpm source code
    mkdir -p build/cpm/CleanIDE
171
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
172
    #Add dependencies
173
    cp -r src/clean-libraries-master/Libraries/StdLib/* build/cpm/CleanIDE/Util/
174
175

    #Patch project file
176
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
177
178
179
180
181
182
183
184
185
186

    #Build
    cd build/cpm/CleanIDE
       ../clean-build/cpm.exe CpmWin.prj
    cd ../../..

    #mkdir -p $1/Tools/Temp
    cp build/cpm/CleanIDE/cpm/cpm.exe target/clean-base/cpm.exe

    mkdir -p target/clean-base/Config
187
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs target/clean-base/Config/IDEEnvs
188
189
190
191
}

build_compiler() { # $1:target $2:clean system
    mkdir -p build/compiler
192
    cp -r src/compiler-itask/* build/compiler/
193
194
195
196
197
198

    cp build/compiler/backendC/CleanCompilerSources/backend.h build/compiler/backend/backend.h
    
    #TODO: Use an intermediately built htoclean

    BACKEND_H=`cygpath --windows --absolute "build/compiler/backend/backend.h"`
199
    build/clean/Tools/htoclean/htoclean.exe $BACKEND_H
200

201
    #TEMPORARY: Use patched project file, the one in the source does not work
202
    cp $PACKAGE/$OS-$ARCH/txt/CleanCompiler64.prj build/compiler/CleanCompiler64.prj
203

204
    cd build/compiler
205
206
207
208
209
210
211
212
213
214
215
216
217
218
	COCL_PRJ=`cygpath --windows --absolute "CleanCompiler64.prj"`

	#Try cpm first, otherwise try the clean ide
	if test -f ../clean/cpm.exe; then
           ../clean/cpm.exe CleanCompiler64.prj
	else
           ../clean/CleanIDE.exe --batch-build $COCL_PRJ
	fi
    cd ../..

    mkdir -p "$1/Tools/Clean System 64"

    #TEMPORARY HACK UNTIL WE HAVE A NEWER BOOTSTRAP VERSION
    if test -f build/compiler/CleanCompiler64.exe.exe; then
219
    	cp build/compiler/CleanCompiler64.exe.exe "$1/Tools/Clean System 64/CleanCompilerITasks64.exe"
220
    else
221
    	cp build/compiler/CleanCompiler64.exe "$1/Tools/Clean System 64/CleanCompilerITasks64.exe"
222
223
224
    fi
}

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
build_compiler_master() { # $1:target $2:clean system
    mkdir -p build/compiler-master
    cp -r src/compiler-master/* build/compiler-master/

    cp build/compiler-master/backendC/CleanCompilerSources/backend.h build/compiler-master/backend/backend.h

    #TODO: Use an intermediately built htoclean

    BACKEND_H=`cygpath --windows --absolute "build/compiler-master/backend/backend.h"`
    build/clean/Tools/htoclean/htoclean.exe $BACKEND_H

    #TEMPORARY: Use patched project file, the one in the source does not work
    cp $PACKAGE/$OS-$ARCH/txt/CleanCompiler64.prj build/compiler-master/CleanCompiler64.prj

    cd build/compiler-master
	COCL_PRJ=`cygpath --windows --absolute "CleanCompiler64.prj"`

	#Try cpm first, otherwise try the clean ide
	if test -f ../clean/cpm.exe; then
           ../clean/cpm.exe CleanCompiler64.prj
	else
           ../clean/CleanIDE.exe --batch-build $COCL_PRJ
	fi
    cd ../..

    mkdir -p "$1/Tools/Clean System 64"

    #TEMPORARY HACK UNTIL WE HAVE A NEWER BOOTSTRAP VERSION
    if test -f build/compiler-master/CleanCompiler64.exe.exe; then
254
    	cp build/compiler-master/CleanCompiler64.exe.exe "$1/Tools/Clean System 64/CleanCompiler64.exe"
255
    else
256
    	cp build/compiler-master/CleanCompiler64.exe "$1/Tools/Clean System 64/CleanCompiler64.exe"
257
258
259
    fi
}

260
261
262
263
264
build_docs () { #$1:target $2:clean system
    cp src/clean-ide-master/CleanLicenseConditions.txt $1/CleanLicenseConditions.txt
    #cp $PACKAGE/$OS-$ARCH/txt/README $1/README.md
}

265
266
267
268
269
build_stdenv() { # $1:target $2: clean system
    mkdir -p $1/Libraries/StdEnv

    # Copy the platform independent files
    for a in _library _startup _system
270
    do cp src/stdenv-master/$a.dcl $1/Libraries/StdEnv/ ;
271
272
273
274
    done

    for a in StdArray StdBool StdChar StdCharList StdClass StdDebug StdEnum StdEnv \
	  StdInt StdFile StdReal StdString \
275
	  StdFunc StdFunctions StdList StdMisc StdOrdList StdOverloaded StdOverloadedList \
276
	  StdStrictLists StdTuple StdMaybe _SystemArray _SystemEnum _SystemEnumStrict \
277
	  _SystemStrictLists _SystemStrictMaybes StdGeneric _SystemDynamic StdDynamic;
278
    do cp src/stdenv-master/$a.[di]cl $1/Libraries/StdEnv/ ;
279
280
281
    done

    # Overwrite 64-bit specific files
282
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/_SystemStrictLists.icl $1/Libraries/StdEnv/_SystemStrictLists.icl
283
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/_SystemStrictMaybes.icl $1/Libraries/StdEnv/_SystemStrictMaybes.icl
284
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdInt.dcl $1/Libraries/StdEnv/StdInt.dcl
285
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdReal.dcl $1/Libraries/StdEnv/StdReal.dcl
286
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdReal.icl $1/Libraries/StdEnv/StdReal.icl
287
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdString.dcl $1/Libraries/StdEnv/StdString.dcl
288
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdString.icl $1/Libraries/StdEnv/StdString.icl
289
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdFile.dcl $1/Libraries/StdEnv/StdFile.dcl
290
    cp src/stdenv-master/StdEnv\ 64\ Changed\ Files/StdFile.icl $1/Libraries/StdEnv/StdFile.icl
291
292
293

    STDENV_SYSTEM_MODULES="StdBool StdChar StdFile StdInt StdMisc StdReal StdString"
    for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
294
        "$1/Tools/Clean System 64/CleanCompiler64.exe" -ou -pm -pt -P "$1/Libraries/StdEnv/$stdenv_build_m" -dynamic;
295
296
    done
    for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
297
        "$1/Tools/Clean System 64/CleanCompiler64.exe" -ou -pm -pt -P "$1/Libraries/StdEnv/$stdenv_build_m"; 
298
299
300
301
302
    done
}

build_argenv() { # $1:target
    mkdir -p build/libraries/
303
    cp -r src/clean-libraries-master/Libraries/ArgEnvWindows build/libraries/ArgEnv
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
    #TODO: Should compile the c part of this library and not use object file from svn
    #(cd build/libraries/ArgEnv
    #    gcc -c ArgEnvC.c -o ArgEnvC.o
    #)

    mkdir -p "$1/Libraries/ArgEnv/Clean System Files"
    for f in ArgEnvC.c ArgEnv.dcl printenv.icl ArgEnv.icl README.txt;
    do  cp build/libraries/ArgEnv/$f $1/Libraries/ArgEnv/$f
    done
    cp build/libraries/ArgEnv/Clean\ System\ Files/* "$1/Libraries/ArgEnv/Clean System Files/"
    #cp "build/libraries/ArgEnv/ArgEnvC.o" "$1/Libraries/ArgEnv/Clean System Files/"
}

build_dynamics() { #$1:target
    #Copy minimal Dynamics libraries
    mkdir -p "$1/Libraries/Dynamics/Clean System Files"
320
321
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/extension/StdCleanTypes.dcl $1/Libraries/Dynamics/
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/extension/StdCleanTypes.icl $1/Libraries/Dynamics/
322
}
323

324
325
326
build_generics() { #$1:target
    #Copy generics library
    mkdir -p $1/Libraries/Generics
327
    cp src/clean-libraries-master/Libraries/GenLib/*.[id]cl $1/Libraries/Generics/
328
}
329

330
331
build_directory() { #$1:target
    mkdir -p build/Directory
332
    cp -r src/clean-libraries-master/Libraries/Directory/* build/Directory/
333
    cp src/clean-tools-trunk/htoclean/Clean.h "build/Directory/Clean System Files Windows/Clean.h"
334
335
336
337
338
339
340
341
342

    cd "build/Directory/Clean System Files Windows"
         gcc -c -O cDirectory.c
    cd ../../..

    mkdir -p "$1/Libraries/Directory/Clean System Files"
    cp build/Directory/*.[id]cl $1/Libraries/Directory/
    cp build/Directory/Clean\ System\ Files\ Windows/* $1/Libraries/Directory/Clean\ System\ Files/
}
343

344
345
346
build_stdlib() { #$1:target
    #Copy generics library
    mkdir -p $1/Libraries/StdLib
347
    cp src/clean-libraries-master/Libraries/StdLib/*.[id]cl $1/Libraries/StdLib/
348
}
349

350
351
build_objectio() { #$1:target
    mkdir -p build/ioobjects
352
    cp -r "src/clean-libraries-master/Libraries/ObjectIO/ObjectIO/OS Windows/Windows_C_12" "build/objectio"
353
354
355
356
357
358
359
360
361
362

    #Compile c files
    for c in build/objectio/*.c; do
        vscc "$c"
    done

    #Copy .o files to target
    mkdir -p "$1/Libraries/ObjectIO/OS Windows/Clean System Files"
    cp build/objectio/*.obj "$1/Libraries/ObjectIO/OS Windows/Clean System Files/"
    # Copy clean files to target
363
364
365
    cp src/clean-libraries-master/Libraries/ObjectIO/ObjectIO/*.[id]cl $1/Libraries/ObjectIO/
    cp src/clean-libraries-master/Libraries/ObjectIO/ObjectIO/OS\ Windows/*.[id]cl $1/Libraries/ObjectIO/OS\ Windows/
    cp src/clean-libraries-master/Libraries/ObjectIO/ObjectIO/OS\ Windows/Clean\ System\ Files/*_library $1/Libraries/ObjectIO/OS\ Windows/Clean\ System\ Files/
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
}

vscc() { # $1: C .c file path

	COMMAND=`cygpath --unix $COMSPEC`
	vscc_file=`cygpath --absolute --windows "$1"`
	vscc_dir=`dirname "$1"`
	vscc_object_file=`basename $vscc_file .c`.obj
	(cd "$vscc_dir"
	 cat <<EOBATCH | "$COMMAND"
@call "$VSSETENV" amd64
@cl /nologo /c /GS- "$vscc_file" /Fo"$vscc_object_file"
EOBATCH
	)
}

build_clean_c_components () { # $1:target
    mkdir -p $1
    build_codegenerator $1
    build_compiler_backend $1
    build_runtimesystem_c $1
    build_clm $1
}

build_clean() { # $1:target $2: clean system
    mkdir -p $1

    #Copy all C components (they are built only once)
    cp -r target/clean-c-components/* $1/

    #Create a Temp directory for compiler output
    mkdir -p $1/Temp

399
400
401
402
    build_compiler $1 $2
    build_compiler_master $1 $2
    build_linker $1 $2

403
404
405
406
407
408
409
410
411
412
413
414
415
    # Build all Clean components
    # Standard libraries
    build_stdenv $1 $2
    # Rts and compiler
    build_runtimesystem_clean $1 $2
}

#### Main build process ####

# Build components written in C (code generator, runtime system and clm)
build_clean_c_components target/clean-c-components

# First pass: build a clean system using the bootstrap clean system
Bas Lijnse's avatar
Bas Lijnse committed
416
417
export PATH=`pwd`/build/clean/Tools:$CUR_PATH
export CLEAN_HOME=`cygpath --windows --absolute build/clean`
418

419
build_clean target/clean-intermediate build/clean
420
# Standard libraries as dependencies for the second pass
421
422
423
424
425
426
build_dynamics target/clean-intermediate build/clean
build_generics target/clean-intermediate build/clean
build_directory target/clean-intermediate build/clean
build_argenv target/clean-intermediate build/clean
build_stdlib target/clean-intermediate build/clean
build_objectio target/clean-intermediate build/clean
427

428
429
430
431
432
# TODO: Temporary: the new compiler generates new ABC code (with optimized
# instance calls), so we need to regenerate the ABC of StdEnv before trying to
# build a new Clean system. This needs to be fixed elsewhere.
rm build/clean/Libraries/StdEnv/Clean\ System\ Files/{Std,_System}*.abc

433
434
435
436
# Build cpm using the freshly built intermediate clean system
# and a little help from the bootstrap clean system
build_cpm_intermediate

437
438
439
440
# Preserve htoclean (we should build it instead)
mkdir -p target/clean-intermediate/Tools/htoclean
cp build/clean/Tools/htoclean/htoclean.exe target/clean-intermediate/Tools/htoclean/

Bas Lijnse's avatar
Bas Lijnse committed
441
# Second pass: Build a minimal clean system using the clean system from the previous pass
442
rm -rf build
Bas Lijnse's avatar
Bas Lijnse committed
443
444
mkdir -p build/clean
cp -r target/clean-intermediate/* build/clean/
445

446
build_clean target/clean-base build/clean
447
build_cpm_base
448
build_docs target/clean-base build/clean