blob: aec6ec2e61fc1d04571f075294540276982997fc [file] [log] [blame]
Christian Lavoieafc6d8f2011-02-20 02:39:19 +00001#!/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
6OUT="Make.deps"
7TMP="Make.deps.tmp"
8
9if [ -f $OUT ] && ! [ -w $OUT ]; then
10 echo "$0: $OUT is read-only; aborting." 1>&2
11 exit 1
12fi
13
14# Get list of directories from Makefile
15dirs=$(sed '1,/^DIRS=/d; /^$/,$d; s/\\//g' Makefile)
16dirs2=$(sed '1,/^DIRS=/d; /^$/,$d; s/\\//g' $GOROOT/src/pkg/Makefile)
17dirs3="thrift"
18dirpat=$(echo $dirs $dirs2 $dirs3 | sed 's/ /|/g; s/.*/^(&)$/')
19
20for dir in $dirs; do (
21 cd $dir || exit 1
22
23 sources=$(sed -n 's/\.go\\/.go/p' Makefile)
24 sources=$(ls $sources 2> /dev/null) # remove .s, .c, etc.
25
26 deps=$(
27 sed -n '/^import.*"/p; /^import[ \t]*(/,/^)/p' $sources /dev/null |
28 cut -d '"' -f2 |
29 egrep "$dirpat" |
30 grep -v "^$dir\$" |
31 sed 's/$/.install/' |
32 sort -u
33 )
34
35 echo $dir.install: $deps
36) done > $TMP
37
38for dir in $dirs2; do (
39 echo $dir.install: \${GOROOT}/pkg/\${GOOS}_\${GOARCH}/${dir}.a
40) done >> $TMP
41for dir in $dirs3; do (
42 echo $dir.install: \${GOROOT}/pkg/\${GOOS}_\${GOARCH}/${dir}.a
43) done >> $TMP
44
45mv $TMP $OUT