Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | #!/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\/\* "; |
| 21 | if(@ARGV > 0) |
| 22 | { |
| 23 | foreach $opt (@ARGV) |
| 24 | { |
| 25 | $headerfile .= "$opt "; |
| 26 | } |
| 27 | } |
| 28 | else |
| 29 | { |
| 30 | $headerfile .= "No options were specified"; |
| 31 | } |
| 32 | $headerfile .=" \*\/\n\n\n"; |
| 33 | |
| 34 | use Getopt::Long; |
| 35 | GetOptions("-o=s" => \$outfile, "-f=s" =>\$configfile, "-t=s" => \$templatedir, "-i=s" => \$include); |
| 36 | |
| 37 | $include = ""; |
| 38 | |
| 39 | |
| 40 | # Getting and verifying the necessary options: |
| 41 | if(!$configfile) { |
| 42 | die "Config file name is missing."; |
| 43 | } |
| 44 | else { |
| 45 | if (!(-e $configfile)) { |
| 46 | die "Could not find config file $configfile."; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if(!$templatedir) { |
| 51 | die "Directoryname is missing."; |
| 52 | } |
| 53 | |
| 54 | if(!$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: |
| 67 | open(OMPTS_CONF,$configfile) or die "Could not open the global config file $configfile."; |
| 68 | while(<OMPTS_CONF>){ |
| 69 | $headerfile .= $_; |
| 70 | } |
| 71 | close(OMPTS_CONF); |
| 72 | |
| 73 | # searching the tests: |
| 74 | opendir TEMPLATEDIR, $templatedir or die "Could not open dir $templatedir."; |
| 75 | @templates = grep /(.*)\.c/, readdir TEMPLATEDIR; |
| 76 | closedir TEMPLATEDIR; |
| 77 | |
| 78 | # inserting the function declarations: |
| 79 | foreach $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: |
| 98 | open(OUTFILE,">".$outfile) or die "Could not create the haedaerfile ($outfile)"; |
| 99 | print OUTFILE $headerfile."\n"; |
| 100 | close(OUTFILE); |
| 101 | |