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