forked from open-mpi/ompi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_headers_in_ompi.pl
executable file
·178 lines (135 loc) · 4.88 KB
/
test_headers_in_ompi.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/perl
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
#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;
}