gen-gdblib-inc.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #!/usr/bin/env bash
  2. if [ "$1" == "--help" ]; then
  3. echo "Script used to easily create collection of libraries needed"
  4. echo "to generate a Free Pascal IDE with debugger support."
  5. echo "Usage: Copy this script to the directory where you just compile"
  6. echo "a specific GNU debugger (for a specific target)"
  7. echo "and run ./$0 in that directory"
  8. echo "After, you will need to run a second script, copy-libs.sh"
  9. echo "with a single parameter specifying to which directory the libraries"
  10. echo "should be copied."
  11. echo "Possible parameters for this script:"
  12. echo "implicitlibs=\"space separated list if system librairies used\""
  13. fi
  14. if [ "${1#implicitlibs=}" != "$1" ]; then
  15. implicitlibs=${1#implicitlibs=}
  16. echo "Also adding implicit libs \"$implicitlibs\""
  17. fi
  18. if [ "${PATHEXT}" != "" ]; then
  19. EXEEXT=.exe
  20. if [ "${DJDIR}" != "" ]; then
  21. libdir=${DJDIR}/lib
  22. else
  23. libdir=/lib
  24. fi
  25. else
  26. EXEEXT=
  27. libdir=/lib
  28. fi
  29. echo "Deleting gdb${EXEEXT} to force recompile"
  30. rm -f gdb${EXEEXT}
  31. echo "Rebuilding gdb${EXEEXT}"
  32. MAKE=`which gmake 2> /dev/null`
  33. if [ "${MAKE}" == "" ]; then
  34. MAKE=make
  35. fi
  36. ${MAKE} gdb${EXEEXT} | tee make.log
  37. gdb_full_version=`sed -n "s:.*version.*\"\(.*\)\".*:\1:p" version.c`
  38. gdbcvs=`sed -n "s:.*version.*\"\(.*\)cvs\(.*\)\".*:\1cvs\2:p" version.c`
  39. gdb_version1=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1:p" version.c`
  40. gdb_version2=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\2:p" version.c`
  41. gdb_version=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1.\2:p" version.c`
  42. echo found full version is ${gdb_full_version}
  43. echo found version is ${gdb_version}
  44. if [ ${gdb_version2} -lt 10 ]; then
  45. gdbversion=${gdb_version1}0${gdb_version2}
  46. else
  47. gdbversion=${gdb_version1}${gdb_version2}
  48. fi
  49. cat make.log | gawk '
  50. BEGIN {
  51. doprint=0
  52. }
  53. # We look for the compilation line
  54. # either gcc or cc
  55. /cc / { doprint=1; }
  56. {
  57. if ( doprint == 1 ) {
  58. print $0
  59. }
  60. }
  61. ! /\\$/ { doprint=0; }
  62. ' | tee comp-cmd.log
  63. gcccompiler=`sed -n "s:\([A-Za-z0-9_-]*gcc\) .*:\1:p" comp-cmd.log`
  64. if [ "$gcccompiler" != "" ]; then
  65. gcclibs=`$gcccompiler -print-search-dirs | sed -n "s#.*libraries: =\(.*\)#\1#p" `
  66. if [ "$gcclibs" != "" ]; then
  67. libdir=${gcclibs//:/ }
  68. echo "gcc libs are \"$libdir\""
  69. fi
  70. fi
  71. # Try to locate all libraries
  72. echo Creating ./copy-libs.sh script
  73. cat comp-cmd.log | gawk -v libdir="${libdir}" -v implibs="${implicitlibs}" '
  74. BEGIN {
  75. print "#!/usr/bin/env bash"
  76. print "# copy-libs.sh generated by awk script"
  77. print "INSTALL=`which ginstall 2> /dev/null `"
  78. print "if [ "$INSTALL" == "" ]; then"
  79. print " INSTALL=install"
  80. print "fi"
  81. print "if [ \"$1\" != \"\" ]; then"
  82. print " destdir=$1"
  83. print " $INSTALL -d ${destdir}"
  84. print "else"
  85. print " echo $0 destdir"
  86. print " echo destdir should be the location where libgdb.a"
  87. print " echo and all other archives should be copied"
  88. print " exit"
  89. print "fi"
  90. print "# Copy gdblib.inc file"
  91. print "cp gdblib.inc ${destdir}"
  92. }
  93. {
  94. nb = split ($0,list);
  95. for (i=1; i<=nb; i++) {
  96. if ( list[i] ~ /lib[^ ]*\.a/ ) {
  97. staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"\\1\\2 ","g",list[i]);
  98. print "cp " staticlib " ${destdir}";
  99. }
  100. if ( list[i] ~ /lib[^ ]*\.so/ ) {
  101. dynamiclib = gensub (/([^ ]*)(lib[^ ]*\.so)/,"\\1\\2 ","g",list[i]);
  102. print "echo " dynamiclib " found";
  103. }
  104. if ( list[i] ~ /-l/ ) {
  105. systemlib = gensub (/-l([^ ]*)/,"lib\\1.a ","g",list[i]);
  106. print "systemlib=`find " libdir " -name " systemlib " 2> /dev/null `" ;
  107. print "if [ \"${systemlib}\" != \"\" ]; then";
  108. print " echo System lib found: ${systemlib}";
  109. print " cp ${systemlib} ${destdir}";
  110. print "else";
  111. print " echo Library " systemlib " not found, shared library assumed";
  112. print "fi";
  113. }
  114. }
  115. }
  116. END {
  117. nb = split (implibs,list);
  118. for (i=1;i<=nb; i++) {
  119. systemlib = "lib" list[i] ".a";
  120. print "echo Adding system library " systemlib;
  121. print "systemlib=`find " libdir " -name " systemlib " 2> /dev/null `" ;
  122. print "if [ \"${systemlib}\" != \"\" ]; then";
  123. print " echo System lib found: ${systemlib}";
  124. print " cp ${systemlib} ${destdir}";
  125. print "else";
  126. print " echo Library " systemlib " not found, shared library assumed";
  127. print "fi";
  128. }
  129. }
  130. ' | tee copy-libs.sh
  131. chmod u+x ./copy-libs.sh
  132. # For later
  133. echo Creating ./gdblib.inc file
  134. # Generate gdblib.inc file
  135. cat comp-cmd.log |gawk -v gdbcvs=${gdbcvs} -v implibs="${implicitlibs}" \
  136. -v gdbversion=${gdbversion} '
  137. BEGIN {
  138. use_mingw=0;
  139. print "{ libgdb.inc file generated by awk script }"
  140. print "{$define GDB_V" gdbversion " }"
  141. if (gdbcvs) {
  142. print "{$define GDB_CVS}"
  143. }
  144. print "{$ifdef COMPILING_GDBINT_UNIT }"
  145. }
  146. {
  147. nb = split ($0,list);
  148. for (i=1; i<=nb; i++) {
  149. if ( list[i] ~ /lib[^ ]*\.a/ ) {
  150. staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"{$LINKLIB \\2} { found in \\1 }","g",list[i]);
  151. print staticlib;
  152. if ( list[i] ~/mingw/ ) {
  153. use_mingw=1
  154. }
  155. }
  156. if ( list[i] ~ /-D__USE_MINGW_/ ) {
  157. use_mingw=1
  158. }
  159. if ( list[i] ~ /lib[^ ]*\.so/ ) {
  160. dynamiclib = gensub (/([^ ]*)(lib[^ ]*\.so)/,"{$LINKLIB \\2} { found in \\1 }","g",list[i]);
  161. librarypath = gensub (/([^ ]*)(lib[^ ]*\.so)/,"{$LIBRARYPATH \\1} { for \\2 }","g",list[i]);
  162. print dynamiclib;
  163. print librarypath;
  164. }
  165. if ( list[i] ~ /-l/ ) {
  166. systemlib = gensub (/-l([^ ]*)/,"{$LINKLIB \\1} { with -l gcc option}","g",list[i]);
  167. print systemlib;
  168. }
  169. }
  170. }
  171. END {
  172. nb = split (implibs,list);
  173. for (i=1;i<=nb; i++) {
  174. print "{$LINKLIB " list[i] "} { implicit library } "
  175. }
  176. print "{$endif COMPILING_GDBINT_UNIT }"
  177. print "{$undef NotImplemented}"
  178. if ( use_mingw == 1 ) {
  179. print "{$define USE_MINGW_GDB}"
  180. }
  181. }
  182. ' | tee gdblib.inc