#!/usr/local/bin/perl # The following perl script will convert a directory full with Fortran # functions, into C and create a Makefile to allow the user to compile it # like a decent human being. # ########################### # CONFIGURE this script: # # Where is your f2c executable located? $f2c_exec = "/hyak/lf/bin/f2c"; # # Where is your f2c.h header file? $f2c_header = "/hyak/lf/include/f2c.h"; # # You are DONE CONFIGURING! ############################ # Copyright (C) 1996 Eleftherios Gkioulekas # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ############################################################### # Get the name of the directory where all the action takes place $directory = $ARGV[0]; chdir($directory); # Get a list of all the Fortran files in there open(LIST,"ls *.f |") || die "Can't do ls *.f in $directory"; @file_list = ; chop(@file_list); close(LIST); # Obtain a list of the names without the extension grep(s/(\w+)\.f/$1/g,@file_list); # # Now apply f2c on every one of these files # print "Translating files.\n"; $i = 0; foreach $file (@file_list) { system("$f2c_exec -P ${file}.f"); } # # Put together the prototypes # print "Making C Prototypes. -> $directory.h \n"; unlink $directory.h; open(HEADER,">$directory.h") || die "Can't create $directory.h : $!"; print HEADER <<"END"; /* ** ${directory}.h ** Created automagically by dirf2c which was ** written by his Majesty Mr.Elef */ #ifndef __defined_${directory}_h__fortran_calls #define __defined_${directory}_h__fortran_calls /* extern "C" escape for C++ programs */ #ifdef __cplusplus extern "C" { #endif /* *********************************************************************** */ END foreach $file (@file_list) { open(FILE,"${file}.P"); @thefile = ; close(FILE); print HEADER @thefile; unlink("${file}.P"); print HEADER <<"END"; /* *********************************************************************** */ END } print HEADER <<"END"; /* close the extern "C" escape */ #ifdef __cplusplus } #endif /* close the outer #ifndef */ #endif /* Enjoy! */ END close(FILE); # # Put together a Makefile # print "Making Make script.\n"; unlink "Make"; open(SCRIPT,">Make") || die "Can't create Makefile : $!"; print SCRIPT <<"END"; #!/bin/csh # This script has been generated by the dirf2c program # which was written by his Majesty Mr.Elef # setenv compiler "gcc -c " echo "Compiling lib${directory}.a" rm -f lib${directory}.a END # How many files are on the list? $howmany = $#file_list; foreach $file (@file_list) { print SCRIPT << "END"; \$compiler $file.c ar cr lib${directory}.a $file.o rm -f $file.o echo "$file.o done. $howmany files to go." END $howmany -= 1; } print SCRIPT "ranlib lib${directory}.a\n"; close(SCRIPT); # Give executable permissions to the Make script chmod(0755,"Make"); # # Finally, make sure to install a copy of f2c.h # system("cp $f2c_header f2c.h");