PR fortran/77666
[official-gcc.git] / libgo / match.sh
blob23db19478fa15f008464f6161ad1b9c4cf05881c
1 #!/bin/sh
3 # Copyright 2016 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Given a source directory, returns the non-test Go files that should
8 # be built for this target. This implements Go's build constraints in
9 # a shell script. There is similar code in testsuite/gotest.
11 set -e
13 LANG=C
14 LC_ALL=C
15 LC_CTYPE=C
16 export LANG LC_ALL LC_CTYPE
18 srcdir=""
19 goarch=""
20 goos=""
21 extrafiles=""
22 cmdlinetag="nosuchtag"
23 cgotag="cgo"
25 for arg; do
26 case "x$arg" in
27 x--srcdir)
28 srcdir=$2
29 shift
30 shift
32 x--srcdir=*)
33 srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
34 shift
36 x--goarch)
37 goarch=$2
38 shift
39 shift
41 x--goarch=*)
42 goarch=`echo $1 | sed -e 's/^--goarch=//'`
43 shift
45 x--goos)
46 goos=$2
47 shift
48 shift
50 x--goos=*)
51 goos=`echo $1 | sed -e 's/^--goos=//'`
52 shift
54 x--extrafiles)
55 extrafiles=$2
56 shift
57 shift
59 x--extrafiles=*)
60 extrafiles=`echo $1 | sed -e 's/^--extrafiles=//'`
61 shift
63 x--tag)
64 cmdlinetag=$2
65 shift
66 shift
68 x--tag=*)
69 cmdlinetag=`echo $1 | sed -e 's/^--tag=//'`
70 shift
72 x--nocgo)
73 cgotag="nosuchtag"
74 shift
77 echo 1>&2 "unknown argument $arg"
78 exit 1
80 esac
81 done
83 cd $srcdir
85 gofiles=
86 for f in *.go; do
87 case $f in
88 *_test.go)
90 *.go)
91 gofiles="$gofiles $f"
93 esac
94 done
96 if test "$gofiles" = ""; then
97 echo 1>&2 "no non-test .go files in $srcdir"
98 exit 1
101 matched=
102 for f in $gofiles; do
103 tag1=`echo $f | sed -e 's/^.*_\([^_]*\).go$/\1/'`
104 tag2=`echo $f | sed -e 's/^.*_\([^_]*\)_[^_]*.go$/\1/'`
105 if test x$tag1 = x$f; then
106 tag1=
108 if test x$tag2 = x$f; then
109 tag2=
112 case "$tag1" in
113 "") ;;
114 $goarch) ;;
115 $goos) ;;
116 android | darwin | dragonfly | freebsd | linux | nacl | netbsd | openbsd | plan9 | solaris | windows)
117 tag1=nonmatchingtag
119 386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | ppc64 | ppc64le | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | mipso32 | mipsn32 | mipsn64 | mipso64 | ppc | s390 | s390x | sparc | sparc64)
120 tag1=nonmatchingtag
122 esac
124 case "$tag2" in
125 "") ;;
126 $goarch) ;;
127 $goos) ;;
128 android | darwin | dragonfly | freebsd | linux | nacl | netbsd | openbsd | plan9 | solaris | windows)
129 tag2=nonmatchingtag
131 386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | ppc64 | ppc64le | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | mipso32 | mipsn32 | mipsn64 | mipso64 | ppc | s390 | s390x | sparc | sparc64)
132 tag2=nonmatchingtag
134 esac
136 if test x$tag1 != xnonmatchingtag -a x$tag2 != xnonmatchingtag; then
137 # Pipe through cat so that `set -e` doesn't affect fgrep.
138 tags=`sed '/^package /q' < $f | grep '^// +build ' | cat`
139 omatch=true
140 first=true
141 match=false
142 for tag in $tags; do
143 case $tag in
144 "//")
146 "+build")
147 if test "$first" = "true"; then
148 first=false
149 elif test "$match" = "false"; then
150 omatch=false
152 match=false
154 $goos | $goarch | $cgotag | $cmdlinetag)
155 match=true
157 "!"$goos | "!"$goarch | "!"$cgotag | "!"$cmdlinetag)
159 *,*)
160 cmatch=true
161 for ctag in `echo $tag | sed -e 's/,/ /g'`; do
162 case $ctag in
163 $goos | $goarch | $cgotag | $cmdlinetag)
165 "!"$goos | "!"$goarch | "!"$cgotag | "!"$cmdlinetag)
166 cmatch=false
168 "!"*)
171 cmatch=false
173 esac
174 done
175 if test "$cmatch" = "true"; then
176 match=true
179 "!"*)
180 match=true
182 esac
183 done
185 if test "$match" = "false" -a "$first" = "false"; then
186 omatch=false
189 if test "$omatch" = "true"; then
190 matched="$matched $srcdir/$f"
193 done
195 echo $matched $extrafiles
197 exit 0