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 trunk/EXTERNAL/MISC – NEMO

source: trunk/EXTERNAL/MISC/makemake_XMLIO.perl @ 1722

Last change on this file since 1722 was 1722, checked in by rblod, 14 years ago

Add sx9mercure as new target

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