~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/Make.pkg

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-04-20 17:36:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110420173648-ifergoxyrm832trd
Tags: upstream-2011.03.07.1
Import upstream version 2011.03.07.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009 The Go Authors. All rights reserved.
 
2
# Use of this source code is governed by a BSD-style
 
3
# license that can be found in the LICENSE file.
 
4
 
 
5
all: package
 
6
package: _obj/$(TARG).a
 
7
testpackage: _test/$(TARG).a
 
8
 
 
9
include $(QUOTED_GOROOT)/src/Make.common
 
10
 
 
11
# The quietgcc wrapper is for our own source code
 
12
# while building the libraries, not arbitrary source code
 
13
# as encountered by cgo.
 
14
ifeq ($(HOST_CC),quietgcc)
 
15
HOST_CC:=gcc
 
16
endif
 
17
ifeq ($(HOST_LD),quietgcc)
 
18
HOST_LD:=gcc
 
19
endif
 
20
 
 
21
# GNU Make 3.80 has a bug in lastword
 
22
# elem=$(lastword $(subst /, ,$(TARG)))
 
23
TARG_words=$(subst /, ,$(TARG))
 
24
elem=$(word $(words $(TARG_words)),$(TARG_words))
 
25
 
 
26
ifeq ($(elem),$(TARG))
 
27
dir=
 
28
else
 
29
dir=$(patsubst %/$(elem),%,$(TARG))
 
30
endif
 
31
 
 
32
pkgdir=$(QUOTED_GOROOT)/pkg/$(GOOS)_$(GOARCH)
 
33
 
 
34
INSTALLFILES+=$(pkgdir)/$(TARG).a
 
35
 
 
36
# The rest of the cgo rules are below, but these variable updates
 
37
# must be done here so they apply to the main rules.
 
38
ifdef CGOFILES
 
39
GOFILES+=$(patsubst %.go,_obj/%.cgo1.go,$(CGOFILES)) _obj/_cgo_gotypes.go
 
40
CGO_OFILES+=$(patsubst %.go,%.cgo2.o,$(CGOFILES)) _cgo_export.o
 
41
OFILES+=_cgo_defun.$O _cgo_import.$O $(CGO_OFILES)
 
42
endif
 
43
 
 
44
PREREQ+=$(patsubst %,%.make,$(DEPS))
 
45
 
 
46
coverage:
 
47
        gotest
 
48
        6cov -g $(shell pwd) $O.out | grep -v '_test\.go:'
 
49
 
 
50
CLEANFILES+=*.so _obj _test _testmain.go *.exe _cgo* *.cgo[12].*
 
51
 
 
52
test:
 
53
        gotest
 
54
 
 
55
bench:
 
56
        gotest -test.bench=. -test.run="Do not run tests"
 
57
 
 
58
nuke: clean
 
59
        rm -f $(pkgdir)/$(TARG).a
 
60
 
 
61
testpackage-clean:
 
62
        rm -f _test/$(TARG).a
 
63
 
 
64
install: $(INSTALLFILES)
 
65
 
 
66
$(pkgdir)/$(TARG).a: _obj/$(TARG).a
 
67
        @test -d $(QUOTED_GOROOT)/pkg && mkdir -p $(pkgdir)/$(dir)
 
68
        cp _obj/$(TARG).a "$@"
 
69
 
 
70
_go_.$O: $(GOFILES) $(PREREQ)
 
71
        $(GC) -o $@ $(GOFILES)
 
72
 
 
73
_gotest_.$O: $(GOFILES) $(GOTESTFILES) $(PREREQ)
 
74
        $(GC) -o $@ $(GOFILES) $(GOTESTFILES)
 
75
 
 
76
_obj/$(TARG).a: _go_.$O $(OFILES)
 
77
        @mkdir -p _obj/$(dir)
 
78
        rm -f _obj/$(TARG).a
 
79
        gopack grc $@ _go_.$O $(OFILES)
 
80
 
 
81
_test/$(TARG).a: _gotest_.$O $(OFILES)
 
82
        @mkdir -p _test/$(dir)
 
83
        rm -f _test/$(TARG).a
 
84
        gopack grc $@ _gotest_.$O $(OFILES)
 
85
 
 
86
importpath:
 
87
        @echo $(TARG)
 
88
 
 
89
dir:
 
90
        @echo $(dir)
 
91
 
 
92
# To use cgo in a Go package, add a line
 
93
#
 
94
#       CGOFILES=x.go y.go
 
95
#
 
96
# to the main Makefile.  This signals that cgo should process x.go
 
97
# and y.go when building the package.
 
98
# There are three optional variables to set, CGO_CFLAGS, CGO_LDFLAGS,
 
99
# and CGO_DEPS, which specify compiler flags, linker flags, and linker
 
100
# dependencies to use when compiling (using gcc) the C support for
 
101
# x.go and y.go.
 
102
 
 
103
# Cgo translates each x.go file listed in $(CGOFILES) into a basic
 
