1 |
#! /usr/bin/env bash |
2 |
# |
3 |
# $Header: /u/gcmpack/MITgcm_contrib/jmc_script/mk_options_list,v 1.1 2012/08/10 21:29:06 jmc Exp $ |
4 |
# $Name: $ |
5 |
|
6 |
# generate list of CPP Options used in Fortran source files |
7 |
# arguments = list of Fortran source files |
8 |
|
9 |
clean=1 |
10 |
listOpt='TTT.listOpt' |
11 |
get_sd='options_get.sed' |
12 |
sortsd='options_sort.sed' |
13 |
tmpfil=TTT.$$ |
14 |
#echo $tmpfil |
15 |
|
16 |
if [ $# -eq 0 ] ; then |
17 |
echo "Usage: `basename $0` {list_of_files}" |
18 |
echo " generate list of CPP Options used in all the Fortran source files" |
19 |
echo " which are given in argument list {list_of_files}" |
20 |
echo " or : `basename $0` -clean" |
21 |
echo " just clean-up temp files" |
22 |
exit |
23 |
fi |
24 |
if test $1 = '-clean' ; then |
25 |
LIST=`ls -C $get_sd $sortsd $listOpt 2>/dev/null` |
26 |
#echo "LIST='$LIST'" |
27 |
if test "x$LIST" != x ; then |
28 |
echo " remove: $LIST" ; rm -f $LIST |
29 |
else |
30 |
echo " no file to remove" |
31 |
fi |
32 |
exit |
33 |
fi |
34 |
|
35 |
|
36 |
if [ $clean -ge 3 ] ; then rm -f $get_sd $sortsd ; fi |
37 |
if test -f $get_sd ; then ls -l $get_sd |
38 |
else |
39 |
cat <<EOF >> $get_sd |
40 |
/^#.*\\\\ *$/{N |
41 |
s/\\\\// |
42 |
p |
43 |
} |
44 |
EOF |
45 |
fi |
46 |
if test -f $sortsd ; then ls -l $sortsd |
47 |
else |
48 |
cat <<EOF >> $sortsd |
49 |
/^ccc /d |
50 |
s/\/\*.*\*\/// |
51 |
s/^# *ifndef// |
52 |
s/^# *ifdef// |
53 |
s/^# *if// |
54 |
s/^# *elif// |
55 |
s/||//g |
56 |
s/&&//g |
57 |
s/(//g |
58 |
s/)//g |
59 |
s/defined//g |
60 |
s/!//g |
61 |
EOF |
62 |
fi |
63 |
|
64 |
rm -f $listOpt |
65 |
for xx in $* |
66 |
do |
67 |
echo "ccc start file: $xx -----------------" >> $listOpt |
68 |
sed -n '/^ .*\\ *$/p' $xx | sed 's/\\ *$//' >> $listOpt |
69 |
echo "ccc above: between cont line | below: 1rst and last of cont line" >> $listOpt |
70 |
sed '/^ .*\\ *$/d' $xx > $tmpfil |
71 |
sed -n -f $get_sd $tmpfil >> $listOpt |
72 |
echo "ccc below: single line" >> $listOpt |
73 |
sed '/^# *e*l*if.*\\ *$/d' $tmpfil | sed -n '/^# *e*l*if/p' >> $listOpt |
74 |
echo "ccc end file: $xx -----------------" >> $listOpt |
75 |
rm -f $tmpfil |
76 |
done |
77 |
LIST=`sed -f $sortsd $listOpt` |
78 |
if [ $clean -ge 2 ] ; then |
79 |
rm -f $listOpt |
80 |
fi |
81 |
|
82 |
for xx in $LIST |
83 |
do |
84 |
echo $xx >> $tmpfil |
85 |
done |
86 |
|
87 |
echo "-- used CPP options:" |
88 |
cat $tmpfil | sort | uniq |
89 |
if [ $clean -ge 1 ] ; then rm -f $tmpfil ; fi |