Make.inc 3.39 KB
Newer Older
1 2 3 4
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

5
# Makefile included by all other Go makefiles.
6 7 8 9 10 11 12 13 14

# Clear variables that must come from Makefiles,
# not the environment.
LIB:=
TARG:=
GOFILES:=
HFILES:=
OFILES:=
YFILES:=
15

16
# GOROOT must be set.
17
ifeq ($(GOROOT),)
18
$(error $$GOROOT is not set; use gomake or set $$GOROOT in your environment)
19 20
endif

21 22 23
# Set up GOROOT_FINAL, GOARCH, GOOS if needed.
GOROOT_FINAL?=$(GOROOT)

24 25 26 27
ifeq ($(GOHOSTOS),)
GOHOSTOS:=$(shell uname | tr A-Z a-z | sed 's/mingw/windows/; s/.*windows.*/windows/')
endif

28
ifeq ($(GOOS),)
29
GOOS:=$(GOHOSTOS)
30 31 32 33 34
endif

ifeq ($(GOOS),darwin)
else ifeq ($(GOOS),freebsd)
else ifeq ($(GOOS),linux)
Rob Pike's avatar
Rob Pike committed
35
else ifeq ($(GOOS),tiny)
36
else ifeq ($(GOOS),plan9)
37 38
else ifeq ($(GOOS),windows)
else
Russ Cox's avatar
Russ Cox committed
39
$(error Invalid $$GOOS '$(GOOS)'; must be darwin, freebsd, linux, plan9, tiny, or windows)
40 41
endif

42 43
ifeq ($(GOHOSTARCH),)
ifeq ($(GOHOSTOS),darwin)
44 45
# Even on 64-bit platform, darwin uname -m prints i386.
# Check for amd64 with sysctl instead.
46
GOHOSTARCH:=${shell if sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null; then echo amd64; else uname -m | sed 's/i386/386/'; fi}
47 48
else
# Ask uname -m for the processor.
49
GOHOSTARCH:=${shell uname -m | sed 's/^..86$$/386/; s/^.86$$/386/; s/x86_64/amd64/; s/arm.*/arm/'}
50 51 52
endif
endif

53 54 55 56
ifeq ($(GOARCH),)
GOARCH:=$(GOHOSTARCH)
endif

Andrew Gerrand's avatar
Andrew Gerrand committed
57 58 59 60 61
# darwin requires GOHOSTARCH match GOARCH
ifeq ($(GOOS),darwin)
GOHOSTARCH:=$(GOARCH)
endif

62 63 64 65 66
ifeq ($(GOARCH),386)
O:=8
else ifeq ($(GOARCH),amd64)
O:=6
else ifeq ($(GOARCH),arm)
67

68
O:=5
69 70 71 72 73
ifeq ($(GOOS),linux)
else
$(error Invalid $$GOOS '$(GOOS)' for GOARCH=arm; must be linux)
endif

74 75 76 77
else
$(error Invalid $$GOARCH '$(GOARCH)'; must be 386, amd64, or arm)
endif

78
# Save for recursive make to avoid recomputing.
79
export GOARCH GOOS GOHOSTARCH GOHOSTOS
80

81 82 83 84 85 86 87 88 89 90 91
# ugly hack to deal with whitespaces in $GOROOT
nullstring :=
space := $(nullstring) # a space at the end
QUOTED_GOROOT:=$(subst $(space),\ ,$(GOROOT))

# default GOBIN
ifndef GOBIN
GOBIN=$(QUOTED_GOROOT)/bin
endif
QUOTED_GOBIN=$(subst $(space),\ ,$(GOBIN))

92 93 94 95 96 97 98
AS=${O}a
CC=${O}c
GC=${O}g
LD=${O}l
OS=568vq
CFLAGS=-FVw

99 100 101 102
HOST_CC=quietgcc
HOST_LD=quietgcc
HOST_O=o
HOST_YFLAGS=-d
103
HOST_AR?=ar
Russ Cox's avatar
Russ Cox committed
104 105 106 107 108 109 110 111 112 113 114

# These two variables can be overridden in the environment
# to build with other flags.  They are like $CFLAGS and $LDFLAGS
# in a more typical GNU build.  We are more explicit about the names
# here because there are different compilers being run during the
# build (both gcc and 6c, for example).
HOST_EXTRA_CFLAGS?=-ggdb -O2
HOST_EXTRA_LDFLAGS?=

HOST_CFLAGS=-I"$(GOROOT)/include" $(HOST_EXTRA_CFLAGS)
HOST_LDFLAGS=$(HOST_EXTRA_LDFLAGS)
115 116
PWD=$(shell pwd)

117 118 119 120 121 122 123 124
# Make environment more standard.
LANG:=
LC_ALL:=C
LC_CTYPE:=C
GREP_OPTIONS:=
GREP_COLORS:=
export LANG LC_ALL LC_CTYPE GREP_OPTIONS GREP_COLORS

125 126 127
go-env:
	@echo export GOARCH=$(GOARCH)
	@echo export GOOS=$(GOOS)
128 129
	@echo export GOHOSTARCH=$(GOHOSTARCH)
	@echo export GOHOSTOS=$(GOHOSTOS)
130 131 132 133 134 135 136
	@echo export O=$O
	@echo export AS="$(AS)"
	@echo export CC="$(CC)"
	@echo export GC="$(GC)"
	@echo export LD="$(LD)"
	@echo export OS="$(OS)"
	@echo export CFLAGS="$(CFLAGS)"
137 138 139 140 141
	@echo export LANG="$(LANG)"
	@echo export LC_ALL="$(LC_ALL)"
	@echo export LC_CTYPE="$(LC_CTYPE)"
	@echo export GREP_OPTIONS="$(GREP_OPTIONS)"
	@echo export GREP_COLORS="$(GREP_COLORS)"
142 143 144 145 146
	@echo MAKE_GO_ENV_WORKED=1

# Don't let the targets in this file be used
# as the default make target.
.DEFAULT_GOAL:=