gen-gdblib-inc.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/bash
  2. if [ "$1" != "" ]; then
  3. destdir=$1
  4. fi
  5. if [ "${PATHEXT}" != "" ]; then
  6. EXEEXT=.exe
  7. if [ "${DJDIR}" != "" ]; then
  8. libdir=${DJDIR}/lib
  9. else
  10. libdir=/lib
  11. fi
  12. else
  13. EXEEXT=
  14. libdir=/lib
  15. fi
  16. echo "Deleting gdb${EXEEXT} to force recompile"
  17. rm -f gdb${EXEEXT}
  18. echo "Rebuilding gdb${EXEEXT}"
  19. make gdb${EXEEXT} | tee make.log
  20. gdb_full_version=`sed -n "s:.*version.*\"\(.*\)\".*:\1:p" version.c`
  21. gdbcvs=`sed -n "s:.*version.*\"\(.*\)cvs\(.*\)\".*:\1cvs\2:p" version.c`
  22. gdb_version1=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1:p" version.c`
  23. gdb_version2=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\2:p" version.c`
  24. gdb_version=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1.\2:p" version.c`
  25. echo found full version is ${gdb_full_version}
  26. echo found version is ${gdb_version}
  27. if [ ${gdb_version2} -lt 10 ]; then
  28. gdbversion=${gdb_version1}0${gdb_version2}
  29. else
  30. gdbversion=${gdb_version1}${gdb_version2}
  31. fi
  32. if [ "${destdir}" == "" ]; then
  33. destdir=./libgdb
  34. fi
  35. if ! [ -d ${destdir} ]; then
  36. mkdir ${destdir}
  37. fi
  38. cat make.log | gawk '
  39. BEGIN {
  40. doprint=0
  41. }
  42. # We look for the compilation line
  43. # either gcc or cc
  44. /cc / { doprint=1; }
  45. {
  46. if ( doprint == 1 ) {
  47. print $0
  48. }
  49. }
  50. ! /\\$/ { doprint=0; }
  51. ' | tee comp-cmd.log
  52. # Try to locate all libraries
  53. echo Creating ./copy-libs.sh script
  54. cat comp-cmd.log |gawk -v destdir=${destdir} -v libdir=${libdir} '
  55. BEGIN {
  56. print "#!/bin/bash"
  57. print "# copy-libs.sh generated by awk script"
  58. print "if [ \"$1\" != \"\" ]; then"
  59. print " destdir=$1"
  60. print " ginstall -d ${destdir}"
  61. print "else"
  62. print " echo $0 destdir"
  63. print " echo destdir should be the location where libgdb.a"
  64. print " echo and all other archives should be copied"
  65. print " exit"
  66. print "fi"
  67. print "# Copy gdblib.inc file"
  68. print "cp gdblib.inc ${destdir}"
  69. }
  70. {
  71. nb = split ($0,list);
  72. for (i=1; i<=nb; i++) {
  73. if ( list[i] ~ /lib[^ ]*\.a/ ) {
  74. staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"\\1\\2 ","g",list[i]);
  75. print "cp " staticlib " ${destdir}";
  76. }
  77. if ( list[i] ~ /-l/ ) {
  78. systemlib = gensub (/-l([^ ]*)/,"lib\\1.a ","g",list[i]);
  79. print "systemlib=`find " libdir " -name " systemlib "`" ;
  80. print "if [ \"${systemlib}\" != \"\" ]; then";
  81. print "echo System lib found: ${systemlib}";
  82. print "cp ${systemlib} ${destdir}";
  83. print "else";
  84. print "echo Library " systemlib " not found, shared library assumed";
  85. print "fi";
  86. }
  87. }
  88. }
  89. ' | tee copy-libs.sh
  90. chmod u+x ./copy-libs.sh
  91. # For later
  92. echo Creating ./gdblib.inc file
  93. # Generate gdblib.inc file
  94. cat comp-cmd.log |gawk -v gdbcvs=${gdbcvs} -v destdir=${destdir} -v gdbversion=${gdbversion} '
  95. BEGIN {
  96. use_mingw=0;
  97. print "{ libgdb.inc file generated by awk script }"
  98. print "{$define GDB_V" gdbversion " }"
  99. if (gdbcvs) {
  100. print "{$define GDB_CVS}"
  101. }
  102. print "{$ifdef COMPILING_GDBINT_UNIT }"
  103. }
  104. {
  105. nb = split ($0,list);
  106. for (i=1; i<=nb; i++) {
  107. if ( list[i] ~ /lib[^ ]*\.a/ ) {
  108. staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"{$LINKLIB \\2} { found in \\1 }","g",list[i]);
  109. print staticlib;
  110. if ( list[i] ~/mingw/ ) {
  111. use_mingw=1
  112. }
  113. }
  114. if ( list[i] ~ /-l/ ) {
  115. systemlib = gensub (/-l([^ ]*)/,"{$LINKLIB \\1} { with -l gcc option}","g",list[i]);
  116. print systemlib;
  117. }
  118. }
  119. }
  120. END {
  121. print "{$endif COMPILING_GDBINT_UNIT }"
  122. print "{$undef NotImplemented}"
  123. if ( use_mingw == 1 ) {
  124. print "{$define USE_MINGW_GDB}"
  125. }
  126. }
  127. ' | tee gdblib.inc