Some perl scripts to fix headers in windows. Not yet perfect
This commit was SVN r2942.
Этот коммит содержится в:
родитель
a8764a7155
Коммит
8c5626cd66
125
contrib/fix_headers.pl
Исполняемый файл
125
contrib/fix_headers.pl
Исполняемый файл
@ -0,0 +1,125 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
if (scalar(@ARGV) != 1) {
|
||||
print "Usage:
|
||||
./fix_headers.pl <header_file_list>\n";
|
||||
exit(3);
|
||||
}
|
||||
|
||||
$header_file = @ARGV[0];
|
||||
$temp_file = "/tmp/temp.c";
|
||||
|
||||
open(HEADERS, "$header_file") || print "Could not open $header_file\n";
|
||||
open(MOD_FILES, "> modified_files.txt") || print "Could not open modified.txt\n";
|
||||
|
||||
while (<HEADERS>) {
|
||||
|
||||
#open all the c files
|
||||
#check if this header is present
|
||||
#if it is present, then substitute it with the protection
|
||||
|
||||
|
||||
$header_string = $_;
|
||||
chomp($header_string);
|
||||
$protection = $_;
|
||||
$protection =~ s/\./_/;
|
||||
$protection =~ s/\//_/;
|
||||
$protection =~ s/#include//;
|
||||
$protection =~ tr/a-z/A-z/;
|
||||
$protection =~ s/\s<//;
|
||||
$protection =~ s/>//;
|
||||
$protection = "HAVE_" . $protection;
|
||||
|
||||
print $protection;
|
||||
|
||||
$string_to_replace = "#ifdef $protection$_#endif\n";
|
||||
|
||||
print $string_to_replace;
|
||||
|
||||
open(C_FILES, "find . -name *.c |") || print "find failed\n";
|
||||
while (<C_FILES>) {
|
||||
$c_file = $_;
|
||||
if (not /mca/) {
|
||||
open(C_FILE, "$c_file") || print "Open failed on $c_file\n";
|
||||
chomp($protection);
|
||||
|
||||
#ensure that this protection has not been already put in place
|
||||
$protected = 0;
|
||||
$written_to_file = 0;
|
||||
|
||||
while (<C_FILE>) {
|
||||
if (/$protection/) {
|
||||
$protected = 1;
|
||||
}
|
||||
}
|
||||
close (C_FILE);
|
||||
if ($protected == 0) {
|
||||
#this file is not yet protected
|
||||
open(C_FILE, "$c_file") || print "Open failed on $c_file\n";
|
||||
open(TEMP, "> $temp_file") || print "Open failed on temp.c \n";
|
||||
|
||||
while (<C_FILE>) {
|
||||
if (/$header_string/) {
|
||||
print TEMP $string_to_replace;
|
||||
print "Replacing defintion ---- $c_file";
|
||||
if ($written_to_file == 0) {
|
||||
print MOD_FILES $c_file;
|
||||
$written_to_file = 1;
|
||||
}
|
||||
} else {
|
||||
print TEMP $_;
|
||||
}
|
||||
}
|
||||
close (TEMP_C);
|
||||
system("cp $temp_file $c_file");
|
||||
}
|
||||
}
|
||||
}
|
||||
close (C_FILES);
|
||||
|
||||
#Now to do the same for header files
|
||||
open(H_FILES, "find . -name *.h |") || print "find failed\n";
|
||||
while (<H_FILES>) {
|
||||
|
||||
$h_file = $_;
|
||||
if (not /mca/) {
|
||||
open(H_FILE, "$h_file") || print "Open failed on $h_file\n";
|
||||
chomp($protection);
|
||||
|
||||
#ensure that this protection has not been already put in place
|
||||
$protected = 0;
|
||||
$written_to_file = 0;
|
||||
|
||||
while (<H_FILE>) {
|
||||
if (/$protection/) {
|
||||
$protected = 1;
|
||||
}
|
||||
}
|
||||
close (H_FILE);
|
||||
if ($protected == 0) {
|
||||
#this file is not yet protected
|
||||
open(H_FILE, "$h_file") || print "Open failed on $h_file\n";
|
||||
open(TEMP, "> $temp_file") || print "Open failed on temp.c \n";
|
||||
|
||||
while (<H_FILE>) {
|
||||
if (/$header_string/) {
|
||||
print TEMP $string_to_replace;
|
||||
print "Replacing defintion ---- $h_file";
|
||||
if ($written_to_file == 0) {
|
||||
print MOD_FILES $h_file;
|
||||
$written_to_file = 1;
|
||||
}
|
||||
} else {
|
||||
print TEMP $_;
|
||||
}
|
||||
}
|
||||
close (TEMP_C);
|
||||
system("cp $temp_file $h_file");
|
||||
}
|
||||
}
|
||||
}
|
||||
close (H_FILES);
|
||||
}
|
||||
close(HEADERS);
|
||||
close(MOD_FILES);
|
||||
system("rm -f $temp_file");
|
161
contrib/test_headers_in_ompi.pl
Исполняемый файл
161
contrib/test_headers_in_ompi.pl
Исполняемый файл
@ -0,0 +1,161 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
#this is the perl scripty foo which does the following tasks
|
||||
# 1. Extract the #include <*.h> files which are present in both header and source files
|
||||
# 2. Do some basic formatting
|
||||
# 3. Check if these included files are present on the platform which has been given
|
||||
|
||||
if (scalar(@ARGV) != 2) {
|
||||
print "Usage:
|
||||
./depend.pl <compiler-name>\n";
|
||||
exit(3);
|
||||
}
|
||||
|
||||
$includes_file = "headers.txt";
|
||||
$return = &get_header_files($includes_file);
|
||||
|
||||
$test_file = "test_headers.txt";
|
||||
$return = &parse_header_files($includes_file, $test_file);
|
||||
|
||||
$source_tree = @ARGV[0];
|
||||
$CC = @ARGV[1];
|
||||
$result_file = "results.txt";
|
||||
$return = &test_for_headers($test_file, $result_file, $CC);
|
||||
|
||||
# this file is used to extract which header files are included in a particular
|
||||
# source file. Kind of a neat implementation
|
||||
sub get_header_files {
|
||||
|
||||
local($dump_file) = @_;
|
||||
|
||||
open(C_FILES, "find $source_tree -name \*.c |") || print "could not find source files\n";
|
||||
open(H_FILES, "find $source_tree -name \*.c |") || print "could not find header files\n";
|
||||
|
||||
open(DUMP, "> $dump_file") || print "Could not open $dump_file\n";
|
||||
|
||||
while (<C_FILES>) {
|
||||
$file_h = $_;
|
||||
print DUMP "Processing $file_h";
|
||||
open(FILE_H, "$file_h") || print "could not open file for reading\n";
|
||||
|
||||
#grep for the pattern which we want
|
||||
while (<FILE_H>) {
|
||||
if (/#include </) {
|
||||
print DUMP $_, "\n";
|
||||
}
|
||||
}
|
||||
print DUMP "=============================================================================\n"
|
||||
}
|
||||
|
||||
while (<H_FILES>) {
|
||||
$file_h = $_;
|
||||
print DUMP "Processing $file_h";
|
||||
open(FILE_H, "$file_h") || print "could not open file for reading\n";
|
||||
|
||||
#grep for the pattern which we want
|
||||
while (<FILE_H>) {
|
||||
if (/#include </) {
|
||||
print DUMP $_, "\n";
|
||||
}
|
||||
}
|
||||
print DUMP "=============================================================================\n"
|
||||
}
|
||||
|
||||
close (C_FILES);
|
||||
close (H_FILES);
|
||||
close (DUMP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#this simply constructs the header file list from dump and dump_pl and then checks whether all the
|
||||
#header files are present
|
||||
sub parse_header_files {
|
||||
|
||||
local($includes_file, $test_file) = @_;
|
||||
|
||||
open(SOURCE,"$includes_file") || print "Could not open $includes_file for reading\n";
|
||||
open(DUMP,"> $test_file") || print "Could not open $test_file for reading\n";
|
||||
|
||||
while (<SOURCE>) {
|
||||
if (/#include </){
|
||||
print DUMP $_;
|
||||
}
|
||||
}
|
||||
|
||||
close(SOURCE);
|
||||
close(DUMP);
|
||||
|
||||
|
||||
#remove all the unnecessary comments from headers.txt
|
||||
open (HEADER, "$test_file") || print "Could not open $test_file for reading\n";
|
||||
open(TEMP, "> temp.txt") || print "Could not open temp.txt for writing\n";
|
||||
|
||||
while(<HEADER>) {
|
||||
#remove leading white spaces
|
||||
s/^\s*//;
|
||||
#remove anything after <*.h>
|
||||
s/>{1,1}.*\n/>\n/;
|
||||
#remove anything before #include
|
||||
s/^.*#include/#include/;
|
||||
print TEMP $_;
|
||||
}
|
||||
|
||||
close(HEADER);
|
||||
close(TEMP);
|
||||
|
||||
#remove duplicate occurences of the file
|
||||
system("sort temp.txt | uniq > $test_file");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#this suroutine is used to test if a particular header is present or absent in a particular language
|
||||
sub test_for_headers {
|
||||
|
||||
local($test_file, $result_file, $CC) = @_;
|
||||
local($temp) = "temp.c";
|
||||
|
||||
print "CC = $CC\n";
|
||||
|
||||
open(HEADER, "$test_file") || print "Could not open $test_file for reading\n";
|
||||
open(RESULTS, "> $result_file") || print "Could not open $result_file for writing\n";
|
||||
|
||||
while(<HEADER>) {
|
||||
print $_;
|
||||
|
||||
#create the file for compilation
|
||||
chomp $_;
|
||||
$string = "
|
||||
|
||||
$_ /*this is the include file to be tested for*/
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
";
|
||||
|
||||
open(TEMP, "> $temp") || print "Could not open $temp for writing\n";
|
||||
print TEMP $string;
|
||||
close(TEMP);
|
||||
|
||||
$compiled = system("$CC $temp");
|
||||
|
||||
if ($compiled == 0) {
|
||||
print "$_ is present\n";
|
||||
} else {
|
||||
print RESULTS "$_\n";
|
||||
}
|
||||
|
||||
system("rm -Rf $temp");
|
||||
system("rm -Rf temp.*");
|
||||
|
||||
}
|
||||
|
||||
close(HEADER);
|
||||
close(RESULTS);
|
||||
|
||||
return 0;
|
||||
}
|
Загрузка…
x
Ссылка в новой задаче
Block a user