xref: /netbsd-src/external/gpl3/binutils.old/dist/symlink-tree (revision 75fd0b742a7e4a64301bc6c44e9bc5240c58bb92)
1*75fd0b74Schristos#!/bin/sh
2*75fd0b74Schristos# Create a symlink tree.
3*75fd0b74Schristos#
4*75fd0b74Schristos# Copyright (C) 1995, 2000, 2003  Free Software Foundation, Inc.
5*75fd0b74Schristos#
6*75fd0b74Schristos# This file is free software; you can redistribute it and/or modify
7*75fd0b74Schristos# it under the terms of the GNU General Public License as published by
8*75fd0b74Schristos# the Free Software Foundation; either version 2 of the License, or
9*75fd0b74Schristos# (at your option) any later version.
10*75fd0b74Schristos#
11*75fd0b74Schristos# This program is distributed in the hope that it will be useful,
12*75fd0b74Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*75fd0b74Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*75fd0b74Schristos# GNU General Public License for more details.
15*75fd0b74Schristos#
16*75fd0b74Schristos# You should have received a copy of the GNU General Public License
17*75fd0b74Schristos# along with this program; if not, write to the Free Software
18*75fd0b74Schristos# Foundation, Inc., 51 Franklin Street, Fifth Floor,
19*75fd0b74Schristos# Boston, MA 02110-1301, USA.
20*75fd0b74Schristos#
21*75fd0b74Schristos# As a special exception to the GNU General Public License, if you
22*75fd0b74Schristos# distribute this file as part of a program that contains a
23*75fd0b74Schristos# configuration script generated by Autoconf, you may include it under
24*75fd0b74Schristos# the same distribution terms that you use for the rest of that program.
25*75fd0b74Schristos#
26*75fd0b74Schristos# Please report bugs to <gcc-bugs@gnu.org>
27*75fd0b74Schristos# and send patches to <gcc-patches@gnu.org>.
28*75fd0b74Schristos
29*75fd0b74Schristos# Syntax: symlink-tree srcdir "ignore1 ignore2 ..."
30*75fd0b74Schristos#
31*75fd0b74Schristos# where srcdir is the directory to create a symlink tree to,
32*75fd0b74Schristos# and "ignoreN" is a list of files/directories to ignore.
33*75fd0b74Schristos
34*75fd0b74Schristosprog=$0
35*75fd0b74Schristossrcdir=$1
36*75fd0b74Schristosignore="$2"
37*75fd0b74Schristos
38*75fd0b74Schristosif test $# -lt 1; then
39*75fd0b74Schristos  echo "symlink-tree error:  Usage: symlink-tree srcdir \"ignore1 ignore2 ...\""
40*75fd0b74Schristos  exit 1
41*75fd0b74Schristosfi
42*75fd0b74Schristos
43*75fd0b74Schristosignore_additional=". .. CVS"
44*75fd0b74Schristos
45*75fd0b74Schristos# If we were invoked with a relative path name, adjust ${prog} to work
46*75fd0b74Schristos# in subdirs.
47*75fd0b74Schristoscase ${prog} in
48*75fd0b74Schristos/* | [A-Za-z]:[\\/]*) ;;
49*75fd0b74Schristos*) prog=../${prog} ;;
50*75fd0b74Schristosesac
51*75fd0b74Schristos
52*75fd0b74Schristos# Set newsrcdir to something subdirectories can use.
53*75fd0b74Schristoscase ${srcdir} in
54*75fd0b74Schristos/* | [A-Za-z]:[\\/]*) newsrcdir=${srcdir} ;;
55*75fd0b74Schristos*) newsrcdir=../${srcdir} ;;
56*75fd0b74Schristosesac
57*75fd0b74Schristos
58*75fd0b74Schristosfor f in `ls -a ${srcdir}`; do
59*75fd0b74Schristos  if [ -d ${srcdir}/$f ]; then
60*75fd0b74Schristos    found=
61*75fd0b74Schristos    for i in ${ignore} ${ignore_additional}; do
62*75fd0b74Schristos      if [ "$f" = "$i" ]; then
63*75fd0b74Schristos	found=yes
64*75fd0b74Schristos      fi
65*75fd0b74Schristos    done
66*75fd0b74Schristos    if [ -z "${found}" ]; then
67*75fd0b74Schristos      echo "$f		..working in"
68*75fd0b74Schristos      if [ -d $f ]; then true; else mkdir $f; fi
69*75fd0b74Schristos      (cd $f; ${prog} ${newsrcdir}/$f "${ignore}")
70*75fd0b74Schristos    fi
71*75fd0b74Schristos  else
72*75fd0b74Schristos    echo "$f		..linked"
73*75fd0b74Schristos    rm -f $f
74*75fd0b74Schristos    ln -s ${srcdir}/$f .
75*75fd0b74Schristos  fi
76*75fd0b74Schristosdone
77*75fd0b74Schristos
78*75fd0b74Schristosexit 0
79