blob: be303e0e463ba78fc99928c2260db64ba145fde8 (
plain)
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
|
#!/bin/sh
if [ $# -lt 4 ]; then
echo "Usage: $0 <working dir> <input dir> <global mk> <arch [arch [arch ...]]"
exit 1
fi
workingdir=$1
input=$2
globalmk=$3
shift 3
OLDPWD=$PWD
MAKEFILE_TMP=gencode.mk.tmp
MAKEFILE_EXT=gencode.mk
cd ${workingdir}
echo=`which echo`
rm -f ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
$echo "include ${globalmk}" >> ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
if [ "$1" = "-" ]; then
OPCODES=`find ${input} -name '*c' -and -not -name '*.tmpl.c' -exec basename {} \; | cut -d. -f2 | sort | uniq`
else
OPCODES=`find ${input} -name '*c' -and -not -name '*.tmpl.c' -exec basename {} \; | cut -d. -f3 | sort | uniq`
fi
# Génération des en-têtes de décodage
for arch in $*;
do
if [ ${arch} = "-" ]; then
arch_name=""
arch_name_dotted=""
else
arch_name="${arch}_"
arch_name_dotted="${arch}_."
fi
$echo -n "${arch_name}HEADER_FILES =" | tr [:lower:] [:upper:] >> ${MAKEFILE_TMP}
has_header=""
for op in $OPCODES;
do
template="${input}/*.${arch_name_dotted}${op}.c"
sources=`ls $template 2> /dev/null`
if [ -z "${sources}" ]; then
continue
fi
for src in ${sources};
do
has_header="yes"
$echo -ne " \\" >> ${MAKEFILE_TMP}
$echo -ne "\n\t" >> ${MAKEFILE_TMP}
$echo -n ${src} | sed "s/${op}.c$/opcodes.h/" >> ${MAKEFILE_TMP}
done
done
$echo >> ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
$echo -n "${arch_name}opcodes.h: " >> ${MAKEFILE_TMP}
$echo "\$(${arch_name}HEADER_FILES)" | tr [:lower:] [:upper:] >> ${MAKEFILE_TMP}
if [ -z "${has_header}" ]; then
$echo -e "\techo > \$@" >> ${MAKEFILE_TMP}
else
$echo -e "\t\$(cini_verbose)cat ${input}/${arch_name_dotted}opcodes.tmpl.h > \$@" >> ${MAKEFILE_TMP}
$echo -e "\t\$(cgen_verbose)cat \$^ >> \$@" >> ${MAKEFILE_TMP}
$echo -e "\t\$(cfini_verbose)echo >> \$@" >> ${MAKEFILE_TMP}
$echo -en "\t\$(cfini_verbose)echo \"#endif\t /* " >> ${MAKEFILE_TMP}
$echo -en '`cat \$@ | grep "#define" | cut -d " " -f 2`' >> ${MAKEFILE_TMP}
$echo -e " */\" >> \$@" >> ${MAKEFILE_TMP}
fi
$echo >> ${MAKEFILE_TMP}
done
$echo >> ${MAKEFILE_TMP}
# Génération des codes d'instructions
for op in $OPCODES;
do
for arch in $*;
do
if [ ${arch} = "-" ]; then
arch_name=""
arch_name_dotted=""
else
arch_name="${arch}_"
arch_name_dotted="${arch}_."
fi
template="${input}/*.${arch_name_dotted}${op}.c"
sources=`ls $template 2> /dev/null`
if [ -z "${sources}" ]; then
continue
fi
$echo -n "${op}_${arch_name}FILES =" | tr [:lower:] [:upper:] >> ${MAKEFILE_TMP}
for src in ${sources};
do
$echo -ne " \\" >> ${MAKEFILE_TMP}
$echo -ne "\n\t${src}" >> ${MAKEFILE_TMP}
done
$echo >> ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
$echo -n "${arch_name}${op}.c: " >> ${MAKEFILE_TMP}
$echo -n "\$(${op}_${arch_name}FILES)" | tr [:lower:] [:upper:] >> ${MAKEFILE_TMP}
$echo " ${arch_name}opcodes.h" >> ${MAKEFILE_TMP}
$echo -e "\t\$(cini_verbose)cat ${input}/${arch_name_dotted}${op}.tmpl.c > \$@" >> ${MAKEFILE_TMP}
$echo -ne "\t\$(cgen_verbose)cat \$(" >> ${MAKEFILE_TMP}
$echo -ne "${op}_${arch_name}FILES" | tr [:lower:] [:upper:] >> ${MAKEFILE_TMP}
$echo -e ") >> \$@" >> ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
done
done
$echo >> ${MAKEFILE_TMP}
# Génération de la liste des sources
$echo -n "GENERATED_FILES =" >> ${MAKEFILE_TMP}
for arch in $*;
do
if [ ${arch} = "-" ]; then
arch_name=""
arch_name_dotted=""
else
arch_name="${arch}_"
arch_name_dotted="${arch}_."
fi
$echo -ne " \\" >> ${MAKEFILE_TMP}
$echo -ne "\n\t${arch_name}opcodes.h" >> ${MAKEFILE_TMP}
for op in $OPCODES;
do
template="${input}/*.${arch_name_dotted}${op}.c"
sources=`ls $template 2> /dev/null`
if [ ! -z "${sources}" ]; then
$echo -ne " \\" >> ${MAKEFILE_TMP}
$echo -ne "\n\t${arch_name}${op}.c" >> ${MAKEFILE_TMP}
continue
fi
done
done
$echo >> ${MAKEFILE_TMP}
$echo >> ${MAKEFILE_TMP}
# Validation finale
if [ ! -f ]; then
rm -rf ${MAKEFILE_EXT}
mv ${MAKEFILE_TMP} ${MAKEFILE_EXT}
else
hash_tmp=`md5sum ${MAKEFILE_TMP} | cut -d ' ' -f 1`
hash_ext=`md5sum ${MAKEFILE_EXT} | cut -d ' ' -f 1`
if [ "${hash_tmp}" = "${hash_ext}" ]; then
rm -f ${MAKEFILE_TMP}
echo "${MAKEFILE_EXT} is up to date."
else
rm -f ${MAKEFILE_EXT}
mv ${MAKEFILE_TMP} ${MAKEFILE_EXT}
echo "${MAKEFILE_EXT} is updated."
fi
fi
cd ${OLDPWD}
|