-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake
More file actions
executable file
·336 lines (288 loc) · 8.39 KB
/
make
File metadata and controls
executable file
·336 lines (288 loc) · 8.39 KB
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
#!/bin/sh
# stolen from ffmpeg configure like a pig
# this is brutal and stupid... then easy and explicit
# Prevent locale nonsense from breaking basic text processing.
LC_ALL=C
export LC_ALL
major=0
minor=0
micro=0
asm_name=cmingcnasm
asm_slib_name=lib$asm_name.so.$major.$minor.$micro
asm_slib_soname=lib$asm_name.so.$major
asm_slib_export_map=lib$asm_name.export_map
asm_dbin_name=$asm_name
dis_name=cmingcndis
dis_slib_name=lib$dis_name.so.$major.$minor.$micro
dis_slib_soname=lib$dis_name.so.$major
dis_slib_export_map=lib$dis_name.export_map
dis_dbin_name=$dis_name
#-------------------------------------------------------------------------------
ulinux_target_arch_asm_srcs='
ulinux/arch/args_env.s
'
ulinux_c_srcs='
ulinux/utils/mem.c
ulinux/utils/ascii/string/vsprintf.c
ulinux/utils/ascii/block/conv/decimal/decimal.c
ulinux/utils/ascii/block/conv/hexadecimal/hexadecimal.c
ulinux/utils/ascii/block/conv/binary/binary.c
'
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
shared_srcs='
msgs.c
'
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
asm_lib_shared_objs='
msgs.o
'
asm_lib_ulinux_objs='
decimal.o
binary.o
hexadecimal.o
vsprintf.o
mem.o
'
asm_lib_srcs='
src_parse.c
m_emit.c
libcmingcnasm.c
'
asm_bin_ulinux_objs='
args_env.o
mem.o
vsprintf.o
'
asm_bin_srcs='
cmingcnasm.c
'
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
dis_lib_shared_objs='
msgs.o
'
dis_lib_ulinux_objs='
vsprintf.o
mem.o
'
dis_lib_srcs='
libcmingcndis.c
'
dis_bin_ulinux_objs='
args_env.o
mem.o
vsprintf.o
'
dis_bin_srcs='
cmingcndis.c
'
#-------------------------------------------------------------------------------
clean_do(){
files="
$asm_lib_shared_objs
$asm_lib_ulinux_objs
$asm_bin_ulinux_objs
$asm_slib_name
$asm_dbin_name
$dis_lib_shared_objs
$dis_lib_ulinux_objs
$dis_bin_ulinux_objs
$dis_slib_name
$dis_dbin_name
"
for src_file in $dis_bin_srcs $dis_lib_srcs $asm_bin_srcs $asm_lib_srcs
do
obj=${src_file%.c}
obj=${obj}.o
files="$obj $files"
done
rm -f $files
rm -f ulinux/arch
rmdir ulinux
exit 0
}
################################################################################
# find source path
if test -f make; then
src_path=.
else
src_path=$(cd $(dirname "$0"); pwd)
echo "$src_path" | grep -q '[[:blank:]]' &&
die "Out of tree builds are impossible with whitespace in source path."
test -e "$src_path/config.h" &&
die "Out of tree builds are impossible with config.h in source dir."
fi
is_in(){
value=$1
shift
for var in $*; do
[ $var = $value ] && return 0
done
return 1
}
append(){
var=$1
shift
eval "$var=\"\$$var $*\""
}
die(){
echo "$0"
exit 1
}
die_unknown(){
echo "Unknown option \"$1\"."
echo "See $0 --help for available options."
exit 1
}
set_default(){
for opt; do
eval : \${$opt:=\$${opt}_default}
done
}
CMDLINE_SET='
arch
asm
pic_cc
slib_ccld_tmpl
dbin_ccld
'
#command line, set defaults
arch_default=$(uname -m | sed -e s/i.86/x86/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/)
asm_default=as
pic_cc_default='gcc -Wall -Wextra -Wno-missing-field-initializers -c -fpic -O0'
slib_ccld_tmpl_default='gcc -shared -nostdlib -Wl,-soname=$soname,--version-script=$export_map'
dbin_ccld_default="gcc -nostdlib"
ln_s_default='ln -sf'
set_default arch asm pic_cc slib_ccld_tmpl dbin_ccld ln_s
show_help(){
cat <<EOF
Usage: make [options] [operations]
Operations: [default is to build the shared libraries and binaries]:
clean clean build products
Options: [defaults in brackets after descriptions]
Help options:
--help print this message
Advanced options (experts only):
--arch=ARCH use ulinux target ARCH [$arch_default]
--asm=ASM use target arch assembler command line ASM [$asm_default]
--pic-cc=CC use target arch C compiler command line CC for PIC (Position Independant Code) object [$pic_cc_default]
--slib-ccld-tmpl=CCLD use linker command line template CCLD for target arch shared lib [$slib_ccld_tmpl_default]
--dbin-ccld=CCLD use linker command line CCLD for target arch dynamic binaries [$dbin_ccld_default]
EOF
exit 0
}
for opt do
optval="${opt#*=}"
case "$opt" in
clean) clean_do
;;
--help|-h) show_help
;;
*)
optname="${opt%%=*}"
optname="${optname#--}"
optname=$(echo "$optname" | sed 's/-/_/g')
if is_in $optname $CMDLINE_SET; then
eval $optname='$optval'
elif is_in $optname $CMDLINE_APPEND; then
append $optname "$optval"
else
die_unknown $opt
fi
;;
esac
done
#-------------------------------------------------------------------------------
#configure our ultra-thin linux user API abstraction layer
rm -f ulinux/arch
mkdir -p ulinux
$ln_s $src_path/ulinux/archs/$arch ulinux/arch
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#assemble src files
target_arch_asm_srcs="
$ulinux_target_arch_asm_srcs
"
for src_file in $target_arch_asm_srcs
do
obj=${src_file%.s}
obj=${obj}.o
echo ASM $src_file
$asm -o $(basename $obj) $src_file
done
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#C compile pic src files
pic_srcs="
$ulinux_c_srcs
$shared_srcs
$asm_lib_srcs
$asm_bin_srcs
$dis_lib_srcs
$dis_bin_srcs
"
for src_file in $pic_srcs
do
obj=${src_file%.c}
obj=${obj}.o
echo PIC_CC $src_file
$pic_cc -o $(basename $obj) -I./ -I$src_path $src_path/$src_file
pic_objs="$obj $pic_objs"
done
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#link the asm slib
for src_file in $asm_lib_srcs
do
obj=${src_file%.c}
obj=${obj}.o
asm_slib_objs="$obj $asm_slib_objs"
done
asm_slib_objs="$asm_slib_objs $asm_lib_shared_objs $asm_lib_ulinux_objs"
soname=$asm_slib_soname
export_map=$src_path/$asm_slib_export_map
slib_ccld=$(eval echo $slib_ccld_tmpl)
echo SLIB_CCLD $asm_slib_name
$slib_ccld -o $asm_slib_name $asm_slib_objs
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#link the asm binary
for src_file in $asm_bin_srcs
do
obj=${src_file%.c}
obj=${obj}.o
asm_dbin_objs="$obj $asm_dbin_objs"
done
asm_dbin_objs="$asm_dbin_objs $asm_bin_ulinux_objs"
echo DBIN_CCLD $asm_dbin_name
$dbin_ccld -o $asm_dbin_name $asm_slib_name $asm_dbin_objs
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#link the dis slib
for src_file in $dis_lib_srcs
do
obj=${src_file%.c}
obj=${obj}.o
dis_slib_objs="$obj $dis_slib_objs"
done
dis_slib_objs="$dis_slib_objs $dis_lib_shared_objs $dis_lib_ulinux_objs"
soname=$dis_slib_soname
export_map=$src_path/$dis_slib_export_map
slib_ccld=$(eval echo $slib_ccld_tmpl)
echo SLIB_CCLD $dis_slib_name
$slib_ccld -o $dis_slib_name $dis_slib_objs
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#link the dis binary
for src_file in $dis_bin_srcs
do
obj=${src_file%.c}
obj=${obj}.o
dis_dbin_objs="$obj $dis_dbin_objs"
done
dis_dbin_objs="$dis_dbin_objs $dis_bin_ulinux_objs"
echo DBIN_CCLD $dis_dbin_name
$dbin_ccld -o $dis_dbin_name $dis_slib_name $dis_dbin_objs
#-------------------------------------------------------------------------------