3 # Copyright (c) 2010-2011, 2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
10 use Getopt::Long qw(GetOptions);
12 #open TMP,">mk_supernovae.pl.args";
13 #map {print TMP "$_ "} @ARGV;
18 print "USAGE: mk_supernovae.pl [--fragile=file]* --out=file file1 file2*\n";
19 print " --help: show this message\n";
20 print " --fragile=file: specify that file is fragile and shouldn't be supernovaed\n";
21 print " --out=file: specify the name of the output file\n";
22 print "elements may be separated by semi-columns (;) instead of spaces, too\n";
26 my @fragile_files=undef;
30 Getopt::Long::config('permute','no_getopt_compat', 'no_auto_abbrev');
34 'fragile=s' =>\@fragile_files,
35 'out=s' =>\$outfile) or usage(1);
37 @fragile_files = split(/;/,join(';',@fragile_files));
38 @fragile_files = split(/ /,join(' ',@fragile_files));
40 usage(0) if (defined($help));
41 unless(defined($outfile)) {
42 print "ERROR: No outfile defined.\n";
46 #print "mk_supernovae: generate $outfile\n";
48 open OUT, ">$outfile" or die "ERROR: cannot open $outfile: $!\n";
51 #define SUPERNOVAE_MODE 1
53 # define _GNU_SOURCE /* for getline() with older libc */
56 # define _SVID_SOURCE /* strdup() */
58 #ifndef _ISOC99_SOURCE
59 # define _ISOC99_SOURCE /* isfinite() */
61 #ifndef _ISO_C99_SOURCE
62 # define _ISO_C99_SOURCE /* isfinite() */
73 open IN,"$filename" || die "ERROR: cannot read $filename: $!\n";
84 map {$fragile{$_}=1} @fragile_files;
85 my @args = split(/;/,join(';',@ARGV));
86 @args = split(/ /,join(' ',@args));
88 foreach my $file (@args) {
89 if ($fragile{$file}) {
90 print "mk_supernovae: $file is fragile, skip it\n";
93 # print "mk_supernovae: process $file\n";
97 print OUT "/* file $file */\n";
98 if ($file eq "xbt/log.c") {
99 print OUT " #define _simgrid_log_category__default &_simgrid_log_category__log\n";
101 my $ctn = readfile($file);
102 if ($ctn =~ m/XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY/s) {
104 $default =~ s/.*XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY[^(]*\(([^,)]*).*$/$1/s;
105 print OUT " #define _simgrid_log_category__default &_simgrid_log_category__$default\n";
107 print OUT " /* no default category in file $file */\n";
111 print OUT " #include \"$file\"\n";
112 print OUT " #undef _simgrid_log_category__default\n" if $needundef;
116 print "mk_supernovae: $outfile contains $nbfile files inlined\n";