The Go Programming Language

Text file src/pkg/deps.bash

     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	eval $(gomake --no-print-directory -f ../Make.inc go-env)
     7	
     8	OUT="Make.deps"
     9	TMP="Make.deps.tmp"
    10	
    11	if [ -f $OUT ] && ! [ -w $OUT ]; then
    12		echo "$0: $OUT is read-only; aborting." 1>&2
    13		exit 1
    14	fi
    15	
    16	# Get list of directories from Makefile
    17	dirs=$(gomake --no-print-directory echo-dirs)
    18	dirpat=$(echo $dirs C | awk '{
    19		for(i=1;i<=NF;i++){ 
    20			x=$i
    21			gsub("/", "\\/", x)
    22			printf("/^(%s)$/\n", x)
    23		}
    24	}')
    25	
    26	for dir in $dirs; do (
    27		cd $dir || exit 1
    28	
    29		sources=$(sed -n 's/^[ 	]*\([^ 	]*\.go\)[ 	]*\\*[ 	]*$/\1/p' Makefile)
    30		sources=$(echo $sources | sed 's/\$(GOOS)/'$GOOS'/g')
    31		sources=$(echo $sources | sed 's/\$(GOARCH)/'$GOARCH'/g')
    32		# /dev/null here means we get an empty dependency list if $sources is empty
    33		# instead of listing every file in the directory.
    34		sources=$(ls $sources /dev/null 2> /dev/null)  # remove .s, .c, etc.
    35	
    36		deps=$(
    37			sed -n '/^import.*"/p; /^import[ \t]*(/,/^)/p' $sources /dev/null |
    38			cut -d '"' -f2 |
    39			awk "$dirpat" |
    40			grep -v "^$dir\$" |
    41			sed 's/$/.install/' |
    42			sed 's;^C\.install;runtime/cgo.install;' |
    43			sort -u
    44		)
    45	
    46		echo $dir.install: $deps
    47	) done > $TMP
    48	
    49	mv $TMP $OUT

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.