summaryrefslogtreecommitdiff
path: root/gotools/Makefile.am
blob: bde5e432531b9e8ae12b420b8c793147e27abbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Makefile for gotools
#   Copyright (C) 2015-2016 Free Software Foundation, Inc.
#
# 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

if NATIVE
# Use the compiler we just built.
GOCOMPILER = $(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET)
else
GOCOMPILER = $(GOC)
endif

GOCFLAGS = $(CFLAGS_FOR_TARGET)
GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)

AM_GOCFLAGS = -I $(libgodir)
AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@

libgosrcdir = $(srcdir)/../libgo/go
cmdsrcdir = $(libgosrcdir)/cmd

go_cmd_go_files = \
	$(cmdsrcdir)/go/alldocs.go \
	$(cmdsrcdir)/go/bug.go \
	$(cmdsrcdir)/go/build.go \
	$(cmdsrcdir)/go/clean.go \
	$(cmdsrcdir)/go/context.go \
	$(cmdsrcdir)/go/discovery.go \
	$(cmdsrcdir)/go/doc.go \
	$(cmdsrcdir)/go/env.go \
	$(cmdsrcdir)/go/fix.go \
	$(cmdsrcdir)/go/fmt.go \
	$(cmdsrcdir)/go/generate.go \
	$(cmdsrcdir)/go/get.go \
	$(cmdsrcdir)/go/go11.go \
	$(cmdsrcdir)/go/help.go \
	$(cmdsrcdir)/go/http.go \
	$(cmdsrcdir)/go/list.go \
	$(cmdsrcdir)/go/main.go \
	$(cmdsrcdir)/go/note.go \
	$(cmdsrcdir)/go/pkg.go \
	$(cmdsrcdir)/go/run.go \
	$(cmdsrcdir)/go/signal.go \
	$(cmdsrcdir)/go/signal_unix.go \
	$(cmdsrcdir)/go/test.go \
	$(cmdsrcdir)/go/testflag.go \
	$(cmdsrcdir)/go/tool.go \
	$(cmdsrcdir)/go/vcs.go \
	$(cmdsrcdir)/go/version.go \
	$(cmdsrcdir)/go/vet.go \
	$(libgodir)/zstdpkglist.go

go_cmd_gofmt_files = \
	$(cmdsrcdir)/gofmt/doc.go \
	$(cmdsrcdir)/gofmt/gofmt.go \
	$(cmdsrcdir)/gofmt/internal.go \
	$(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
	echo 'const defaultCC = "$(bindir)/$(GCC_INSTALL_NAME)"' >> zdefaultcc.go.tmp
	echo 'const defaultCXX = "$(bindir)/$(GXX_INSTALL_NAME)"' >> zdefaultcc.go.tmp
	echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
	$(SHELL) $(srcdir)/../move-if-change zdefaultcc.go.tmp zdefaultcc.go
	$(STAMP) $@ 

MOSTLYCLEANFILES = zdefaultcc.go s-zdefaultcc

if NATIVE

# 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)
noinst_PROGRAMS = cgo$(EXEEXT)
man_MANS = go.1 gofmt.1

go$(EXEEXT): $(go_cmd_go_files) zdefaultcc.go $(LIBGODEP)
	$(GOLINK) $(go_cmd_go_files) zdefaultcc.go $(LIBS) $(NET_LIBS)
gofmt$(EXEEXT): $(go_cmd_gofmt_files) $(LIBGODEP)
	$(GOLINK) $(go_cmd_gofmt_files) $(LIBS) $(NET_LIBS)
cgo$(EXEEXT): $(go_cmd_cgo_files) zdefaultcc.go $(LIBGODEP)
	$(GOLINK) $(go_cmd_cgo_files) zdefaultcc.go $(LIBS) $(NET_LIBS)

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)

# 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.
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;

# check-go-tools runs `go test cmd/go` in our environment.
check-go-tool: go$(EXEEXT) check-head check-gccgo
	rm -rf check-go-dir
	$(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/
	$(CHECK_ENV) \
	GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
	export GOPATH; \
	(cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) >& cmd_go-testlog || true
	grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'

# The check targets runs the tests and assembles the output files.
check: check-head check-go-tool
	mv gotools.head gotools.sum
	cp gotools.sum gotools.log
	for file in cmd_go-testlog; do \
	  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
	pass=`grep -c '^PASS' gotools.sum`; \
	if test "$${pass}" -ne "0"; then \
	  echo "# of expected passes		$${pass}" >> gotools.sum; \
	fi
	fail=`grep -c '^FAIL' gotools.sum`; \
	if test "$${fail}" -ne "0"; then \
	  echo "# of unexpected failures	$${fail}" >> gotools.sum; \
	fi
	untested=`grep -c '^UNTESTED' gotools.sum`; \
	if test "$${untested}" -ne "0"; then \
	  echo "# of untested testcases		$${untested}" >> gotools.sum; \
	fi
	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

.PHONY: check check-head check-go-tool

else

# 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.

endif

mostlyclean-local:
	rm -rf check-go-dir