* configure.ac: Substitute GOC_FOR_TARGET and GCC_FOR_TARGET.
[official-gcc.git] / gotools / Makefile.am
blob41a2c72dc5b82cd7aa35d0bad2f16cf39379b002
1 # Makefile for gotools
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.
8
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.
13
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
31 if NATIVE
32 # Use the compiler we just built.
33 GOCOMPILER = $(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET)
34 else
35 GOCOMPILER = $(GOC)
36 endif
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
49 go_cmd_go_files = \
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
87 go_cmd_cgo_files = \
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
108         $(STAMP) $@ 
110 MOSTLYCLEANFILES = \
111         zdefaultcc.go s-zdefaultcc \
112         check-gccgo check-gcc gotools.head *-testlog gotools.sum gotools.log \
113         *.sent
115 mostlyclean-local:
116         rm -rf check-go-dir check-runtime-dir cgo-test-dir carchive-test-dir
118 if NATIVE
120 # For a native build we build the programs using the newly built libgo
121 # and install them as regular programs.
123 bin_PROGRAMS = go$(EXEEXT) gofmt$(EXEEXT)
124 noinst_PROGRAMS = cgo$(EXEEXT)
125 man_MANS = go.1 gofmt.1
127 go$(EXEEXT): $(go_cmd_go_files) zdefaultcc.go $(LIBGODEP)
128         $(GOLINK) $(go_cmd_go_files) zdefaultcc.go $(LIBS) $(NET_LIBS)
129 gofmt$(EXEEXT): $(go_cmd_gofmt_files) $(LIBGODEP)
130         $(GOLINK) $(go_cmd_gofmt_files) $(LIBS) $(NET_LIBS)
131 cgo$(EXEEXT): $(go_cmd_cgo_files) zdefaultcc.go $(LIBGODEP)
132         $(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go $(LIBS) $(NET_LIBS)
134 install-exec-local: cgo$(EXEEXT)
135         $(MKDIR_P) $(DESTDIR)$(libexecsubdir)
136         rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
137         $(INSTALL_PROGRAM) cgo$(exeext) $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
139 uninstall-local:
140         rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
142 # Run tests using the go tool, and frob the output to look like that
143 # generated by DejaGNU.  The main output of this is two files:
144 # gotools.sum and gotools.log.
146 # check-head starts generating the log files in DejaGNU format.  This
147 # is a separate target so that the date is approximately when we start
148 # running the tests.
149 check-head:
150         @echo "Test Run By $${USER} on `date`" > gotools.head
151         @echo "Native configuration is $(host_triplet)" >> gotools.head
152         @echo >> gotools.head
153         @echo "         === gotools tests ===" >> gotools.head
154         @echo >> gotools.head
156 # check-gccgo is a little shell script that executes gccgo with the
157 # options to pick up the newly built libgo.
158 check-gccgo: Makefile
159         rm -f $@ $@.tmp
160         echo "#!/bin/sh" > $@.tmp
161         abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
162         echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L $${abs_libgodir}/.libs" >> $@.tmp
163         chmod +x $@.tmp
164         mv -f $@.tmp $@
166 # check-gcc is a little shell script that executes the newly built gcc
167 # with the options to pick up the newly built libgo.
168 check-gcc: Makefile
169         rm -f $@ $@.tmp
170         echo "#!/bin/sh" > $@.tmp
171         abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
172         echo "$(GCC_FOR_TARGET)" '"$$@"' "-L $${abs_libgodir} -L $${abs_libgodir}/.libs" >> $@.tmp
173         chmod +x $@.tmp
174         mv -f $@.tmp $@
176 # CHECK_ENV sets up the environment to run the newly built go tool.
177 # If you change this, change ECHO_ENV, below.
178 CHECK_ENV = \
179         PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
180         export PATH; \
181         GCCGO="$(abs_builddir)/check-gccgo"; \
182         export GCCGO; \
183         CC="$(abs_builddir)/check-gcc"; \
184         export CC; \
185         GCCGOTOOLDIR="$(abs_builddir)"; \
186         export GCCGOTOOLDIR; \
187         GO_TESTING_GOTOOLS=yes; \
188         export GO_TESTING_GOTOOLS; \
189         abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
190         LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
191         export LD_LIBRARY_PATH; \
192         GOROOT=$${abs_libgodir}; \
193         export GOROOT;
195 # ECHO_ENV is a variant of CHECK_ENV to put into a testlog file.
196 # It assumes that abs_libgodir is set.
197 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}`
199 # check-go-tools runs `go test cmd/go` in our environment.
200 check-go-tool: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo check-gcc
201         rm -rf check-go-dir cmd_go-testlog
202         $(MKDIR_P) check-go-dir/src/cmd/go
203         cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
204         cp $(libgodir)/zstdpkglist.go check-go-dir/src/cmd/go/
205         cp zdefaultcc.go check-go-dir/src/cmd/go/
206         cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
207         @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
208         abs_checkdir=`cd check-go-dir && $(PWD_COMMAND)`; \
209         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
210         $(CHECK_ENV) \
211         GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
212         export GOPATH; \
213         (cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) > cmd_go-testlog 2>&1 || true
214         grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
216 # check-runtime runs `go test runtime` in our environment.
217 # The runtime package is also tested as part of libgo,
218 # but the runtime tests use the go tool heavily, so testing
219 # here too will catch more problems.
220 check-runtime: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo check-gcc
221         rm -rf check-runtime-dir runtime-testlog
222         $(MKDIR_P) check-runtime-dir
223         @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
224         LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
225         GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
226         GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
227         files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
228         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
229         $(CHECK_ENV) \
230         GC="$${GCCGO} -fgo-compiling-runtime"; \
231         export GC; \
232         GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
233         GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
234         files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go" --tag=libffi`; \
235         $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" -test.v >> runtime-testlog 2>&1 || true
236         grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
238 # check-cgo-test runs `go test misc/cgo/test` in our environment.
239 check-cgo-test: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo check-gcc
240         rm -rf cgo-test-dir cgo-testlog
241         $(MKDIR_P) cgo-test-dir/misc/cgo
242         cp -r $(libgomiscdir)/cgo/test cgo-test-dir/misc/cgo/
243         @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
244         echo "cd cgo-test-dir/misc/cgo/test && $(ECHO_ENV) GOTRACEBACK=2 $(abs_builddir)/go$(EXEEXT) test -test.short -test.v" > cgo-testlog
245         $(CHECK_ENV) \
246         GOTRACEBACK=2; \
247         export GOTRACEBACK; \
248         (cd cgo-test-dir/misc/cgo/test && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) >> cgo-testlog 2>&1 || true
249         grep '^--- ' cgo-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
251 # check-carchive-test runs `go test misc/cgo/testcarchive/carchive_test.go`
252 # in our environment.
253 check-carchive-test: go$(EXEEXT) cgo$(EXEEXT) check-head check-gccgo check-gcc
254         rm -rf carchive-test-dir carchive-testlog
255         $(MKDIR_P) carchive-test-dir/misc/cgo
256         cp -r $(libgomiscdir)/cgo/testcarchive carchive-test-dir/misc/cgo/
257         @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
258         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
259         $(CHECK_ENV) \
260         LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
261         export LIBRARY_PATH; \
262         (cd carchive-test-dir/misc/cgo/testcarchive && $(abs_builddir)/go$(EXEEXT) test -test.v carchive_test.go) >> carchive-testlog 2>&1 || true
263         grep '^--- ' carchive-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
265 # The check targets runs the tests and assembles the output files.
266 check: check-head check-go-tool check-runtime check-cgo-test check-carchive-test
267         @mv gotools.head gotools.sum
268         @cp gotools.sum gotools.log
269         @for file in cmd_go-testlog runtime-testlog cgo-testlog carchive-testlog; do \
270           testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
271           echo "Running $${testname}" >> gotools.sum; \
272           echo "Running $${testname}" >> gotools.log; \
273           sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
274           grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' >> gotools.sum; \
275         done
276         @echo >> gotools.sum
277         @echo "         === gotools Summary ===" >> gotools.sum
278         @pass=`grep -c '^PASS' gotools.sum`; \
279         if test "$${pass}" -ne "0"; then \
280           echo "# of expected passes            $${pass}" >> gotools.sum; \
281         fi
282         @fail=`grep -c '^FAIL' gotools.sum`; \
283         if test "$${fail}" -ne "0"; then \
284           echo "# of unexpected failures        $${fail}" >> gotools.sum; \
285         fi
286         @untested=`grep -c '^UNTESTED' gotools.sum`; \
287         if test "$${untested}" -ne "0"; then \
288           echo "# of untested testcases         $${untested}" >> gotools.sum; \
289         fi
290         @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
291         @echo >> gotools.log
292         @echo "runtest completed at `date`" >> gotools.log
293         @if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
295 .PHONY: check check-head check-go-tool check-runtime check-cgo-test check-carchive-test
297 else
299 # For a non-native build we have to build the programs using a
300 # previously built host (or build -> host) Go compiler.  We should
301 # only do this if such a compiler is available.  We also need to get
302 # the right values for GOARCH and GOOS in the default build context in
303 # the go/build package.  Figure this out later.
305 endif