#!/bin/sh ###################################################################### # ccache-update-links December 2005 # Horms horms@verge.net.au # # ccache-update-links # Updates symlinks for use with ccache # Copyright (C) 2005 Horms # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA # ###################################################################### set -e if [ -z "$SEARCH_PATH" ]; then SEARCH_PATH=${PATH} fi TARGETS="cc gcc gc++" CCACHE_BIN="`which ccache`" usage () { echo "Usage: ccache-update-links DIR" >&2 exit 1 } stat_id () { if [ -e "$1" ]; then stat --format=%d:%i "$1" fi } if [ $# -ne 1 ]; then usage fi case $1 in -*) usage ;; esac DEST="$1/" if [ ! -e "$DEST" ]; then echo "ccache-update-links: $DEST does not exist" >&2 exit 1 fi DEST_ID=`stat_id "$DEST"` for d in `echo $SEARCH_PATH | tr ':' '\n'`; do SOURCE_ID=`stat_id "$d"` if [ -z "$SOURCE_ID" -o "$SOURCE_ID" = "$DEST_ID" ]; then continue fi for t in $TARGETS; do cd "$d" for b in $t $t-* *-$t *-$t-*; do if [ ! -x "$b" -o -d "$b" ]; then continue; fi if [ -L "$DEST/$b" ]; then rm "$DEST/$b" fi (cd "$DEST"; ln -s "$CCACHE_BIN" "$b"; ) done done done