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