| 1 | #! /bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | # mkclone - symlink every file appearing in $src/MANIFEST to a corresponding
|
|---|
| 4 | # file in the target directory ($1). Directories specified in
|
|---|
| 5 | # MANIFEST are created in the target directory
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright (C) 1996-2002 Free Software Foundation, Inc.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is free software; you can redistribute it and/or modify
|
|---|
| 10 | # it under the terms of the GNU General Public License as published by
|
|---|
| 11 | # the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 12 | # any later version.
|
|---|
| 13 | #
|
|---|
| 14 | # This program is distributed in the hope that it will be useful,
|
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | # GNU General Public License for more details.
|
|---|
| 18 | #
|
|---|
| 19 | # You should have received a copy of the GNU General Public License
|
|---|
| 20 | # along with this program; if not, write to the Free Software
|
|---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|---|
| 22 | #
|
|---|
| 23 | prog=`basename $0`
|
|---|
| 24 |
|
|---|
| 25 | SRCDIR=src
|
|---|
| 26 |
|
|---|
| 27 | USAGE="usage: $prog [-m manifest] [-s srcdir] [-v] [-d] [-h] target"
|
|---|
| 28 | while getopts dhm:s:v opt
|
|---|
| 29 | do
|
|---|
| 30 | case "$opt" in
|
|---|
| 31 | m) MANIFEST=$OPTARG ;;
|
|---|
| 32 | s) SRCDIR=$OPTARG ;;
|
|---|
| 33 | v) verbose=y ;;
|
|---|
| 34 | d) ECHO=echo debug=y ;;
|
|---|
| 35 | h) hardlinks=y ;;
|
|---|
| 36 | ?) echo $USAGE >&2
|
|---|
| 37 | exit 2;;
|
|---|
| 38 | esac
|
|---|
| 39 | done
|
|---|
| 40 |
|
|---|
| 41 | : ${MANIFEST:=${SRCDIR}/MANIFEST}
|
|---|
| 42 |
|
|---|
| 43 | [ -n "$debug" ] && verbose=
|
|---|
| 44 |
|
|---|
| 45 | shift $(( $OPTIND - 1 ))
|
|---|
| 46 |
|
|---|
| 47 | if [ $# -lt 1 ]; then
|
|---|
| 48 | echo $USAGE >&2
|
|---|
| 49 | exit 2
|
|---|
| 50 | fi
|
|---|
| 51 |
|
|---|
| 52 | if [ ! -f $MANIFEST ]; then
|
|---|
| 53 | echo "$prog: $MANIFEST: no such file or directory" >&2
|
|---|
| 54 | echo "$prog: must be run with valid -s argument or from source directory" >&2
|
|---|
| 55 | exit 1
|
|---|
| 56 | fi
|
|---|
| 57 |
|
|---|
| 58 | rm_ltmp=false
|
|---|
| 59 | LINKTEMP=`mktemp -t linktmp.XXXXXXXX 2>/dev/null`
|
|---|
| 60 | if [ -z "$LINKTEMP" ]; then
|
|---|
| 61 | : ${TMPDIR:=/tmp}
|
|---|
| 62 | LINKTEMP=${TMPDIR}/linktmp.$$
|
|---|
| 63 | rm_ltmp=true
|
|---|
| 64 | fi
|
|---|
| 65 |
|
|---|
| 66 | $rm_ltmp && rm -f ${LINKTEMP}
|
|---|
| 67 | # if the user specified hard links, then do that. otherwise, try to use
|
|---|
| 68 | # symlinks if they're present
|
|---|
| 69 | if [ -n "$hardlinks" ]; then
|
|---|
| 70 | LN=ln
|
|---|
| 71 | elif (ln -s /dev/null ${LINKTEMP}) >/dev/null 2>&1; then
|
|---|
| 72 | LN="ln -s"
|
|---|
| 73 | else
|
|---|
| 74 | LN=ln
|
|---|
| 75 | fi
|
|---|
| 76 | rm -f ${LINKTEMP}
|
|---|
| 77 |
|
|---|
| 78 | TARGET=$1
|
|---|
| 79 |
|
|---|
| 80 | if [ ! -d "$TARGET" ]; then
|
|---|
| 81 | mkdir "$TARGET"
|
|---|
| 82 | fi
|
|---|
| 83 |
|
|---|
| 84 | echo "${prog}: creating clone of bash source tree (from $SRCDIR) in $TARGET"
|
|---|
| 85 |
|
|---|
| 86 | cd "$TARGET" || { echo "${prog}: cannot cd to $TARGET" >&2 ; exit 1; }
|
|---|
| 87 |
|
|---|
| 88 | while read fname type mode
|
|---|
| 89 | do
|
|---|
| 90 | [ -z "$fname" ] && continue
|
|---|
| 91 |
|
|---|
| 92 | case "$fname" in
|
|---|
| 93 | \#*) continue ;;
|
|---|
| 94 | esac
|
|---|
| 95 |
|
|---|
| 96 | case "$type" in
|
|---|
| 97 | d) [ -n "$verbose" ] && echo mkdir $fname
|
|---|
| 98 | $ECHO mkdir $fname ;; # already in $TARGET
|
|---|
| 99 | f) fn=${fname##*/}
|
|---|
| 100 | case "$fname" in
|
|---|
| 101 | */*) dn=${fname%/*} ;;
|
|---|
| 102 | *) dn=. ;;
|
|---|
| 103 | esac
|
|---|
| 104 | if [ -n "$verbose" ] || [ -n "$debug" ]; then
|
|---|
| 105 | echo "( cd $dn && $LN $SRCDIR/$fname $fn )"
|
|---|
| 106 | fi
|
|---|
| 107 | [ -z "$debug" ] && ( cd $dn && $LN $SRCDIR/$fname $fn )
|
|---|
| 108 | ;;
|
|---|
| 109 | *) echo "${prog}: ${fname}: unknown file type $type" 1>&2 ;;
|
|---|
| 110 | esac
|
|---|
| 111 | done < $MANIFEST
|
|---|
| 112 |
|
|---|
| 113 | # special
|
|---|
| 114 | SPECIAL="parser-built y.tab.c y.tab.h"
|
|---|
| 115 |
|
|---|
| 116 | rm -f $SPECIAL
|
|---|
| 117 | for sf in $SPECIAL
|
|---|
| 118 | do
|
|---|
| 119 | [ -n "$verbose" ] && echo cp -p $SRCDIR/$sf $TARGET
|
|---|
| 120 | $ECHO cp -p $SRCDIR/$sf $TARGET
|
|---|
| 121 | done
|
|---|
| 122 |
|
|---|
| 123 | exit 0
|
|---|