-
Notifications
You must be signed in to change notification settings - Fork 0
/
cshift.in
506 lines (405 loc) · 13.1 KB
/
cshift.in
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
#! /bin/csh -f
# cshift --
#
# Copyright (c)1996, 1997, 1998 The Regents of the University of
# California (Regents). All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for educational, research, and not-for-profit purposes,
# without fee and without a signed licensing agreement, is hereby
# granted, provided that the above copyright notice, this paragraph and
# the following two paragraphs appear in all copies, modifications, and
# distributions.
#
# Contact The Office of Technology Licensing, UC Berkeley, 2150 Shattuck
# Avenue, Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, for
# commercial licensing opportunities.
#
# IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
# SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
# ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION
# TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.
# Shell script to be used as a driver for the compilation process of a
# SHIFT program (from source to executable.)
# @configure_input@
#------------------------------------------------------------------------------
# Setup
set cshift_debugging = 0
set prefix = @prefix@
set exec_prefix = @exec_prefix@
set bindir = @bindir@
set libdir = @libdir@
set includedir = @includedir@
set shic_prg = @bindir@/shic
set CC = "@CC@"
if (! $?CPP ) then
set cpreproc = "@CPP@"
else
set cpreproc = "$CPP"
endif
set x_includes = @x_includes@
set x_libraries = @x_libraries@
set TCLLIBPATH = @TCLLIBPATH@
set TCLINCLUDEPATH = @TCLINCLUDEPATH@
set TKLIBPATH = @TKLIBPATH@
set TKINCLUDEPATH = @TKINCLUDEPATH@
set BLTLIBPATH = @BLTLIBPATH@
set BLTINCLUDEPATH = @BLTINCLUDEPATH@
set GCLIBPATH = @GCLIBPATH@
set GCINCLUDEPATH = @GCINCLUDEPATH@
set SHIFT_GUI_SETUP_P = @SETUP_SHIFT_GUI_P@
set BLT_CHECKED_P = @CHECK_BLT_INSTALLED_P@
set ENABLE_GC_USE_P = @ENABLE_GC_SUPPORT_P@
set LIBS = ( @LIBS@ )
set configuration = @CONFIGURATION_TARGET@
# Setting up monitoring.
# These variables contain templates for the call to the profiler and
# the memory scanner (we kind of assume 'quantify' and 'purify').
set profiler = ""
set memory_scanner = ""
# Setting -I and -L options
# Dealing with GUI
if ( $configuration == ttyonly ) then
set I_options = ( -I$includedir )
set L_options = ( -L$libdir )
else
set I_options = ( -I$includedir \
-I$BLTINCLUDEPATH \
-I$TKINCLUDEPATH \
-I$TCLINCLUDEPATH \
-I$x_includes \
)
set L_options = ( -L$libdir \
-L$BLTLIBPATH \
-L$TKLIBPATH \
-L$TCLLIBPATH \
-L$x_libraries \
)
endif
# Dealing with GC
if ($ENABLE_GC_USE_P == yes) then
set I_options = ( ${I_options[1]} -I$GCINCLUDEPATH ${I_options[2-]} )
set L_options = ( ${L_options[1]} -L$GCLIBPATH ${L_options[2-]} )
endif
set CPP_options = ()
# The cc linker complains if no -w option is present
if ( $CC == "cc" ) then
set CC_options = (-w)
else
set CC_options = ()
endif
set extra_libraries = ()
set shift_only_p = 0
set quantify_options = ()
set purify_options = ()
if ($?SHIFT_LIBS) then
set shift_libraries = ( $SHIFT_LIBS )
else
set shift_libraries = ( $libdir/shift.a $libdir/libDebug.a )
if ( $configuration == graphic.env ) then
set shift_libraries = ( $shift_libraries $libdir/libSocket.a )
endif
if ( $ENABLE_GC_USE_P == yes ) then
set shift_libraries = ( $GCLIBPATH/gc.a $shift_libraries )
endif
endif
set foreign_files = ()
#------------------------------------------------------------------------------
# Command line option processing
# The list is traversed many times but it should not be too time consuming.
if ( $#argv == 0 ) then
goto print_help
endif
# Print help message and exit if '-h' or '--help' switches have been given,
# or print configure message if '--config' switch has been given.
foreach cmd_opt ( $argv )
if ( "$cmd_opt" == '-h' || "$cmd_opt" == '--help') goto print_help
if ( "$cmd_opt" == '--config' ) goto print_config
if ( "$cmd_opt" == '--show-cshift-env' ) set cshift_debugging = 1
if ( "$cmd_opt" == '-v' || "$cmd_opt" == '--version' ) then
shic -v
exit 0
endif
end
set HS_file = $argv[1] ; shift argv
if ( ! -r $HS_file ) then
echo cshift: no SHIFT file named $HS_file found.
echo ''
exit 1
endif
set SIM_file = ${HS_file:r}.sim
# Process other options
set option_used_p = no
set cmd_options = ( $argv )
foreach cmd_opt ( $argv )
if ( $option_used_p == yes ) then
set option_used_p = no
continue
endif
switch ( "$cmd_opt" )
case -I*:
set I_options = ( $I_options "$cmd_opt" )
breaksw
case -L*:
set L_options = ( $L_options "$cmd_opt" )
breaksw
case -l*:
set extra_libraries = ( $extra_libraries "$cmd_opt" )
case -CPP=*:
set cpreproc = "`echo ${cmd_opt} | sed s/-CPP=//`"
breaksw
case -CC=*:
set CC = "`echo ${cmd_opt} | sed s/-CC=//`"
breaksw
case -SC=*:
set shic_prg = "`echo ${cmd_opt} | sed s/-SC=//`"
breaksw
case -SL=*:
case --shift-libraries=*:
set sed_cmd = "sed -e s/-SL=// -e s/--shift-libraries// -e s/:/\ /"
set shift_libraries = ( `echo ${cmd_opt} | ${sed_cmd}` )
breaksw
case -ff:
case --foreign-files:
shift cmd_options
set foreign_files = ( $cmd_options[*] )
break
breaksw
case -so:
case --shift-only:
# This shifting might be an error.
shift cmd_options
set shift_only_p = 1
breaksw
case -o:
shift cmd_options
set SIM_file = $cmd_options[1]
set option_used_p = yes
breaksw
case --profile=*:
set profiler = "`echo ${cmd_opt} | sed s/^--profile=//`"
breaksw
case --memory-scanner=*
set memory_scanner = "`echo ${cmd_opt} | sed s/^--memory-scanner=//`"
breaksw
# Recognized CPP command line switches
case -B:
case -C:
case -p:
case -P:
case -R:
case -T:
case -undef:
case -D*:
case -U*:
case -Y*:
set CPP_options = ( $CPP_options "$cmd_opt" )
breaksw
# Unrecognized CPP command line switches
case -H:
case -M:
echo "cshift: unusable CPP option: $cmd_opt"
exit 1
breaksw
# Recognized 'quantify' and 'purify' command line switches
case -cache-dir=*:
case -always-use-cache-dir*:
case -linker=*:
case '-g++'*:
set purify_options = ( $purify_options "${cmd_opt}" )
set quantify_options = ( $quantify_options "${cmd_opt}" )
breaksw
case -ignore-runtime-environment*:
case -use-machine=*:
case -collection-granularity=*:
case -collector=*:
case -print-home-dir:
set quantify_options = ( $quantify_options "${cmd_opt}" )
breaksw
# All the remaining options are assumed to be C options (this is
# really to accommodate the godzillion options of 'gcc'.
# Unrecognized command line switches
default:
# echo "cshift: unrecognized command line option $cmd_opt"
# echo ''
# exit 1
# breaksw
set CC_options = ( $CC_options "$cmd_opt" )
breaksw
endsw
shift cmd_options
end
# Check which profiler and memory scanner we are using
if ($profiler != quantify && $#quantify_options != 0) then
echo 'cshift: warning: discarding the profiler options:'
echo " $quantify_options"
set quantify_options = ()
endif
if ($memory_scanner != purify && $#purify_options != 0) then
echo 'cshift: warning: discarding the memory scanner options:'
echo " $purify_options"
set purify_options = ()
endif
# Make sure the '-B' option is within the CPP option list.
# This might be a bogus setup with some C preprocessors, but we do not
# have a better idea.
# set CPP_options = (-B $CPP_options)
set CPP_options = ()
if ( $cshift_debugging ) then
echo IOPT = $I_options
echo LOPT = $L_options
echo FF = $foreign_files
echo CC = $CC
echo CPP = $cpreproc
echo CPP_options = $CPP_options
echo CC_options = $CC_options
echo shift_libraries = $shift_libraries
echo extra_libraries = $extra_libraries
echo LIBS = $LIBS
endif
#------------------------------------------------------------------------------
# Preprocessing and Compiling
# In order not to change the main of the 'shic' program we do this
# trick with environment variables
set c_compiler_error = 0
set c_compiler_status = 0
set shic_error = 0
set shic_ret_status = 0
# Check for tester program
set tester_prg = ""
set tester_opts = ()
if ("$memory_scanner" != "" && "$profiler" != "") then
echo 'cshift: error: both options --profile and --memory-scanner'
echo ' have been passed on the command line.'
echo ''
exit 1
else if ("$memory_scanner" != "") then
set tester_prg = $memory_scanner
set tester_opts = $purify_options
else if ("$profiler" != "") then
set tester_prg = $profiler
set tester_opts = $quantify_options
endif
# $CPP $CPP_options $I_options $HS_file ${HS_file:r}.hsp
# setenv CPP "$cpreproc $CPP_options $I_options"
echo "cshift: compiling to C..."
# $shic_prg ${HS_file:r}.hsp
env CPP="$cpreproc $CPP_options $I_options" ${shic_prg} "${HS_file}"
if ($status != 0) then
set shic_ret_status = $status
set shic_error = 1
else if (! $shift_only_p ) then
if ("${tester_prg}" != "") then
echo -n "cshift: compiling C intermediate code (instrumenting with "
echo "$tester_prg)..."
env CPP="$cpreproc" \
$tester_prg $tester_opts $CC -o $SIM_file \
$CC_options \
$CPP_options \
$I_options \
$L_options \
${HS_file:r}.c \
$foreign_files \
$shift_libraries \
$extra_libraries \
$LIBS
if ($status != 0) then
set c_compiler_status = $status
set c_compiler_error = 1
endif
else
echo "cshift: compiling C intermediate code..."
env CPP="$cpreproc" \
$CC -o $SIM_file \
$CC_options \
$CPP_options \
$I_options \
$L_options \
${HS_file:r}.c \
$foreign_files \
$shift_libraries \
$extra_libraries \
$LIBS
if ($status != 0) then
set c_compiler_status = $status
set c_compiler_error = 1
endif
endif
endif
#------------------------------------------------------------------------------
# Wrapup
if ($shic_error) then
echo "cshift: error: the SHIFT compiler generated an error."
echo " The return status was [$shic_ret_status]."
exit 1
else if ($c_compiler_error) then
echo "cshift: error: the C compiler generated an error."
echo " The return status was [$c_compiler_status]."
exit 1
else
echo "cshift: done compiling the SHIFT file $HS_file."
echo " the resulting executable simulation was left"
echo " in file $SIM_file."
echo ''
exit 0
endif
#------------------------------------------------------------------------------
# Special code chunks (this is a simple 'csh' script: no "functions" are
# available, so 'gotos' are used.)
print_help:
set noglob
echo 'Usage: cshift <filename>.hs [options] [[-ff|--foreign-files] <files>'
echo ' <options> are:'
echo ' [-h|--help] prints this message'
echo ' [-v|--version] prints the version number'
echo ' [--config] prints the current configuration of script'
echo ' [-so|--shift-only] do not run the C compiler'
echo ' -I<include dir> (repeatable)'
echo ' -L<library dir> (repeatable)'
echo ' -l<library name> (repeatable)'
echo ' -CPP=<C preprocessor command>'
echo ' -CC=<C compiler command>'
echo ' -SC=<SHIFT compiler command>'
echo ' --profile=<profiler command> (e.g. "quantify")'
echo ' --memory-scanner=<memory scanner command> (e.g. "purify")'
echo ' "quantify" or "purify" options'
echo ' C preprocessor and C compiler options'
echo ''
unset noglob
exit 0
print_config:
set noglob
echo 'cshift current configuration:'
echo " command used: "`which $0`
if ( $?CC ) then
echo " C compiler command: $CC"
endif
if ( $?CPP ) then
echo " C preprocessor command: $CPP"
endif
echo " CPP_options: $CPP_options"
echo " I_options: $I_options"
echo " graphic environment enabled: $SHIFT_GUI_SETUP_P"
if ( $SHIFT_GUI_SETUP_P == yes ) then
echo " Tcl Library Location: $TCLLIBPATH"
echo " Tcl Include Dir Location: $TCLINCLUDEPATH"
echo " Tk Library Location: $TKLIBPATH"
echo " Tk Include Dir Location: $TKINCLUDEPATH"
if ( $BLT_CHECKED_P == yes ) then
# This is disgusting!
echo " BLT Library Location: $BLTLIBPATH"
echo " BLT Include Dir Location: $BLTINCLUDEPATH"
endif
endif
echo ''
unset noglob
exit 0
# end of file -- cshift --
# @configure_input@