preprocess.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # // (C) Copyright Tobias Schwinger
  2. # //
  3. # // Use modification and distribution are subject to the boost Software License
  4. # // Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
  5. # // Preprocess and run this script.
  6. # //
  7. # // Invocation example using the GNU preprocessor:
  8. # //
  9. # // g++ -I$BOOST_ROOT -x c++ preprocess.pl -E |perl
  10. # //
  11. # // or in two steps:
  12. # //
  13. # // g++ -I$BOOST_ROOT -x c++ preprocess.pl -E >temp.pl
  14. # // perl temp.pl
  15. #define die(x) 1
  16. die("ERROR: this script has to be preprocessed, stopped");
  17. #undef die
  18. use strict vars;
  19. use File::Spec updir,curdir,catfile,canonpath,splitpath,file_name_is_absolute;
  20. # // --- Settings
  21. my $up = File::Spec->updir();
  22. # // Relative path to the destination directory.
  23. my $path = File::Spec->catdir($up,$up,$up,'boost','typeof');
  24. my $license = qq@
  25. /\/ Copyright (C) 2005 Arkadiy Vertleyb
  26. /\/ Copyright (C) 2005 Peder Holt
  27. /\/
  28. /\/ Use modification and distribution are subject to the boost Software License,
  29. /\/ Version 1.0. (See http:/\/www.boost.org/LICENSE_1_0.txt).
  30. /\/ Preprocessed code, do not edit manually !
  31. @;
  32. # //---
  33. # // Find this script's directory if run directly from the shell (not piped)
  34. $path = File::Spec->canonpath
  35. ( File::Spec->catfile
  36. ( File::Spec->file_name_is_absolute($0)
  37. ? $0 : (File::Spec->curdir(),$0)
  38. , $up
  39. , File::Spec->splitpath($path)
  40. )
  41. ) unless ($0 eq '-');
  42. die
  43. ( ($0 eq '-')
  44. ? "ERROR: please run from this script's directory, stopped"
  45. : "ERROR: target directoty not found, stopped"
  46. ) unless (-d $path);
  47. # // Tidy up the contents and write it to a file
  48. sub write_down(name,contents)
  49. {
  50. my($name,$contents) = @_;
  51. my $filename = $name;
  52. my $fqfname = File::Spec->catfile($path,$filename);
  53. $contents =~ s"(((\n|^)\s*\#[^\n]+)|(\s*\n)){2,}"\n"g; # "
  54. print STDERR "Writing file: '$filename'\n";
  55. open my($file),">$fqfname"
  56. or die "ERROR: unable to open file '$filename' for writing, stopped";
  57. print $file $license;
  58. print $file $contents;
  59. close $file;
  60. }
  61. # // Include external components to ensure they don't end up in the recorded
  62. # // output
  63. #define BOOST_TYPEOF_PP_INCLUDE_EXTERNAL
  64. my $sewer = <<'%--%-EOF-%--%'
  65. #include <boost/typeof/vector.hpp>
  66. #undef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  67. %--%-EOF-%--%
  68. ; $sewer = '';
  69. #define BOOST_TYPEOF_PREPROCESSING_MODE
  70. #define BOOST_TYPEOF_LIMIT_SIZE 50
  71. #define BOOST_TYPEOF_PP_NEXT_SIZE 100
  72. &write_down('vector50.hpp',<<'%--%-EOF-%--%'
  73. #include <boost/typeof/vector.hpp>
  74. %--%-EOF-%--%
  75. );
  76. #undef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  77. #undef BOOST_TYPEOF_LIMIT_SIZE
  78. #define BOOST_TYPEOF_LIMIT_SIZE 100
  79. #define BOOST_TYPEOF_PP_NEXT_SIZE 149
  80. &write_down('vector100.hpp',<<'%--%-EOF-%--%'
  81. #include <boost/typeof/vector.hpp>
  82. %--%-EOF-%--%
  83. );
  84. #undef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  85. #undef BOOST_TYPEOF_LIMIT_SIZE
  86. #define BOOST_TYPEOF_LIMIT_SIZE 150
  87. #define BOOST_TYPEOF_PP_NEXT_SIZE 199
  88. &write_down('vector150.hpp',<<'%--%-EOF-%--%'
  89. #include <boost/typeof/vector.hpp>
  90. %--%-EOF-%--%
  91. );
  92. #undef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  93. #undef BOOST_TYPEOF_LIMIT_SIZE
  94. #define BOOST_TYPEOF_LIMIT_SIZE 200
  95. #define BOOST_TYPEOF_PP_NEXT_SIZE 250
  96. &write_down('vector200.hpp',<<'%--%-EOF-%--%'
  97. #include <boost/typeof/vector.hpp>
  98. %--%-EOF-%--%
  99. );