1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/bin/bash
# proc cache: takes the input file (INAME=<filename>) and calculates its
# checksum. If it can find a matching output file for <filename,checksum>,
# then it simply returns that file.
# If there is no cache hit, then it tries to run the real 'proc' and put its
# output into the cache. If the real 'proc' is not available, then it returns
# an error message.
PROC_CACHE_DIR=${PROC_CACHE_DIR:-$HOME/.proc_cache_dir}
if [ ! -d "$PROC_CACHE_DIR" ]; then
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: creating $PROC_CACHE_DIR"
mkdir -p "$PROC_CACHE_DIR"
fi
arg_md5sum=$(echo "$@" | md5sum - )
arg_md5sum=${arg_md5sum:0:32}
for opt in "$@"; do
case "$opt" in
INAME=*)
filename=${opt:6}
file_md5sum=$(md5sum ${filename}.pc)
file_md5sum=${file_md5sum:0:32}
;;
esac
done
cached_filename="${file_md5sum}_${arg_md5sum}_${filename}.c"
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: looking for '$PROC_CACHE_DIR/$cached_filename'"
if [ -r "$PROC_CACHE_DIR/$cached_filename" ]; then
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: fetching cached '$PROC_CACHE_DIR/$cached_filename' to '$filename.c'"
cp "$PROC_CACHE_DIR/$cached_filename" "$filename.c"
exit 0
fi
# let's call the real one
abs_progname=$(cd $(dirname $0); echo $PWD)/$(basename $0)
real_proc=$(which -a proc | grep -v $abs_progname | head -1)
if [ -z "$real_proc" ]; then
echo "Command not found: proc" >&2
exit -1
fi
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: $real_proc $@"
$real_proc $@
ret=$?
if [ -r "$filename.c" -a ! -r "$PROC_CACHE_DIR/$cached_filename" ]; then
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: caching '$filename.c' to '$PROC_CACHE_DIR/$cached_filename'"
cp "$filename.c" "$PROC_CACHE_DIR/$cached_filename"
for h in $(ls $ORACLE_HOME/precomp/public/*.h); do
hbase=$(basename $h)
grep -q "#include <$hbase>" "$filename.c"
if [ $? -eq 0 ]; then
if [ ! -d "$PROC_CACHE_DIR/precomp/public" ]; then
mkdir -p $PROC_CACHE_DIR/precomp/public
fi
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: caching '$hbase' to '$PROC_CACHE_DIR//precomp/public/${hbase}'"
cp $h $PROC_CACHE_DIR/precomp/public/${hbase}
fi
done
if [ ! -r "$PROC_CACHE_DIR/precomp/lib/env_precomp.mk" ]; then
[ 'yes' = "$PROC_CACHE_VERBOSE" ] && echo "proc-cache: creating fake '$PROC_CACHE_DIR/precomp/lib/env_precomp.mk'"
if [ ! -d "$PROC_CACHE_DIR/precomp/lib" ]; then
mkdir -p $PROC_CACHE_DIR/precomp/lib
fi
echo 'LLIBCLIENT=-lclntsh -lnnz10' >$PROC_CACHE_DIR/precomp/lib/env_precomp.mk
echo 'LIBHOME=$(ORACLE_LIBRARY_PATH)' >>$PROC_CACHE_DIR/precomp/lib/env_precomp.mk
fi
fi
exit $ret
|