forked from minoca/os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menv.ck
1947 lines (1410 loc) · 38.3 KB
/
menv.ck
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
124
125
126
127
128
129
130
131
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
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
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
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
680
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
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
801
802
803
804
805
806
807
808
809
810
811
812
813
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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*++
Copyright (c) 2017 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
[email protected] for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
env.ck
Abstract:
This build module contains the environment and functions used throughout
the Minoca OS build.
Author:
Evan Green 1-Feb-2017
Environment:
Build
--*/
//
// -------------------------------------------------------------------- Imports
//
from mingen import config;
from os import getenv, basename;
//
// -------------------------------------------------------------------- Globals
//
var mconfig;
//
// ------------------------------------------------------------------ Functions
//
function
initListFromEnvironment (
name,
default
)
/*++
Routine Description:
This routine gets an environment variable. It either returns that
environment variable wrapped in a list, or the given default.
Arguments:
name - Supplies the name of the environment variable.
default - Supplies the default value to return if not set.
Return Value:
Returns eithe the provided default or has the contents of the environment
variable wrapped in a list.
--*/
{
var value = getenv(name);
if (value != null) {
return [value];
}
return default;
}
function
getTools (
)
/*++
Routine Description:
This routine is called as part of setupEnv, at the end. It returns the
basic set of tools used by the environment.
Arguments:
None.
Return Value:
Returns a list of the basic tools used in the environment.
--*/
{
var buildCflagsLine = "$BUILD_BASE_CPPFLAGS $CPPFLAGS " +
"$BUILD_BASE_CFLAGS $CFLAGS -MMD -MF $OUT.d ";
var buildAsflagsLine = buildCflagsLine +
"$BUILD_BASE_ASFLAGS $ASFLAGS ";
var buildLdflagsLine = "$BUILD_BASE_LDFLAGS $LDFLAGS ";
var cflagsLine = "$BASE_CPPFLAGS $CPPFLAGS $BASE_CFLAGS $CFLAGS "
"-MMD -MF $OUT.d ";
var asflagsLine = cflagsLine + "$BASE_ASFLAGS $ASFLAGS ";
var entries;
var ldflagsLine = "-Wl,-Map=$OUT.map $BASE_LDFLAGS $LDFLAGS ";
var symlinkCommand = "ln -sf $SYMLINK_IN $OUT";
var buildLdLine = "$BUILD_CC " + buildLdflagsLine +
"-o $OUT $IN -Bdynamic $DYNLIBS";
var tools;
if (mconfig.build_os == "Windows") {
symlinkCommand = "cp $IN $OUT";
}
//
// On Mac OS there shouldn't be a -Bdynamic flag to indicate the start of
// the dynamic libraries section.
//
if (mconfig.build_os == "Darwin") {
buildLdLine = "$BUILD_CC " + buildLdflagsLine +
"-o $OUT $IN $DYNLIBS";
//
// Create a .map file (except on Mac, which doesn't support it).
//
} else {
buildLdflagsLine = "-Wl,-Map=$OUT.map " + buildLdflagsLine;
}
//
// Define the tools used.
//
tools = [
//
// C compiler for target binaries.
//
{
"type": "tool",
"name": "cc",
"command": "$CC " + cflagsLine + "-c -o $OUT $IN",
"description": "Compiling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// C++ compiler for target binaries.
//
{
"type": "tool",
"name": "cxx",
"command": "$CXX " + cflagsLine + "-c -o $OUT $IN",
"description": "Compiling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// Linker for target binaries.
//
{
"type": "tool",
"name": "ld",
"command": "$CC " + ldflagsLine + "-o $OUT $IN -Bdynamic $DYNLIBS",
"description": "Linking - $OUT",
},
//
// Static archiver for target binaries.
//
{
"type": "tool",
"name": "ar",
"command": "$AR rcs $OUT $IN",
"description": "Building Library - $OUT",
},
//
// Assembler for target binaries.
//
{
"type": "tool",
"name": "as",
"command": "$CC " + asflagsLine + "-c -o $OUT $IN",
"description": "Assembling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// Objcopy for target binaries.
//
{
"type": "tool",
"name": "objcopy",
"command": "$SHELL -c \"cd `dirname $IN` && "
"$OBJCOPY $OBJCOPY_FLAGS `basename $IN` $OUT\"",
"description": "Objectifying - $IN"
},
//
// Strip for target binaries.
//
{
"type": "tool",
"name": "strip",
"command": "$STRIP $STRIP_FLAGS -o $OUT $IN",
"description": "Stripping - $OUT",
},
//
// C compiler for the build machine.
//
{
"type": "tool",
"name": "build_cc",
"command": "$BUILD_CC " + buildCflagsLine + "-c -o $OUT $IN",
"description": "Compiling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// C++ compiler for the build machine.
//
{
"type": "tool",
"name": "build_cxx",
"command": "$BUILD_CXX " + buildCflagsLine + "-c -o $OUT $IN",
"description": "Compiling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// Linker for the build machine.
//
{
"type": "tool",
"name": "build_ld",
"command": "$BUILD_CC " + buildLdflagsLine +
"-o $OUT $IN -Bdynamic $DYNLIBS",
"description": "Linking - $OUT",
},
//
// Static archiver for the build machine.
//
{
"type": "tool",
"name": "build_ar",
"command": "$BUILD_AR rcs $OUT $IN",
"description": "Building Library - $OUT",
},
//
// Assembler for the build machine.
//
{
"type": "tool",
"name": "build_as",
"command": "$BUILD_CC " + buildAsflagsLine + "-c -o $OUT $IN",
"description": "Assembling - $IN",
"depsformat": "gcc",
"depfile": "$OUT.d"
},
//
// Strip for the build machine.
//
{
"type": "tool",
"name": "build_strip",
"command": "$BUILD_STRIP $STRIP_FLAGS -o $OUT $IN",
"description": "Stripping - $OUT",
},
//
// Windows resource compiler for the build machine.
//
{
"type": "tool",
"name": "build_rcc",
"command": "$RCC -o $OUT $IN",
"description": "Compiling Resource - $IN",
},
//
// ACPI assembler used to build firmware images.
//
{
"type": "tool",
"name": "iasl",
"command": "$SHELL -c \"$IASL $IASL_FLAGS -p $OUT $IN > $OUT.stdout\"",
"description": "Compiling ASL - $IN"
},
//
// Copy files from one location to another.
//
{
"type": "tool",
"name": "copy",
"command": "$SHELL -c \"cp $CPFLAGS $IN $OUT && [ -z $CHMOD_FLAGS ] || "
"chmod $CHMOD_FLAGS $OUT\"",
"description": "Copying - $IN -> $OUT"
},
//
// Create symbolic links (or just copy on Windows).
//
{
"type": "tool",
"name": "symlink",
"command": symlinkCommand,
"description": "Symlinking - $OUT"
},
//
// Touch a file with the date.
//
{
"type": "tool",
"name": "stamp",
"command": "$SHELL -c \"date > $OUT\"",
"description": "Stamp - $OUT"
},
//
// Touch to create a timestamped empty file.
//
{
"type": "tool",
"name": "touch",
"command": "touch $OUT",
"description": "Touch - $OUT"
},
//
// Create a directory.
//
{
"type": "tool",
"name": "mkdir",
"command": "mkdir -p $OUT",
"description": "mkdir $OUT"
},
//
// Generate a version.h.
//
{
"type": "tool",
"name": "gen_version",
"command": "$SHELL $S/tasks/build/print_version.sh $OUT $FORM "
"$MAJOR $MINOR $REVISION $RELEASE $SERIAL $BUILD_STRING",
"description": "Versioning - $OUT"
}];
return tools;
}
function
setupEnv (
)
/*++
Routine Description:
This routine is called once to set up the build environment.
Arguments:
None.
Return Value:
Returns the basic set of tools used by the environment.
--*/
{
var archVariant;
//
// Prefer Ninja files.
//
config.format ?= "ninja";
//
// Set up the Minoca config dictionary.
//
mconfig = {};
mconfig.build_os = config.build_os;
mconfig.build_machine = config.build_machine;
mconfig.build_variant = "";
if (mconfig.build_machine == "i686") {
mconfig.build_arch = "x86";
} else if (mconfig.build_machine == "i586") {
mconfig.build_arch = "x86";
mconfig.build_variant = "q";
} else if ((mconfig.build_machine == "armv7") ||
(mconfig.build_machine == "armv6")) {
mconfig.build_arch = mconfig.build_machine;
} else if (mconfig.build_machine == "x86_64") {
mconfig.build_arch = "x64";
}
mconfig.arch = getenv("ARCH");
mconfig.arch ?= mconfig.build_arch;
mconfig.arch ?= "x86";
mconfig.debug = getenv("DEBUG");
mconfig.debug ?= "dbg";
mconfig.variant = getenv("VARIANT");
mconfig.variant ?= mconfig.build_variant;
mconfig.release_level = "SystemReleaseDevelopment";
mconfig.cflags = initListFromEnvironment("CFLAGS",
["-O2", "-Wall", "-Werror"]);
mconfig.kernelCflags = [];
mconfig.cppflags = initListFromEnvironment("CPPFLAGS", []);
mconfig.ldflags = initListFromEnvironment("LDFLAGS", []);
mconfig.asflags = initListFromEnvironment("ASFLAGS", []);
mconfig.stripflags = initListFromEnvironment("STRIP_FLAGS", []);
mconfig.build_cc = getenv("BUILD_CC");
mconfig.build_cc ?= "gcc";
mconfig.build_ar = getenv("BUILD_AR");
mconfig.build_ar ?= "ar";
mconfig.build_strip = getenv("BUILD_STRIP");
mconfig.build_strip ?= "strip";
config.output ?= "$S/../" + mconfig.arch + mconfig.variant + mconfig.debug +
"/obj/os";
mconfig.outroot = "$O/../..";
mconfig.binroot = mconfig.outroot + "/bin";
mconfig.stripped = mconfig.binroot + "/stripped";
mconfig.cc = getenv("CC");
mconfig.ar = getenv("AR");
mconfig.objcopy = getenv("OBJCOPY");
mconfig.strip = getenv("STRIP");
mconfig.rcc = getenv("RCC");
mconfig.rcc ?= "windres";
mconfig.iasl = getenv("IASL");
mconfig.iasl ?= "iasl";
mconfig.shell = getenv("SHELL");
mconfig.shell ?= "sh";
mconfig.target = null;
//
// Add in the command line variables, then define the derived variables.
//
for (key in config.cmdvars) {
mconfig[key] = config.cmdvars[key];
}
archVariant = mconfig.arch + mconfig.variant;
if (!mconfig.target) {
if (archVariant == "x86") {
mconfig.target = "i686-pc-minoca";
} else if (archVariant == "x86q") {
mconfig.target = "i586-pc-minoca";
} else if ((mconfig.arch == "armv7") || (mconfig.arch == "armv6")) {
mconfig.target = "arm-none-minoca";
} else if (mconfig.arch == "x64") {
mconfig.target = "x86_64-pc-minoca";
} else {
Core.raise(ValueError("Unknown architecture" + mconfig.arch));
}
}
mconfig.native = false;
if ((mconfig.build_os == "Minoca") &&
(mconfig.arch == mconfig.build_arch)) {
mconfig.native = true;
}
if (mconfig.native) {
mconfig.cc ?= mconfig.build_cc;
mconfig.ar ?= mconfig.build_ar;
mconfig.strip ?= mconfig.build_strip;
mconfig.objcopy ?= "objcopy";
} else {
mconfig.cc ?= mconfig.target + "-gcc";
mconfig.ar ?= mconfig.target + "-ar";
mconfig.strip ?= mconfig.target + "-strip";
mconfig.objcopy ?= mconfig.target + "-objcopy";
}
if (mconfig.debug == "dbg") {
mconfig.cflags += ["-DDEBUG=1"];
} else {
mconfig.cflags += ["-Wno-unused-but-set-variable", "-DNDEBUG"];
}
mconfig.cflags += ["-fno-builtin",
"-g",
"-save-temps=obj",
"-ffunction-sections",
"-fdata-sections",
"-fvisibility=hidden"];
mconfig.cppflags += ["-I$S/include"];
mconfig.build_cflags = [] + mconfig.cflags;
mconfig.build_cppflags = [] + mconfig.cppflags;
mconfig.cflags += ["-fpic"];
//
// Windows cannot handle -fpic, but everyone else can.
//
if (mconfig.build_os == "Windows") {
mconfig.build_cflags += ["-mno-ms-bitfields"];
} else {
mconfig.build_cflags += ["-fpic"];
}
if (mconfig.build_os == "Darwin") {
mconfig.build_cflags += ["-Wno-tautological-compare",
"-Wno-parentheses-equality"];
}
//
// Add some architecture variant flags.
//
if (archVariant == "x86q") {
mconfig.cppflags += ["-Wa,-momit-lock-prefix=yes", "-march=i586"];
} else if (archVariant == "x64") {
mconfig.kernelCflags = ["-mno-sse", "-mno-red-zone"];
} else if (archVariant == "armv6") {
mconfig.cflags += ["-march=armv6zk", "-marm", "-mfpu=vfp"];
}
mconfig.build_asflags = [];
mconfig.asflags += ["-Wa,-g"];
mconfig.build_ldflags = initListFromEnvironment("BUILD_LDFLAGS",
[] + mconfig.ldflags);
mconfig.ldflags += ["-Wl,--gc-sections"];
//
// Mac OS cannot handle --gc-sections or strip -p.
//
if (mconfig.build_os != "Darwin") {
mconfig.build_ldflags += ["-Wl,--gc-sections"];
mconfig.stripflags += ["-p"];
}
//
// Define the set of variables that get passed all the way through to the
// final Make/ninja file. Passing these on as variables rather than
// substituting during the mingen build process allows for a smaller
// build file, and easier manual tweaking by the user.
//
config.vars = {
"BUILD_CC": mconfig.build_cc,
"BUILD_AR": mconfig.build_ar,
"BUILD_STRIP": mconfig.build_strip,
"CC": mconfig.cc,
"AR": mconfig.ar,
"STRIP": mconfig.strip,
"OBJCOPY": mconfig.objcopy,
"RCC": mconfig.rcc,
"IASL": mconfig.iasl,
"SHELL": mconfig.shell,
"BASE_CFLAGS": mconfig.cflags,
"KERNEL_CFLAGS": mconfig.kernelCflags,
"BASE_CPPFLAGS": mconfig.cppflags,
"BASE_LDFLAGS": mconfig.ldflags,
"BASE_ASFLAGS": mconfig.asflags,
"BUILD_BASE_CFLAGS": mconfig.build_cflags,
"BUILD_BASE_CPPFLAGS": mconfig.build_cppflags,
"BUILD_BASE_LDFLAGS": mconfig.build_ldflags,
"BUILD_BASE_ASFLAGS": mconfig.build_asflags,
"STRIP_FLAGS": mconfig.stripflags,
"IASL_FLAGS": ["-we"],
"CPFLAGS": "-p",
};
if (config.verbose) {
Core.print("Minoca Build Configuration:");
for (key in mconfig) {
Core.print("\t%s: %s" % [key, mconfig[key].__str()]);
}
}
return getTools();
}
function
addConfig (
entry,
name,
value
)
/*++
Routine Description:
This routine adds a configure option to a list, ensuring that both the
config dictionary and option already exist.
Arguments:
entry - Supplies the entry to add the configure option to.
name - Supplies the name of the option to add.
value - Supplies the new value to add to the list of options.
Return Value:
None.
--*/
{
if (!entry.get("config")) {
entry.config = {};
}
if (!entry.config.get(name)) {
entry.config[name] = [];
}
entry.config[name] += [value];
return;
}
function
group (
name,
entries
)
/*++
Routine Description:
This routine creates a phony target that groups a bunch of different
targets together under a common name.
Arguments:
name - Supplies the name of the new group target.
entries - Supplies the list of entries.
Return Value:
Returns a list containing the entry for the group target.
--*/
{
var entry = {
"label": name,
"type": "target",
"tool": "phony",
"inputs": entries,
"config": {}
};
return [entry];
}
function
touch (
destination,
destinationLabel,
mode
)
/*++
Routine Description:
This routine creates an empty file target.
Arguments:
destination - Supplies the copy destination.
destinationLabel - Supplies a label naming the target.
mode - Supplies the chmod mode of the destination.
Return Value:
Returns a list containing the copy entry.
--*/
{
var config = {};
if (mode) {
config["CHMOD_FLAGS"] = mode;
}
destinationLabel ?= destination;
var entry = {
"type": "target",
"tool": "touch",
"label": destinationLabel,
"output": destination,
"config": config
};
return [entry];
}
function
makedir (
destination,
destinationLabel
)
/*++
Routine Description:
This routine creates an empty directory target.
Arguments:
destination - Supplies the copy destination.
destinationLabel - Supplies a label naming the target.
Return Value:
Returns a list containing the copy entry.
--*/
{
destinationLabel ?= destination;
var entry = {
"type": "target",
"tool": "mkdir",
"label": destinationLabel,
"output": destination,
};
return [entry];
}
function
copy (
source,
destination,
destinationLabel,
flags,
mode
)
/*++
Routine Description:
This routine creates a target that copies a file from one place to another.
Arguments:
source - Supplies the source to copy.
destination - Supplies the copy destination.
destinationLabel - Supplies a label naming the copy target.
flags - Supplies the flags to include in the copy.
mode - Supplies the chmod mode of the destination.
Return Value:
Returns a list containing the copy entry.
--*/
{
var config = {};
if (flags) {
config["CPFLAGS"] = flags;
}
if (mode) {
config["CHMOD_FLAGS"] = mode;
}
var entry = {
"type": "target",
"tool": "copy",
"label": destinationLabel,
"inputs": [source],
"output": destination,
"config": config
};
if (!destinationLabel) {
entry["label"] = destination;
}
return [entry];
}
function
strip (
params
)
/*++
Routine Description:
This routine converts an entry to a strip entry, where the target will be
stripped.
Arguments:
params - Supplies the existing entry.
Return Value:
Returns a list containing the strip entry.
--*/
{
params.type = "target";
params.tool = "strip";
if (params.get("build")) {
params.tool = "build_strip";
}
return [params];
}
function
binplace (
params
)
/*++
Routine Description:
This routine replaces the current target with a copied version in the
final bin directory. This will also create a stripped version in the
stripped directory unless told not to.
Arguments:
params - Supplies the existing entry.
Return Value:
Returns a list containing the strip entry.
--*/
{
var build = params.get("build");
var copiedEntry;
var cpflags = params.get("cpflags");;
var destination;
var destinationLabel;
var destinationPath;
var element;
var entries = [];
var extraCopy;
var fileName;
var label = params.get("label");
var mode = params.get("mode");
var newOriginalLabel;
var originalTarget;
var source = params.get("output");
var strippedEntry;
var strippedOutput;
label ?= source;
source ?= label;
if ((!label) || (!source)) {
Core.raise(ValueError("Label or output must be defined"));
}
//
// Set the output since the label is going to be renamed and create the
// copy target.
//
params.output = source;
params.type = "target";
fileName = basename(source);
destination = params.get("binplace");
newOriginalLabel = label + "_orig";
originalTarget = ":" + newOriginalLabel;
//
// Create the first or only one with the genuine label.
//
element = destination;
if (element is List) {
element = element[0];
}
if (!element) {
element = "bin";
}
destinationPath = mconfig.outroot + "/" + element + "/" + fileName;
copiedEntry = copy(originalTarget,
destinationPath,
label,
cpflags,
mode)[0];
entries.append(copiedEntry);
//
// Handle binplacing into several areas.
//
if (destination is List) {
for (index in 1..destination.length()) {
element = destination[index];