Ticket #52: relaytool-stub-c.diff

File relaytool-stub-c.diff, 3.3 kB (added by res, 1 year ago)
  • bin/relaytool

    old new  
    366367     
    367368} 
    368369 
     370function fakerelay() { 
     371    lib="$1" 
     372    libname=$( echo $( basename "$lib" ) | sed 's/\.so.*//' | tr '-' '_' | tr '.' '_' ) 
     373    soname=$( objdump -x "$lib" |grep SONAME | awk '{print $2}' ) 
     374    outfile="$outdir/`basename "$soname"`.stub.c" 
     375 
     376    echo -n "$outfile" 
     377 
     378    cat <<EOF >"$outfile" 
     379/* automatically generated: `date` by `id -un`@`uname -n`, do not edit 
     380 * 
     381 * Built by relaytool, a program for building delay-load jumptables 
     382 * relaytool is (C) 2004 Mike Hearn <mike@navi.cx> 
     383 * See http://autopackage.org/ for details. 
     384 */ 
     385 
     386#ifdef __cplusplus 
     387    extern "C" { 
     388#endif 
     389 
     390/* 1 if present, 0 if not */ 
     391int ${libname}_is_present = 1; 
     392 
     393/* 1 if present, 0 if not, 0 with warning to stderr if lib not present or symbol not found */ 
     394int ${libname}_symbol_is_present(char * s) 
     395{ 
     396    return 1; 
     397} 
     398 
     399#ifdef __cplusplus 
     400    } 
     401#endif 
     402EOF 
     403     
     404} 
     405 
    369406no_replace=false 
    370407replace_all=false 
    371408arch_ok=false 
    372409arch_ptr_size=0 
     
    465506                        echo -n "$stubobj " 
    466507                    fi 
    467508 
     509                    echo -n "-l$lib " 
     510                     
     511                    spfound=true 
     512                    break; 
     513                fi 
     514            done 
     515 
     516            if ! $spfound; then 
     517                error could not find "$lib" in search path 
     518            fi 
     519        elif $found && ! $arch_ok; then 
     520            #echo -n "-Dlib${lib}_is_present -D\"lib${lib}_symbol_is_present(sym)=1\" $a " 
     521            #libname=$( echo $( basename "$lib" ) | sed 's/\.so.*//' | tr '-' '_' | tr '.' '_' ) 
     522            #echo -n "-Dlib${libname}_is_present -Dlib${libname}_symbol_is_present(sym)=1 $a "            
     523              
     524            # yes, so let's find its absolute filename by checking in each search path directory 
     525            spfound=false 
     526            for d in ${searchpath[@]}; do 
     527                if [ -e "$d/lib$lib.so" ]; then 
     528                 
     529                    absname=$( readfinallink "$d/lib$lib.so" ) 
     530                    if [ $? != 0 ] || [ ! -f "$absname" ]; then 
     531                        error broken symlink "$absname" 
     532                    fi 
     533                     
     534                    stubfile=$( fakerelay "$absname" ) 
     535 
     536                    # now we have to compile the stub 
     537                    if [ $? == 0 ]; then 
     538                        stubobj=$( echo "$stubfile" | sed 's/\.c$/\.o/' ) 
     539                        # remove -include flags from CFLAGS, if any 
     540                        CFLAGS=$( echo $CFLAGS | sed 's/-include .*\.h//g' ) 
     541                        ${CC:-gcc} ${CFLAGS} -fPIC -c -o "$stubobj" "$stubfile" 2>/dev/tty 
     542                        echo -n "$stubobj " 
     543                    fi 
     544 
    468545                    if $no_replace; then 
    469546                        echo -n "-l$lib " 
    470547                    fi 
     
    477554            if ! $spfound; then 
    478555                error could not find "$lib" in search path 
    479556            fi 
    480         elif $found && ! $arch_ok; then 
    481             echo -n "-Dlib${lib}_is_present -D\"lib${lib}_symbol_is_present(sym)=1\" $a " 
    482             libname=$( echo $( basename "$lib" ) | sed 's/\.so.*//' | tr '-' '_' | tr '.' '_' ) 
    483             echo -n "-Dlib${libname}_is_present -Dlib${libname}_symbol_is_present(sym)=1 $a "             
    484557        else 
    485558            echo -n "$a " 
    486559        fi