2015-01-10 05:23:09 +08:00
# Makefile for gotools
2016-06-07 16:54:22 +08:00
# Copyright (C) 2015-2016 Free Software Foundation, Inc.
2015-01-10 05:23:09 +08:00
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
ACLOCAL_AMFLAGS = -I ./config -I ../config
gcc_version := $( shell $( GCC_FOR_TARGET) -dumpversion)
libexecsubdir = $( libexecdir) /gcc/$( target_noncanonical) /$( gcc_version)
mkinstalldirs = $( SHELL) $( toplevel_srcdir) /mkinstalldirs
PWD_COMMAND = $$ { PWDCMD-pwd}
STAMP = echo timestamp >
libgodir = ../$( target_noncanonical) /libgo
LIBGODEP = $( libgodir) /libgo.la
2015-01-10 08:23:48 +08:00
i f N A T I V E
# Use the compiler we just built.
2015-12-03 03:27:58 +08:00
GOCOMPILER = $( GOC_FOR_TARGET) $( XGCC_FLAGS_FOR_TARGET)
2015-01-10 08:23:48 +08:00
e l s e
GOCOMPILER = $( GOC)
e n d i f
2015-01-10 05:23:09 +08:00
GOCFLAGS = $( CFLAGS_FOR_TARGET)
2015-01-10 08:23:48 +08:00
GOCOMPILE = $( GOCOMPILER) $( GOCFLAGS)
2015-01-10 05:23:09 +08:00
2017-05-19 06:44:12 +08:00
AM_GOCFLAGS = -I $( libgodir)
2015-01-24 07:11:59 +08:00
AM_LDFLAGS = -L $( libgodir) -L $( libgodir) /.libs
2015-03-13 00:44:36 +08:00
GOLINK = $( GOCOMPILER) $( GOCFLAGS) $( AM_GOCFLAGS) $( LDFLAGS) $( AM_LDFLAGS) -o $@
2015-01-10 05:23:09 +08:00
2017-06-15 03:26:21 +08:00
libgosrcdir = $( srcdir) /../libgo/go
cmdsrcdir = $( libgosrcdir) /cmd
2017-06-30 00:01:38 +08:00
libgomiscdir = $( srcdir) /../libgo/misc
2015-01-10 05:23:09 +08:00
go_cmd_go_files = \
2015-11-01 05:29:38 +08:00
$( cmdsrcdir) /go/alldocs.go \
2017-01-14 08:05:42 +08:00
$( cmdsrcdir) /go/bug.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/build.go \
$( cmdsrcdir) /go/clean.go \
$( cmdsrcdir) /go/context.go \
$( cmdsrcdir) /go/discovery.go \
2015-11-01 05:29:38 +08:00
$( cmdsrcdir) /go/doc.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/env.go \
$( cmdsrcdir) /go/fix.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/fmt.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/generate.go \
$( cmdsrcdir) /go/get.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/go11.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/help.go \
$( cmdsrcdir) /go/http.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/list.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/main.go \
2015-11-01 05:29:38 +08:00
$( cmdsrcdir) /go/note.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/pkg.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/run.go \
$( cmdsrcdir) /go/signal.go \
$( cmdsrcdir) /go/signal_unix.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /go/test.go \
2015-01-15 08:27:56 +08:00
$( cmdsrcdir) /go/testflag.go \
$( cmdsrcdir) /go/tool.go \
$( cmdsrcdir) /go/vcs.go \
$( cmdsrcdir) /go/version.go \
2015-03-25 03:50:31 +08:00
$( cmdsrcdir) /go/vet.go \
$( libgodir) /zstdpkglist.go
2015-01-10 05:23:09 +08:00
go_cmd_gofmt_files = \
$( cmdsrcdir) /gofmt/doc.go \
$( cmdsrcdir) /gofmt/gofmt.go \
2016-02-04 05:58:02 +08:00
$( cmdsrcdir) /gofmt/internal.go \
2015-01-10 05:23:09 +08:00
$( cmdsrcdir) /gofmt/rewrite.go \
$( cmdsrcdir) /gofmt/simplify.go
go_cmd_cgo_files = \
$( cmdsrcdir) /cgo/ast.go \
$( cmdsrcdir) /cgo/doc.go \
$( cmdsrcdir) /cgo/gcc.go \
$( cmdsrcdir) /cgo/godefs.go \
$( cmdsrcdir) /cgo/main.go \
$( cmdsrcdir) /cgo/out.go \
$( cmdsrcdir) /cgo/util.go
GCCGO_INSTALL_NAME := $( shell echo gccgo| sed '$(program_transform_name)' )
GCC_INSTALL_NAME := $( shell echo gcc| sed '$(program_transform_name)' )
GXX_INSTALL_NAME := $( shell echo g++| sed '$(program_transform_name)' )
zdefaultcc.go : s -zdefaultcc ; @true
s-zdefaultcc : Makefile
echo 'package main' > zdefaultcc.go.tmp
echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"' >> zdefaultcc.go.tmp
2017-06-27 06:47:18 +08:00
echo 'const defaultCC = "$(GCC_INSTALL_NAME)"' >> zdefaultcc.go.tmp
echo 'const defaultCXX = "$(GXX_INSTALL_NAME)"' >> zdefaultcc.go.tmp
2017-01-14 08:05:42 +08:00
echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
2015-01-10 05:23:09 +08:00
$( SHELL) $( srcdir) /../move-if-change zdefaultcc.go.tmp zdefaultcc.go
$( STAMP) $@
2017-06-30 00:01:38 +08:00
MOSTLYCLEANFILES = \
zdefaultcc.go s-zdefaultcc \
check-gccgo gotools.head *-testlog gotools.sum gotools.log
mostlyclean-local :
rm -rf check-go-dir check-runtime-dir cgo-test-dir carchive-test-dir
2015-01-10 08:23:48 +08:00
2015-01-10 05:23:09 +08:00
i f N A T I V E
# For a native build we build the programs using the newly built libgo
# and install them as regular programs.
bin_PROGRAMS = go$( EXEEXT) gofmt$( EXEEXT)
2015-01-22 12:19:11 +08:00
noinst_PROGRAMS = cgo$( EXEEXT)
2015-01-23 09:42:08 +08:00
man_MANS = go.1 gofmt.1
2015-01-10 05:23:09 +08:00
go$(EXEEXT) : $( go_cmd_go_files ) zdefaultcc .go $( LIBGODEP )
2015-01-20 17:26:50 +08:00
$( GOLINK) $( go_cmd_go_files) zdefaultcc.go $( LIBS) $( NET_LIBS)
2015-01-10 05:23:09 +08:00
gofmt$(EXEEXT) : $( go_cmd_gofmt_files ) $( LIBGODEP )
2015-01-20 17:26:50 +08:00
$( GOLINK) $( go_cmd_gofmt_files) $( LIBS) $( NET_LIBS)
2015-01-10 05:23:09 +08:00
cgo$(EXEEXT) : $( go_cmd_cgo_files ) zdefaultcc .go $( LIBGODEP )
2015-01-20 17:26:50 +08:00
$( GOLINK) $( go_cmd_cgo_files) zdefaultcc.go $( LIBS) $( NET_LIBS)
2015-01-10 05:23:09 +08:00
2015-01-22 12:19:11 +08:00
install-exec-local : cgo $( EXEEXT )
$( MKDIR_P) $( DESTDIR) $( libexecsubdir)
rm -f $( DESTDIR) $( libexecsubdir) /cgo$( exeext)
$( INSTALL_PROGRAM) cgo$( exeext) $( DESTDIR) $( libexecsubdir) /cgo$( exeext)
uninstall-local :
rm -f $( DESTDIR) $( libexecsubdir) /cgo$( exeext)
2017-06-15 03:26:21 +08:00
# Run tests using the go tool, and frob the output to look like that
# generated by DejaGNU. The main output of this is two files:
# gotools.sum and gotools.log.
# check-head starts generating the log files in DejaGNU format. This
# is a separate target so that the date is approximately when we start
# running the tests.
check-head :
@echo " Test Run By $$ {USER} on `date` " > gotools.head
@echo " Native configuration is $( host_triplet) " >> gotools.head
@echo >> gotools.head
@echo " === gotools tests ===" >> gotools.head
@echo >> gotools.head
# check-gccgo is a little shell script that executes gccgo with the
# options to pick up the newly built libgo.
check-gccgo : Makefile
rm -f $@
echo "#!/bin/sh" > $@
abs_libgodir = ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
echo " $( GOCOMPILE) " '"$$@"' " -I $$ {abs_libgodir} -L $$ {abs_libgodir} -L $$ {abs_libgodir}/.libs " >> $@
chmod +x $@
# CHECK_ENV sets up the environment to run the newly built go tool.
2017-06-30 00:01:38 +08:00
# If you change this, change ECHO_ENV, below.
2017-06-15 03:26:21 +08:00
CHECK_ENV = \
PATH = ` echo $( abs_builddir) :$$ { PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,' ` ; \
export PATH; \
GCCGO = " $( abs_builddir) /check-gccgo " ; \
export GCCGO; \
GCCGOTOOLDIR = " $( abs_builddir) " ; \
export GCCGOTOOLDIR; \
GO_TESTING_GOTOOLS = yes; \
export GO_TESTING_GOTOOLS; \
abs_libgodir = ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
LD_LIBRARY_PATH = ` echo $$ { abs_libgodir} /.libs:$$ { LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,' ` ; \
export LD_LIBRARY_PATH;
2017-06-30 00:01:38 +08:00
# ECHO_ENV is a variant of CHECK_ENV to put into a testlog file.
# It assumes that abs_libgodir is set.
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,:*$$,,' `
2017-06-15 03:26:21 +08:00
# check-go-tools runs `go test cmd/go` in our environment.
2017-06-30 00:01:38 +08:00
check-go-tool : go $( EXEEXT ) cgo $( EXEEXT ) check -head check -gccgo
rm -rf check-go-dir cmd_go-testlog
2017-06-15 03:26:21 +08:00
$( MKDIR_P) check-go-dir/src/cmd/go
cp $( cmdsrcdir) /go/*.go check-go-dir/src/cmd/go/
cp $( libgodir) /zstdpkglist.go check-go-dir/src/cmd/go/
cp zdefaultcc.go check-go-dir/src/cmd/go/
cp -r $( cmdsrcdir) /go/testdata check-go-dir/src/cmd/go/
2017-06-30 00:01:38 +08:00
@abs_libgodir= ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
abs_checkdir = ` cd check-go-dir && $( PWD_COMMAND) ` ; \
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
2017-06-15 03:26:21 +08:00
$( CHECK_ENV) \
GOPATH = ` cd check-go-dir && $( PWD_COMMAND) ` ; \
export GOPATH; \
2017-06-16 14:58:06 +08:00
( cd check-go-dir/src/cmd/go && $( abs_builddir) /go$( EXEEXT) test -test.short -test.v) > cmd_go-testlog 2>& 1 || true
2017-06-15 03:26:21 +08:00
grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
2017-06-30 00:01:38 +08:00
# check-runtime runs `go test runtime` in our environment.
# The runtime package is also tested as part of libgo,
# but the runtime tests use the go tool heavily, so testing
# here too will catch more problems.
check-runtime : go $( EXEEXT ) cgo $( EXEEXT ) check -head check -gccgo
rm -rf check-runtime-dir runtime-testlog
$( MKDIR_P) check-runtime-dir
@abs_libgodir= ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
LD_LIBRARY_PATH = ` echo $$ { abs_libgodir} /.libs:$$ { LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,' ` ; \
GOARCH = ` $( abs_builddir) /go$( EXEEXT) env GOARCH` ; \
GOOS = ` $( abs_builddir) /go$( EXEEXT) env GOOS` ; \
files = ` $( SHELL) $( libgosrcdir) /../match.sh --goarch= $$ { GOARCH} --goos= $$ { GOOS} --srcdir= $( libgosrcdir) /runtime --extrafiles= " $( libgodir) /runtime_sysinfo.go $( libgodir) /sigtab.go " --tag= libffi` ; \
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
$( CHECK_ENV) \
GC = " $$ {GCCGO} -fgo-compiling-runtime " ; \
export GC; \
GOARCH = ` $( abs_builddir) /go$( EXEEXT) env GOARCH` ; \
GOOS = ` $( abs_builddir) /go$( EXEEXT) env GOOS` ; \
files = ` $( SHELL) $( libgosrcdir) /../match.sh --goarch= $$ { GOARCH} --goos= $$ { GOOS} --srcdir= $( libgosrcdir) /runtime --extrafiles= " $( libgodir) /runtime_sysinfo.go $( libgodir) /sigtab.go " --tag= libffi` ; \
$( SHELL) $( libgosrcdir) /../testsuite/gotest --goarch= $$ { GOARCH} --goos= $$ { GOOS} --basedir= $( libgosrcdir) /.. --srcdir= $( libgosrcdir) /runtime --pkgpath= runtime --pkgfiles= " $$ {files} " -test.v >> runtime-testlog 2>& 1 || true
grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
# check-cgo-test runs `go test misc/cgo/test` in our environment.
check-cgo-test : go $( EXEEXT ) cgo $( EXEEXT ) check -head check -gccgo
rm -rf cgo-test-dir cgo-testlog
$( MKDIR_P) cgo-test-dir/misc/cgo
cp -r $( libgomiscdir) /cgo/test cgo-test-dir/misc/cgo/
@abs_libgodir= ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
echo " cd cgo-test-dir/misc/cgo/test && $( ECHO_ENV) GOTRACEBACK=2 $( abs_builddir) /go $( EXEEXT) test -test.short -test.v " > cgo-testlog
$( CHECK_ENV) \
GOTRACEBACK = 2; \
export GOTRACEBACK; \
( cd cgo-test-dir/misc/cgo/test && $( abs_builddir) /go$( EXEEXT) test -test.short -test.v) >> cgo-testlog 2>& 1 || true
grep '^--- ' cgo-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
# check-carchive-test runs `go test misc/cgo/testcarchive/carchive_test.go`
# in our environment.
check-carchive-test : go $( EXEEXT ) cgo $( EXEEXT ) check -head check -gccgo
rm -rf carchive-test-dir carchive-testlog
$( MKDIR_P) carchive-test-dir/misc/cgo
cp -r $( libgomiscdir) /cgo/testcarchive carchive-test-dir/misc/cgo/
@abs_libgodir= ` cd $( libgodir) && $( PWD_COMMAND) ` ; \
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
$( CHECK_ENV) \
LIBRARY_PATH = ` echo $$ { abs_libgodir} /.libs:$$ { LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,' ` ; \
export LIBRARY_PATH; \
( cd carchive-test-dir/misc/cgo/testcarchive && $( abs_builddir) /go$( EXEEXT) test -test.v carchive_test.go) >> carchive-testlog 2>& 1 || true
grep '^--- ' carchive-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
2017-06-15 03:26:21 +08:00
# The check targets runs the tests and assembles the output files.
2017-06-30 00:01:38 +08:00
check : check -head check -go -tool check -runtime check -cgo -test check -carchive -test
@mv gotools.head gotools.sum
@cp gotools.sum gotools.log
@for file in cmd_go-testlog runtime-testlog cgo-testlog carchive-testlog; do \
2017-06-15 03:26:21 +08:00
testname = ` echo $$ { file} | sed -e 's/-testlog//' -e 's|_|/|' ` ; \
echo " Running $$ {testname} " >> gotools.sum; \
echo " Running $$ {testname} " >> gotools.log; \
sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $$ { file} >> gotools.log; \
grep '^--- ' $$ { file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' >> gotools.sum; \
done
@echo >> gotools.sum
@echo " === gotools Summary ===" >> gotools.sum
2017-06-30 00:01:38 +08:00
@pass= ` grep -c '^PASS' gotools.sum` ; \
2017-06-15 03:26:21 +08:00
if test " $$ {pass} " -ne "0" ; then \
echo " # of expected passes $$ {pass} " >> gotools.sum; \
fi
2017-06-30 00:01:38 +08:00
@fail= ` grep -c '^FAIL' gotools.sum` ; \
2017-06-15 03:26:21 +08:00
if test " $$ {fail} " -ne "0" ; then \
echo " # of unexpected failures $$ {fail} " >> gotools.sum; \
fi
2017-06-30 00:01:38 +08:00
@untested= ` grep -c '^UNTESTED' gotools.sum` ; \
2017-06-15 03:26:21 +08:00
if test " $$ {untested} " -ne "0" ; then \
echo " # of untested testcases $$ {untested} " >> gotools.sum; \
fi
2017-06-30 00:01:38 +08:00
@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
@echo >> gotools.log
@echo "runtest completed at `date`" >> gotools.log
@if grep '^FAIL' gotools.sum >/dev/null 2>& 1; then exit 1; fi
2017-06-15 03:26:21 +08:00
2017-06-30 00:01:38 +08:00
.PHONY : check check -head check -go -tool check -runtime check -cgo -test check -carchive -test
2017-06-15 03:26:21 +08:00
2015-01-10 05:23:09 +08:00
e l s e
# For a non-native build we have to build the programs using a
# previously built host (or build -> host) Go compiler. We should
# only do this if such a compiler is available. We also need to get
# the right values for GOARCH and GOOS in the default build context in
# the go/build package. Figure this out later.
e n d i f