### Make supernovae files and libs
+#############################################################################
+### Add here every files that should not be supernovaed (generated files) ###
+#############################################################################
set(simgrid_fragile_sources
-src/gras/DataDesc/ddt_parse.yy.c
-src/surf/surfxml_parse.c
-src/xbt/graphxml_parse.c
-src/simdag/sd_daxloader.c
+ src/gras/DataDesc/ddt_parse.yy.c
+ src/surf/surfxml_parse.c
+ src/xbt/graphxml_parse.c
+ src/simdag/sd_daxloader.c
)
set(gras_fragile_sources
-src/gras/DataDesc/ddt_parse.yy.c
-src/xbt/graphxml_parse.c
+ src/gras/DataDesc/ddt_parse.yy.c
+ src/xbt/graphxml_parse.c
)
-set(temp_src_smpi "")
-set(temp_src_simgrid "")
-set(temp_src_gras "")
-if(enable_smpi)
- foreach(file ${SMPI_SRC})
- set(temp_src_smpi "${temp_src_smpi} ${file}")
- endforeach(file ${SMPI_SRC})
-endif(enable_smpi)
+#####################################################
+### END OF CONFIGURATION, NO NEED TO READ FURTHER ###
+#####################################################
-foreach(file ${simgrid_sources})
- set(en_plus yes)
- foreach(file_delete ${simgrid_fragile_sources})
- if(file_delete MATCHES "${file}")
- set(en_plus no)
- #message("${file}")
- endif(file_delete MATCHES "${file}")
- endforeach (file_delete ${simgrid_fragile_sources})
- if(en_plus)
- if(file MATCHES "src/xbt/log.c")
- set(file "xbt/log.c")
- endif(file MATCHES "src/xbt/log.c")
- set(temp_src_simgrid "${temp_src_simgrid} ${file}")
- endif(en_plus)
-endforeach(file ${simgrid_sources})
+### Rebuild the supernovae source files
-foreach(file ${gras_sources})
- set(en_plus yes)
- foreach(file_delete ${gras_fragile_sources})
- if(file_delete MATCHES "${file}")
- set(en_plus no)
- #message("${file}")
- endif(file_delete MATCHES "${file}")
- endforeach (file_delete ${gras_fragile_sources})
- if(en_plus)
- if(file MATCHES "src/xbt/log.c")
- set(file "xbt/log.c")
- endif(file MATCHES "src/xbt/log.c")
- set(temp_src_gras "${temp_src_gras} ${file}")
- endif(en_plus)
-endforeach(file ${gras_sources})
+set_source_files_properties(${PROJECT_DIRECTORY}/src/supernovae_sg.c;${PROJECT_DIRECTORY}/src/supernovae_gras.c;${PROJECT_DIRECTORY}/src/supernovae_smpi.c
+ PROPERTIES GENERATED true)
-exec_program("${CMAKE_COMMAND} -E remove -f ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${PROJECT_DIRECTORY}/src/supernovae_smpi.c" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/src/mk_supernovae.sh" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${temp_src_simgrid}" "${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SUPER_OK")
-exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${temp_src_gras}" "${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SUPER_OK")
-if(enable_smpi)
- exec_program("${PROJECT_DIRECTORY}/src/mk_supernovae.sh ${PROJECT_DIRECTORY}/src/supernovae_smpi.c ${temp_src_smpi}" "${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SUPER_OK")
-endif(enable_smpi)
+exec_program("${CMAKE_COMMAND} -E remove -f ${PROJECT_DIRECTORY}/src/supernovae_sg.c
+ ${PROJECT_DIRECTORY}/src/supernovae_gras.c
+ ${PROJECT_DIRECTORY}/src/supernovae_smpi.c"
+ OUTPUT_VARIABLE "SUPER_OK")
-add_library(simgrid SHARED ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${simgrid_fragile_sources})
+exec_program("chmod +x ${PROJECT_DIRECTORY}/src/mk_supernovae.pl" OUTPUT_VARIABLE "SUPER_OK")
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c
+ DEPENDS ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+ COMMAND perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c '--fragile=${simgrid_fragile_sources}' '${simgrid_sources}'
+ WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+ COMMENT "Generating supernovae_sg.c"
+)
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c
+ DEPENDS ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+ COMMAND perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c '--fragile=${gras_fragile_sources}' '${gras_sources}'
+ WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+ COMMENT "Generating supernovae_gras.c"
+)
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c
+ DEPENDS ${PROJECT_DIRECTORY}/src/mk_supernovae.pl
+ COMMAND perl ${PROJECT_DIRECTORY}/src/mk_supernovae.pl --out=${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c '${SMPI_SRC}'
+ WORKING_DIRECTORY ${PROJECT_DIRECTORY}
+ COMMENT "Generating supernovae_smpi.c"
+)
+
+### Make sure that the libs are built from the supernovae sources
+ add_library(simgrid SHARED ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c ${simgrid_fragile_sources})
+ add_dependencies(simgrid ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
+
if(enable_lib_static)
- add_library(simgrid_static STATIC ${PROJECT_DIRECTORY}/src/supernovae_sg.c ${simgrid_fragile_sources})
+ add_library(simgrid_static STATIC ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c ${simgrid_fragile_sources})
+ add_dependencies(simgrid_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_sg.c)
endif(enable_lib_static)
-add_library(gras SHARED ${PROJECT_DIRECTORY}/src/supernovae_gras.c ${gras_fragile_sources})
-if(enable_smpi)
- add_library(smpi SHARED ${PROJECT_DIRECTORY}/src/supernovae_smpi.c)
+
+ add_library(gras SHARED ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c ${gras_fragile_sources})
+ add_dependencies(gras ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_gras.c)
+
+ if(enable_smpi)
+ add_library(smpi SHARED ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
+ add_dependencies(smpi ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
if(enable_lib_static)
- add_library(smpi_static STATIC ${PROJECT_DIRECTORY}/src/supernovae_smpi.c)
- endif(enable_lib_static)
-endif(enable_smpi)
+ add_library(smpi_static STATIC ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
+ add_dependencies(smpi_static ${CMAKE_CURRENT_BINARY_DIR}/src/supernovae_smpi.c)
+ endif(enable_lib_static)
+ endif(enable_smpi)
--- /dev/null
+#! /usr/bin/perl
+
+use strict;
+use Getopt::Long qw(GetOptions);
+
+#open TMP,">mk_supernovae.pl.args";
+#map {print TMP "$_ "} @ARGV;
+#close TMP;
+
+sub usage($) {
+ my $ret;
+ print "USAGE: mk_supernovae.pl [--fragile=file]* --out=file file1 file2*\n";
+ print " --help: show this message\n";
+ print " --fragile=file: specify that file is fragile and shouldn't be supernovaed\n";
+ print " --out=file: specify the name of the output file\n";
+ print "elements may be separated by semi-columns (;) instead of spaces, too\n";
+ exit $ret;
+}
+
+my @fragile_files=undef;
+my $outfile=undef;
+my $help;
+
+Getopt::Long::config('permute','no_getopt_compat', 'no_auto_abbrev');
+GetOptions(
+ 'help|h' => \$help,
+
+ 'fragile=s' =>\@fragile_files,
+ 'out=s' =>\$outfile) or usage(1);
+
+@fragile_files = split(/;/,join(';',@fragile_files));
+@fragile_files = split(/ /,join(' ',@fragile_files));
+
+usage(0) if (defined($help));
+unless(defined($outfile)) {
+ print "ERROR: No outfile defined.\n";
+ usage(1);
+}
+
+#print "mk_supernovae: generate $outfile\n";
+
+open OUT, ">$outfile" or die "ERROR: cannot open $outfile: $!\n";
+
+print OUT <<EOF
+#define SUPERNOVAE_MODE 1
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE /* for getline() with older libc */
+#endif
+#include <ctype.h>
+#include "portable.h"
+#include "xbt.h"
+
+EOF
+ ;
+
+sub readfile($) {
+ my $filename=shift;
+ open IN,"$filename" || die "ERROR: cannot read $filename: $!\n";
+ my $res;
+ while (<IN>) {
+ $res .= $_;
+ }
+ close IN;
+ return $res;
+}
+
+
+my %fragile;
+map {$fragile{$_}=1} @fragile_files;
+my @args = split(/;/,join(';',@ARGV));
+@args = split(/ /,join(' ',@args));
+my $nbfile=0;
+foreach my $file (@args) {
+ if ($fragile{$file}) {
+ print "mk_supernovae: $file is fragile, skip it\n";
+ next;
+ }
+# print "mk_supernovae: process $file\n";
+ $nbfile++;
+
+ my $needundef=1;
+ print OUT "/* file $file */\n";
+ if ($file eq "xbt/log.c") {
+ print OUT " #define _simgrid_log_category__default &_simgrid_log_category__log\n";
+ } else {
+ my $ctn = readfile($file);
+ if ($ctn =~ m/XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY/s) {
+ my $default=$ctn;
+ $default =~ s/.*XBT_LOG_[^ ]*?DEFAULT_[^ ]*?CATEGORY[^(]*\(([^,)]*).*$/$1/s;
+ print OUT " #define _simgrid_log_category__default &_simgrid_log_category__$default\n";
+ } else {
+ print OUT " /* no default category in file $file */\n";
+ $needundef = 0;
+ }
+ }
+ print OUT " #include \"$file\"\n";
+ print OUT " #undef _simgrid_log_category__default\n" if $needundef;
+ print OUT "\n";
+}
+close OUT;
+print "mk_supernovae: $outfile contains $nbfile files inlined\n";