104
# translation of x.go, called _obj/x.cgo1.go. Additionally, three other
 
105
# files are created:
 
106
#
 
107
#       _obj/_cgo_gotypes.go    - declarations needed for all .go files in the package; imports "unsafe"
 
108
#       _obj/_cgo_defun.c       - C trampoline code to be compiled with 6c and linked into the package
 
109
#       _obj/x.cgo2.c   - C implementations compiled with gcc to create a dynamic library
 
110
#
 
111
 
 
112
ifdef CGOFILES
 
113
_obj/_cgo_run: $(CGOFILES)
 
114
        @mkdir -p _obj
 
115
        CGOPKGPATH=$(dir) cgo -- $(CGO_CFLAGS) $(CGOFILES)
 
116
        touch _obj/_cgo_run
 
117
 
 
118
# _CGO_CFLAGS and _CGO_LDFLAGS are defined via the evaluation of _cgo_flags.
 
119
# The include happens before the commands in the recipe run,
 
120
# so it cannot be done in the same recipe that runs cgo.
 
121
_obj/_load_cgo_flags: _obj/_cgo_run
 
122
        $(eval include _obj/_cgo_flags)
 
123
 
 
124
# Include any previous flags in case cgo files are up to date.
 
125
-include _obj/_cgo_flags
 
126
 
 
127
# Ugly but necessary - cgo writes these files too.
 
128
_obj/_cgo_gotypes.go _obj/_cgo_export.c _obj/_cgo_export.h _obj/_cgo_main.c _obj/_cgo_defun.c: _obj/_load_cgo_flags
 
129
        @true
 
130
 
 
131
_obj/%.cgo1.go _obj/%.cgo2.c: _obj/_cgo_defun.c
 
132
        @true
 
133
endif
 
134
 
 
135
# Compile rules for gcc source files.
 
136
%.o: %.c
 
137
        $(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -fPIC -O2 -o $@ -c $(CGO_CFLAGS) $(_CGO_CFLAGS) $*.c
 
138
 
 
139
%.o: _obj/%.c
 
140
        $(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -I . -g -fPIC -O2 -o $@ -c $(CGO_CFLAGS) $(_CGO_CFLAGS) $^
 
141
 
 
142
# To find out which symbols are needed from external libraries
 
143
# and which libraries are needed, we build a simple a.out that
 
144
# links all the objects we just created and then use cgo -dynimport
 
145
# to inspect it.  That is, we make gcc tell us which dynamic symbols
 
146
# and libraries are involved, instead of duplicating gcc's logic ourselves.
 
147
# After main we have to define all the symbols that will be provided
 
148
# by Go code.  That's crosscall2 and any exported symbols.
 
149
 
 
150
_cgo1_.o: _cgo_main.o $(CGO_OFILES)
 
151
        $(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -fPIC -O2 -o $@ $^ $(CGO_LDFLAGS) $(_CGO_LDFLAGS)
 
152
 
 
153
_obj/_cgo_import.c: _cgo1_.o
 
154
        @mkdir -p _obj
 
155
        cgo -dynimport _cgo1_.o >$@_ && mv -f $@_ $@
 
156
 
 
157
# The rules above added x.cgo1.go and _cgo_gotypes.go to $(GOFILES),
 
158
# added _cgo_defun.$O to $OFILES, and added the installed copy of
 
159
# package_x.so (built from x.cgo2.c) to $(INSTALLFILES).
 
160
 
 
161
# Have to run gcc with the right size argument on hybrid 32/64 machines.
 
162
_CGO_CFLAGS_386=-m32
 
163
_CGO_CFLAGS_amd64=-m64
 
164
_CGO_LDFLAGS_freebsd=-shared -lpthread -lm
 
165
_CGO_LDFLAGS_linux=-shared -lpthread -lm
 
166
_CGO_LDFLAGS_darwin=-dynamiclib -Wl,-undefined,dynamic_lookup
 
167
_CGO_LDFLAGS_windows=-shared -lm -mthreads
 
168
 
 
169
# Have to compile the runtime header.
 
170
RUNTIME_CFLAGS=-I$(pkgdir)
 
171
 
 
172
# Compile _cgo_defun.c with 6c; needs access to the runtime headers.
 
173
_cgo_defun.$O: _obj/_cgo_defun.c
 
174
        $(CC) $(CFLAGS) $(RUNTIME_CFLAGS) -I . -o "$@" _obj/_cgo_defun.c
 
175
 
 
176
# Generic build rules.
 
177
# These come last so that the rules above can override them
 
178
# for more specific file names.
 
179
%.$O: %.c $(HFILES)
 
180
        $(CC) $(CFLAGS) -o "$@" $*.c
 
181
 
 
182
%.$O: _obj/%.c $(HFILES)
 
183
        $(CC) $(CFLAGS) -I . -o "$@" _obj/$*.c
 
184
 
 
185
%.$O: %.s
 
186
        $(AS) $*.s