build.sh 15.2 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
61
62
63
64
65
66
67
68
69
70

    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

    for objectfile in _startup0.o _startup1.o _startup1Profile.o _startup1Trace.o _startup2.o _startup3.o _startup4.o ; do
        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/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/_system.abc $1/Libraries/StdEnv/Clean\ System\ Files/_system.abc
    cp src/clean-libraries-trunk/Libraries/StdEnv/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
100

    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
    mkdir -p build
101
    cp -r src/clean-tools-trunk build/tools
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    cd build/tools/clm

	#increase clm path size (or else it will crash when building cpm)
	sed "s/PATH_NAME_STRING_SIZE 256/PATH_NAME_STRING_SIZE 1024/" < clm.c > clm_.c
	mv clm_.c clm.c

        make -f Makefile.windows-x86 clm
    cd ../../..

    mkdir -p $1/Tools
    cp build/tools/clm/clm.exe $1/Tools/clm.exe
}
build_cpm_intermediate () {
    #Copy the clean system for building
    mkdir -p build/cpm/clean-build
    mkdir -p build/cpm/clean-target

119
    cp -r build/clean/* build/cpm/clean-build/
120
121
    cp -r target/clean-intermediate/* build/cpm/clean-target/

122
    #Get batchbuild source code
123
    mkdir -p build/cpm/CleanIDE
124
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
125
    #Add dependencies
126
    cp -r src/clean-libraries-trunk/Libraries/StdLib/* build/cpm/CleanIDE/Util/
127
128

    #Patch project file
129
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
130
131
132
133
134
135
136
137

    #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
138
139
140
141

    #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/
142
143
    cp build/cpm/CleanIDE/BatchBuild.exe build/cpm/clean-target/

144
145
    #Create a fresh copy of the IDE source for cpm
    rm -rf build/cpm/CleanIDE/*
146
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
147
    #Add dependencies
148
    cp -r src/clean-libraries-trunk/Libraries/StdLib/* build/cpm/CleanIDE/Util/
149
    #Patch project file
150
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
151
152

    # Patch IDEEnvs for batchbuild
153
    mkdir -p build/cpm/clean-target/Config
154
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs build/cpm/clean-target/Config/IDEEnvs
155
156
157
158
159
160
161
162
163

    #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
164
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs target/clean-intermediate/Config/IDEEnvs
165
166
167
168
169
170
171
172
173
174
175
176
}

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
177
    cp -r src/clean-ide-master/* build/cpm/CleanIDE/
178
179
    #Add dependencies
    cp -r src/clean-libraries-trunk/Libraries/StdLib/* build/cpm/CleanIDE/Util/
180
181

    #Patch project file
182
    cp $PACKAGE/$OS-$ARCH/txt/CpmWin.prj build/cpm/CleanIDE/CpmWin.prj
183
184
185
186
187
188
189
190
191
192

    #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
193
    cp $PACKAGE/$OS-$ARCH/txt/IDEEnvs target/clean-base/Config/IDEEnvs
194
195
196
197
}

build_compiler() { # $1:target $2:clean system
    mkdir -p build/compiler
198
    cp -r src/compiler-itask/* build/compiler/
199
200
201
202
203
204

    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"`
205
    build/clean/Tools/htoclean/htoclean.exe $BACKEND_H
206

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

210
    cd build/compiler
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
	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
    	cp build/compiler/CleanCompiler64.exe.exe "$1/Tools/Clean System 64/CleanCompiler64.exe"
    else
    	cp build/compiler/CleanCompiler64.exe "$1/Tools/Clean System 64/CleanCompiler64.exe"
    fi
}

build_stdenv() { # $1:target $2: clean system
    mkdir -p $1/Libraries/StdEnv

    # Copy the platform independent files
    for a in _library _startup _system
236
    do cp src/clean-libraries-trunk/Libraries/StdEnv/$a.dcl $1/Libraries/StdEnv/ ;
237
238
239
240
    done

    for a in StdArray StdBool StdChar StdCharList StdClass StdDebug StdEnum StdEnv \
	  StdInt StdFile StdReal StdString \
241
	  StdFunc StdFunctions StdList StdMisc StdOrdList StdOverloaded StdOverloadedList \
242
	  StdStrictLists StdTuple StdMaybe _SystemArray _SystemEnum _SystemEnumStrict \
243
	  _SystemStrictLists StdGeneric;
244
    do cp src/clean-libraries-trunk/Libraries/StdEnv/$a.[di]cl $1/Libraries/StdEnv/ ;
245
246
247
    done

    # Overwrite 64-bit specific files
248
249
250
251
252
    cp src/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/_SystemStrictLists.icl $1/Libraries/StdEnv/_SystemStrictLists.icl
    cp src/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/StdInt.dcl $1/Libraries/StdEnv/StdInt.dcl
    cp src/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/StdReal.icl $1/Libraries/StdEnv/StdReal.icl
    cp src/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/StdString.icl $1/Libraries/StdEnv/StdString.icl
    cp src/clean-libraries-trunk/Libraries/StdEnv/StdEnv\ 64\ Changed\ Files/StdFile.icl $1/Libraries/StdEnv/StdFile.icl
253

254
255
256
    patch $1/lib/StdEnv/StdGeneric.icl < $PACKAGE/$OS-$ARCH/txt/StdGeneric.icl.patch
    patch $1/lib/StdEnv/StdGeneric.dcl < $PACKAGE/$OS-$ARCH/txt/StdGeneric.dcl.patch

257
258
    STDENV_SYSTEM_MODULES="StdBool StdChar StdFile StdInt StdMisc StdReal StdString"
    for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
259
        "$2/Tools/Clean System 64/CleanCompiler64.exe" -ou -pm -pt -P "$1/Libraries/StdEnv/$stdenv_build_m" -dynamic;
260
261
    done
    for stdenv_build_m in $STDENV_SYSTEM_MODULES; do
262
        "$2/Tools/Clean System 64/CleanCompiler64.exe" -ou -pm -pt -P "$1/Libraries/StdEnv/$stdenv_build_m"; 
263
    done
264

265
266
267
268
}

build_argenv() { # $1:target
    mkdir -p build/libraries/
269
    cp -r src/clean-libraries-trunk/Libraries/ArgEnvWindows build/libraries/ArgEnv
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
    #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"
286
287
288
289
290
291
    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/
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/extension/StdDynamic.dcl $1/Libraries/Dynamics/
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/extension/StdDynamicNoLinker.icl $1/Libraries/Dynamics/StdDynamic.icl
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/implementation/_SystemDynamic.dcl $1/Libraries/Dynamics/
    cp src/clean-dynamic-system-trunk/dynamics/StdDynamicEnv/implementation/_SystemDynamic.icl $1/Libraries/Dynamics/
292
293
294
295
}
build_generics() { #$1:target
    #Copy generics library
    mkdir -p $1/Libraries/Generics
296
    cp src/clean-libraries-trunk/Libraries/GenLib/*.[id]cl $1/Libraries/Generics/
297
298
299
}
build_directory() { #$1:target
    mkdir -p build/Directory
300
301
    cp -r src/clean-libraries-trunk/Libraries/Directory/* build/Directory/
    cp src/clean-tools-trunk/htoclean/Clean.h "build/Directory/Clean System Files Windows/Clean.h"
302
303
304
305
306
307
308
309
310
311
312
313

    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/
}
build_stdlib() { #$1:target
    #Copy generics library
    mkdir -p $1/Libraries/StdLib
314
    cp src/clean-libraries-trunk/Libraries/StdLib/*.[id]cl $1/Libraries/StdLib/
315
316
317
}
build_objectio() { #$1:target
    mkdir -p build/ioobjects
318
    cp -r "src/clean-libraries-trunk/Libraries/ObjectIO/ObjectIO/OS Windows/Windows_C_12" "build/objectio"
319
320
321
322
323
324
325
326
327
328

    #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
329
330
331
    cp src/clean-libraries-trunk/Libraries/ObjectIO/ObjectIO/*.[id]cl $1/Libraries/ObjectIO/
    cp src/clean-libraries-trunk/Libraries/ObjectIO/ObjectIO/OS\ Windows/*.[id]cl $1/Libraries/ObjectIO/OS\ Windows/
    cp src/clean-libraries-trunk/Libraries/ObjectIO/ObjectIO/OS\ Windows/Clean\ System\ Files/*_library $1/Libraries/ObjectIO/OS\ Windows/Clean\ System\ Files/
332
333
334
335
336
337
338
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
}

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

    #Copy docs
366
    cp src/clean-ide-master/CleanLicenseConditions.txt $1/CleanLicenseConditions.txt
367
368
369
    #cp txt/README $1/README.md

    mkdir -p $1/Help
370
    cp src/language-report-master/CleanLangRep.2.2.pdf $1/Help/
371
    mkdir -p $1/Help/CleanLangRep/
372
373
374
    cp src/language-report-master/*.htm $1/Help/CleanLangRep/
    cp src/language-report-master/*.css $1/Help/CleanLangRep/
    cp src/language-report-master/*.png $1/Help/CleanLangRep/
375
    mkdir -p $1/Help/CleanLangRep/CleanRep.2.2_files/
376
    cp src/language-report-master/CleanRep.2.2_files/* $1/Help/CleanLangRep/CleanRep.2.2_files/
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

    # Build all Clean components
    # Standard libraries
    build_stdenv $1 $2
    # Rts and compiler
    build_runtimesystem_clean $1 $2
    build_compiler $1 $2
    build_linker $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
393
394
export PATH=`pwd`/build/clean/Tools:$CUR_PATH
export CLEAN_HOME=`cygpath --windows --absolute build/clean`
395

396
build_clean target/clean-intermediate build/clean
397
# Standard libraries as dependencies for the second pass
398
399
400
401
402
403
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
404
405
406
407
408

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

409
410
411
412
# 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
413
# Second pass: Build a minimal clean system using the clean system from the previous pass
414
rm -rf build
Bas Lijnse's avatar
Bas Lijnse committed
415
416
mkdir -p build/clean
cp -r target/clean-intermediate/* build/clean/
417

418
build_clean target/clean-base build/clean
419
build_cpm_base