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
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
31 LIBGOTOOL = $(libgodir)/libgotool.a
34 # Use the compiler we just built.
35 GOCOMPILER = $(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET)
40 GOCFLAGS = $(CFLAGS_FOR_TARGET)
41 GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
43 AM_GOCFLAGS = -I $(libgodir)
44 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
45 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
47 libgosrcdir = $(srcdir)/../libgo/go
48 cmdsrcdir = $(libgosrcdir)/cmd
49 libgomiscdir = $(srcdir)/../libgo/misc
52 $(cmdsrcdir)/go/alldocs.go \
53 $(cmdsrcdir)/go/go11.go \
54 $(cmdsrcdir)/go/main.go
56 go_cmd_gofmt_files = \
57 $(cmdsrcdir)/gofmt/doc.go \
58 $(cmdsrcdir)/gofmt/gofmt.go \
59 $(cmdsrcdir)/gofmt/internal.go \
60 $(cmdsrcdir)/gofmt/rewrite.go \
61 $(cmdsrcdir)/gofmt/simplify.go
64 $(cmdsrcdir)/cgo/ast.go \
65 $(cmdsrcdir)/cgo/doc.go \
66 $(cmdsrcdir)/cgo/gcc.go \
67 $(cmdsrcdir)/cgo/godefs.go \
68 $(cmdsrcdir)/cgo/main.go \
69 $(cmdsrcdir)/cgo/out.go \
70 $(cmdsrcdir)/cgo/util.go
73 $(cmdsrcdir)/vet/doc.go \
74 $(cmdsrcdir)/vet/main.go
76 go_cmd_buildid_files = \
77 $(cmdsrcdir)/buildid/buildid.go \
78 $(cmdsrcdir)/buildid/doc.go
80 go_cmd_test2json_files = \
81 $(cmdsrcdir)/test2json/main.go
83 GCCGO_INSTALL_NAME := $(shell echo gccgo|sed '$(program_transform_name)')
84 GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
85 GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)')
87 zdefaultcc.go: s-zdefaultcc; @true
88 s-zdefaultcc: Makefile
89 echo 'package main' > zdefaultcc.go.tmp
90 echo 'func defaultGCCGO(goos, goarch string) string { return "$(bindir)/$(GCCGO_INSTALL_NAME)" }' >> zdefaultcc.go.tmp
91 echo 'func defaultCC(goos, goarch string) string { return "$(GCC_INSTALL_NAME)" }' >> zdefaultcc.go.tmp
92 echo 'func defaultCXX(goos, goarch string) string { return "$(GXX_INSTALL_NAME)" }' >> zdefaultcc.go.tmp
93 echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
94 $(SHELL) $(srcdir)/../move-if-change zdefaultcc.go.tmp zdefaultcc.go
98 zdefaultcc.go s-zdefaultcc \
99 check-gccgo check-gcc gotools.head *-testlog gotools.sum gotools.log \
103 -chmod -R u+w check-go-dir
104 rm -rf check-go-dir check-runtime-dir cgo-test-dir carchive-test-dir
108 # For a native build we build the programs using the newly built libgo
109 # and install them as regular programs.
111 bin_PROGRAMS = go$(EXEEXT) gofmt$(EXEEXT)
112 noinst_PROGRAMS = cgo$(EXEEXT) vet$(EXEEXT) buildid$(EXEEXT) test2json$(EXEEXT)
113 man_MANS = go.1 gofmt.1
115 go$(EXEEXT): $(go_cmd_go_files) $(LIBGOTOOL) $(LIBGODEP)
116 $(GOLINK) $(go_cmd_go_files) $(LIBGOTOOL) $(LIBS) $(NET_LIBS)
117 gofmt$(EXEEXT): $(go_cmd_gofmt_files) $(LIBGODEP)
118 $(GOLINK) $(go_cmd_gofmt_files) $(LIBS) $(NET_LIBS)
119 cgo$(EXEEXT): $(go_cmd_cgo_files) zdefaultcc.go $(LIBGOTOOL) $(LIBGODEP)
120 $(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go $(LIBGOTOOL) $(LIBS) $(NET_LIBS)
121 vet$(EXEEXT): $(go_cmd_vet_files) $(LIBGOTOOL) $(LIBGODEP)
122 $(GOLINK) $(go_cmd_vet_files) $(LIBGOTOOL) $(LIBS) $(NET_LIBS)
123 buildid$(EXEEXT): $(go_cmd_buildid_files) $(LIBGOTOOL) $(LIBGODEP)
124 $(GOLINK) $(go_cmd_buildid_files) $(LIBGOTOOL) $(LIBS) $(NET_LIBS)
125 test2json$(EXEEXT): $(go_cmd_test2json_files) $(LIBGOTOOL) $(LIBGODEP)
126 $(GOLINK) $(go_cmd_test2json_files) $(LIBGOTOOL) $(LIBS) $(NET_LIBS)
128 install-exec-local: $(noinst_PROGRAMS)
129 $(MKDIR_P) $(DESTDIR)$(libexecsubdir)
130 for f in $(noinst_PROGRAMS); do \
131 rm -f $(DESTDIR)$(libexecsubdir)/$$f; \
132 $(INSTALL_PROGRAM) $$f $(DESTDIR)$(libexecsubdir)/$$f; \
136 for f in $(noinst_PROGRAMS); do \
137 rm -f $(DESTDIR)$(libexecsubdir)/$$f; \
142 # Number of seconds before tests time out.
143 GOTOOLS_TEST_TIMEOUT = 600
145 # Run tests using the go tool, and frob the output to look like that
146 # generated by DejaGNU. The main output of this is two files:
147 # gotools.sum and gotools.log.
149 # check-head starts generating the log files in DejaGNU format. This
150 # is a separate target so that the date is approximately when we start
153 @echo "Test Run By $${USER} on `date`" > gotools.head
154 @echo "Native configuration is $(host_triplet)" >> gotools.head
155 @echo >> gotools.head
156 @echo " === gotools tests ===" >> gotools.head
157 @echo >> gotools.head
159 # check-gccgo is a little shell script that executes gccgo with the
160 # options to pick up the newly built libgo and libstdc++.
161 check-gccgo: Makefile
163 echo "#!/bin/sh" > $@.tmp
164 abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
165 echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L $${abs_libgodir}/.libs -B$${abs_libgodir}/../libstdc++-v3/src/.libs -B$${abs_libgodir}/../libstdc++-v3/libsupc++/.libs" >> $@.tmp
169 # check-gcc is a little shell script that executes the newly built gcc
170 # with the options to pick up the newly built libgo and libstdc++.
173 echo "#!/bin/sh" > $@.tmp
174 abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
175 echo "$(GCC_FOR_TARGET)" '"$$@"' "-L $${abs_libgodir} -L $${abs_libgodir}/.libs -B$${abs_libgodir}/../libstdc++-v3/src/.libs -B$${abs_libgodir}/../libstdc++-v3/libsupc++/.libs" >> $@.tmp
179 # CHECK_ENV sets up the environment to run the newly built go tool.
180 # If you change this, change ECHO_ENV, below.
181 # The fl shell variable is used to avoid having FAIL appear
182 # in the log unnecessarily.
184 PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
186 GCCGO="$(abs_builddir)/check-gccgo"; \
188 CC="$(abs_builddir)/check-gcc"; \
190 GCCGOTOOLDIR="$(abs_builddir)"; \
191 export GCCGOTOOLDIR; \
192 GO_TESTING_GOTOOLS=yes; \
193 export GO_TESTING_GOTOOLS; \
194 abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
195 LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
196 export LD_LIBRARY_PATH; \
197 GOROOT=$${abs_libgodir}; \
199 GOCACHE=$(abs_builddir)/gocache-test; \
201 fl1="FA"; fl2="IL"; fl="$${fl1}$${fl2}";
203 # ECHO_ENV is a variant of CHECK_ENV to put into a testlog file.
204 # It assumes that abs_libgodir is set.
205 ECHO_ENV = PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'` GCCGO='$(abs_builddir)/check-gccgo' CC='$(abs_builddir)/check-gcc' GCCGOTOOLDIR='$(abs_builddir)' GO_TESTING_GOTOOLS=yes LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'` GOROOT=`echo $${abs_libgodir} GOCACHE='$(abs_builddir)/gocache-test'`
207 # check-go-tool runs `go test cmd/go` in our environment.
208 check-go-tool: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
209 -chmod -R u+w check-go-dir
210 rm -rf check-go-dir cmd_go-testlog
211 $(MKDIR_P) check-go-dir/src/cmd/go
212 cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
213 cp -r $(cmdsrcdir)/go/internal check-go-dir/src/cmd/go/
214 cp $(libgodir)/zdefaultcc.go check-go-dir/src/cmd/go/internal/cfg/
215 cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
216 cp -r $(cmdsrcdir)/internal check-go-dir/src/cmd/
217 cp $(libgodir)/objabi.go check-go-dir/src/cmd/internal/objabi/
218 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
219 abs_checkdir=`cd check-go-dir && $(PWD_COMMAND)`; \
220 echo "cd check-go-dir/src/cmd/go && $(ECHO_ENV) GOPATH=$${abs_checkdir} $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > cmd_go-testlog
222 GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
224 (cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v) >> cmd_go-testlog 2>&1 || echo "--- $${fl}: go test cmd/go (0.00s)" >> cmd_go-testlog
225 grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
227 # check-runtime runs `go test runtime` in our environment.
228 # The runtime package is also tested as part of libgo,
229 # but the runtime tests use the go tool heavily, so testing
230 # here too will catch more problems.
231 check-runtime: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
232 rm -rf check-runtime-dir runtime-testlog
233 $(MKDIR_P) check-runtime-dir
234 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
235 LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
236 export LD_LIBRARY_PATH; \
237 GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
238 GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
239 files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
240 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}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog
242 GC="$${GCCGO} -fgo-compiling-runtime"; \
244 GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
245 GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
246 files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
247 $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v >> runtime-testlog 2>&1 || echo "--- $${fl}: go test runtime (0.00s)" >> runtime-testlog
248 grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
250 # check-cgo-test runs `go test misc/cgo/test` in our environment.
251 check-cgo-test: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
252 rm -rf cgo-test-dir cgo-testlog
253 $(MKDIR_P) cgo-test-dir/misc/cgo
254 cp -r $(libgomiscdir)/cgo/test cgo-test-dir/misc/cgo/
255 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
256 echo "cd cgo-test-dir/misc/cgo/test && $(ECHO_ENV) GOTRACEBACK=2 $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > cgo-testlog
259 export GOTRACEBACK; \
260 (cd cgo-test-dir/misc/cgo/test && $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v) >> cgo-testlog 2>&1 || echo "--- $${fl}: go test misc/cgo/test (0.00s)" >> cgo-testlog
261 grep '^--- ' cgo-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
263 # check-carchive-test runs `go test misc/cgo/testcarchive/carchive_test.go`
264 # in our environment.
265 check-carchive-test: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
266 rm -rf carchive-test-dir carchive-testlog
267 $(MKDIR_P) carchive-test-dir/misc/cgo
268 cp -r $(libgomiscdir)/cgo/testcarchive carchive-test-dir/misc/cgo/
269 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
270 echo "cd carchive-test-dir/misc/cgo/testcarchive && $(ECHO_ENV) LIBRARY_PATH=`echo $${abs_libgodir}/.libs` $(abs_builddir)/go$(EXEEXT) test -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v carchive_test.go" > carchive-testlog
272 LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
273 export LIBRARY_PATH; \
274 (cd carchive-test-dir/misc/cgo/testcarchive && $(abs_builddir)/go$(EXEEXT) test -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v carchive_test.go) >> carchive-testlog 2>&1 || echo "--- $${fl}: go test misc/cgo/testcarchive (0.00s)" >> carchive-testlog
275 grep '^--- ' carchive-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
277 # check-vet runs `go test cmd/vet` in our environment.
278 check-vet: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
279 rm -rf check-vet-dir cmd_vet-testlog
280 $(MKDIR_P) check-vet-dir/src/cmd/internal check-vet-dir/src/cmd/vendor/golang.org/x
281 cp -r $(cmdsrcdir)/vet check-vet-dir/src/cmd/
282 cp -r $(cmdsrcdir)/internal/objabi check-vet-dir/src/cmd/internal
283 cp $(libgodir)/objabi.go check-vet-dir/src/cmd/internal/objabi/
284 cp -r $(libgosrcdir)/golang.org/x/tools check-vet-dir/src/cmd/vendor/golang.org/x/
285 @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
286 abs_checkdir=`cd check-vet-dir && $(PWD_COMMAND)`; \
287 echo "cd check-vet-dir/src/cmd/vet && $(ECHO_ENV) GOPATH=$${abs_checkdir} $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > cmd_vet-testlog
289 GOPATH=`cd check-vet-dir && $(PWD_COMMAND)`; \
291 (cd check-vet-dir/src/cmd/vet && $(abs_builddir)/go$(EXEEXT) test -test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v) >> cmd_vet-testlog 2>&1 || echo "--- $${fl}: go test cmd/vet (0.00s)" >> cmd_vet-testlog
292 grep '^--- ' cmd_vet-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
294 # The check targets runs the tests and assembles the output files.
295 check: check-head check-go-tool check-runtime check-cgo-test check-carchive-test check-vet
296 @mv gotools.head gotools.sum
297 @cp gotools.sum gotools.log
298 @for file in cmd_go-testlog runtime-testlog cgo-testlog carchive-testlog cmd_vet-testlog; do \
299 testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
300 echo "Running $${testname}" >> gotools.sum; \
301 echo "Running $${testname}" >> gotools.log; \
302 sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
303 grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' | sort -k 2 >> gotools.sum; \
306 @echo " === gotools Summary ===" >> gotools.sum
307 @pass=`grep -c '^PASS' gotools.sum`; \
308 if test "$${pass}" -ne "0"; then \
309 echo "# of expected passes $${pass}" >> gotools.sum; \
311 @fail=`grep -c '^FAIL' gotools.sum`; \
312 if test "$${fail}" -ne "0"; then \
313 echo "# of unexpected failures $${fail}" >> gotools.sum; \
315 @untested=`grep -c '^UNTESTED' gotools.sum`; \
316 if test "$${untested}" -ne "0"; then \
317 echo "# of untested testcases $${untested}" >> gotools.sum; \
319 @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
321 @echo "runtest completed at `date`" >> gotools.log
322 @if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
324 .PHONY: check check-head check-go-tool check-runtime check-cgo-test check-carchive-test check-vet
328 # For a non-native build we have to build the programs using a
329 # previously built host (or build -> host) Go compiler. We should
330 # only do this if such a compiler is available. We also need to get
331 # the right values for GOARCH and GOOS in the default build context in
332 # the go/build package. Figure this out later.