4 use Getopt::Long qw(GetOptions);
6 #open TMP,">mk_supernovae.pl.args";
7 #map {print TMP "$_ "} @ARGV;
12 print "USAGE: mk_supernovae.pl [--fragile=file]* --out=file file1 file2*\n";
13 print " --help: show this message\n";
14 print " --fragile=file: specify that file is fragile and shouldn't be supernovaed\n";
15 print " --out=file: specify the name of the output file\n";
16 print "elements may be separated by semi-columns (;) instead of spaces, too\n";
20 my @fragile_files=undef;
24 Getopt::Long::config('permute','no_getopt_compat', 'no_auto_abbrev');
28 'fragile=s' =>\@fragile_files,
29 'out=s' =>\$outfile) or usage(1);
31 @fragile_files = split(/;/,join(';',@fragile_files));
32 @fragile_files = split(/ /,join(' ',@fragile_files));
34 usage(0) if (defined($help));
35 unless(defined($outfile)) {
36 print "ERROR: No outfile defined.\n";
40 #print "mk_supernovae: generate $outfile\n";
42 open OUT, ">$outfile" or die "ERROR: cannot open $outfile: $!\n";
45 #define SUPERNOVAE_MODE 1
47 # define _GNU_SOURCE /* for getline() with older libc */
58 open IN,"$filename" || die "ERROR: cannot read $filename: $!\n";
69 map {$fragile{$_}=1} @fragile_files;
70 my @args = split(/;/,join(';',@ARGV));
71 @args = split(/ /,join(' ',@args));
73 foreach my $file (@args) {
74 if ($fragile{$file}) {
75 print "mk_supernovae: $file is fragile, skip it\n";
78 # print "mk_supernovae: process $file\n";
82 print OUT "/* file $file */\n";
83 if ($file eq "xbt/log.c") {
84 print OUT " #define _simgrid_log_category__default &_simgrid_log_category__log\n";
86 my $ctn = readfile($file);
87 if ($ctn =~ m/XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY/s) {
89 $default =~ s/.*XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY[^(]*\(([^,)]*).*$/$1/s;
90 print OUT " #define _simgrid_log_category__default &_simgrid_log_category__$default\n";
92 print OUT " /* no default category in file $file */\n";
96 print OUT " #include \"$file\"\n";
97 print OUT " #undef _simgrid_log_category__default\n" if $needundef;
101 print "mk_supernovae: $outfile contains $nbfile files inlined\n";