New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
makemake_XMLIO.perl in tags/nemo_v3_2_beta/EXTERNAL/MISC – NEMO

source: tags/nemo_v3_2_beta/EXTERNAL/MISC/makemake_XMLIO.perl @ 7709

Last change on this file since 7709 was 1560, checked in by rblod, 15 years ago

external: some additions to test IOSERVER with NVTK

  • Property svn:executable set to *
File size: 12.7 KB
Line 
1#!/usr/bin/perl
2#
3# Usage: makemake {<program name> {<F90 compiler or fc or f77 or cc or c>}}
4#
5# Generate a Makefile from the sources in the current directory.  The source
6# files may be in either C, FORTRAN 77, Fortran 90 or some combination of
7# these languages.  If the F90 compiler specified is cray or parasoft, then
8# the Makefile generated will conform to the conventions of these compilers.
9# To run makemake, it will be necessary to modify the first line of this script
10# to point to the actual location of Perl on your system.
11#
12# Written by Michael Wester <wester@math.unm.edu> February 16, 1995
13# Cotopaxi (Consulting), Albuquerque, New Mexico
14#
15open(MAKEFILE, "> AA_make");
16#
17#print MAKEFILE "PROG =\t$ARGV[0]\n\n";
18#
19# Misc
20
21print MAKEFILE "VPATH=../src/IOSERVER:../src/XMLIO\n";
22print MAKEFILE "MAKE_NAM = \$(MAKE)\n";
23print MAKEFILE "ifneq (\$(MAKE_NAM),\$(M_K))\n";
24print MAKEFILE " \@\$(error You must invoke this Makefile with the \$(M_K) command)\n";
25print MAKEFILE "endif\n";
26print MAKEFILE "USER_DIR = \$(shell /bin/pwd)\n";
27print MAKEFILE "MAKE_DIR = '??'\n";
28print MAKEFILE "ifneq (\$(USER_DIR),\$(MAKE_DIR))\n";
29print MAKEFILE " \@\$(error You must invoke this Makefile from its directory)\n";
30print MAKEFILE "endif\n";
31print MAKEFILE "#-\n";
32print MAKEFILE "#-Q- aix6 F_O = \$(F_P) -O3 -qextname -qsuffix=cpp=F90 -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
33print MAKEFILE "#-Q- aix F_O = \$(F_P) -O3 -qextname -qsuffix=cpp=F90 -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
34print MAKEFILE "#-Q- osxxlf F_O = \$(F_P) -O3 -qextname -qsuffix=cpp=F90 -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
35print MAKEFILE "F_O := \$(F_O) -I../../../lib\n";
36print MAKEFILE "P_O := \$(P_O) -traditional\n";
37print MAKEFILE "#-Q- aix6 L_O = \$(F_P) -q64 -O3\n"; 
38print MAKEFILE "#-Q- aix L_O = \$(F_P) -q64 -O3\n"; 
39print MAKEFILE "prefix=''\n";
40print MAKEFILE "#-Q- aix6 prefix='-WF,'\n";
41print MAKEFILE "#-Q- aix prefix='-WF,'\n";
42print MAKEFILE "override P_P := \$(P_P:\%=\$(prefix)\%)\n\n";
43print MAKEFILE "#---------------------------------------------------------------------\n";
44print MAKEFILE "#- Create libioserver and libxmlio\n";
45print MAKEFILE "#---------------------------------------------------------------------\n\n";
46
47print MAKEFILE ".PRECIOUS : \$(MODEL_LIB1) \$(MODEL_LIB2)\n";
48print MAKEFILE "SXMODEL_LIB1 = \$(MODEL_LIB1)\n";
49print MAKEFILE "SXMODEL_LIB2 = \$(MODEL_LIB2)\n";
50print MAKEFILE "ifeq (\$(L_X),1)\n";
51print MAKEFILE "SXMODEL_LIB1 = \$(LIBDIR)/libsxioserver.a\n";
52print MAKEFILE "SXMODEL_LIB2 = \$(LIBDIR)/libsxxmlio.a\n";
53print MAKEFILE ".PRECIOUS : \$(SXMODEL_LIB1) \$(SXMODEL_LIB2)\n";
54print MAKEFILE "endif\n\n";
55
56# Source listing
57#IOSERVER
58print MAKEFILE "MODS1 =\t";
59@srcs = < ../src/IOSERVER/*.F90 ../src/IOSERVER/*.f90>;
60&PrintWords(8, 0, @srcs);
61print MAKEFILE "\n\n";
62#
63# Object listing
64#
65print MAKEFILE "OBJSMODS1 =\t";
66@objs =  @srcs;
67foreach (@objs) { s/\.[^.]+$/.o/ };
68         foreach $objs (@objs) {
69         @tab = split('/', $objs);
70         $objs = $tab[$#tab] ;
71         if( "$objs" eq 'server.o' ){
72         $objs = ''};
73         };
74         
75&PrintWords(8, 0, @objs);
76print MAKEFILE "\n\n";
77
78# Source listing
79#XMLIO
80print MAKEFILE "MODS2 =\t";
81@srcs = < ../src/XMLIO/*.F90 ../src/XMLIO/*.f90>;
82&PrintWords(8, 0, @srcs);
83print MAKEFILE "\n\n";
84#
85# Object listing
86#
87print MAKEFILE "OBJSMODS2 =\t";
88@objs =  @srcs;
89foreach (@objs) { s/\.[^.]+$/.o/ };
90         foreach $objs (@objs) {
91         @tab = split('/', $objs);
92         $objs = $tab[$#tab] ;
93         if( "$objs" eq 'test_xmlio.o' ){
94         $objs = ''};
95         };
96
97&PrintWords(8, 0, @objs);
98print MAKEFILE "\n\n";
99
100#
101# make
102#
103print MAKEFILE ".SUFFIXES: .f90 .F90\n\n";
104
105print MAKEFILE "all: libioipsl libxmlf90 dirxml \$(MODEL_LIB2)(\$(OBJSMODS2)) key \$(MODEL_LIB1)(\$(OBJSMODS1)) server.o EXEC_BIN\n";
106print MAKEFILE "\t\@echo IOSERVER is OK\n\n";
107
108# mpi or not
109print MAKEFILE "key :\n";
110print MAKEFILE "\t\-\@if [ \"`cat KEY_CPP`\" \!= \"\$(P_P)\" ] \; then \\\n";
111print MAKEFILE "\techo \"\$(P_P)\" > KEY_CPP \; fi\n\n";
112
113
114# Main program
115print MAKEFILE "ifneq  (,\$(findstring NO_MPI,\$(P_P)))\n";
116print MAKEFILE "EXEC_BIN :\n";
117print MAKEFILE "server.o :\n";
118print MAKEFILE "else\n";
119print MAKEFILE "EXEC_BIN : server.o\n";
120print MAKEFILE "\t\$(F_L) \$(L_O) -o ../../../bin/server.exe server.o \$(MODEL_LIB1) \$(MODEL_LIB2) ../../../lib/libioipsl.a \$(NCDF_LIB) ../../../lib/libxmlio_server/libxmlf90.a\n";
121print MAKEFILE "server.o :       ../src/IOSERVER/server.f90\n";
122print MAKEFILE "\t\@\$(F_C) \$(F_O) -c ../src/IOSERVER/server.f90\n";
123print MAKEFILE "endif\n\n";
124
125
126# .f90 -> .o
127#
128
129print MAKEFILE "#Rules for ioserver\n";
130print MAKEFILE "#---- Using VPATH instead \$(MODEL_LIB1)(%.o): ../src/IOSERVER/%.f90\n";
131print MAKEFILE "\$(MODEL_LIB1)(%.o): %.f90\n";
132print MAKEFILE "\t\$(F_C) \$(F_O) -I\$(NCDF_INC) \$<\n";
133print MAKEFILE "\t\$(A_C) \$(MODEL_LIB1) \$*.o\n";
134print MAKEFILE "ifeq (\$(L_X),1)\n";
135print MAKEFILE "\t\$(A_X) \$(SXMODEL_LIB1) \$*.o\n";
136print MAKEFILE "endif\n";
137print MAKEFILE "#-Q- sgi6       mv \$(shell echo \$* | tr '[:lower:]' '[:upper:]').mod \$(MODDIR)\n";
138print MAKEFILE "ifeq (\$(M_M),1)\n";
139print MAKEFILE "\t\@mv -f *.mod \$(MODDIR)  2> /dev/null || true\n";
140print MAKEFILE "endif\n";
141print MAKEFILE "\t\$(RM) \$*.o\n\n";
142
143print MAKEFILE "#Rules for ioserver\n";
144#print MAKEFILE "\$src/IOSERVER/%.f90: ../src/IOSERVER/%.F90\n";
145#print MAKEFILE "\t@\$(P_C) \$(P_O) \$(P_P) src/IOSERVER/\$(*F).F90 > src/IOSERVER/\$(*F).f90\n\n";
146print MAKEFILE "#---- Using VPATH instead \$(MODEL_LIB1)(%.o): ../src/IOSERVER/%.F90\n";
147print MAKEFILE "\$(MODEL_LIB1)(%.o): %.F90 KEY_CPP\n";
148print MAKEFILE "\t\$(F_C) \$(F_O) \$(P_P) -I\$(NCDF_INC) -I../src/IOSERVER \$<\n";
149print MAKEFILE "\t\$(A_C) \$(MODEL_LIB1) \$*.o\n";
150print MAKEFILE "ifeq (\$(L_X),1)\n";
151print MAKEFILE "\t\$(A_X) \$(SXMODEL_LIB1) \$*.o\n";
152print MAKEFILE "endif\n";
153print MAKEFILE "#-Q- sgi6       mv \$(shell echo \$* | tr '[:lower:]' '[:upper:]').mod \$(MODDIR)\n";
154print MAKEFILE "ifeq (\$(M_M),1)\n";
155print MAKEFILE "\t\@mv -f *.mod \$(MODDIR)  2> /dev/null || true\n";
156print MAKEFILE "endif\n";
157print MAKEFILE "\t\$(RM) \$*.o\n\n";
158
159print MAKEFILE "#Rules for xmlio\n";
160print MAKEFILE "#---- Using VPATH instead \$(MODEL_LIB1)(%.o): ../src/XMLIO/%.F90\n";
161print MAKEFILE "\$(MODEL_LIB2)(%.o): %.f90\n";
162print MAKEFILE "\t\$(F_C) \$(F_O) -I\$(NCDF_INC) -I../src/XMLIO \$<\n";
163print MAKEFILE "\t\$(A_C) \$(MODEL_LIB2) \$*.o\n";
164print MAKEFILE "ifeq (\$(L_X),1)\n";
165print MAKEFILE "\t\$(A_X) \$(SXMODEL_LIB2) \$*.o\n";
166print MAKEFILE "endif\n";
167print MAKEFILE "#-Q- sgi6       mv \$(shell echo \$* | tr '[:lower:]' '[:upper:]').mod \$(MODDIR)\n";
168print MAKEFILE "ifeq (\$(M_M),1)\n";
169print MAKEFILE "\t\@mv -f *.mod \$(MODDIR)  2> /dev/null || true\n";
170print MAKEFILE "endif\n";
171print MAKEFILE "\t\$(RM) \$*.o\n\n";
172
173
174
175
176print MAKEFILE "dirxml: \n";
177print MAKEFILE "\t\@if [ ! -d ../../../lib/libxmlio_server ] ; then mkdir ../../../lib/libxmlio_server ; fi\n\n";
178
179print MAKEFILE "# IOIPSL library\n";
180print MAKEFILE "libioipsl :\n";
181print MAKEFILE "\t(cd ../../IOIPSL/src ; \$(M_K) -f Makefile )\n\n";
182
183print MAKEFILE "# XMLF90 library\n";
184print MAKEFILE "libxmlf90 :\n";
185print MAKEFILE "\t(cd ../../XMLF90/external ; \$(M_K) -f Makefile )\n\n";
186
187#
188# make clean
189#
190print MAKEFILE "clean:\n";
191print MAKEFILE "\t\$(RM) *.*~ Makefile~ core *.o *.mod i.*.L *.L\n";
192print MAKEFILE "\t\$(RM) server.o \$(MODEL_LIB1) \$(MODEL_LIB2)\n\n";
193#
194#
195# Dependency listings
196#
197&MakeDependsf90($ARGV[1],IOSERVER,MODEL_LIB1);
198&MakeDependsf90($ARGV[1],XMLIO,MODEL_LIB2);
199&MakeDepends("*.f *.F", '^\s*include\s+["\']([^"\']+)["\']');
200&MakeDepends("*.c",     '^\s*#\s*include\s+["\']([^"\']+)["\']');
201
202#
203# &PrintWords(current output column, extra tab?, word list); --- print words
204#    nicely
205#
206sub PrintWords {
207   local($columns) = 78 - shift(@_);
208   local($extratab) = shift(@_);
209   local($wordlength);
210   #
211   print MAKEFILE @_[0];
212   $columns -= length(shift(@_));
213   foreach $word (@_) {
214      $wordlength = length($word);
215      if ($wordlength + 1 < $columns) {
216         print MAKEFILE " $word";
217         $columns -= $wordlength + 1;
218         }
219      else {
220         #
221         # Continue onto a new line
222         #
223         if ($extratab) {
224            print MAKEFILE " \\\n\t\t$word";
225            $columns = 62 - $wordlength;
226            }
227         else {
228            print MAKEFILE " \\\n\t$word";
229            $columns = 70 - $wordlength;
230            }
231         }
232      }
233   }
234
235#
236# &LanguageCompiler(compiler, sources); --- determine the correct language
237#    compiler
238#
239sub LanguageCompiler {
240   local($compiler) = &toLower(shift(@_));
241   local(@srcs) = @_;
242   #
243   if (length($compiler) > 0) {
244      CASE: {
245         grep(/^$compiler$/, ("fc", "f77")) &&
246            do { $compiler = "FC"; last CASE; };
247         grep(/^$compiler$/, ("cc", "c"))   &&
248            do { $compiler = "CC"; last CASE; };
249         $compiler = "F90";
250         }
251      }
252   else {
253      CASE: {
254         grep(/\.f90$/, @srcs)   && do { $compiler = "F90"; last CASE; };
255         grep(/\.(f|F)$/, @srcs) && do { $compiler = "FC";  last CASE; };
256         grep(/\.c$/, @srcs)     && do { $compiler = "CC";  last CASE; };
257         $compiler = "???";
258         }
259      }
260   $compiler;
261   }
262
263#
264# &toLower(string); --- convert string into lower case
265#
266sub toLower {
267   local($string) = @_[0];
268   $string =~ tr/A-Z/a-z/;
269   $string;
270   }
271
272#
273# &uniq(sorted word list); --- remove adjacent duplicate words
274#
275sub uniq {
276   local(@words);
277   foreach $word (@_) {
278      if ($word ne $words[$#words]) {
279         push(@words, $word);
280         }
281      }
282   @words;
283   }
284
285#
286# &MakeDepends(language pattern, include file sed pattern); --- dependency
287#    maker
288#
289sub MakeDepends {
290   local(@incs);
291   local($lang) = @_[0];
292   local($pattern) = @_[1];
293   #
294   foreach $file (<${lang}>) {
295      open(FILE, $file) || warn "Cannot open $file: $!\n";
296      while (<FILE>) {
297         /$pattern/i && push(@incs, $1);
298         }
299      if (defined @incs) {
300         $file =~ s/\.[^.]+$/.o/;
301         @tab = split('/', $file);
302         $file = '$(MODEL_LIB)(' . $tab[$#tab] . ')' ;
303         print MAKEFILE "$file: ";
304         &PrintWords(length($file) + 2, 0, @incs);
305         print MAKEFILE "\n";
306         undef @incs;
307         }
308      }
309   }
310
311#
312# &MakeDependsf90(f90 compiler); --- FORTRAN 90 dependency maker
313#
314sub MakeDependsf90 {
315   local($compiler) = &toLower(@_[0]);
316   local(@dependencies);
317   local(%filename);
318   local(@incs);
319   local(@modules);
320   local($objfile);
321   local($DIR) = @_[1];
322   local($MODEL_LIB) = @_[2];
323   #
324   # Associate each module with the name of the file that contains it
325   #
326   foreach $file (<../*/*/*.f90>) {
327      open(FILE, $file) || warn "Cannot open $file: $!\n";
328      while (<FILE>) {
329         /^\s*module\s+([^\s!]+)/i &&
330            ($filename{&toLower($1)} = $file) =~ s/\.f90$/.o/;
331         }
332      }
333   foreach $file (<../*/*/*.F90>) {
334      open(FILE, $file) || warn "Cannot open $file: $!\n";
335      while (<FILE>) {
336         /^\s*module\s+([^\s!]+)/i &&
337            ($filename{&toLower($1)} = $file) =~ s/\.F90$/.o/;
338         }
339      }
340
341   #
342   # Print the dependencies of each file that has one or more include's or
343   # references one or more modules
344   #
345   foreach $file (<../src/$DIR/*.f90 ../src/$DIR/*.F90>) {
346      open(FILE, $file);
347      while (<FILE>) {
348         /^\s*include\s+["\']([^"\']+)["\']/i && push(@incs, $1);
349         /^\s*use\s+([^\s,!]+)/i && push(@modules, &toLower($1));
350         }
351      if (defined @incs || defined @modules) {
352#         ($objfile = $file) =~ s/\.F90$/.o/;
353         ($objfile = $file) =~ s/\.[fF]90$/.o/;
354         @tab = split('/', $objfile);
355         $objfile = '$(' . $MODEL_LIB . ')(' . $tab[$#tab] . ')' ;
356
357         print MAKEFILE "$objfile: ";
358         undef @dependencies;
359         foreach $module (@modules) {
360            push(@dependencies, $filename{$module});
361            }
362         @dependencies = &uniq(sort(@dependencies));
363
364         foreach $dependencies (@dependencies) {
365           
366         @tab = split('/', $dependencies);
367         $dependencies = '$(' . $MODEL_LIB . ')(' . $tab[$#tab] . ')';
368
369             if( "$DIR" eq 'IOSERVER'  && "$dependencies" eq '$(MODEL_LIB1)(xmlio.o)' ) {
370               $dependencies = '$(MODEL_LIB2)'
371#                $dependencies = ''
372
373             }         
374         }
375
376         foreach $incs (@incs) {
377         @tab = split('/', $incs);
378         @incs = '../src' . '/' . $DIR. '/' . $tab[$#tab] ;
379         }
380        foreach $incs (@incs) {
381             if( "$incs" eq '../src/IOSERVER/mpif.h' ||  "$incs" eq '../src/IOSERVER/VT.inc' ||  "$incs" eq  '../src/IOSERVER/ios_mpif.h' ) {
382                $incs = '';
383       }
384       }
385
386 
387
388         &PrintWords(length($objfile) + 2, 0,
389                     @dependencies, &uniq(sort(@incs)));
390         print MAKEFILE "\n";
391         undef @incs;
392         undef @modules;
393         #
394         #
395         }
396      }
397   }
Note: See TracBrowser for help on using the repository browser.