home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / slo.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-09-16  |  4.2 KB  |  179 lines

  1. #!/bin/sh
  2. ##
  3. ##  slo.h -- (S)eparate (L)inker (O)ptions by library class
  4. ##  Written by Ralf S. Engelschall <rse@apache.org>
  5. ##
  6. #
  7. # This script falls under the Apache License.
  8. # See http://www.apache.org/docs/LICENSE
  9.  
  10.  
  11. DIFS='     
  12. '
  13.  
  14. #   
  15. #   parse out -L and -l options from command line
  16. #
  17. DIRS=''
  18. LIBS=''
  19. ARGV=''
  20. optprev=""
  21. OIFS="$IFS" IFS="$DIFS"
  22. for opt
  23. do
  24.     #   concatenate with previous option if exists
  25.     if [ ".$optprev" != . ]; then
  26.         opt="${optprev}${opt}";
  27.         optprev=''
  28.     fi
  29.     #   remember options for arg when used stand-alone
  30.     if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then
  31.         optprev="$opt"
  32.         continue;
  33.     fi
  34.     #   split argument into option plus option argument
  35.     arg="`echo $opt | cut -c3-`"
  36.     opt="`echo $opt | cut -c1-2`"
  37.     #   store into containers
  38.     case $opt in
  39.         -L) DIRS="$DIRS:$arg" ;;
  40.         -l) LIBS="$LIBS:$arg" ;;
  41.          *) ARGV="$ARGV $opt" ;;
  42.     esac
  43. done
  44. IFS="$OIFS"
  45.  
  46. #
  47. #   set linker default directories
  48. #
  49. DIRS_DEFAULT='/lib:/usr/lib'
  50. if [ ".$LD_LIBRARY_PATH" != . ]; then
  51.     DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
  52. fi
  53.  
  54. #
  55. #   sort options by class
  56. #
  57. DIRS_OBJ=''
  58. LIBS_OBJ=''
  59. DIRS_PIC=''
  60. LIBS_PIC=''
  61. DIRS_DSO=''
  62. LIBS_DSO=''
  63.  
  64. #    for each library...
  65. OIFS="$IFS" IFS=':'
  66. for lib in $LIBS; do
  67.     [ ".$lib" = . ] && continue
  68.  
  69.     found='no'
  70.     found_indefdir='no'
  71.     found_type=''
  72.     found_dir=''
  73.  
  74.     #    for each directory...
  75.     OIFS2="$IFS" IFS=":$DIFS"
  76.     for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
  77.         [ ".$dir" = . ] && continue
  78.         [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
  79.         [ ! -d $dir ] && continue
  80.  
  81.         #    search the file
  82.         OIFS3="$IFS" IFS="$DIFS"
  83.         for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do
  84.              [ ".$file" = . ] && continue
  85.              case $file in
  86.                  *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
  87.                       found=yes;
  88.                       found_type=DSO; 
  89.                       break 
  90.                       ;;
  91.                  *.lo|*.la )
  92.                       found=yes;
  93.                       found_type=PIC 
  94.                       ;;
  95.                  *.a )
  96.                       if [ ".$found_type" = . ]; then
  97.                           found=yes
  98.                           found_type=OBJ 
  99.                       fi
  100.                       ;;
  101.              esac
  102.         done
  103.         IFS="$OIFS3"
  104.         if [ ".$found" = .yes ]; then
  105.             found_dir="$dir"
  106.             break
  107.         fi
  108.     done
  109.     IFS="$OIFS2"
  110.  
  111.     if [ ".$found" = .yes ]; then
  112.         if [ ".$found_indefdir" != .yes ]; then
  113.             eval "dirlist=\"\${DIRS_${found_type}}:\""
  114.             if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then
  115.                 eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\""
  116.             fi
  117.             eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  118.         else
  119.             eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  120.         fi
  121.     else
  122.         LIBS_OBJ="$LIBS_OBJ:$lib"
  123.         #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
  124.         #echo "splitlibs:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
  125.         #echo "splitlibs:Warning: $dirlist" 1>&1
  126.     fi
  127. done
  128. IFS="$OIFS"
  129.  
  130. #
  131. #   also pass-through unused dirs even if it's useless
  132. #
  133. OIFS="$IFS" IFS=':'
  134. for dir in $DIRS; do
  135.     dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
  136.     if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then
  137.         DIRS_OBJ="$DIRS_OBJ:$dir"
  138.     fi
  139. done
  140. IFS="$OIFS"
  141.  
  142. #
  143. #   reassemble the options but seperated by type
  144. #
  145. OIFS="$IFS" IFS="$DIFS"
  146. for type in OBJ PIC DSO; do
  147.     OIFS2="$IFS" IFS=':'
  148.     eval "libs=\"\$LIBS_${type}\""
  149.     opts=''
  150.     for lib in $libs; do
  151.         [ ".$lib" = . ] && continue
  152.         opts="$opts -l$lib"
  153.     done
  154.     eval "LIBS_${type}=\"$opts\""
  155.  
  156.     eval "dirs=\"\$DIRS_${type}\""
  157.     opts=''
  158.     for dir in $dirs; do
  159.         [ ".$dir" = . ] && continue
  160.         opts="$opts -L$dir"
  161.     done
  162.     eval "DIRS_${type}=\"$opts\""
  163.     IFS="$OIFS2"
  164. done
  165. IFS="$OIFS"
  166.  
  167. #
  168. #   give back results
  169. #
  170. OIFS="$IFS" IFS="$DIFS"
  171. for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
  172.     eval "val=\"\$${var}\""
  173.     val="`echo $val | sed -e 's/^ *//'`"
  174.     echo "SLO_${var}=\"${val}\""
  175. done
  176. IFS="$OIFS"
  177.  
  178. ##EOF##
  179.