123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #!/usr/bin/perl
- use strict;
- use Getopt::Long;
- my($initfini) = "initfini.s";
- my($crti) = "crti.S";
- my($crtn) = "crtn.S";
- my($alignval) = "";
- my($endp) = 0;
- my($end) = 0;
- my($omitcrti) = 0;
- my($omitcrtn) = 0;
- my($discard) = 0;
- my($line);
- # Get commandline parameters
- Getopt::Long::Configure("no_ignore_case", "bundling");
- &GetOptions( "initfini=s" => \$initfini,
- "crti=s" => \$crti,
- "crtn=s" => \$crtn,
- );
- chomp($initfini);
- chomp($crti);
- chomp($crtn);
- if ($initfini) {
- open(INITFINI,"<$initfini") or
- die "(fatal) Can't open $initfini$!";
- } else {
- die "(fatal) Please give me an --initfini argument$!";
- }
- while(<INITFINI>) {
- if (/\.endp/) {
- $endp=1;
- next;
- }
- if (/\.end/) {
- $end=1;
- next;
- }
- if (/\.align(.*)/) {
- $alignval=$1;
- next;
- }
- }
- close(INITFINI);
- if ($initfini) {
- open(INITFINI,"<$initfini") or
- die "(fatal) Can't open $initfini$!";
- } else {
- die "(fatal) Please give me an --initfini argument$!";
- }
- if ($crti) {
- open(CRTI,">$crti") or
- die "(fatal) Can't open $crti$!";
- } else {
- die "(fatal) Please give me a --asm argument$!";
- }
- if ($crtn) {
- open(CRTN,">$crtn") or
- die "(fatal) Can't open $crtn$!";
- } else {
- die "(fatal) Please give me a --asm argument$!";
- }
- while(<INITFINI>) {
- if (/HEADER_ENDS/) {
- $omitcrti = 1;
- $omitcrtn = 1;
- next;
- }
- if (/PROLOG_BEGINS/) {
- $omitcrti = 0;
- $omitcrtn = 0;
- next;
- }
- if (/^i_am_not_a_leaf/) {
- $discard = 1;
- next;
- }
- if (/^_init:/ || /^_fini:/) {
- $omitcrtn = 1;
- }
- if (/PROLOG_PAUSES/) {
- $omitcrti = 1;
- next;
- }
- if (/PROLOG_UNPAUSES/) {
- $omitcrti = 0;
- next;
- }
- if (/PROLOG_ENDS/) {
- $omitcrti = 1;
- next;
- }
- if (/EPILOG_BEGINS/) {
- $omitcrtn = 0;
- next;
- }
- if (/EPILOG_ENDS/) {
- $omitcrtn = 1;
- next;
- }
- if (/TRAILER_BEGINS/) {
- $omitcrti = 0;
- $omitcrtn = 0;
- next;
- }
- if (/END_INIT/) {
- if ($endp) {
- s/END_INIT/.endp _init/;
- } else {
- if($end) {
- s/END_INIT/.end _init/;
- } else {
- s/END_INIT//;
- }
- }
- }
- if (/END_FINI/) {
- if ($endp) {
- s/END_FINI/.endp _fini/;
- } else {
- if($end) {
- s/END_FINI/.end _fini/;
- } else {
- s/END_FINI//;
- }
- }
- }
- if (/ALIGN/) {
- if($alignval) {
- s/ALIGN/.align $alignval/;
- } else {
- s/ALIGN//;
- }
- }
- if (!$omitcrti && !$discard) {
- print CRTI;
- }
- if (!$omitcrtn && !$discard) {
- print CRTN;
- }
- $discard = 0;
- }
- close(INITFINI);
- close(CRTI);
- close(CRTN);
|