initfini.awk 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #! /usr/bin/awk -f
  2. # Contributed by Christian MICHON <christian_michon@yahoo.fr> to
  3. # eliminate the compile time dependancy on perl introduced by
  4. # Erik's older initfini.pl
  5. # vim:ai:sw=2:
  6. BEGIN \
  7. { alignval="";
  8. endp=0;
  9. end=0;
  10. system("touch crt[in].S");
  11. system("/bin/rm -f crt[in].S");
  12. omitcrti=0;
  13. omitcrtn=0;
  14. glb_idx = 0;
  15. while(getline < "initfini.s")
  16. { if(/\.endp/) {endp=1}
  17. if(/\.end/) {end=1}
  18. if(/\.align/) {alignval=$2}
  19. # here comes some special stuff for the SuperH targets
  20. # We search for all labels, which uses the _GLOBAL_OFFSET_TABLE_
  21. # definition, and store them in the glb_label array.
  22. if(/_GLOBAL_OFFSET_TABLE_/) {
  23. glb_label[glb_idx] = last;
  24. glb_idx += 1;
  25. glb = $0;
  26. }
  27. last = $1;
  28. }
  29. close("initfini.s");
  30. }
  31. # special rules for the SuperH targets (They do nothing on other targets)
  32. /SH_GLB_BEGINS/ && glb_idx==0 {omitcrti +=1}
  33. /_init_SH_GLB/ && glb_idx>=1 {print glb_label[0] glb >> "crti.S"}
  34. /_fini_SH_GLB/ && glb_idx>=2 {print glb_label[1] glb >> "crti.S"}
  35. /SH_GLB_ENDS/ && glb_idx==0 {omitcrti -=1}
  36. /SH_GLB/ || /_GLOBAL_OFFSET_TABLE_/{getline}
  37. # special rules for H8/300 (sorry quick hack)
  38. /.h8300h/ {end=0}
  39. # rules for all targets
  40. /HEADER_ENDS/{omitcrti=1;omitcrtn=1;getline}
  41. /PROLOG_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  42. /i_am_not_a_leaf/{getline}
  43. /_init:/||/_fini:/{omitcrtn=1}
  44. /PROLOG_PAUSES/{omitcrti=1;getline}
  45. /PROLOG_UNPAUSES/{omitcrti=0;getline}
  46. /PROLOG_ENDS/{omitcrti=1;getline}
  47. /EPILOG_BEGINS/{omitcrtn=0;getline}
  48. /EPILOG_ENDS/{omitcrtn=1;getline}
  49. /TRAILER_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  50. /END_INIT/ \
  51. { if(endp)
  52. { gsub("END_INIT",".endp _init",$0)
  53. }
  54. else
  55. { if(end)
  56. { gsub("END_INIT",".end _init",$0)
  57. }
  58. else
  59. { gsub("END_INIT","",$0)
  60. }
  61. }
  62. }
  63. /END_FINI/ \
  64. { if(endp)
  65. { gsub("END_FINI",".endp _fini",$0)
  66. }
  67. else
  68. { if(end)
  69. { gsub("END_FINI",".end _fini",$0)
  70. }
  71. else
  72. { gsub("END_FINI","",$0)
  73. }
  74. }
  75. }
  76. /ALIGN/ \
  77. { if(alignval!="")
  78. { gsub("ALIGN",sprintf(".align %s",alignval),$0)
  79. }
  80. else
  81. { gsub("ALIGN","",$0)
  82. }
  83. }
  84. omitcrti==0 {print >> "crti.S"}
  85. omitcrtn==0 {print >> "crtn.S"}
  86. END \
  87. { close("crti.S");
  88. close("crtn.S");
  89. }