-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh.make.dev
766 lines (666 loc) · 17.8 KB
/
sh.make.dev
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
#!/bin/bash
#
########################################################################
#
# How to use this script?
#
# Simply run this command:
#
# ./sh.make.dev
#
# then you'll know what to do. Make sure you did in advance
# chmod +x sh.make
# so that the script can run in such manner.
#
########################################################################
SRC="src"
TST="test"
DAT="data"
lib="libNRinC.a"
prefix=${HOME}/apps/shared
#
#
#
aDIR=( $SRC $TST main )
nDIR=${#aDIR[@]}
aSRC=( $SRC )
nSRC=${#aSRC[@]}
aLIB=( $lib )
#
#
ODIR=${prefix}
build=${ODIR}/build
OTMP=${build}/tmp
OBIN=${ODIR}/bin
OLIB=${ODIR}/lib
OINC=${ODIR}/include
OOBJ=${ODIR}/obj
IINC=`pwd`/$SRC
PDAT=`pwd`/$DAT
libna=$lib
mylib=${OLIB}/${libna}
COMP=""
DEPS=""
OPTI=""
FLAG=""
# arFLAG="r"
arFLAG="rcs"
Delay='timeout'
Dtime='1s'
#
# GNU COMPILER:
#
_use_gcc ()
{
COMP="gcc"
# DEPS="-Wall -ansi"
# DEPS="-Wall -std=c90"
DEPS="-ansi"
OPTI="-O3"
FLAG="$OPTI $DEPS -I ./ -I $IINC "
}
#
# INTEL COMPILER:
#
_use_icc ()
{
# COMP="icc"
COMP="icc_run icc"
# DEPS="-ansi"
DEPS="-diag-disable=10441 -ansi"
OPTI="-O3"
FLAG="$OPTI $DEPS -I./ -I$IINC "
}
#
# icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
#
#
# CHOOSE YOUR COMPILER:
# _use_gfortran
# _use_ifort
# _use_icc
_use_gcc
echo "COMP = $COMP"
echo "DEPS = $DEPS"
echo "OPTI = $OPTI"
## echo "FLAG = $FLAG"
echo "arFLAG = $arFLAG"
mkdir -p $OLIB $OINC $OBIN $OOBJ $build
#######################################################################
#
# subroutines:
#
#######################################################################
_print_usage ()
{
cat << XXX
COMMAND ARGUMENT ROUTINE
$0 lib _make_lib
$0 test _make_test
$0 clean _make_clean
$0 cleanmd5 _clean_md5
$0 distclean _make_distclean
$0 all _make_clean && _make_lib && _make_test
$0 showme _make_showme
$0 test xr*.c _make_main_glob test xr*.c
$0 compile x.c -o x.exe _make_compile x.c -o x.exe
Examples:
$0 all to run everything, i.e., ./sh_make lib and test.
$0 distclean to clean all the outputs.
$0 clean to clean only .o and .exe files
$0 cleanmd5 to clean md5 files so that we can recompile all
$0 lib to complie source and make the lib: ${libna}
$0 test to compile, link, and run all the tests.
$0 showme to show flags to compile programs and link to the lib.
$0 test xr*.c to compile, link, and run all test/xr*.c files.
$0 test xgaussj.c to compile, link, and run only test/xgaussj.c
$0 compile test/xgaussj.c -o xgaussj.exe
to compile test/xgaussj.c, and produce xgaussj.exe
At the first time, we can run the following commands stepwise:
$0 clean
$0 lib
$0 test
XXX
}
#
_ischanged()
{
res=0
if [ $# -ge 1 ]
then
file=$1
fingerprintfile=/tmp/${1}.md5savefile
if [ ! -f $file ]
then
echo "Warning: $file does not exist!"
res=0
else
filemd5=`md5sum $file | cut -d " " -f1`
#
# check md5 and show error when we meet empty file
#
if [ -z $filemd5 ]
then
echo "Warning: File $filemd5 is empty"
res=0
echo $res
return
fi
if [ -f $fingerprintfile ]
then
# get the saved md5
savedmd5=`cat $fingerprintfile`
# check again if its empty
if [ -z $savedmd5 ]
then
echo "Warning: File $savedmd5The is empty"
res=0
echo $res
return
fi
# compare the saved md5 with the one we have now
if [ "$savedmd5" = "$filemd5" ]
then
# echo "Ok. File $file has NOT been changed"
res=0
else
# echo "Ok. File $file has been changed"
res=1
fi
else #if [ ! -f $fingerprintfile ]; then
res=1
fi
echo $filemd5 > $fingerprintfile
fi
fi
#
echo $res
return
}
#
_clean_md5savefile()
{
if [ $# -ge 1 ]
then
file=$1
fingerprintfile=/tmp/${1}.md5savefile
if [ -f $file ]
then
if [ -f $fingerprintfile ]
then
/bin/rm $fingerprintfile
echo "OK. $fingerprintfile removed."
else
echo "OK. $fingerprintfile not found."
fi
else
echo "Warning: $file unknown. Skip!"
fi
fi
}
#
_clean_md5_prim ()
{
for f in *.c
do
_clean_md5savefile $f
done
}
_clean_md5 ()
{
here=`pwd`
for (( i=0; i<${nDIR}; i++ ))
do
d=${aDIR[$i]}
if [ -d $d ]
then
cd $d
_clean_md5_prim
cd $here
fi
done
unset here
}
#
_make_test ()
{
echo "########################################################################"
echo "Go to $TST"
here=`pwd`
aux="$OPTI $DEPS"
cd $TST
ln -fs ../${DAT}/* .
for f in `ls *.c`
do
echo '----------------------------------------------------------'
h=`basename $f .c`
g=${h}.exe
k=${h}.inp
set -x
${COMP} ${OPTI} ${DEPS} -I${OINC} $f $mylib -lm -o $g
if [ -f $k ]
then
./$g < $k
else
./$g
fi
set +x
done
# rm *.dat
cd $here
unset here
#
echo "Done. Leave $TST"
echo
echo "Note: Tests which need input from keyboard will be skiped"
echo " Run them manually later."
echo
echo "########################################################################"
}
#
_make_main_glob ()
{
dir=$1 ; shift ;
pat=$1 ; shift ;
echo "########################################################################"
echo "Go to $dir"
here=`pwd`
aux="$OPTI $DEPS"
cd $dir
ln -fs ${PDAT}/* .
for f in `ls $pat `
do
echo '----------------------------------------------------------'
h=`basename $f .c`
g=${h}.exe
k=${h}.inp
set -x
${COMP} ${OPTI} ${DEPS} -I${OINC} $f $mylib -lm -o $g
if [ -f $k ]
then
./$g < $k
else
./$g
fi
set +x
done
cd $here
unset here
#
echo "Done. Leave $dir"
echo "########################################################################"
}
#
_make_compile ()
{
aux="$OPTI $DEPS"
cmd="${COMP} ${OPTI} ${DEPS} -I${OINC} $@ $mylib -lm "
echo
echo $cmd
eval $cmd
}
_make_showme ()
{
cat << XXX
USAGE:
${COMP} ${OPTI} ${DEPS} -I${OINC} main.c $mylib -lm
EXAMPLES:
${COMP} ${OPTI} ${DEPS} -I${OINC} test/xairy.c $mylib -lm
./a.out
XXX
}
_make_clean_prim ()
{
d=$1; shift;
if [ -d $d ]
then
echo "Go to ${d}/"
cd $d
echo " /bin/rm -f *.o *.mod *.exe *.a *.out *.dat"
/bin/rm -f *.o *.mod *.exe *.a *.out *.dat
echo "Left ${d}/"
fi
}
#
_make_clean ()
{
here=`pwd`
#
for (( i=0; i<${nDIR}; i++ ))
do
d=${aDIR[$i]}
_make_clean_prim $d
cd $here
done
#
unset here
}
#
_make_distclean ()
{
_clean_md5
_make_clean
echo " /bin/rm -rf ${OLIB} ${OINC} ${OOBJ} ${build}"
/bin/rm -rf ${OLIB} ${OINC} ${OOBJ} ${build}
}
#
_make_src ()
{
for (( i=0; i<${nSRC}; i++ ))
do
d=${aSRC[$i]}
mkdir -p ${OOBJ}/${d}
_make_src_prim $d ${OOBJ}/${d}
done
}
_make_src_prim ()
{
src=$1; shift;
out=$1; shift;
#
if [ -d "$src" ]
then
echo "Directory $src exists."
else
echo "Error: Directory $src does not exist!"
exit 1
fi
#
if [ -d "$out" ]
then
echo "Directory $out exists."
else
echo "Warning: Directory $out does not exist. Create it!"
fi
#
here=`pwd`
#
echo "########################################################################"
echo "Compiling *.c inside $src --> $out ..."
#
# Compiling Fortran codes
#
cd $src
echo "Entering $src ..."
#
# source codes:
for f in *.c
do
if [ -f $f ]
then
g=`basename $f`
h=`echo $g | sed 's/\.c//g'`
if [[ $( _ischanged $g ) -eq 1 ]]
then
echo "${COMP} ${FLAG} -c $f -o ${out}/${h}.o"
time ${COMP} ${FLAG} -c $f -o ${out}/${h}.o
# else
# echo "${f} is not changed. Skipped."
fi
fi
done
#
# include:
for f in ${IINC}/*.h
do
if [ -f $f ]
then
cp -f $f ${OINC}/
fi
done
#
cd $here
echo "Leaving $src."
#
unset f here
echo "Compiling Done."
echo "########################################################################"
}
#
_make_lib ()
{
echo "########################################################################"
echo "Making ${mylib}"
#
_make_src
#
set -x
#
List=''
#
for (( i=0; i<${nSRC}; i++ ))
do
d=${aSRC[$i]}
List=" $List ${OOBJ}/${d}/*.o "
done
/bin/rm -rf ${mylib}
ar $arFLAG ${mylib} $List
#
set +x
#
echo "Done"
echo "Check *.a in ${OLIB}"
echo "Check *.h in ${OINC}"
echo "########################################################################"
}
#
#######################################################################
#
# main:
#
#######################################################################
# set -x
if [ $# -gt 0 ]
then
opt=$1
if [ "$opt" = "clean" ]
then
_make_clean
elif [ "$opt" = "distclean" ]
then
_make_distclean
elif [ "$opt" = "test" ]
then
if [ $# -eq 2 ]
then
_make_main_glob $1 $2
else
_make_test
fi
elif [ "$opt" = "compile" ]
then
shift
_make_compile $@
elif [ "$opt" = "lib" ]
then
_make_lib
elif [ "$opt" = "all" ]
then
_clean_md5
_make_lib
_make_test
elif [ "$opt" = "cleanmd5" ]
then
_clean_md5
elif [ "$opt" = "showme" ]
then
_make_showme
else
_print_usage
exit 1 ;
fi
else
_print_usage
exit 1 ;
fi
# set +x
########################################################################
#
# GCC: Some Dialect Options
#
# https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
#
# -ansi
#
# In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.
#
# This turns off certain features of GCC that are incompatible with ISO C90
# (when compiling C code), or of standard C++ (when compiling C++ code), such as the asm
# and typeof keywords, and predefined macros such as unix and vax that identify the type
# of system you are using. It also enables the undesirable and rarely used ISO trigraph
# feature. For the C compiler, it disables recognition of C++ style ‘//’ comments as well as
# the inline keyword.
#
# The alternate keywords __asm__, __extension__, __inline__ and __typeof__ continue to
# work despite -ansi. You would not want to use them in an ISO C program, of course, but it is
# useful to put them in header files that might be included in compilations done with -ansi.
# Alternate predefined macros such as __unix__ and __vax__ are also available, with or
# without -ansi.
#
# The -ansi option does not cause non-ISO programs to be rejected gratuitously. For that,
# -Wpedantic is required in addition to -ansi. See Warning Options.
#
# The macro __STRICT_ANSI__ is predefined when the -ansi option is used. Some header files
# may notice this macro and refrain from declaring certain functions or defining certain macros
# that the ISO standard doesn’t call for; this is to avoid interfering with any programs that
# might use these names for other things.
#
# Functions that are normally built in but do not have semantics defined by ISO C (such as
# alloca and ffs) are not built-in functions when -ansi is used. See Other built-in functions
# provided by GCC, for details of the functions affected.
#
#
# -std=
#
# Determine the language standard. See Language Standards Supported by GCC, for details of
# these standard versions. This option is currently only supported when compiling C or C++.
#
# The compiler can accept several base standards, such as ‘c90’ or ‘c++98’, and GNU dialects
# of those standards, such as ‘gnu90’ or ‘gnu++98’. When a base standard is specified, the
# compiler accepts all programs following that standard plus those using GNU extensions that
# do not contradict it. For example, -std=c90 turns off certain features of GCC that are
# incompatible with ISO C90, such as the asm and typeof keywords, but not other GNU extensions
# that do not have a meaning in ISO C90, such as omitting the middle term of a ?: expression.
# On the other hand, when a GNU dialect of a standard is specified, all features supported by
# the compiler are enabled, even when those features change the meaning of the base standard.
# As a result, some strict-conforming programs may be rejected. The particular standard is
# used by -Wpedantic to identify which features are GNU extensions given that version of the
# standard. For example -std=gnu90 -Wpedantic warns about C++ style ‘//’ comments, while
# -std=gnu99 -Wpedantic does not.
#
# A value for this option must be provided; possible values are
#
# ‘c90’
# ‘c89’
# ‘iso9899:1990’
#
# Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are
# disabled). Same as -ansi for C code.
# ‘iso9899:199409’
#
# ISO C90 as modified in amendment 1.
# ‘c99’
# ‘c9x’
# ‘iso9899:1999’
# ‘iso9899:199x’
#
# ISO C99. This standard is substantially completely supported, modulo bugs and
# floating-point issues (mainly but not entirely relating to optional C99 features from
# Annexes F and G). See https://gcc.gnu.org/c99status.html for more information. The names
# ‘c9x’ and ‘iso9899:199x’ are deprecated.
# ‘c11’
# ‘c1x’
# ‘iso9899:2011’
#
# ISO C11, the 2011 revision of the ISO C standard. This standard is substantially
# completely supported, modulo bugs, floating-point issues (mainly but not entirely relating
# to optional C11 features from Annexes F and G) and the optional Annexes K (Bounds-checking
# interfaces) and L (Analyzability). The name ‘c1x’ is deprecated.
# ‘c17’
# ‘c18’
# ‘iso9899:2017’
# ‘iso9899:2018’
#
# ISO C17, the 2017 revision of the ISO C standard (published in 2018). This standard
# is same as C11 except for corrections of defects (all of which are also applied with -std=c11)
# and a new value of __STDC_VERSION__, and so is supported to the same extent as C11.
# ‘c2x’
#
# The next version of the ISO C standard, still under development. The support for
# this version is experimental and incomplete.
# ‘gnu90’
# ‘gnu89’
#
# GNU dialect of ISO C90 (including some C99 features).
# ‘gnu99’
# ‘gnu9x’
#
# GNU dialect of ISO C99. The name ‘gnu9x’ is deprecated.
# ‘gnu11’
# ‘gnu1x’
#
# GNU dialect of ISO C11. The name ‘gnu1x’ is deprecated.
# ‘gnu17’
# ‘gnu18’
#
# GNU dialect of ISO C17. This is the default for C code.
# ‘gnu2x’
#
# The next version of the ISO C standard, still under development, plus GNU
# extensions. The support for this version is experimental and incomplete.
# ‘c++98’
# ‘c++03’
#
# The 1998 ISO C++ standard plus the 2003 technical corrigendum and some additional
# defect reports. Same as -ansi for C++ code.
# ‘gnu++98’
# ‘gnu++03’
#
# GNU dialect of -std=c++98.
# ‘c++11’
# ‘c++0x’
#
# The 2011 ISO C++ standard plus amendments. The name ‘c++0x’ is deprecated.
# ‘gnu++11’
# ‘gnu++0x’
#
# GNU dialect of -std=c++11. The name ‘gnu++0x’ is deprecated.
# ‘c++14’
# ‘c++1y’
#
# The 2014 ISO C++ standard plus amendments. The name ‘c++1y’ is deprecated.
# ‘gnu++14’
# ‘gnu++1y’
#
# GNU dialect of -std=c++14. The name ‘gnu++1y’ is deprecated.
# ‘c++17’
# ‘c++1z’
#
# The 2017 ISO C++ standard plus amendments. The name ‘c++1z’ is deprecated.
# ‘gnu++17’
# ‘gnu++1z’
#
# GNU dialect of -std=c++17. This is the default for C++ code. The name ‘gnu++1z’ is deprecated.
# ‘c++20’
# ‘c++2a’
#
# The 2020 ISO C++ standard plus amendments. Support is experimental, and could change
# in incompatible ways in future releases. The name ‘c++2a’ is deprecated.
# ‘gnu++20’
# ‘gnu++2a’
#
# GNU dialect of -std=c++20. Support is experimental, and could change in incompatible
# ways in future releases. The name ‘gnu++2a’ is deprecated.
# ‘c++2b’
# ‘c++23’
#
# The next revision of the ISO C++ standard, planned for 2023. Support is highly
# experimental, and will almost certainly change in incompatible ways in future releases.
# ‘gnu++2b’
# ‘gnu++23’
#
# GNU dialect of -std=c++2b. Support is highly experimental, and will almost
# certainly change in incompatible ways in future releases.
#
#
#