FreeCalypso > hg > fc-selenite
annotate scripts/ti/make_cmd.pl @ 158:8fe0cde2fd79
doc/Compiling: update for SE J100 target and fc-host-tools-r10
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 17 Mar 2019 07:20:28 +0000 |
parents | f10cbd8a51c4 |
children |
rev | line source |
---|---|
13
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #!perl |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 # generate a dynamic Linker command file |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 # PARAMETER ARE: |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 # 0 : Name of the file with the parameters |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 # 1 : Name of the Linker command file (output) |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 # 2 : value of the TOOL_CHOICE variable |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 # 3 : Name of the Linker command file template |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 # 4 - (n-1) : Name of the libraries |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #$argcount = @ARGV; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 my $lnk_opt_file=$ARGV[0]; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 my $cmd_file=$ARGV[1]; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 my $toolchoice_type = $ARGV[2]; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 my $cmd_file_temp=$ARGV[3]; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 my %section; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 open (TMP,$lnk_opt_file)||die "can't open file\n"; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 # parse the parameter file and construct replacement strings |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 # |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 # the file contains entries of the following form |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 # (BSS_LIBS (.bss)) |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 # or |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 # (BSS_LIBS (.bss) CONST_LIBS (.text, .const)) |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 # or |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 # (BSS_LIBS (.bss)) (BSS_LIBS (.bss) CONST_LIBS (.text, .const)) |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 # |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 # the syntax is as follows, white space and line breaks are not significant |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 # <ENTRY> := <lp> <PAIR><lp> |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 # <PAIR> := <name> <SECTION> |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 # <SECTION> := <lp><free_text><lp> |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 # <lp> := ( |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 # <rp> := ) |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 # <name> := [A-Za-z_]+ |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 # <free_text> := [^()]+ |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 # |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 # each entry will be linked with one library passed on the command line |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 my $line; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 my $count; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 while ($line=<TMP>) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 # find <ENTRY> |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 while ($line =~ /\((\s*\w+\s*\([^\(\)]+\))+\)/) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 $line = $'; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 $match = $&; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 # find <PAIR> |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 while ($match =~ /\s*(\w+)\s*(\([^\(\)]+\))/ ) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 $match = $'; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 $section{"$1"} .= "$ARGV[$count+4] $2\n"; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 $count++; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 open (TMP1, ">$cmd_file"); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 open (TMP,$cmd_file_temp); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 while ($line=<TMP>) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 my $replaced = 0; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 foreach $key (keys(%section)) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if ($line =~ /\($key\)/g) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 # insert the Libs |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 $line = $section{$key}; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 $replaced = 1; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 # NEW COMPILER MANAGEMENT |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 # If use of VISUAL LINKER, needs to manage trampoline download. |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 # Case of: |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 # - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 # - TOOL_CHOICE == 3 => compiler & linker v2.54 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if ($toolchoice_type == 0) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 $line =~ s(COMMENT1START)(/*); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 $line =~ s(COMMENT1END)(*/); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 $line =~ s(COMMENT2START)(); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 $line =~ s(COMMENT2END)(); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } else { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 $line =~ s(COMMENT1START)(); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 $line =~ s(COMMENT1END)(); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 $line =~ s(COMMENT2START)(/*); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 $line =~ s(COMMENT2END)(*/); |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if ($replaced || !($line =~ /^\s*\$\(\s*\w+\s*\)\s*$/ )) { |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 print TMP1 $line; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 close TMP; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 close TMP1; |
f10cbd8a51c4
scripts: pruned import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 unlink $tmp_file; |