/[MITgcm]/MITgcm_contrib/jmc_script/mk_mkfile
ViewVC logotype

Annotation of /MITgcm_contrib/jmc_script/mk_mkfile

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Mon Jan 23 23:40:01 2012 UTC (12 years, 2 months ago) by jmc
Branch: MAIN
CVS Tags: testing_tag01, HEAD
Changes since 1.1: +20 -15 lines
updated to work with SIZE.h.mpi

1 jmc 1.1 #! /usr/bin/env bash
2    
3 jmc 1.2 # $Header: $
4     # $Name: $
5    
6 jmc 1.1 mkfile='Makefile'
7 jmc 1.2 if [ $# -ge 1 ] ; then
8 jmc 1.1 if test $1 = '-h' ; then
9     echo "Usage: `basename $0` MAKEFILE (default: 'Makefile') ; [-h] print this"
10     exit 9
11     fi
12     mkfile=$1
13     fi
14 jmc 1.2
15 jmc 1.1 if test ! -f $mkfile ; then
16     echo "`basename $0` error: missing file '$mkfile'"
17     exit 8
18     fi
19    
20     cmdline=`grep '^# .*genmake2 ' $mkfile | sed 's/^# *//'`
21     echo " get Command-Line from file '$mkfile' :"
22     echo $cmdline
23    
24     printf "=== Parse Options ===\n"
25     CMDLINE=
26     MODS=
27     flg=0
28     MPI=0
29     prev=
30     dbq=0 ; sgq=0 ; keep=
31     # put newline between word in cmdline:
32     # CMDLINE=`echo $cmdline | awk '{ for(i=1;i<=NF;i++) print $i}'`
33     #echo "CMDLINE='$CMDLINE'"
34     for xx in $cmdline
35     do
36     arg=`echo $xx`
37     # glue multiple words argument (unbalanced starting & ending double quote)
38     n1=`echo $xx | grep -c '^"'`
39     n2=`echo $xx | grep -c '"$'`
40     if [ $n1 -eq 1 -a $n2 -eq 0 ] ; then
41     dbq=1; keep=$xx
42     continue
43     fi
44     if [ $n1 -eq 0 -a $dbq -eq 1 ] ; then
45 jmc 1.2 if [ $n2 -eq 1 ] ; then
46     n1=$dbq ; dbq=0
47 jmc 1.1 xx="$keep $xx"
48 jmc 1.2 else
49 jmc 1.1 keep="$keep $xx"
50     continue
51     fi
52     fi
53     # remove starting & ending double quote
54     if [ $n1 -eq 1 -a $n2 -eq 1 ] ; then
55     arg=`echo $xx | sed 's/^"//' | sed 's/"$//'`
56     fi
57     # glue multiple words argument (unbalanced starting & ending single quote)
58     n1=`echo $xx | grep -c "^'"`
59     n2=`echo $xx | grep -c "'$"`
60     if [ $n1 -eq 1 -a $n2 -eq 0 ] ; then
61     sgq=1; keep=$xx
62     continue
63     fi
64     if [ $n1 -eq 0 -a $sgq -eq 1 ] ; then
65 jmc 1.2 if [ $n2 -eq 1 ] ; then
66     n1=$sgq ; sgq=0
67 jmc 1.1 xx="$keep $xx"
68 jmc 1.2 else
69 jmc 1.1 keep="$keep $xx"
70     continue
71     fi
72     fi
73     # remove starting & ending single quote
74     if [ $n1 -eq 1 -a $n2 -eq 1 ] ; then
75     arg=`echo $xx | sed "s/^'//" | sed "s/'$//"`
76     fi
77     # process "arg"
78     opt=`expr "x$arg" : 'x[^=]*=\(.*\)'`
79     # echo "xx='$xx' ; arg='$arg' ; opt='$opt'"
80     # sav "arg" to CMDLINE <- not actually used
81     #eqs=`echo $arg | grep -c '='`
82     #if [ $eqs -gt 0 ] ; then
83     # pfx=`echo $arg | sed 's/=.*$/=/'`
84     # nw=`echo $opt | wc -w`
85     # if test $nw = '1' ; then
86     # CMDLINE="$CMDLINE $pfx$opt"
87     # else
88     # CMDLINE="$CMDLINE $pfx'$opt'"
89     # fi
90     #else
91     nw=`echo $arg | wc -w`
92     if test $nw = '1' ; then
93     CMDLINE="$CMDLINE $arg"
94     else
95     CMDLINE="$CMDLINE '$arg'"
96     fi
97     #fi
98     if test -n "$prev" -a $flg = '1' ; then
99     eval "$prev=\$arg"
100     prev=
101     continue
102     fi
103     case $arg in
104 jmc 1.2 -mpi | --mpi | -mpi=* | --mpi=* )
105 jmc 1.1 MPI=`expr $MPI + 1` ;;
106 jmc 1.2 -mods | --mods | -mo | --mo )
107 jmc 1.1 prev=MODS
108     flg=`expr $flg + 1` ;;
109 jmc 1.2 -mods=* | --mods=* | -mo=* | --mo=* )
110 jmc 1.1 MODS=$opt
111     flg=`expr $flg + 1` ;;
112     *) ;;
113     esac
114     done
115    
116     printf "=== \n"
117     echo " Set MPI='$MPI' ; MODS='$MODS'"
118     #echo "flg='$flg'"
119    
120     if [ $flg -lt 1 ] ; then
121     echo "`basename $0` error: no '-mods' found"
122     exit 4
123     fi
124     if [ $flg -gt 1 ] ; then
125     echo "`basename $0` error: found multiple '-mods' ($flg)"
126     exit 3
127     fi
128     if [ $MPI -gt 1 ] ; then
129     echo "`basename $0` error: found multiple '-mpi' ($MPI)"
130     exit 2
131     fi
132    
133     #---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
134    
135     printf "=== Link / Unlink *_mpi files from 'MODS' dirs ===\n"
136     printf " MODS dir: "
137     MPI_LNKF=
138     for d in $MODS ; do
139     if test ! -d $d ; then
140     echo
141     echo "Error: MODS directory \"$d\" not found!"
142     exit 1
143     else
144     printf "$d "
145     #SOURCEDIRS="$SOURCEDIRS $d"
146     #INCLUDEDIRS="$INCLUDEDIRS $d"
147     #-------------------------------------------------------
148     # Put special links so that MPI specific files are used
149     MPI_FILES=`(cd $d ; find . -name "*_mpi" -print)`
150     for i in $MPI_FILES ; do
151     ii=`echo $i | sed 's:^\./::'`
152     name=`echo $ii | sed 's:_mpi::' `
153     if test $MPI = 0 ; then
154     # NO: We undo an _mpi symbolically linked file
155     if test -L $name ; then
156     cmp $name "$d/$ii" > /dev/null 2>&1
157     RETVAL=$?
158     if test "x$RETVAL" = x0 ; then
159     printf "Un-linking $name ; "
160     rm -f $name
161     fi
162     fi
163     else
164     # YES: We symbolically link this file (with conditions if already there)
165 jmc 1.2 src="$d/$ii"
166     if test $name = "SIZE.h" -a -f SIZE.h.mpi ; then src="SIZE.h.mpi" ; fi
167 jmc 1.1 if test -L $name ; then
168 jmc 1.2 cmp $src $name > /dev/null 2>&1
169 jmc 1.1 RETVAL=$?
170 jmc 1.2 yy=0 ;
171 jmc 1.1 for xx in $MPI_LNKF ; do if test $xx = $name ; then yy=1 ; fi ; done
172     if test "x$RETVAL" != x0 -a $yy = 0 ; then
173     # remove sym-link if different and has not just been linked
174     printf "Un-link + "
175     rm -f $name
176     fi
177     if test "x$RETVAL" = x0 ; then
178     # if identical, keep sym-link and keep record of it
179     MPI_LNKF="$MPI_LNKF $name"
180     fi
181     fi
182     if ! test -f $name ; then
183     # make sym-link and keep record of it
184 jmc 1.2 printf "Linking $src to $name ; "
185     ln -sf $src $name
186 jmc 1.1 MPI_LNKF="$MPI_LNKF $name"
187     fi
188     fi
189     done
190     #-------------------------------------------------------
191     fi
192     done
193     echo
194     echo "MPI_LNKF='$MPI_LNKF'"
195    
196     #---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
197     printf "=== Generate new Makefile ===\n"
198     #echo $CMDLINE
199     #eval $CMDLINE
200     echo $cmdline
201     eval $cmdline

  ViewVC Help
Powered by ViewVC 1.1.22