2 # Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
18 ACLOCAL_AMFLAGS = -I ./config -I ../config
20 gcc_version := $(shell $(GCC_FOR_TARGET) -dumpversion)
22 libexecsubdir = $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
24 mkinstalldirs = $(SHELL) $(toplevel_srcdir)/mkinstalldirs
25 PWD_COMMAND = $${PWDCMD-pwd}
26 STAMP = echo timestamp >
28 libgodir = ../$(target_noncanonical)/libgo
29 LIBGODEP = $(libgodir)/libgo.la
32 # Use the compiler we just built.
33 GOCOMPILER = $(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET)
38 GOCFLAGS = $(CFLAGS_FOR_TARGET)
39 GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
41 AM_GOCFLAGS = -I $(libgodir)
42 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
43 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
45 libgosrcdir = $(srcdir)/../libgo/go
46 cmdsrcdir = $(libgosrcdir)/cmd
47 libgomiscdir = $(srcdir)/../libgo/misc
50 $(cmdsrcdir)/go/alldocs.go \
51 $(cmdsrcdir)/go/bug.go \
52 $(cmdsrcdir)/go/build.go \
53 $(cmdsrcdir)/go/clean.go \
54 $(cmdsrcdir)/go/context.go \
55 $(cmdsrcdir)/go/discovery.go \
56 $(cmdsrcdir)/go/doc.go \
57 $(cmdsrcdir)/go/env.go \
58 $(cmdsrcdir)/go/fix.go \
59 $(cmdsrcdir)/go/fmt.go \
60 $(cmdsrcdir)/go/generate.go \
61 $(cmdsrcdir)/go/get.go \
62 $(cmdsrcdir)/go/go11.go \
63 $(cmdsrcdir)/go/help.go \
64 $(cmdsrcdir)/go/http.go \
65 $(cmdsrcdir)/go/list.go \
66 $(cmdsrcdir)/go/main.go \
67 $(cmdsrcdir)/go/note.go \
68 $(cmdsrcdir)/go/pkg.go \
69 $(cmdsrcdir)/go/run.go \
70 $(cmdsrcdir)/go/signal.go \
71 $(cmdsrcdir)/go/signal_unix.go \
72 $(cmdsrcdir)/go/test.go \
73 $(cmdsrcdir)/go/testflag.go \
74 $(cmdsrcdir)/go/tool.go \
75 $(cmdsrcdir)/go/vcs.go \
76 $(cmdsrcdir)/go/version.go \
77 $(cmdsrcdir)/go/vet.go \
78 $(libgodir)/zstdpkglist.go
80 go_cmd_gofmt_files = \
81 $(cmdsrcdir)/gofmt/doc.go \
82 $(cmdsrcdir)/gofmt/gofmt.go \
83 $(cmdsrcdir)/gofmt/internal.go \
84 $(cmdsrcdir)/gofmt/rewrite.go \
85 $(cmdsrcdir)/gofmt/simplify.go
88 $(cmdsrcdir)/cgo/ast.go \
89 $(cmdsrcdir)/cgo/doc.go \
90 $(cmdsrcdir)/cgo/gcc.go \
91 $(cmdsrcdir)/cgo/godefs.go \
92 $(cmdsrcdir)/cgo/main.go \
93 $(cmdsrcdir)/cgo/out.go \
94 $(cmdsrcdir)/cgo/util.go
96 GCCGO_INSTALL_NAME := $(shell echo gccgo|sed '$(program_transform_name)')
97 GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
98 GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)')
100 zdefaultcc.go: s-zdefaultcc; @true
101 s-zdefaultcc: Makefile
102 echo 'package main' > zdefaultcc.go.tmp
103 echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"' >> zdefaultcc.go.tmp
104 echo 'const defaultCC = "$(GCC_INSTALL_NAME)"' >> zdefaultcc.go.tmp
105 echo 'const defaultCXX = "$(GXX_INSTALL_NAME)"' >> zdefaultcc.go.tmp
106 echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
107 $(SHELL) $(srcdir)/../move-if-change zdefaultcc.go.tmp zdefaultcc.go
111 zdefaultcc.go s-zdefaultcc \
112 check-gccgo gotools.head *-testlog gotools.sum gotools.log
115 rm -rf check-go-dir check-runtime-dir cgo-test-dir carchive-test-dir
119 # For a native build we build the programs using the newly built libgo
120 # and install them as regular programs.
122 bin_PROGRAMS = go$(EXEEXT) gofmt$(EXEEXT)
123 noinst_PROGRAMS = cgo$(EXEEXT)
124 man_MANS = go.1 gofmt.1
126 go$(EXEEXT): $(go_cmd_go_files) zdefaultcc.go $(LIBGODEP)
127 $(GOLINK) $(go_cmd_go_files) zdefaultcc.go $(LIBS) $(NET_LIBS)
128 gofmt$(EXEEXT): $(go_cmd_gofmt_files) $(LIBGODEP)
129 $(GOLINK) $(go_cmd_gofmt_files) $(LIBS) $(NET_LIBS)
130 cgo$(EXEEXT): $(go_cmd_cgo_files) zdefaultcc.go $(LIBGODEP)
131 $(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go $(LIBS) $(NET_LIBS)
133 install-exec-local: cgo$(EXEEXT)
134 $(MKDIR_P) $(DESTDIR)$(libexecsubdir)
135 rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
136 $(INSTALL_PROGRAM) cgo$(exeext) $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
139 rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
141 # Run tests using the go tool, and frob the output to look like that
142 # generated by DejaGNU. The main output of this is two files:
143 # gotools.sum and gotools.log.
145 # check-head starts generating the log files in DejaGNU format. This
146 # is a separate target so that the date is approximately when we start
149 @echo "Test Run By $${USER} on `date`" > gotools.head
150 @echo "Native configuration is $(host_triplet)" >> gotools.head
151 @echo >> gotools.head
152 @echo " === gotools tests ===" >> gotools.head
153 @echo >> gotools.head
155 # check-gccgo is a little shell script that executes gccgo with the
156 # options to pick up the newly built libgo.
157 check-gccgo: Makefile
159 echo "#!/bin/sh" > $@
160 abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
161 echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L $${abs_libgodir}/.libs" >> $@
164 # CHECK_ENV sets up the environment to run the newly built go tool.
165 # If you change this, change ECHO_ENV, below.
167 PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
169 GCCGO="$(abs_builddir)/check-gccgo"; \
171 GCCGOTOOLDIR="$(abs_builddir)"; \
172 export GCCGOTOOLDIR; \
173 GO_TESTING_GOTOOLS=yes; \
174 export GO_TESTING_GOTOOLS; \
175 abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
176 LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
177 export LD_LIBRARY_PATH;
179 # ECHO_ENV is a variant of CHECK_ENV to put into a testlog file.
180 # It assumes that abs_libgodir is set.
181 ECHO_ENV = PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'` GCCGO='$(abs_builddir)/check-gccgo' GCCGOTOOLDIR='$(abs_builddir)' GO_TESTING_GOTOOLS=yes LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`
183 # check-go-tools runs `go test cmd/go` in our environment.
184 check-go-tool: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo
185 rm -rf check-go-dir cmd_go-testlog
186 $(MKDIR_P) check-go-dir/src/cmd/go
187 cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
188 cp $(libgodir)/zstdpkglist.go check-go-dir/src/cmd/go/
189 cp zdefaultcc.go check-go-dir/src/cmd/go/
190 cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
191 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
192 abs_checkdir=`cd check-go-dir && $(PWD_COMMAND)`; \
193 echo "cd check-go-dir/src/cmd/go && $(ECHO_ENV) GOPATH=$${abs_checkdir} $(abs_builddir)/go$(EXEEXT) test -test.short -test.v" > cmd_go-testlog
195 GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
197 (cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) > cmd_go-testlog 2>&1 || true
198 grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
200 # check-runtime runs `go test runtime` in our environment.
201 # The runtime package is also tested as part of libgo,
202 # but the runtime tests use the go tool heavily, so testing
203 # here too will catch more problems.
204 check-runtime: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo
205 rm -rf check-runtime-dir runtime-testlog
206 $(MKDIR_P) check-runtime-dir
207 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
208 LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
209 GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
210 GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
211 files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
212 echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' -test.v" > runtime-testlog
214 GC="$${GCCGO} -fgo-compiling-runtime"; \
216 GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
217 GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
218 files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
219 $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" -test.v >> runtime-testlog 2>&1 || true
220 grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
222 # check-cgo-test runs `go test misc/cgo/test` in our environment.
223 check-cgo-test: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo
224 rm -rf cgo-test-dir cgo-testlog
225 $(MKDIR_P) cgo-test-dir/misc/cgo
226 cp -r $(libgomiscdir)/cgo/test cgo-test-dir/misc/cgo/
227 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
228 echo "cd cgo-test-dir/misc/cgo/test && $(ECHO_ENV) GOTRACEBACK=2 $(abs_builddir)/go$(EXEEXT) test -test.short -test.v" > cgo-testlog
231 export GOTRACEBACK; \
232 (cd cgo-test-dir/misc/cgo/test && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) >> cgo-testlog 2>&1 || true
233 grep '^--- ' cgo-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
235 # check-carchive-test runs `go test misc/cgo/testcarchive/carchive_test.go`
236 # in our environment.
237 check-carchive-test: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo
238 rm -rf carchive-test-dir carchive-testlog
239 $(MKDIR_P) carchive-test-dir/misc/cgo
240 cp -r $(libgomiscdir)/cgo/testcarchive carchive-test-dir/misc/cgo/
241 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
242 echo "cd carchive-test-dir/misc/cgo/testcarchive && $(ECHO_ENV) LIBRARY_PATH=`echo $${abs_libgodir}/.libs` $(abs_builddir)/go$(EXEEXT) test -test.v carchive_test.go" > carchive-testlog
244 LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
245 export LIBRARY_PATH; \
246 (cd carchive-test-dir/misc/cgo/testcarchive && $(abs_builddir)/go$(EXEEXT) test -test.v carchive_test.go) >> carchive-testlog 2>&1 || true
247 grep '^--- ' carchive-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
249 # The check targets runs the tests and assembles the output files.
250 check: check-head check-go-tool check-runtime check-cgo-test check-carchive-test
251 @mv gotools.head gotools.sum
252 @cp gotools.sum gotools.log
253 @for file in cmd_go-testlog runtime-testlog cgo-testlog carchive-testlog; do \
254 testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
255 echo "Running $${testname}" >> gotools.sum; \
256 echo "Running $${testname}" >> gotools.log; \
257 sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
258 grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' >> gotools.sum; \
261 @echo " === gotools Summary ===" >> gotools.sum
262 @pass=`grep -c '^PASS' gotools.sum`; \
263 if test "$${pass}" -ne "0"; then \
264 echo "# of expected passes $${pass}" >> gotools.sum; \
266 @fail=`grep -c '^FAIL' gotools.sum`; \
267 if test "$${fail}" -ne "0"; then \
268 echo "# of unexpected failures $${fail}" >> gotools.sum; \
270 @untested=`grep -c '^UNTESTED' gotools.sum`; \
271 if test "$${untested}" -ne "0"; then \
272 echo "# of untested testcases $${untested}" >> gotools.sum; \
274 @echo `echo $(GOC_FOR_TARGET) | sed -e 's/ .*//'` `$(GOC_FOR_TARGET) -v 2>&1 | grep " version" | sed -n -e 's/.* \(version.*$$\)/\1/p'` >> gotools.sum
276 @echo "runtest completed at `date`" >> gotools.log
277 @if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
279 .PHONY: check check-head check-go-tool check-runtime check-cgo-test check-carchive-test
283 # For a non-native build we have to build the programs using a
284 # previously built host (or build -> host) Go compiler. We should
285 # only do this if such a compiler is available. We also need to get
286 # the right values for GOARCH and GOOS in the default build context in
287 # the go/build package. Figure this out later.