initfini.awk 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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("/bin/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. # rules for all targets
  38. /HEADER_ENDS/{omitcrti=1;omitcrtn=1;getline}
  39. /PROLOG_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  40. /i_am_not_a_leaf/{getline}
  41. /_init:/||/_fini:/{omitcrtn=1}
  42. /PROLOG_PAUSES/{omitcrti=1;getline}
  43. /PROLOG_UNPAUSES/{omitcrti=0;getline}
  44. /PROLOG_ENDS/{omitcrti=1;getline}
  45. /EPILOG_BEGINS/{omitcrtn=0;getline}
  46. /EPILOG_ENDS/{omitcrtn=1;getline}
  47. /TRAILER_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  48. /END_INIT/ \
  49. { if(endp)
  50. { gsub("END_INIT",".endp _init",$0)
  51. }
  52. else
  53. { if(end)
  54. { gsub("END_INIT",".end _init",$0)
  55. }
  56. else
  57. { gsub("END_INIT","",$0)
  58. }
  59. }
  60. }
  61. /END_FINI/ \
  62. { if(endp)
  63. { gsub("END_FINI",".endp _fini",$0)
  64. }
  65. else
  66. { if(end)
  67. { gsub("END_FINI",".end _fini",$0)
  68. }
  69. else
  70. { gsub("END_FINI","",$0)
  71. }
  72. }
  73. }
  74. /ALIGN/ \
  75. { if(alignval!="")
  76. { gsub("ALIGN",sprintf(".align %s",alignval),$0)
  77. }
  78. else
  79. { gsub("ALIGN","",$0)
  80. }
  81. }
  82. omitcrti==0 {print >> "crti.S"}
  83. omitcrtn==0 {print >> "crtn.S"}
  84. END \
  85. { close("crti.S");
  86. close("crtn.S");
  87. }