home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / src / clisp-link.in < prev    next >
Encoding:
Text File  |  1994-12-20  |  4.3 KB  |  121 lines

  1. #!/bin/sh
  2. # Usage: clisp-link command [more args]
  3. # where   command = link, add-module
  4. # Bruno Haible 19.10.1994
  5.  
  6. usage () {
  7. echo "Usage: $0 command ..." 2>&1
  8. exit 1
  9. }
  10.  
  11. with_dynamic_modules='@with_dynamic_modules@'
  12.  
  13. if [ $# = 0 ] ; then
  14.   usage
  15. fi
  16.  
  17. case "$1" in
  18.   link)
  19.     # Usage: clisp-link link dir
  20.     if [ $# != 2 ] ; then
  21.       echo "Usage: $0 link dir" 2>&1
  22.       exit 1
  23.     fi
  24.     dir="$2"
  25.     # Read the variables CC, CFLAGS, CLFLAGS, LIBS, X_LIBS, FILES
  26.     . "$dir"/makevars
  27.     if [ -z "$with_dynamic_modules" ] ; then
  28.       # Generate new modules.o, compiled from modules.c, includes modules.h
  29.       ${CC} ${CFLAGS} -I"$dir" -Ilinkkit -c linkkit/modules.c -o "$dir"/modules.o
  30.       # Generate new lisp.run
  31.       (cd "$dir" ; ${CC} ${CFLAGS} ${CLFLAGS} modules.o lisp.a ${LIBS} ${X_LIBS} -o lisp.run)
  32.     else
  33.       (cd "$dir" ; ${CC} ${CFLAGS} ${CLFLAGS} lisp.a ${LIBS} ${X_LIBS} -o lisp.run)
  34.     fi
  35.     ;;
  36.   add-module)
  37.     # Usage: clisp-link add-module modulename source-dir destination-dir
  38.     if [ $# != 4 ] ; then
  39.       echo "Usage: $0 add-module modulename source-dir destination-dir" 2>&1
  40.       exit 1
  41.     fi
  42.     modulename="$2"
  43.     sourcedir="$3"
  44.     destinationdir="$4"
  45.     if [ ! -d "$sourcedir" ] ; then
  46.       echo "$0: $sourcedir is not a directory" 2>&1
  47.       exit 1
  48.     fi
  49.     if [ ! -f "$destinationdir" ] ; then
  50.       mkdir "$destinationdir"
  51.     fi
  52.     if [ ! -d "$destinationdir" ] ; then
  53.       echo "$0: $destinationdir is not a directory" 2>&1
  54.       exit 1
  55.     fi
  56.     absolute_sourcedir=`cd "$sourcedir" ; /bin/pwd`
  57.     absolute_destinationdir=`cd "$destinationdir" ; /bin/pwd`
  58.     if [ "$absolute_sourcedir" = "$absolute_destinationdir" ] ; then
  59.       echo "$0: directories $sourcedir and $destinationdir may not be the same" 2>&1
  60.       exit 1
  61.     fi
  62.     if [ ! -r "$sourcedir"/lisp.a -o ! -x "$sourcedir"/lisp.run -o ! -r "$sourcedir"/lispinit.mem -o ! -r "$sourcedir"/modules.h -o ! -r "$sourcedir"/makevars ] ; then
  63.       echo "$0: directory $sourcedir does not contain a clisp link kit" 2>&1
  64.       exit 1
  65.     fi
  66.     if [ ! -r linkkit/modules.d -o ! -r linkkit/modules.c -o ! -r linkkit/clisp.h ] ; then
  67.       echo "$0: cannot find modules.d, modules.c, clisp.h" 2>&1
  68.       exit 1
  69.     fi
  70.     if [ ! -r "$modulename/link1.sh" -o ! -r "$modulename/link2.sh" ] ; then
  71.       echo "$0: illegal module name $modulename" 2>&1
  72.       exit 1
  73.     fi
  74.     # Read the variables CC, CFLAGS, CLFLAGS, LIBS, X_LIBS, FILES
  75.     . "$sourcedir"/makevars
  76.     # Prepare the module directory and read the variable NEW_FILES
  77.     . "$modulename"/link1.sh
  78.     if [ -z "$with_dynamic_modules" ] ; then
  79.       # Generate new modules.h
  80.       (cat "$sourcedir"/modules.h ; echo 'MODULE('"$modulename"')') > "$destinationdir"/modules.h
  81.     else
  82.       if [ ! -f "$modulename"/"$modulename"_module.o ] ; then
  83.         # Generate "$modulename"/"$modulename"_module.o
  84.         ${CC} ${CFLAGS} -Ilinkkit -DMODULE="$modulename" -c linkkit/module.cc -o "$modulename"/"$modulename"_module.o
  85.       fi
  86.       NEW_FILES="$modulename"_module.o" $NEW_FILES"
  87.     fi
  88.     # Generate new lisp.a
  89.     for f in ${FILES}; do
  90.       ln "$sourcedir"/$f "$destinationdir"/$f || \
  91.       ln -s "$absolute_sourcedir"/$f "$destinationdir"/$f || \
  92.       cp "$sourcedir"/$f "$destinationdir"/$f
  93.     done
  94.     # Generate other libraries
  95.     for f in ${NEW_FILES}; do
  96.       ln "$modulename"/$f "$destinationdir"/$f || \
  97.       ln -s `/bin/pwd`/"$modulename"/$f "$destinationdir"/$f || \
  98.       cp "$modulename"/$f "$destinationdir"/$f
  99.     done
  100.     # Update the LIBS and FILES variables
  101.     LIBS=${NEW_FILES}' '${LIBS}
  102.     FILES=${FILES}' '${NEW_FILES}
  103.     if [ -z "$with_dynamic_modules" ] ; then
  104.       # Generate new modules.o, compiled from modules.c, includes new modules.h
  105.       ${CC} ${CFLAGS} -I"$destinationdir" -Ilinkkit -c linkkit/modules.c -o "$destinationdir"/modules.o
  106.     fi
  107.     # Generate new lisp.run
  108.     if [ -z "$with_dynamic_modules" ] ; then
  109.       (cd "$destinationdir" ; ${CC} ${CFLAGS} ${CLFLAGS} modules.o lisp.a ${LIBS} ${X_LIBS} -o lisp.run)
  110.     else
  111.       (cd "$destinationdir" ; ${CC} ${CFLAGS} ${CLFLAGS} lisp.a ${LIBS} ${X_LIBS} -o lisp.run)
  112.     fi
  113.     # Generate new lispinit.mem
  114.     . "$modulename"/link2.sh
  115.     # Generate new makevars
  116.     sed -e "s,^LIBS=.*\$,LIBS='${LIBS}'," -e "s,^FILES=.*\$,FILES='${FILES}'," < "$sourcedir"/makevars > "$destinationdir"/makevars
  117.     ;;
  118.   *) usage;;
  119. esac
  120.  
  121.