blob: 7212cece207fddfe38b62caf62435dbc74024d80 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001#!/usr/bin/perl -w
2
3# ompts_makeHeader [options] -f=NAME -t=DIR
4#
5# Creats the headerfile for the OpenMP-Testsuite out of the templatefiles
6# witch are in the default/explicitely specified dir and the settings in the
7# given config file.
8#
9# ATTENTION:
10# At the moment it builts only a c-headerfile!
11#
12# -f=FILENAME: Using file FILENAME as configfile
13# -t=DIR: Directory holding the template files
14#
15# options
16# -i=FILENAME: Include other Headerfile. The files to be included must be specified
17# after setting this option. (Not implemented yet.)
18# -o=FILENAME: outputfilename (default is "omp_testsuite.h")
19
20$headerfile = "\/\* Global headerfile of the OpenMP Testsuite \*\/\n\n\/\* This file was created with the ompts_makeHeader.pl script using the following opions:\ *\/\n\/\* ";
21if(@ARGV > 0)
22{
23 foreach $opt (@ARGV)
24 {
25 $headerfile .= "$opt ";
26 }
27}
28else
29{
30 $headerfile .= "No options were specified";
31}
32$headerfile .=" \*\/\n\n\n";
33
34use Getopt::Long;
35GetOptions("-o=s" => \$outfile, "-f=s" =>\$configfile, "-t=s" => \$templatedir, "-i=s" => \$include);
36
37$include = "";
38
39
40# Getting and verifying the necessary options:
41if(!$configfile) {
42 die "Config file name is missing.";
43}
44else {
45 if (!(-e $configfile)) {
46 die "Could not find config file $configfile.";
47 }
48}
49
50if(!$templatedir) {
51 die "Directoryname is missing.";
52}
53
54if(!$outfile){
55 $outfile = "omp_testsuite.h"; # setting default value for the headerfile
56}
57
58
59
60#@includefiles; # list holing extra includefiles specified by the user
61
62
63# generating the head of the includeguard:
64$headerfile .= "\#ifndef OMP_TESTSUITE_H\n\#define OMP_TESTSUITE_H\n\n";
65
66# inserting general settings out of the configfile:
67open(OMPTS_CONF,$configfile) or die "Could not open the global config file $configfile.";
68while(<OMPTS_CONF>){
69 $headerfile .= $_;
70}
71close(OMPTS_CONF);
72
73# searching the tests:
74opendir TEMPLATEDIR, $templatedir or die "Could not open dir $templatedir.";
75@templates = grep /(.*)\.c/, readdir TEMPLATEDIR;
76closedir TEMPLATEDIR;
77
78# inserting the function declarations:
79foreach $template (@templates){
80 $source = "";
81 open(TEMPLATE,$templatedir."/".$template) or die "Could not open the following sourcefile: ".$templatedir."/".$template;
82 while(<TEMPLATE>){
83 $source .= $_;
84 }
85 close(TEMPLATE);
86 $source =~ /\<ompts\:testcode\:functionname\>(.*)\<\/ompts\:testcode\:functionname\>/;
87 $functionname = $1."(FILE \* logfile);";
88 $source =~ /\<ompts\:directive\>(.*)\<\/ompts\:directive\>/;
89 $directive = $1;
90 $headerfile .= "int test_".$functionname." /* Test for ".$directive." */\n";
91 $headerfile .= "int crosstest_".$functionname." /* Crosstest for ".$directive." */\n";
92}
93
94# inserting the end of the includeguard:
95$headerfile .= "\n#endif";
96
97# craeting the headerfile:
98open(OUTFILE,">".$outfile) or die "Could not create the haedaerfile ($outfile)";
99print OUTFILE $headerfile."\n";
100close(OUTFILE);
101