123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #!/usr/bin/env bash
- usage ()
- {
- echo "Script used to easily create collection of libraries needed"
- echo "to generate a Free Pascal IDE with debugger support."
- echo "Usage: Copy this script to the directory where you just compile"
- echo "a specific GNU debugger (for a specific target)"
- echo "and run ./$0 in that directory"
- echo "After, you will need to run a second script, copy-libs.sh"
- echo "with a single parameter specifying to which directory the libraries"
- echo "should be copied."
- echo "Possible parameters for this script:"
- echo "--forcestatic, to convert all -lname into $LINKLIB libname.a"
- echo "implicitlibs=\"space separated list if system librairies used\""
- }
- if [ "$1" == "--help" ]; then
- usage
- exit
- fi
- if [ "$1" == "--forcestatic" ]; then
- echo "Using only static libraries in gdblib.inc"
- forcestatic=1
- shift
- else
- forcestatic=0
- fi
- if [ "${1#implicitlibs=}" != "$1" ]; then
- implicitlibs=${1#implicitlibs=}
- echo "Also adding implicit libs \"$implicitlibs\""
- shift
- fi
- if [ "$1" != "" ]; then
- echo "Unrecognized option \"$1\""
- usage
- fi
- if [ "${PATHEXT}" != "" ]; then
- EXEEXT=.exe
- if [ "${DJDIR}" != "" ]; then
- libdir=${DJDIR}/lib
- else
- libdir=/lib
- fi
- else
- EXEEXT=
- libdir=/lib
- fi
- if [ "$OSTYPE" == "msys" ]; then
- echo "MSYS system detected"
- in_msys=1
- fi
- echo "Deleting gdb${EXEEXT} to force recompile"
- rm -f gdb${EXEEXT}
- echo "Rebuilding gdb${EXEEXT}"
- MAKE=`which gmake 2> /dev/null`
- if [ "${MAKE}" == "" ]; then
- MAKE=make
- fi
- ${MAKE} gdb${EXEEXT} | tee make.log
- gdb_full_version=`sed -n "s:.*version.*\"\(.*\)\".*:\1:p" version.c`
- gdbcvs=`sed -n "s:.*version.*\"\(.*\)cvs\(.*\)\".*:\1cvs\2:p" version.c`
- gdb_version1=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1:p" version.c`
- gdb_version2=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\2:p" version.c`
- gdb_version=`sed -n "s:.*version.*\"\([0-9]*\)\.\([0-9]*\).*:\1.\2:p" version.c`
- echo found full version is ${gdb_full_version}
- echo found version is ${gdb_version}
- if [ ${gdb_version2} -lt 10 ]; then
- gdbversion=${gdb_version1}0${gdb_version2}
- else
- gdbversion=${gdb_version1}${gdb_version2}
- fi
- cat make.log | gawk '
- BEGIN {
- doprint=0
- }
- # We look for the compilation line
- # either gcc or cc
- /cc / { doprint=1; }
- {
- if ( doprint == 1 ) {
- print $0
- }
- }
- ! /\\$/ { doprint=0; }
- ' | tee comp-cmd.log
- gcccompiler=`sed -n "s:\([A-Za-z0-9_-]*gcc\) .*:\1:p" comp-cmd.log`
- if [ "$gcccompiler" != "" ]; then
- gcclibs=`$gcccompiler -print-search-dirs | sed -n "s#.*libraries: =\(.*\)#\1#p" `
- if [ "$gcclibs" != "" ]; then
- if [ $in_msys -eq 1 ]; then
- # If we are on msys, gcc is mingw, so that it uses c:/dir
- # while find is an msys utility that needs /c/dir path
- # we do this conversion below
- for let in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
- gcclibs=${gcclibs//$let:/\/$let}
- done
- for let in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
- gcclibs=${gcclibs//$let:/\/$let}
- done
- libdir=${gcclibs//;/ }
- else
- # if ; is present in gcclibs,assume this is the separator instead of :
- if [ "${gcclibs//;/ }" != "${gcclibs}" ]; then
- if [ "${gcclibs// /_}" != "${gccclibs}" ]; then
- # list also contains spaces, convert ' ' into '\ '
- gcclibs=${gcclibs// /\\ }
- fi
- libdir=${gcclibs//;/ }
- else
- libdir=${gcclibs//:/ }
- fi
- fi
- echo "gcc libs are \"$libdir\""
- fi
- fi
- # Try to locate all libraries
- echo Creating ./copy-libs.sh script
- cat comp-cmd.log | gawk -v libdir="${libdir}" -v implibs="${implicitlibs}" '
- BEGIN {
- print "#!/usr/bin/env bash"
- print "# copy-libs.sh generated by awk script"
- print "INSTALL=`which ginstall 2> /dev/null `"
- print "if [ "$INSTALL" == "" ]; then"
- print " INSTALL=install"
- print "fi"
- print "if [ \"$1\" != \"\" ]; then"
- print " destdir=$1"
- print " $INSTALL -d ${destdir}"
- print "else"
- print " echo $0 destdir"
- print " echo destdir should be the location where libgdb.a"
- print " echo and all other archives should be copied"
- print " exit"
- print "fi"
- print "# Copy gdblib.inc file"
- print "cp -p gdblib.inc ${destdir}"
- }
- {
- nb = split ($0,list);
- for (i=1; i<=nb; i++) {
- if ( list[i] ~ /lib[^ ]*\.a/ ) {
- print "# Looking for static libs"
- staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"\\1\\2 ","g",list[i]);
- print "cp -p " staticlib " ${destdir}";
- }
- if ( list[i] ~ /lib[^ ]*\.so/ ) {
- dynamiclib = gensub (/([^ ]*)(lib[^ ]*\.so)/,"\\1\\2 ","g",list[i]);
- print "echo " dynamiclib " found";
- }
- if ( list[i] ~ /-l/ ) {
- print "#Looking for shared libs"
- systemlib = gensub (/-l([^ ]*)/,"lib\\1.a ","g",list[i]);
- print "systemlib=`find " libdir " -name " systemlib " -print -quit 2> /dev/null `" ;
- print "if [ \"${systemlib}\" != \"\" ]; then";
- print " echo System lib found: ${systemlib}";
- print " cp -p ${systemlib} ${destdir}";
- print "else";
- print " echo Library " systemlib " not found, shared library assumed";
- print "fi";
- }
- }
- }
- END {
- nb = split (implibs,list);
- for (i=1;i<=nb; i++) {
- systemlib = "lib" list[i] ".a";
- print "echo Adding system library " systemlib;
- print "systemlib=`find " libdir " -name " systemlib " -print -quit 2> /dev/null `" ;
- print "if [ \"${systemlib}\" != \"\" ]; then";
- print " echo System lib found: ${systemlib}";
- print " cp -p ${systemlib} ${destdir}";
- print "else";
- print " echo Library " systemlib " not found, shared library assumed";
- print "fi";
- }
- }
- ' | tee copy-libs.sh
- chmod u+x ./copy-libs.sh
- # For later
- echo Creating ./gdblib.inc file
- # Generate gdblib.inc file
- cat comp-cmd.log |gawk -v gdbcvs=${gdbcvs} -v implibs="${implicitlibs}" \
- -v gdbversion=${gdbversion} -v forcestatic=${forcestatic} '
- BEGIN {
- use_mingw=0;
- print "{ libgdb.inc file generated by awk script }"
- print "{$define GDB_V" gdbversion " }"
- if (gdbcvs) {
- print "{$define GDB_CVS}"
- }
- print "{$ifdef COMPILING_GDBINT_UNIT }"
- }
- {
- nb = split ($0,list);
- for (i=1; i<=nb; i++) {
- if ( list[i] ~ /lib[^ ]*\.a/ ) {
- staticlib = gensub (/([^ ]*)(lib[^ ]*\.a)/,"{$LINKLIB \\2} { found in \\1 }","g",list[i]);
- print staticlib;
- if ( list[i] ~/mingw/ ) {
- use_mingw=1
- }
- }
- if ( list[i] ~ /-D__USE_MINGW_/ ) {
- use_mingw=1
- }
- if ( list[i] ~ /lib[^ ]*\.so/ ) {
- dynamiclib = gensub (/([^ ]*)(lib[^ ]*\.so)/,"{$LINKLIB \\2} { found in \\1 }","g",list[i]);
- librarypath = gensub (/([^ ]*)(lib[^ ]*\.so)/,"{$LIBRARYPATH \\1} { for \\2 }","g",list[i]);
- print dynamiclib;
- print librarypath;
- }
- if ( list[i] ~ /-l/ ) {
- systemlib = gensub (/-l([^ ]*)/,"\\1","g",list[i]);
- if (forcestatic == 1) {
- systemlib="lib" systemlib ".a"
- }
- print "{$LINKLIB " systemlib "} { with -l gcc option}";
- }
- }
- }
- END {
- nb = split (implibs,list);
- for (i=1;i<=nb; i++) {
- if ( list[i] ~ /lib.*\.a/ ) {
- lib=list[i];
- } else {
- if ( forcestatic == 1 ) {
- lib="lib" list[i] ".a";
- } else {
- lib=list[i];
- }
- }
- print "{$LINKLIB " lib "} { implicit library } "
- }
- print "{$endif COMPILING_GDBINT_UNIT }"
- print "{$undef NotImplemented}"
- if ( use_mingw == 1 ) {
- print "{$define USE_MINGW_GDB}"
- }
- }
- ' | tee gdblib.inc
|