gen-gdblib-inc.sh 3.8 KB

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