about summary refs log tree commit diff
path: root/Util/mkdisttree.sh
diff options
context:
space:
mode:
Diffstat (limited to 'Util/mkdisttree.sh')
-rwxr-xr-xUtil/mkdisttree.sh76
1 files changed, 76 insertions, 0 deletions
diff --git a/Util/mkdisttree.sh b/Util/mkdisttree.sh
new file mode 100755
index 000000000..837ebbcc2
--- /dev/null
+++ b/Util/mkdisttree.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+
+if test $# -lt 4; then
+    echo >&2 "Usage: $0 <dist-tree-name> <top-source-dir> <top-build-dir> <type> <make-args>"
+    exit 2
+fi
+
+case "$1" in
+    /*) disttree=$1 ;;
+    *) disttree=`pwd`/$1 ;;
+esac
+
+case "$2" in
+    /*) sdir_top=$2 ;;
+    *) sdir_top=`pwd`/$2 ;;
+esac
+
+case "$3" in
+    /*) dir_top=$3 ;;
+    *) dir_top=`pwd`/$3 ;;
+esac
+
+type=$4
+shift 4
+
+rm -rf $disttree
+
+sed_separate='
+    :1
+    $!{
+	N
+	b1
+    }
+    s/\n/ /g
+    s/^/deplist=;globlist=! /
+    s/$/ !/
+    s/  */ /g
+    s/ \([^?*[!][^?*[!]*\) / !deplist="$deplist \1"! /g
+    s/! !/;/g
+    s/! \([^!]*\) !/;globlist="$globlist \1";/g
+    s/!/;/g
+    s/;;*/;/g
+'
+
+(
+    cd $sdir_top
+    find . \( -name '*.*' -prune -false \) -o \( -name .distfiles -print \)
+) | while read dfn; do
+    subdir=`echo $dfn | sed 's,/\.distfiles$,,'`
+    echo >&2 "Processing directory $subdir..."
+    eval "DISTFILES_$type="
+    . $sdir_top/$dfn
+    eval "distfiles=\$DISTFILES_$type"
+    if test -n "$distfiles"; then
+	cmds=`echo "$distfiles" | sed -e "$sed_separate"`
+	eval "$cmds"
+	if test -n "$deplist" && test -f $dir_top/$subdir/Makefile; then
+	    ( cd $dir_top/$subdir && "$@" $deplist ) || exit 1
+	fi
+	$sdir_top/mkinstalldirs $disttree/$subdir || exit 1
+	for f in $deplist `test -z "$globlist" || ( cd $dir_top/$subdir && eval "echo $globlist")`; do
+	    if test -f $dir_top/$subdir/$f; then
+		ln $dir_top/$subdir/$f $disttree/$subdir/$f || \
+		    cp -p $dir_top/$subdir/$f $disttree/$subdir/$f || exit 1
+	    elif test -f $sdir_top/$subdir/$f; then
+		ln $sdir_top/$subdir/$f $disttree/$subdir/$f || \
+		    cp -p $sdir_top/$subdir/$f $disttree/$subdir/$f || exit 1
+	    else
+		echo >&2 "$0: can't find file $subdir/$f"
+		exit 1
+	    fi
+	done
+    fi
+done
+
+exec chmod -R a+rX,u+w,go-w $disttree