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