Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

make file utility

2 views
Skip to first unread message

Vivek Rao

unread,
Jun 9, 1996, 3:00:00 AM6/9/96
to vi...@uiuc.edu

Is there a utility that helps one create a "make" file for
a Fortran program on the UNIX system? I know one can do it
by hand, but is there an easier way? If you respond to this
question, please email me a copy.
Thanks.

______________________________________
Vivek Rao
vi...@uiuc.edu
http://www-ceg.ceg.uiuc.edu/~vrao/
Univ. of Illinois, Physics Department
1110 W Green St / Urbana IL 61801
______________________________________

John Appleyard

unread,
Jun 10, 1996, 3:00:00 AM6/10/96
to

In article <31BB72...@roma.physics.uiuc.edu>, Vivek Rao
<vr...@roma.physics.uiuc.edu> writes

>Is there a utility that helps one create a "make" file for
>a Fortran program on the UNIX system? I know one can do it
>by hand, but is there an easier way? If you respond to this
>question, please email me a copy.
>Thanks.
>
>

Our AUTOMAKE utility (part of plusFORT) does something like this for
Fortran and C. It generates and maintains the dependency database
itself (complete with include files nested as deep as you like).

In effect it not only makes the make-file, but automatically re-makes it
(with minimal rescanning of source code) when it is out of date.

To put it another way, AUTOMAKE handles the one dependency that
conventional MAKE utilities choke on - that of the make-file on the
source code.

--
John Appleyard Jo...@polyhdrn.demon.co.uk
Polyhedron Software Ltd.
Programs for Programmers - QA, Compilers, Graphics
************ Visit our Web site on http://www.polyhedron.co.uk/ ************

Deutscher

unread,
Jun 10, 1996, 3:00:00 AM6/10/96
to

Vivek Rao (vr...@roma.physics.uiuc.edu) wrote:
: Is there a utility that helps one create a "make" file for
: a Fortran program on the UNIX system? I know one can do it
: by hand, but is there an easier way? If you respond to this
: question, please email me a copy.
: Thanks.

Check GNU make and its docs. I think it offers some aid in automating
the genreation and keeping-up-to date of make files. Stefan

: ______________________________________


: Vivek Rao
: vi...@uiuc.edu
: http://www-ceg.ceg.uiuc.edu/~vrao/
: Univ. of Illinois, Physics Department
: 1110 W Green St / Urbana IL 61801
: ______________________________________

--
==========================================================================
Stefan A. Deutscher, s...@utk.edu, (001)-423-[522-7845|974-7838|574-5897]
home^ UTK^ ORNL^
==========================================================================
If there is software you'd like to have in a native version, visit the:
OS/2 E-mail Campaign Page http://www.andrews.edu/~boyko/email.html
--------------------------------------------------------------------------

Eric Petersen [Aero]

unread,
Jun 13, 1996, 3:00:00 AM6/13/96
to

Vivek Rao writes:

> Is there a utility that helps one create a "make" file for
> a Fortran program on the UNIX system? I know one can do it
> by hand, but is there an easier way? If you respond to this
> question, please email me a copy.
> Thanks.
>

> ______________________________________
> Vivek Rao
> vi...@uiuc.edu
> http://www-ceg.ceg.uiuc.edu/~vrao/
> Univ. of Illinois, Physics Department
> 1110 W Green St / Urbana IL 61801
> ______________________________________

Yes. Michael Wester <wes...@math.unm.edu> has posted a Perl script to create a
make file for all .f, .c and .f90 files in the current directory. I'm including
my copy; contact Michael for the latest version.

========== cut here ==========

#! /usr/local/bin/perl
#
# Usage: makemake {<program name> {<F90 compiler or fc or f77 or cc or c>}}
#
# Generate a Makefile from the sources in the current directory. The source
# files may be in either C, FORTRAN 77, Fortran 90 or some combination of
# these languages. If the F90 compiler specified is cray or parasoft, then
# the Makefile generated will conform to the conventions of these compilers.
# To run makemake, it will be necessary to modify the first line of this script
# to point to the actual location of Perl on your system.
#
# Written by Michael Wester <wes...@math.unm.edu> February 16, 1995
# Cotopaxi (Consulting), Albuquerque, New Mexico
#
open(MAKEFILE, "> Makefile");
#
print MAKEFILE "PROG =\t$ARGV[0]\n\n";
#
# Source listing
#
print MAKEFILE "SRCS =\t";
@srcs = <*.f90 *.f *.F *.c>;
&PrintWords(8, 0, @srcs);
print MAKEFILE "\n\n";
#
# Object listing
#
print MAKEFILE "OBJS =\t";
@objs = @srcs;
foreach (@objs) { s/\.[^.]+$/.o/ };
&PrintWords(8, 0, @objs);
print MAKEFILE "\n\n";
#
# Define common macros
#
print MAKEFILE "LIBS =\t\n\n";
print MAKEFILE "CC = cc\n";
print MAKEFILE "CFLAGS = -O\n";
print MAKEFILE "FC = f77\n";
print MAKEFILE "FFLAGS = -O\n";
print MAKEFILE "F90 = f90\n";
print MAKEFILE "F90FLAGS = -O\n";
print MAKEFILE "LDFLAGS = -s\n\n";
#
# make
#
print MAKEFILE "all: \$(PROG)\n\n";
print MAKEFILE "\$(PROG): \$(OBJS)\n";
print MAKEFILE "\t\$(", &LanguageCompiler($ARGV[1], @srcs);
print MAKEFILE ") \$(LDFLAGS) -o \$@ \$(OBJS) \$(LIBS)\n\n";
#
# make clean
#
print MAKEFILE "clean:\n";
print MAKEFILE "\trm -f \$(PROG) \$(OBJS) *.mod\n\n";
#
# Make .f90 a valid suffix
#
print MAKEFILE ".SUFFIXES: \$(SUFFIXES) .f90\n\n";
#
# .f90 -> .o
#
print MAKEFILE ".f90.o:\n";
print MAKEFILE "\t\$(F90) \$(F90FLAGS) -c \$<\n\n";
#
# Dependency listings
#
&MakeDependsf90($ARGV[1]);
&MakeDepends("*.f *.F", '^\s*include\s+["\']([^"\']+)["\']');
&MakeDepends("*.c", '^\s*#\s*include\s+["\']([^"\']+)["\']');

