1 |
cnh |
1.1 |
#!/bin/csh -f |
2 |
|
|
# |
3 |
cnh |
1.4 |
# $Header: /u/gcmpack/models/MITgcmUV/tools/genmake,v 1.3 1998/07/16 23:50:44 cnh Exp $ |
4 |
cnh |
1.1 |
# |
5 |
|
|
# Makefile generator for MITgcm UV codes |
6 |
|
|
# created by cnh 03/98 |
7 |
|
|
# adapted by aja 06/98 |
8 |
|
|
|
9 |
|
|
# Process command-line arguments |
10 |
|
|
set allargs=( $argv ) |
11 |
|
|
while ($#allargs) |
12 |
|
|
set arg = $allargs[1] |
13 |
|
|
switch ($arg) |
14 |
|
|
case -makefile*: |
15 |
|
|
if ($arg == "-makefile") then |
16 |
|
|
set mfile = ( Makefile ) |
17 |
|
|
else |
18 |
|
|
set mfile = ( `echo $arg | sed 's/-makefile=//' `) |
19 |
|
|
endif |
20 |
|
|
breaksw |
21 |
|
|
case -platform: |
22 |
|
|
case -platform=: |
23 |
|
|
echo "To change platform you must specify one with -platform=" |
24 |
|
|
echo "eg. -platform=sparc or -platform=mips" |
25 |
|
|
exit |
26 |
|
|
breaksw |
27 |
|
|
case -platform*: |
28 |
|
|
set platform = ( `echo $arg | sed 's/-platform=//' `) |
29 |
|
|
breaksw |
30 |
|
|
case -mpi: |
31 |
|
|
echo "Enabling MPI options" |
32 |
|
|
set USEMPI |
33 |
|
|
breaksw |
34 |
|
|
case -help: |
35 |
|
|
echo "usage: $0 [-help] [-makefile[=...]] [-platform=...] [-mpi]" |
36 |
|
|
exit |
37 |
|
|
breaksw |
38 |
|
|
default: |
39 |
|
|
echo "Unknown command-line option: " $arg |
40 |
|
|
echo $0 "-help to show usage" |
41 |
|
|
exit |
42 |
|
|
breaksw |
43 |
|
|
endsw |
44 |
|
|
shift allargs |
45 |
|
|
end |
46 |
|
|
|
47 |
|
|
if ($?platform == 0) set platform = (`uname -p`) |
48 |
|
|
if ($?mfile == 0) set mfile = ( Makefile.$platform ) |
49 |
|
|
set mach = ( `uname -a` ) |
50 |
|
|
echo Operating system: $mach |
51 |
|
|
|
52 |
|
|
# Directories for source, includes, binaries and executables |
53 |
|
|
# Note |
54 |
|
|
# o If you prefer/need everything under a single directory |
55 |
|
|
# copy everything in ../eesupp/src, ../model/src, |
56 |
|
|
# ../eesupp/inc and ../model/inc into a directory and then |
57 |
|
|
# edit the paths below to ./ |
58 |
|
|
set SOURCEDIRS = ( ../eesupp/src/ ../model/src/ ../diags/src/) |
59 |
|
|
set INCLUDEDIRS = ( ../eesupp/inc/ ../model/inc/ ../diags/inc/) |
60 |
|
|
set BUILDDIR = ( ../bin/ ) |
61 |
|
|
set EXEDIR = ( ../exe/ ) |
62 |
|
|
set EXECUTABLE = ( mitgcmuv ) |
63 |
|
|
|
64 |
|
|
# This is the generic configuration. |
65 |
|
|
# Platform specific options are chosen below |
66 |
|
|
set LN = ( 'ln -sf' ) |
67 |
|
|
set CPP = ( '/lib/cpp -P' ) |
68 |
|
|
set KPP = ( ) |
69 |
|
|
set FC = ( 'f77' ) |
70 |
|
|
set LINK = ( 'f77' ) |
71 |
|
|
set DEFINES = ( ) |
72 |
|
|
set INCLUDES = ( ) |
73 |
|
|
set FFLAGS = ( ) |
74 |
|
|
set FOPTIM = ( ) |
75 |
|
|
set KFLAGS1 = ( ) |
76 |
|
|
set KFLAGS2 = ( ) |
77 |
|
|
set LIBS = ( ) |
78 |
|
|
set KPPFILES = ( ) |
79 |
|
|
set NOOPTFILES = ( ) |
80 |
|
|
set NOOPTFLAGS = ( ) |
81 |
|
|
set RMFILES = ( ) |
82 |
|
|
|
83 |
|
|
# We often want to use different compile/link options is using MPI |
84 |
|
|
if ($?USEMPI) then |
85 |
|
|
set USEMPI = ( '+mpi' ) |
86 |
|
|
set DEFINES = ( ${DEFINES} '-DALLOW_USE_MPI -DALWAYS_USE_MPI' ) |
87 |
|
|
else |
88 |
|
|
set USEMPI |
89 |
|
|
# set DEFINES = ( ${DEFINES} '-UALLOW_USE_MPI -UALWAYS_USE_MPI' ) |
90 |
|
|
endif |
91 |
|
|
|
92 |
|
|
# Platform specific options |
93 |
|
|
switch ($platform$USEMPI) |
94 |
|
|
case alpha: |
95 |
|
|
case alpha+mpi: |
96 |
|
|
echo "Configuring for DEC Alpha" |
97 |
|
|
set CPP = ( '/usr/bin/cpp -P' ) |
98 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_DEC' ) |
99 |
|
|
set KPP = ( 'kapf' ) |
100 |
cnh |
1.4 |
set KPPFILES = ( 'main.F' ) |
101 |
cnh |
1.1 |
set KFLAGS1 = ( '-scan=132 -noconc -cmp=' ) |
102 |
|
|
set FC = ( 'f77' ) |
103 |
adcroft |
1.2 |
set FFLAGS = ( '-convert big_endian -r8 -extend_source -u -automatic -call_shared -notransform_loops -align dcommons' ) |
104 |
cnh |
1.1 |
set FOPTIM = ( '-O5 -fast -tune host -inline all' ) |
105 |
|
|
set NOOPTFLAGS = ( '-O0' ) |
106 |
|
|
set LIBS = ( '-lfmpi -lmpi -lkmp_osfp10 -pthread' ) |
107 |
|
|
set NOOPTFILES = ( 'barrier.F different_multiple.F load_external_fields.F') |
108 |
|
|
set RMFILES = ( '*.p.out' ) |
109 |
|
|
breaksw |
110 |
|
|
case mips+mpi: |
111 |
|
|
echo "Configuring for SGI Mips with MPI" |
112 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_SGI' ) |
113 |
|
|
set INCLUDES = ( '-I/usr/local/mpi/include' ) |
114 |
|
|
set FC = ( 'mpif77' ) |
115 |
|
|
set LINK = ( 'mpif77' ) |
116 |
|
|
set FFLAGS = ( '-extend_source -bytereclen -r10000' ) |
117 |
|
|
set FOPTIM = ( '-O3' ) |
118 |
|
|
set RMFILES = ( 'rii_files' ) |
119 |
|
|
breaksw |
120 |
|
|
case mips: |
121 |
|
|
echo "Configuring for SGI Mips" |
122 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_SGI' ) |
123 |
|
|
set INCLUDES = ( '-I/usr/local/mpi/include' ) |
124 |
|
|
set FFLAGS = ( '-extend_source -mp -mpio -bytereclen -r10000 -mips4' ) |
125 |
|
|
set FOPTIM = ( '-O2' ) |
126 |
|
|
set NOOPTFLAGS = ( '-O0' ) |
127 |
|
|
set NOOPTFILES = ( 'barrier.F different_multiple.F ' \ |
128 |
|
|
'load_external_fields.F' ) |
129 |
|
|
set RMFILES = ( 'rii_files' ) |
130 |
|
|
breaksw |
131 |
|
|
case sparc: |
132 |
|
|
set LN = ( '/usr/bin/ln -fs' ) |
133 |
|
|
set CPP = ( '/usr/ccs/lib/cpp -P' ) |
134 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_SUN' ) |
135 |
|
|
set INCLUDES = ( '-I/usr/local/mpi/include' ) |
136 |
|
|
set FFLAGS = ( '-stackvar -explicitpar -vpara -e -u -noautopar') |
137 |
|
|
set FOPTIM = ( '-O5' ) |
138 |
|
|
set NOOPTFLAGS = ( '-O0' ) |
139 |
|
|
set LIBS = ( '-L/usr/local/mpi/lib/solaris/ch_shmem -lmpi -lthread' \ |
140 |
|
|
'-lsocket -lnsl -fast' ) |
141 |
|
|
set NOOPTFILES = ( 'barrier.F different_multiple.F load_external_fields.F') |
142 |
cnh |
1.3 |
breaksw |
143 |
|
|
case onyx: |
144 |
|
|
case onyx+mpi: |
145 |
|
|
echo "Configuring for SGI ONYX running IRIX64" |
146 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_SGI' ) |
147 |
|
|
set INCLUDES = ( '-I/usr/include' ) |
148 |
|
|
set FFLAGS = ( '-extend_source -bytereclen -r10000 -64' ) |
149 |
|
|
set FOPTIM = ( '-O2' ) |
150 |
|
|
set NOOPTFLAGS = ( '-O0' ) |
151 |
|
|
set NOOPTFILES = ( 'barrier.F different_multiple.F ' \ |
152 |
|
|
'load_external_fields.F' ) |
153 |
|
|
set LIBS = ( '-lmpi' ) |
154 |
|
|
breaksw |
155 |
|
|
case exemplar: |
156 |
|
|
case exemplar+mpi: |
157 |
|
|
echo "Configuring for HP Exemplar" |
158 |
|
|
set CPP = ( '/usr/ccs/lbin/cpp -P' ) |
159 |
|
|
set DEFINES = ( ${DEFINES} '-DTARGET_HP' ) |
160 |
|
|
set INCLUDES = ( '-I/opt/mpi/include' ) |
161 |
|
|
set FC = ( 'mpif77' ) |
162 |
|
|
set LINK = ( 'mpif77' ) |
163 |
|
|
set FFLAGS = ( '+es +U77 +Onoautopar +Oexemplar_model' \ |
164 |
|
|
'+Okernel_threads' ) |
165 |
|
|
set FOPTIM = ( '+O2' ) |
166 |
|
|
set NOOPTFLAGS = ( '-O0' ) |
167 |
|
|
set NOOPTFILES = ( 'barrier.F different_multiple.F' \ |
168 |
|
|
'load_external_fields.F' ) |
169 |
cnh |
1.1 |
breaksw |
170 |
|
|
default: |
171 |
|
|
echo "Error: platform not recognized: uname -p = " $platform$USEMPI |
172 |
|
|
exit |
173 |
|
|
breaksw |
174 |
|
|
endsw |
175 |
|
|
|
176 |
|
|
############################################################################### |
177 |
|
|
## ## |
178 |
|
|
## Everything below here should not need to be changed. Platform specific ## |
179 |
|
|
## changes and code specific changes should be configured above this line. ## |
180 |
|
|
## ## |
181 |
|
|
############################################################################### |
182 |
|
|
|
183 |
|
|
# Create list of files |
184 |
|
|
set flist = `ls -1 ${SOURCEDIRS} | grep '.*\.F'` |
185 |
|
|
if ( $#flist ) then |
186 |
|
|
echo -n "SRCFILES = " > srclist.inc |
187 |
|
|
echo -n "F77FILES = " > f77list.inc |
188 |
|
|
echo -n "OBJFILES = " > objlist.inc |
189 |
|
|
foreach ff ( ${flist} ) |
190 |
|
|
set fname = ( ${ff:t} ) |
191 |
|
|
echo ' \' >> srclist.inc |
192 |
|
|
echo -n " " ${fname:r}.F >> srclist.inc |
193 |
|
|
echo ' \' >> f77list.inc |
194 |
|
|
echo -n " " ${fname:r}.f >> f77list.inc |
195 |
|
|
echo ' \' >> objlist.inc |
196 |
|
|
echo -n " " ${fname:r}.o >> objlist.inc |
197 |
|
|
end |
198 |
|
|
echo " " >> srclist.inc |
199 |
|
|
echo " " >> f77list.inc |
200 |
|
|
echo " " >> objlist.inc |
201 |
|
|
else |
202 |
|
|
echo No source files found...\! |
203 |
|
|
exit |
204 |
|
|
endif |
205 |
|
|
|
206 |
|
|
# Convert lists of directories into command-line options |
207 |
|
|
foreach inc ($INCLUDEDIRS) |
208 |
|
|
set INCLUDES = ($INCLUDES -I$inc) |
209 |
|
|
end |
210 |
|
|
set SRCSTARS = ( ) |
211 |
|
|
foreach dr ($SOURCEDIRS) |
212 |
|
|
set SRCSTARS = ("${SRCSTARS}" $dr/\*.F) |
213 |
|
|
end |
214 |
|
|
|
215 |
|
|
set THISHOSTNAME = ( `hostname` ) |
216 |
|
|
set THISCWD = ( `pwd` ) |
217 |
|
|
set THISDATE = ( `date` ) |
218 |
|
|
|
219 |
|
|
########################################### |
220 |
|
|
## This is the template for the makefile ## |
221 |
|
|
########################################### |
222 |
|
|
echo Creating makefile: $mfile |
223 |
|
|
echo "# Multithreaded + multi-processing makefile for $mach" > ${mfile} |
224 |
|
|
echo "# This makefile was generated automatically pn" >> ${mfile} |
225 |
|
|
echo "# $THISDATE" >> ${mfile} |
226 |
|
|
echo "# by the command:" >> ${mfile} |
227 |
|
|
echo "# ${0} $argv" >> ${mfile} |
228 |
|
|
echo "# executed by:" >> ${mfile} |
229 |
|
|
echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> ${mfile} |
230 |
|
|
cat >> ${mfile} <<EOF |
231 |
|
|
# |
232 |
|
|
# BUILDDIR : Directory where object files are written |
233 |
|
|
# SOURCEDIRS : Directories containing the source (.F) files |
234 |
|
|
# INCLUDEDIRS : Directories containing the header-source (.h) files |
235 |
|
|
# EXEDIR : Directory where executable that is generated is written |
236 |
|
|
# EXECUTABLE : Full path of executable binary |
237 |
|
|
# |
238 |
|
|
# CPP : C-preprocessor command |
239 |
|
|
# INCLUDES : Directories searched for header files |
240 |
|
|
# DEFINES : Macro definitions for CPP |
241 |
|
|
# KPP : Special preprocessor command (specific to platform) |
242 |
|
|
# KFLAGS : Flags for KPP |
243 |
|
|
# FC : Fortran compiler command |
244 |
|
|
# FFLAGS : Configuration/debugging options for FC |
245 |
|
|
# FOPTIM : Optimization options for FC |
246 |
|
|
# LINK : Command for link editor program |
247 |
|
|
# LIBS : Library flags /or/ additional optimization/debugging flags |
248 |
|
|
|
249 |
|
|
BUILDDIR = ${BUILDDIR} |
250 |
|
|
SOURCEDIRS = ${SOURCEDIRS} |
251 |
|
|
INCLUDEDIRS = ${INCLUDEDIRS} |
252 |
|
|
EXEDIR = ${EXEDIR} |
253 |
|
|
EXECUTABLE = \$(EXEDIR)${EXECUTABLE} |
254 |
|
|
|
255 |
|
|
# Unix ln (link) |
256 |
|
|
LN = ${LN} |
257 |
|
|
# C preprocessor |
258 |
|
|
CPP = ${CPP} |
259 |
|
|
# Special preprocessor (KAP on DECs, FPP on Crays) |
260 |
|
|
KPP = ${KPP} |
261 |
|
|
# Fortran compiler |
262 |
|
|
FC = ${FC} |
263 |
|
|
# Link editor |
264 |
|
|
LINK = ${LINK} |
265 |
|
|
|
266 |
|
|
# Defines for CPP |
267 |
|
|
DEFINES = ${DEFINES} |
268 |
|
|
# Includes for CPP |
269 |
|
|
INCLUDES = ${INCLUDES} |
270 |
|
|
# Flags for KPP |
271 |
|
|
KFLAGS1 = ${KFLAGS1} |
272 |
|
|
KFLAGS2 = ${KFLAGS2} |
273 |
|
|
# Optim./debug for FC |
274 |
|
|
FFLAGS = ${FFLAGS} |
275 |
|
|
FOPTIM = ${FOPTIM} |
276 |
|
|
# Files that should not be optimized |
277 |
|
|
NOOPTFILES = ${NOOPTFILES} |
278 |
|
|
NOOPTFLAGS = ${NOOPTFLAGS} |
279 |
|
|
# Flags and libraries needed for linking |
280 |
|
|
LIBS = ${LIBS} |
281 |
|
|
|
282 |
|
|
EOF |
283 |
|
|
|
284 |
|
|
cat srclist.inc >> ${mfile} |
285 |
|
|
cat f77list.inc >> ${mfile} |
286 |
|
|
cat objlist.inc >> ${mfile} |
287 |
|
|
rm -f srclist.inc f77list.inc objlist.inc |
288 |
|
|
|
289 |
|
|
cat >> ${mfile} <<EOF |
290 |
|
|
|
291 |
|
|
.SUFFIXES: |
292 |
|
|
.SUFFIXES: .o .f .p .F |
293 |
|
|
|
294 |
|
|
all: \$(EXECUTABLE) |
295 |
|
|
\$(EXECUTABLE): \$(OBJFILES) |
296 |
|
|
\$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS) |
297 |
|
|
links: |
298 |
|
|
@-\$(LN) $SRCSTARS . |
299 |
|
|
depend: |
300 |
|
|
@make links |
301 |
|
|
makedepend -o .f \$(INCLUDES) \$(SRCFILES) |
302 |
|
|
clean: |
303 |
|
|
-rm -rf *.o *.f *.p ${RMFILES} |
304 |
|
|
|
305 |
|
|
# The normal chain of rules is ( .F - .f - .o ) |
306 |
|
|
.F.f: |
307 |
|
|
\$(CPP) \$(DEFINES) \$(INCLUDES) \$< > \$@ |
308 |
|
|
.f.o: |
309 |
|
|
\$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< |
310 |
|
|
|
311 |
|
|
# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain |
312 |
|
|
.F.p: |
313 |
|
|
\$(CPP) \$(DEFINES) \$(INCLUDES) \$< > \$@ |
314 |
|
|
.p.f: |
315 |
|
|
\$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< |
316 |
|
|
EOF |
317 |
|
|
|
318 |
|
|
# Make list of "exceptions" that need ".p" files |
319 |
|
|
foreach sf ($KPPFILES) |
320 |
|
|
set fname=( ${sf:t} ) |
321 |
|
|
echo "${fname:r}.f: ${fname:r}.p" >> ${mfile} |
322 |
|
|
end |
323 |
|
|
foreach sf ($NOOPTFILES) |
324 |
|
|
set fname=( ${sf:t} ) |
325 |
|
|
echo "${fname:r}.o: ${fname:r}.f" >> ${mfile} |
326 |
|
|
echo ' $(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> ${mfile} |
327 |
|
|
end |
328 |
|
|
echo >> ${mfile} |
329 |
|
|
echo "# DO NOT DELETE" >> ${mfile} |
330 |
|
|
|
331 |
|
|
exit |