Christian Lavoie | afc6d8f | 2011-02-20 02:39:19 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2009 The Go Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style |
| 4 | # license that can be found in the LICENSE file. |
| 5 | |
| 6 | OUT="Make.deps" |
| 7 | TMP="Make.deps.tmp" |
| 8 | |
| 9 | if [ -f $OUT ] && ! [ -w $OUT ]; then |
| 10 | echo "$0: $OUT is read-only; aborting." 1>&2 |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | # Get list of directories from Makefile |
| 15 | dirs=$(sed '1,/^DIRS=/d; /^$/,$d; s/\\//g' Makefile) |
| 16 | dirs2=$(sed '1,/^DIRS=/d; /^$/,$d; s/\\//g' $GOROOT/src/pkg/Makefile) |
| 17 | dirpat=$(echo $dirs $dirs2 | sed 's/ /|/g; s/.*/^(&)$/') |
| 18 | |
| 19 | for dir in $dirs; do ( |
| 20 | cd $dir || exit 1 |
| 21 | |
| 22 | sources=$(sed -n 's/\.go\\/.go/p' Makefile) |
| 23 | sources=$(ls $sources 2> /dev/null) # remove .s, .c, etc. |
| 24 | |
| 25 | deps=$( |
| 26 | sed -n '/^import.*"/p; /^import[ \t]*(/,/^)/p' $sources /dev/null | |
| 27 | cut -d '"' -f2 | |
| 28 | egrep "$dirpat" | |
| 29 | grep -v "^$dir\$" | |
| 30 | sed 's/$/.install/' | |
| 31 | sort -u |
| 32 | ) |
| 33 | |
| 34 | echo $dir.install: $deps |
| 35 | ) done > $TMP |
| 36 | |
| 37 | for dir in $dirs2; do ( |
| 38 | echo $dir.install: \${GOROOT}/pkg/\${GOOS}_\${GOARCH}/${dir}.a |
| 39 | ) done >> $TMP |
| 40 | |
| 41 | mv $TMP $OUT |