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_XMLF90.perl in trunk/EXTERNAL/MISC – NEMO

source: trunk/EXTERNAL/MISC/makemake_XMLF90.perl @ 1681

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

external: some additions to test IOSERVER with NVTK

  • Property svn:executable set to *
File size: 8.6 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/cml:../src/dom:../src/sax:../src/strings:../src/xpath:../src/wxml\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- sxdkrz F_O = \$(F_D) \$(F_P) -C vsafe -size_t64 -I \$(MODDIR)\n";
33print MAKEFILE "#-Q- eshpux F_O = \$(F_D) \$(F_P) -C vsafe -I \$(MODDIR)\n";
34print MAKEFILE "#-Q- sx8brodie F_O = \$(F_D) \$(F_P) -I \$(MODDIR)\n";
35print MAKEFILE "#-Q- sx6nec F_O = \$(F_D) \$(F_P) -size_t64 -Wf\,\"-pvctl loopcnt=999999\" -I \$(MODDIR)\n";
36print MAKEFILE "#-Q- sx8mercure F_O = \$(F_D) \$(F_P) -size_t64 -Wf\,\"-pvctl loopcnt=999999\" -I \$(MODDIR)\n";
37print MAKEFILE "#-Q- aix6 F_O = \$(F_P) -O3 -qextname -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
38print MAKEFILE "#-Q- aix F_O = \$(F_P) -O3 -qextname -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
39print MAKEFILE "#-Q- aix osxxlf = \$(F_P) -O3 -qextname -qsuffix=f=f90  -qmoddir=\$(MODDIR) -I \$(MODDIR)\n";
40print MAKEFILE "#---------------------------------------------------------------------\n";
41print MAKEFILE "#- Create libxmlf90\n";
42print MAKEFILE "#---------------------------------------------------------------------\n\n";
43
44print MAKEFILE ".PRECIOUS : \$(MODEL_LIB)\n";
45print MAKEFILE "SXMODEL_LIB = \$(MODEL_LIB)\n";
46print MAKEFILE "ifeq (\$(L_X),1)\n";
47print MAKEFILE "SXMODEL_LIB = \$(LIBDIR)/libsxxmlf90.a\n";
48print MAKEFILE ".PRECIOUS : \$(SXMODEL_LIB)\n";
49print MAKEFILE "endif\n\n";
50
51# Source listing
52#
53print MAKEFILE "MODS1 =\t";
54@srcs = < ../*/*/*.f90 >;
55&PrintWords(8, 0, @srcs);
56print MAKEFILE "\n\n";
57#
58# Object listing
59#
60print MAKEFILE "OBJSMODS1 =\t";
61@objs =  @srcs;
62foreach (@objs) { s/\.[^.]+$/.o/ };
63         foreach $objs (@objs) {
64         @tab = split('/', $objs);
65         $objs = $tab[$#tab] ;
66         };
67
68&PrintWords(8, 0, @objs);
69print MAKEFILE "\n\n";
70#
71# Define common macros
72#
73#print MAKEFILE "LIBS =\t\n\n";
74#print MAKEFILE "CC = cc\n";
75#print MAKEFILE "CFLAGS = -O\n";
76#print MAKEFILE "FC = f77\n";
77#print MAKEFILE "FFLAGS = -O\n";
78#print MAKEFILE "F90 = f90\n";
79#print MAKEFILE "F90FLAGS = -O\n";
80#print MAKEFILE "LDFLAGS = -s\n\n";
81#
82# make
83#
84print MAKEFILE "all: dirxml \$(MODEL_LIB)(\$(OBJSMODS1))\n";
85print MAKEFILE "\t\@echo XMLF90 is OK\n\n";
86
87# .f90 -> .o
88#
89
90print MAKEFILE "#---USE VPATH--- \$(MODEL_LIB)(%.o): ../*/*/%.f90\n";
91print MAKEFILE "\$(MODEL_LIB)(%.o): %.f90\n";
92print MAKEFILE "\t\$(F_C) \$(F_O) -I\$(NCDF_INC) \$<\n";
93print MAKEFILE "\t\$(A_C) \$(MODEL_LIB) \$*.o\n";
94print MAKEFILE "ifeq (\$(L_X),1)\n";
95print MAKEFILE "\t\$(A_X) \$(SXMODEL_LIB) \$*.o\n";
96print MAKEFILE "endif\n";
97print MAKEFILE "#-Q- sgi6       mv \$(shell echo \$* | tr '[:lower:]' '[:upper:]').mod \$(MODDIR)\n";
98print MAKEFILE "ifeq (\$(M_M),1)\n";
99print MAKEFILE "\t\@mv -f *.mod \$(MODDIR)  2> /dev/null || true\n";
100print MAKEFILE "endif\n";
101print MAKEFILE "\t\$(RM) \$*.o\n\n";;
102
103
104print MAKEFILE "dirxml: \n";
105print MAKEFILE "\t\@if [ ! -d ../../../lib/libxmlio_server ] ; then mkdir ../../../lib/libxmlio_server ; fi\n\n";
106#
107# make clean
108#
109print MAKEFILE "clean:\n";
110print MAKEFILE "\t\$(RM) *.*~ Makefile~ core *.o *.mod i.*.L *.L\n";
111print MAKEFILE "\t\$(RM)  \$(MODEL_LIB) \n\n";
112#
113#
114# Dependency listings
115#
116&MakeDependsf90($ARGV[1]);
117&MakeDepends("*.f *.F", '^\s*include\s+["\']([^"\']+)["\']');
118&MakeDepends("*.c",     '^\s*#\s*include\s+["\']([^"\']+)["\']');
119
120#
121# &PrintWords(current output column, extra tab?, word list); --- print words
122#    nicely
123#
124sub PrintWords {
125   local($columns) = 78 - shift(@_);
126   local($extratab) = shift(@_);
127   local($wordlength);
128   #
129   print MAKEFILE @_[0];
130   $columns -= length(shift(@_));
131   foreach $word (@_) {
132      $wordlength = length($word);
133      if ($wordlength + 1 < $columns) {
134         print MAKEFILE " $word";
135         $columns -= $wordlength + 1;
136         }
137      else {
138         #
139         # Continue onto a new line
140         #
141         if ($extratab) {
142            print MAKEFILE " \\\n\t\t$word";
143            $columns = 62 - $wordlength;
144            }
145         else {
146            print MAKEFILE " \\\n\t$word";
147            $columns = 70 - $wordlength;
148            }
149         }
150      }
151   }
152
153#
154# &LanguageCompiler(compiler, sources); --- determine the correct language
155#    compiler
156#
157sub LanguageCompiler {
158   local($compiler) = &toLower(shift(@_));
159   local(@srcs) = @_;
160   #
161   if (length($compiler) > 0) {
162      CASE: {
163         grep(/^$compiler$/, ("fc", "f77")) &&
164            do { $compiler = "FC"; last CASE; };
165         grep(/^$compiler$/, ("cc", "c"))   &&
166            do { $compiler = "CC"; last CASE; };
167         $compiler = "F90";
168         }
169      }
170   else {
171      CASE: {
172         grep(/\.f90$/, @srcs)   && do { $compiler = "F90"; last CASE; };
173         grep(/\.(f|F)$/, @srcs) && do { $compiler = "FC";  last CASE; };
174         grep(/\.c$/, @srcs)     && do { $compiler = "CC";  last CASE; };
175         $compiler = "???";
176         }
177      }
178   $compiler;
179   }
180
181#
182# &toLower(string); --- convert string into lower case
183#
184sub toLower {
185   local($string) = @_[0];
186   $string =~ tr/A-Z/a-z/;
187   $string;
188   }
189
190#
191# &uniq(sorted word list); --- remove adjacent duplicate words
192#
193sub uniq {
194   local(@words);
195   foreach $word (@_) {
196      if ($word ne $words[$#words]) {
197         push(@words, $word);
198         }
199      }
200   @words;
201   }
202
203#
204# &MakeDepends(language pattern, include file sed pattern); --- dependency
205#    maker
206#
207sub MakeDepends {
208   local(@incs);
209   local($lang) = @_[0];
210   local($pattern) = @_[1];
211   #
212   foreach $file (<${lang}>) {
213      open(FILE, $file) || warn "Cannot open $file: $!\n";
214      while (<FILE>) {
215         /$pattern/i && push(@incs, $1);
216         }
217      if (defined @incs) {
218         $file =~ s/\.[^.]+$/.o/;
219         @tab = split('/', $file);
220         $file = '$(MODEL_LIB)(' . $tab[$#tab] . ')' ;
221         print MAKEFILE "$file: ";
222         &PrintWords(length($file) + 2, 0, @incs);
223         print MAKEFILE "\n";
224         undef @incs;
225         }
226      }
227   }
228
229#
230# &MakeDependsf90(f90 compiler); --- FORTRAN 90 dependency maker
231#
232sub MakeDependsf90 {
233   local($compiler) = &toLower(@_[0]);
234   local(@dependencies);
235   local(%filename);
236   local(@incs);
237   local(@modules);
238   local($objfile);
239   #
240   # Associate each module with the name of the file that contains it
241   #
242   foreach $file (<../*/*/*.f90>) {
243      open(FILE, $file) || warn "Cannot open $file: $!\n";
244      while (<FILE>) {
245         /^\s*module\s+([^\s!]+)/i &&
246            ($filename{&toLower($1)} = $file) =~ s/\.f90$/.o/;
247         }
248      }
249   #
250   # Print the dependencies of each file that has one or more include's or
251   # references one or more modules
252   #
253   foreach $file (<../*/*/*.f90>) {
254      open(FILE, $file);
255      while (<FILE>) {
256         /^\s*include\s+["\']([^"\']+)["\']/i && push(@incs, $1);
257         /^\s*use\s+([^\s,!]+)/i && push(@modules, &toLower($1));
258         }
259      if (defined @incs || defined @modules) {
260         ($objfile = $file) =~ s/\.f90$/.o/;
261         @tab = split('/', $objfile);
262         $objfile = '$(MODEL_LIB)(' . $tab[$#tab] . ')' ;
263
264         print MAKEFILE "$objfile: ";
265         undef @dependencies;
266         foreach $module (@modules) {
267            push(@dependencies, $filename{$module});
268            }
269         @dependencies = &uniq(sort(@dependencies));
270
271         foreach $dependencies (@dependencies) {
272         @tab = split('/', $dependencies);
273         $dependencies = '$(MODEL_LIB)(' . $tab[$#tab] . ')';
274         }
275
276         &PrintWords(length($objfile) + 2, 0,
277                     @dependencies, &uniq(sort(@incs)));
278         print MAKEFILE "\n";
279         undef @incs;
280         undef @modules;
281         #
282         #
283         }
284      }
285   }
Note: See TracBrowser for help on using the repository browser.