initfini.pl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/perl
  2. use strict;
  3. use Getopt::Long;
  4. my($initfini) = "initfini.s";
  5. my($crti) = "crti.S";
  6. my($crtn) = "crtn.S";
  7. my($alignval) = "";
  8. my($endp) = 0;
  9. my($end) = 0;
  10. my($omitcrti) = 0;
  11. my($omitcrtn) = 0;
  12. my($line);
  13. # Get commandline parameters
  14. Getopt::Long::Configure("no_ignore_case", "bundling");
  15. &GetOptions( "initfini=s" => \$initfini,
  16. "crti=s" => \$crti,
  17. "crtn=s" => \$crtn,
  18. );
  19. chomp($initfini);
  20. chomp($crti);
  21. chomp($crtn);
  22. if ($initfini) {
  23. open(INITFINI,"<$initfini") or
  24. die "(fatal) Can't open $initfini$!";
  25. } else {
  26. die "(fatal) Please give me an --initfini argument$!";
  27. }
  28. while($line = <INITFINI>) {
  29. if ($line =~ /^\w\.endp/) {
  30. $endp=1;
  31. next;
  32. }
  33. if ($line =~ /^\w\.end/) {
  34. $end=1;
  35. next;
  36. }
  37. if ($line =~ /\w\.align\(.*\)/) {
  38. $alignval=$1;
  39. next;
  40. }
  41. }
  42. close(INITFINI);
  43. if ($initfini) {
  44. open(INITFINI,"<$initfini") or
  45. die "(fatal) Can't open $initfini$!";
  46. } else {
  47. die "(fatal) Please give me an --initfini argument$!";
  48. }
  49. if ($crti) {
  50. open(CRTI,">$crti") or
  51. die "(fatal) Can't open $crti$!";
  52. } else {
  53. die "(fatal) Please give me a --asm argument$!";
  54. }
  55. if ($crtn) {
  56. open(CRTN,">$crtn") or
  57. die "(fatal) Can't open $crtn$!";
  58. } else {
  59. die "(fatal) Please give me a --asm argument$!";
  60. }
  61. while(<INITFINI>) {
  62. if (/HEADER_ENDS/) {
  63. $omitcrti = 1;
  64. $omitcrtn = 1;
  65. next;
  66. }
  67. if (/PROLOG_BEGINS/) {
  68. $omitcrti = 0;
  69. next;
  70. }
  71. if (/PROLOG_PAUSES/) {
  72. $omitcrti = 1;
  73. next;
  74. }
  75. if (/PROLOG_UNPAUSES/) {
  76. $omitcrti = 0;
  77. next;
  78. }
  79. if (/PROLOG_ENDS/) {
  80. $omitcrti = 1;
  81. next;
  82. }
  83. if (/EPILOG_BEGINS/) {
  84. $omitcrtn = 0;
  85. next;
  86. }
  87. if (/EPILOG_ENDS/) {
  88. $omitcrtn = 1;
  89. next;
  90. }
  91. if (/TRAILER_BEGINS/) {
  92. $omitcrti = 0;
  93. $omitcrtn = 0;
  94. next;
  95. }
  96. if (/END_INIT/) {
  97. if ($endp) {
  98. s/END_INIT/.endp _init/;
  99. } else {
  100. if($end) {
  101. s/END_INIT/.end _init/;
  102. } else {
  103. s/END_INIT//;
  104. }
  105. }
  106. }
  107. if (/END_FINI/) {
  108. if ($endp) {
  109. s/END_FINI/.endp _fini/;
  110. } else {
  111. if($end) {
  112. s/END_FINI/.end _fini/;
  113. } else {
  114. s/END_FINI//;
  115. }
  116. }
  117. }
  118. if (/ALIGN/) {
  119. if($alignval) {
  120. s/ALIGN/.align $alignval/;
  121. } else {
  122. s/ALIGN//;
  123. }
  124. }
  125. if (!$omitcrti) {
  126. print CRTI;
  127. }
  128. if (!$omitcrtn) {
  129. print CRTN;
  130. }
  131. }
  132. close(INITFINI);
  133. close(CRTI);
  134. close(CRTN);