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 NEMO/releases/CMIP5_IPSL/EXTERNAL/XMLF90 – NEMO

source: NEMO/releases/CMIP5_IPSL/EXTERNAL/XMLF90/makemake_XMLF90.perl @ 11998

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

Move makefile generator for XMLIO

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