3 |
# $Header$ |
# $Header$ |
4 |
# |
# |
5 |
# Makefile generator for MITgcm UV codes |
# Makefile generator for MITgcm UV codes |
6 |
# created by cnh 03/98 |
# created by cnh 03/98 |
7 |
# adapted by aja 06/98 |
# adapted by aja 06/98 |
8 |
|
# modified by aja 01/00 |
9 |
|
|
10 |
|
# Default lists |
11 |
|
set DISABLE = ( aim ) |
12 |
|
set ENABLE = ( ) |
13 |
|
set MODS = ( ) |
14 |
|
|
15 |
|
# Grab variables/lists from .genmakerc |
16 |
|
if (-r .genmakerc) source .genmakerc |
17 |
|
|
18 |
# Process command-line arguments |
# Process command-line arguments |
19 |
set allargs=( $argv ) |
set allargs=( $argv ) |
33 |
exit |
exit |
34 |
breaksw |
breaksw |
35 |
case -platform*: |
case -platform*: |
36 |
|
if ($?platform) then |
37 |
|
echo Option -platform=dir can only be specified once.; exit 1 |
38 |
|
endif |
39 |
set platform = ( `echo $arg | sed 's/-platform=//' `) |
set platform = ( `echo $arg | sed 's/-platform=//' `) |
40 |
breaksw |
breaksw |
41 |
|
case -rootdir: |
42 |
|
case -rootdir=: |
43 |
|
echo "To specify root directory you must specify one with -rootdir=dir" |
44 |
|
echo "with NO space eg. -rootdir=../../.. or -rootdir=/usr/people/joe/src" |
45 |
|
exit |
46 |
|
breaksw |
47 |
case -rootdir=*: |
case -rootdir=*: |
48 |
|
if ($?ROOTDIR) then |
49 |
|
echo "***" Warning: variable \$ROOTDIR is already set to $ROOTDIR |
50 |
|
echo "***" Command line \"$arg\" will override this. |
51 |
|
endif |
52 |
set ROOTDIR = ( `echo $arg | sed 's/-rootdir=//' `) |
set ROOTDIR = ( `echo $arg | sed 's/-rootdir=//' `) |
53 |
breaksw |
breaksw |
54 |
case -mymods=*: |
case -mods: |
55 |
set MYMODS = ( `echo $arg | sed 's/-mymods=//' `) |
case -mods=: |
56 |
|
echo "To specify an additional source directory you must specify one with -mods=dir" |
57 |
|
echo "with NO space eg. -mods=../code or -mods=/usr/people/joe/src" |
58 |
|
exit |
59 |
|
breaksw |
60 |
|
case -mods=*: |
61 |
|
set MODS = ( $MODS `echo $arg | sed 's/-mods=//' | sed 's/,/ /g' `) |
62 |
|
breaksw |
63 |
|
case -disable: |
64 |
|
case -disable=: |
65 |
|
echo "To disable packages from compilation use -disable=pkg1,pkg2" |
66 |
|
echo "with NO spaces eg. -disable=kpp,gmredi or -disable=all (to enable all packages)" |
67 |
|
exit |
68 |
|
breaksw |
69 |
|
case -disable=*: |
70 |
|
set DISABLE = ( $DISABLE `echo $arg | sed 's/-disable=//' | sed 's/,/ /g' `) |
71 |
|
breaksw |
72 |
|
case -enable: |
73 |
|
case -enable=: |
74 |
|
echo "To enable packages from compilation use -enable=pkg1,pkg2" |
75 |
|
echo "with NO spaces eg. -enable=aim or -enable=all (to enable all packages)" |
76 |
|
echo "-enable overrides -disable, ie. a package listed in both is enabled" |
77 |
|
exit |
78 |
|
breaksw |
79 |
|
case -enable=*: |
80 |
|
set ENABLE = ( $ENABLE `echo $arg | sed 's/-enable=//' | sed 's/,/ /g' `) |
81 |
breaksw |
breaksw |
82 |
case -mpi: |
case -mpi: |
83 |
echo "Enabling MPI options" |
echo "Enabling MPI options" |
88 |
echo "Including paths to JAM libraries" |
echo "Including paths to JAM libraries" |
89 |
breaksw |
breaksw |
90 |
case -help: |
case -help: |
91 |
echo "usage: $0 [-help] [-makefile[=...]] [-platform=...] [-mpi]" |
echo "usage: $0 [-help] [-makefile[=...]] [-platform=...] [-mpi] [-jam] [-disable=pkg1[,pkg2,...]] [-enable=pkg1[,pkg2,...]] [-mods=dir1[,dir2,...]] [-rootdir=dir]" |
92 |
|
cat << EOF |
93 |
|
|
94 |
|
$0 is used to generate the Makefile in the current directory. |
95 |
|
|
96 |
|
Typical invocations are: |
97 |
|
o from "bin": ../tools/genmake |
98 |
|
o from "verification/expt/code": ../../../tools/genmake |
99 |
|
o from "verification/expt/input": ../../../tools/genmake -mods=../code |
100 |
|
o from a scratch directory: ~/mitgcm/tools/genmake -rootdir=~/mitgcm |
101 |
|
or ~/mitgcm/tools/genmake -rootdir=~/mitgcm -mods=~/mymods |
102 |
|
|
103 |
|
Packages (collected modules of code) can be disabled to avoid unnecessary |
104 |
|
compilation of unused code. For instance if you know you will not |
105 |
|
use GM/Redi, KPP and OBCS and they are appropriate turned-off in the |
106 |
|
configuration: |
107 |
|
.../tools/genmake -disable=gmredi,kpp,obcs |
108 |
|
|
109 |
|
If you add some source files you can re-call the previous instance of |
110 |
|
genmake with "make makefile". |
111 |
|
|
112 |
|
genmake also reads the file .genmakerc which can be used to configure |
113 |
|
options (primarily the command-line options above) for particular experiments. |
114 |
|
EOF |
115 |
exit |
exit |
116 |
breaksw |
breaksw |
117 |
default: |
default: |
126 |
# Default actions/options |
# Default actions/options |
127 |
|
|
128 |
# If platform wasn't specified then determine platform type of the host |
# If platform wasn't specified then determine platform type of the host |
129 |
if ($?platform == 0) then |
if (! $?platform) then |
130 |
set platform = (`uname`) |
set platform = (`uname`) |
131 |
endif |
endif |
132 |
# If name of makefile wasn't specified then use default "Makefile" |
# If name of makefile wasn't specified then use default "Makefile" |
133 |
if ($?mfile == 0) set mfile = ( Makefile ) |
if (! $?mfile) set mfile = ( Makefile ) |
134 |
|
|
135 |
set mach = ( `uname -a` ) |
set mach = ( `uname -a` ) |
136 |
echo Operating system: $mach |
echo Operating system: $mach |
137 |
|
|
138 |
|
|
139 |
# Directories for source, includes, binaries and executables |
# Directories for source, includes, binaries and executables |
|
# Note |
|
|
# o If you prefer/need everything under a single directory |
|
|
# copy everything in ../eesupp/src, ../model/src, |
|
|
# ../eesupp/inc and ../model/inc into a directory and then |
|
|
# edit the paths below to ./ |
|
140 |
# |
# |
141 |
# If -rootdir wasn't specified then assume script is being run from bin |
# If -rootdir wasn't specified then assume script is being run from bin |
142 |
# but if it was supplied then we should place the executable in the build dir |
# but if it was supplied then we should place the executable in the build dir |
143 |
if ($?ROOTDIR == 0) then |
if (! $?ROOTDIR) then |
144 |
set ROOTDIR = ( .. ) |
set pwd=`pwd` |
145 |
else |
if ($pwd:t == bin & -d ../model & -d ../eesupp & -d ../pkg) then |
146 |
if ($?EXEDIR == 0) set EXEDIR = ( ./ ) |
set ROOTDIR = ( .. ) |
147 |
|
endif |
148 |
|
endif |
149 |
|
# Scan for logical ROOTDIR |
150 |
|
if (! $?ROOTDIR) then |
151 |
|
foreach dr (. .. ../.. ../../.. ../../../.. ../../../../..) |
152 |
|
if (-d $dr/model & -d $dr/eesupp & -d $dr/pkg) then |
153 |
|
set ROOTDIR = $dr |
154 |
|
echo ROOTDIR was not specified. Setting ROOTDIR = \"$ROOTDIR\" |
155 |
|
break |
156 |
|
endif |
157 |
|
end |
158 |
endif |
endif |
159 |
if ($?MYMODS == 0) then |
if (! $?ROOTDIR) then |
160 |
set SOURCEDIRS = ( $ROOTDIR/{eesupp,model,diags}/src/ $ROOTDIR/pkg/[a-z]*/ ) |
echo Root directory was not specified and could not be determined. |
161 |
set INCLUDEDIRS = ( ./ $ROOTDIR/{eesupp,model,diags}/inc/ $ROOTDIR/pkg/[a-z]*/ ) |
echo Specify the root location of the model source with -rootdir=dir |
162 |
|
exit 1 |
163 |
|
endif |
164 |
|
if (! -d $ROOTDIR) then |
165 |
|
echo Root directory $ROOTDIR not found.;exit 1 |
166 |
|
endif |
167 |
|
# If -mods wasn't specified then we will assume that we can find all the |
168 |
|
# source code in the standard directories |
169 |
|
if (! $?MODS) then |
170 |
|
set SOURCEDIRS = ( ) |
171 |
|
set INCLUDEDIRS = ( . ) |
172 |
else |
else |
173 |
set SOURCEDIRS = ( $MYMODS/ $ROOTDIR/{eesupp,model,diags}/src/ $ROOTDIR/pkg/[a-z]*/ ) |
set SOURCEDIRS = ( $MODS ) |
174 |
set INCLUDEDIRS = ( ./ $MYMODS/ $ROOTDIR/{eesupp,model,diags}/inc/ $ROOTDIR/pkg/[a-z]*/ ) |
set INCLUDEDIRS = ( . $MODS ) |
175 |
|
endif |
176 |
|
if (! $?BUILDDIR) set BUILDDIR = ( . ) |
177 |
|
if (! -d $BUILDDIR) then |
178 |
|
echo Build directory $BUILDDIR not found.;exit 1 |
179 |
|
endif |
180 |
|
if (! $?EXEDIR) then |
181 |
|
set pwd=`pwd` |
182 |
|
if ($pwd:t == bin & -d ../exe & $ROOTDIR == ..) then |
183 |
|
set EXEDIR = ( ../exe ) |
184 |
|
else |
185 |
|
set EXEDIR = ( . ) |
186 |
|
endif |
187 |
|
endif |
188 |
|
if (! -d $EXEDIR) then |
189 |
|
echo Executable directory $EXEDIR not found.;exit 1 |
190 |
endif |
endif |
191 |
if ($?BUILDDIR == 0) set BUILDDIR = ( ./ ) |
if (! $?TOOLSDIR) set TOOLSDIR = ( $ROOTDIR/tools ) |
192 |
if ($?EXEDIR == 0) set EXEDIR = ( $ROOTDIR/exe/ ) |
if (! -d $TOOLSDIR) then |
193 |
if ($?EXECUTABLE == 0) set EXECUTABLE = ( mitgcmuv ) |
echo Tools directory $TOOLSDIR not found.;exit 1 |
194 |
if ($?TOOLSDIR == 0) set TOOLSDIR = ( $ROOTDIR/tools/ ) |
endif |
195 |
|
if (! $?EXECUTABLE) set EXECUTABLE = ( mitgcmuv ) |
196 |
|
|
197 |
|
# Now scan the standard source code tree |
198 |
|
foreach dr ($SOURCEDIRS) |
199 |
|
set adr=$dr |
200 |
|
if (! -d $adr) then |
201 |
|
echo mods directory $adr not found.; exit 1 |
202 |
|
endif |
203 |
|
echo Adding mods directory $adr |
204 |
|
end |
205 |
|
if (! $?PACKAGES) then |
206 |
|
set PACKAGES=() |
207 |
|
foreach pkg (`cd $ROOTDIR/pkg; find . -type d | grep -v CVS | sed 's:\./::' | grep -v "\." | sort`) |
208 |
|
if (-d $ROOTDIR/pkg/$pkg) set PACKAGES=($PACKAGES $pkg) |
209 |
|
end |
210 |
|
endif |
211 |
|
foreach dr ($PACKAGES) |
212 |
|
set enable |
213 |
|
foreach p ($DISABLE) |
214 |
|
if ($p != 'all' & ! -d $ROOTDIR/pkg/$p) then |
215 |
|
echo Specified package \"$p\" does not exist. |
216 |
|
exit 1 |
217 |
|
endif |
218 |
|
if ($dr == $p) unset enable |
219 |
|
if ($p == 'all') unset enable |
220 |
|
# The following allows entire trees to be disabled |
221 |
|
if ($dr:h == $p) unset enable |
222 |
|
if ($dr:h:h == $p) unset enable |
223 |
|
if ($dr:h:h:h == $p) unset enable |
224 |
|
if ($dr:h:h:h:h == $p) unset enable |
225 |
|
end |
226 |
|
foreach p ($ENABLE) |
227 |
|
if ($dr == $p) set enable |
228 |
|
end |
229 |
|
if ($?enable) then |
230 |
|
set adr=$ROOTDIR/pkg/$dr |
231 |
|
if (! -d $adr) then |
232 |
|
echo Source directory $adr not found.; exit 1 |
233 |
|
endif |
234 |
|
echo Adding package directory $adr |
235 |
|
set SOURCEDIRS = ($SOURCEDIRS $adr) |
236 |
|
set INCLUDEDIRS = ($INCLUDEDIRS $adr) |
237 |
|
else |
238 |
|
echo "*" Package \"$dr\" has not been enabled. |
239 |
|
endif |
240 |
|
end |
241 |
|
if (! $?STANDARDDIRS) set STANDARDDIRS=(eesupp model) |
242 |
|
foreach dr ($STANDARDDIRS) |
243 |
|
set adr=$ROOTDIR/$dr/src |
244 |
|
if (! -d $adr) then |
245 |
|
echo Source directory $adr not found.; exit 1 |
246 |
|
endif |
247 |
|
echo Adding source directory $adr |
248 |
|
set SOURCEDIRS = ($SOURCEDIRS $adr) |
249 |
|
set idr = `echo $adr | sed 's/src/inc/'` |
250 |
|
set INCLUDEDIRS = ($INCLUDEDIRS $idr) |
251 |
|
end |
252 |
|
|
253 |
# This is the generic configuration. |
# This is the generic configuration. |
254 |
# Platform specific options are chosen below |
# Platform specific options are chosen below |
289 |
set KPPFILES = ( 'main.F' ) |
set KPPFILES = ( 'main.F' ) |
290 |
set KFLAGS1 = ( '-scan=132 -noconc -cmp=' ) |
set KFLAGS1 = ( '-scan=132 -noconc -cmp=' ) |
291 |
set FC = ( 'f77' ) |
set FC = ( 'f77' ) |
292 |
set FFLAGS = ( '-convert big_endian -r8 -extend_source -u -automatic -call_shared -notransform_loops -align dcommons' ) |
set FFLAGS = ( '-convert big_endian -r8 -extend_source -automatic -call_shared -notransform_loops -align dcommons' ) |
293 |
set FOPTIM = ( '-O5 -fast -tune host -inline all' ) |
set FOPTIM = ( '-O5 -fast -tune host -inline all' ) |
294 |
set NOOPTFLAGS = ( '-O0' ) |
set NOOPTFLAGS = ( '-O0' ) |
295 |
set LIBS = ( '-lfmpi -lmpi -lkmp_osfp10 -pthread' ) |
set LIBS = ( '-lfmpi -lmpi -lkmp_osfp10 -pthread' ) |
427 |
set CPP = ( '/lib/cpp -traditional -P' ) |
set CPP = ( '/lib/cpp -traditional -P' ) |
428 |
set DEFINES = ( ${DEFINES} '-DWORDLENGTH=4' ) |
set DEFINES = ( ${DEFINES} '-DWORDLENGTH=4' ) |
429 |
set FC = ( 'pgf77' ) |
set FC = ( 'pgf77' ) |
430 |
set FFLAGS = ( '-byteswapio' ) |
set FFLAGS = ( '-byteswapio -r8 -Mnodclchk -Mextend' ) |
431 |
set FOPTIM = ( '-tp p6 -v -O2 -Munroll -Mvect=cachesize:512000,transform -Kieee' ) |
set FOPTIM = ( '-tp p6 -v -O2 -Munroll -Mvect=cachesize:512000,transform -Kieee' ) |
432 |
set LINK = ( 'pgf77' ) |
set LINK = ( 'pgf77' ) |
433 |
breaksw |
breaksw |
519 |
if ($#deplist != 0) then |
if ($#deplist != 0) then |
520 |
echo "# These files are linked from $dr" >> srclinks.tmp |
echo "# These files are linked from $dr" >> srclinks.tmp |
521 |
echo $deplist':' >> srclinks.tmp |
echo $deplist':' >> srclinks.tmp |
522 |
echo '\t$(LN) '$dr'$@ $@' >> srclinks.tmp |
echo ' $(LN) '$dr'/$@ $@' >> srclinks.tmp |
523 |
endif |
endif |
524 |
end |
end |
525 |
rm -rf .links.tmp |
rm -rf .links.tmp |
531 |
set THISCWD = ( `pwd` ) |
set THISCWD = ( `pwd` ) |
532 |
set THISDATE = ( `date` ) |
set THISDATE = ( `date` ) |
533 |
|
|
534 |
|
if (-r $mfile) mv -f $mfile $mfile.bak |
535 |
########################################### |
########################################### |
536 |
## This is the template for the makefile ## |
## This is the template for the makefile ## |
537 |
########################################### |
########################################### |
538 |
echo Creating makefile: $mfile |
echo Creating makefile: $mfile |
539 |
echo "# Multithreaded + multi-processing makefile for $mach" > ${mfile} |
echo "# Multithreaded + multi-processing makefile for $mach" > ${mfile} |
540 |
echo "# This makefile was generated automatically pn" >> ${mfile} |
echo "# This makefile was generated automatically on" >> ${mfile} |
541 |
echo "# $THISDATE" >> ${mfile} |
echo "# $THISDATE" >> ${mfile} |
542 |
echo "# by the command:" >> ${mfile} |
echo "# by the command:" >> ${mfile} |
543 |
echo "# ${0} $argv" >> ${mfile} |
echo "# ${0} $argv" >> ${mfile} |
567 |
SOURCEDIRS = ${SOURCEDIRS} |
SOURCEDIRS = ${SOURCEDIRS} |
568 |
INCLUDEDIRS = ${INCLUDEDIRS} |
INCLUDEDIRS = ${INCLUDEDIRS} |
569 |
EXEDIR = ${EXEDIR} |
EXEDIR = ${EXEDIR} |
570 |
EXECUTABLE = \$(EXEDIR)${EXECUTABLE} |
EXECUTABLE = \$(EXEDIR)/${EXECUTABLE} |
571 |
TOOLSDIR = ${TOOLSDIR} |
TOOLSDIR = ${TOOLSDIR} |
572 |
|
|
573 |
EOF |
EOF |
654 |
depend: |
depend: |
655 |
@make links |
@make links |
656 |
makedepend -o .f \$(INCLUDES) \$(SRCFILES) |
makedepend -o .f \$(INCLUDES) \$(SRCFILES) |
657 |
|
|
658 |
links: \$(SRCFILES) |
links: \$(SRCFILES) |
659 |
|
|
660 |
small_f: \$(F77FILES) |
small_f: \$(F77FILES) |
663 |
-rm -rf *.o *.f *.p ${RMFILES} |
-rm -rf *.o *.f *.p ${RMFILES} |
664 |
Clean: |
Clean: |
665 |
@make clean |
@make clean |
666 |
-find . -type l -exec rm {} \; |
@make cleanlinks |
667 |
-rm Makefile.bak |
-rm -f Makefile.bak |
668 |
CLEAN: |
CLEAN: |
669 |
@make Clean |
@make Clean |
670 |
-find \$(ROOTDIR)/verification/*/input/ -name "*.meta" -exec rm {} \; |
-find \$(EXEDIR) -name "*.meta" -exec rm {} \; |
671 |
-find \$(ROOTDIR)/verification/*/input/ -name "*.data" -exec rm {} \; |
-find \$(EXEDIR) -name "*.data" -exec rm {} \; |
672 |
-rm \$(EXECUTABLE) |
-rm -f \$(EXECUTABLE) |
673 |
|
|
674 |
|
makefile: |
675 |
|
${0} $argv |
676 |
|
cleanlinks: |
677 |
|
-find . -type l -exec rm {} \; |
678 |
|
|
679 |
# The normal chain of rules is ( .F - .f - .o ) |
# The normal chain of rules is ( .F - .f - .o ) |
680 |
.F.f: |
.F.f: |