#
# &PrintWords(current output column, extra tab?, word list); --- print words
# nicely
#
sub PrintWords {
local($columns) = 78 - shift(@_);
local($extratab) = shift(@_);
local($wordlength);
#
print MAKEFILE @_[0];
$columns -= length(shift(@_));
foreach $word (@_) {
$wordlength = length($word);
if ($wordlength + 1 < $columns) {
print MAKEFILE " $word";
$columns -= $wordlength + 1;
}
else {
#
# Continue onto a new line
#
if ($extratab) {
print MAKEFILE " \\\n\t\t$word";
$columns = 62 - $wordlength;
}
else {
print MAKEFILE " \\\n\t$word";
$columns = 70 - $wordlength;
}
}
}
}

#
# &LanguageCompiler(compiler, sources); --- determine the correct language
# compiler
#
sub LanguageCompiler {
local($compiler) = &toLower(shift(@_));
local(@srcs) = @_;
#
if (length($compiler) > 0) {
CASE: {
grep(/^$compiler$/, ("fc", "f77")) &&
do { $compiler = "FC"; last CASE; };
grep(/^$compiler$/, ("cc", "c")) &&
do { $compiler = "CC"; last CASE; };
$compiler = "F90";
}
}
else {
CASE: {
grep(/\.f90$/, @srcs) && do { $compiler = "F90"; last CASE; };
grep(/\.(f|F)$/, @srcs) && do { $compiler = "FC"; last CASE; };
grep(/\.c$/, @srcs) && do { $compiler = "CC"; last CASE; };
$compiler = "???";
}
}
$compiler;
}

#
# &toLower(string); --- convert string into lower case
#
sub toLower {
local($string) = @_[0];
$string =~ tr/A-Z/a-z/;
$string;
}

#
# &uniq(sorted word list); --- remove adjacent duplicate words
#
sub uniq {
local(@words);
foreach $word (@_) {
if ($word ne $words[$#words]) {
push(@words, $word);
}
}
@words;
}

#
# &MakeDepends(language pattern, include file sed pattern); --- dependency
# maker
#
sub MakeDepends {
local(@incs);
local($lang) = @_[0];
local($pattern) = @_[1];
#
foreach $file (<${lang}>) {
open(FILE, $file) || warn "Cannot open $file: $!\n";
while (<FILE>) {
/$pattern/i && push(@incs, $1);
}
if (defined @incs) {
$file =~ s/\.[^.]+$/.o/;
print MAKEFILE "$file: ";
&PrintWords(length($file) + 2, 0, @incs);
print MAKEFILE "\n";
undef @incs;
}
}
}

#
# &MakeDependsf90(f90 compiler); --- FORTRAN 90 dependency maker
#
sub MakeDependsf90 {
local($compiler) = &toLower(@_[0]);
local(@dependencies);
local(%filename);
local(@incs);
local(@modules);
local($objfile);
#
# Associate each module with the name of the file that contains it
#
foreach $file (<*.f90>) {
open(FILE, $file) || warn "Cannot open $file: $!\n";
while (<FILE>) {
/^\s*module\s+([^\s!]+)/i &&
($filename{&toLower($1)} = $file) =~ s/\.f90$/.o/;
}
}
#
# Print the dependencies of each file that has one or more include's or
# references one or more modules
#
foreach $file (<*.f90>) {
open(FILE, $file);
while (<FILE>) {
/^\s*include\s+["\']([^"\']+)["\']/i && push(@incs, $1);
/^\s*use\s+([^\s,!]+)/i && push(@modules, &toLower($1));
}
if (defined @incs || defined @modules) {
($objfile = $file) =~ s/\.f90$/.o/;
print MAKEFILE "$objfile: ";
undef @dependencies;
foreach $module (@modules) {
push(@dependencies, $filename{$module});
}
@dependencies = &uniq(sort(@dependencies));
&PrintWords(length($objfile) + 2, 0,
@dependencies, &uniq(sort(@incs)));
print MAKEFILE "\n";
undef @incs;
undef @modules;
#
# Cray F90 compiler
#
if ($compiler eq "cray") {
print MAKEFILE "\t\$(F90) \$(F90FLAGS) -c ";
foreach $depend (@dependencies) {
push(@modules, "-p", $depend);
}
push(@modules, $file);
&PrintWords(30, 1, @modules);
print MAKEFILE "\n";
undef @modules;
}
#
# ParaSoft F90 compiler
#
if ($compiler eq "parasoft") {
print MAKEFILE "\t\$(F90) \$(F90FLAGS) -c ";
foreach $depend (@dependencies) {
$depend =~ s/\.o$/.f90/;
push(@modules, "-module", $depend);
}
push(@modules, $file);
&PrintWords(30, 1, @modules);
print MAKEFILE "\n";
undef @modules;
}
}
}
}

========== end ==========

0 new messages