Makefile.in 7.7 KB
Newer Older
1 2 3 4 5
######################################################################
# Residual auto-configuration
######################################################################

include config.mk
G
Graydon Hoare 已提交
6
MKFILES := Makefile config.mk $(wildcard $(CFG_SRC_DIR)/mk/*.mk)
7 8 9 10 11 12 13

ifneq ($(MAKE_RESTARTS),)
CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
endif

CFG_INFO := $(info cfg: building on $(CFG_OSTYPE) $(CFG_CPUTYPE))

14
ifdef CFG_DISABLE_OPTIMIZE
15
  $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
16
  CFG_RUSTC_FLAGS :=
17
else
18
  CFG_RUSTC_FLAGS := -O
19
endif
20

21
ifdef SAVE_TEMPS
22
  CFG_RUSTC_FLAGS += --save-temps
23
endif
24 25 26
ifdef TIME_PASSES
  CFG_RUSTC_FLAGS += --time-passes
endif
27 28 29
ifdef TIME_LLVM_PASSES
  CFG_RUSTC_FLAGS += --time-llvm-passes
endif
30 31 32
ifdef NO_TYPESTATE
  CFG_RUSTC_FLAGS += --no-typestate
endif
33 34 35
ifdef DEBUG
  CFG_RUSTC_FLAGS += -g
endif
36

G
Graydon Hoare 已提交
37 38
# platform-specific auto-configuration
include $(CFG_SRC_DIR)/mk/platform.mk
39

40 41 42 43 44 45 46
# Run the stage1/2 compilers under valgrind
ifdef VALGRIND_COMPILE
  CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
else
  CFG_VALGRIND_COMPILE :=
endif

47
CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
48
CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
49 50
CFG_STDLIB :=$(call CFG_LIB_NAME,std)

51 52
# version-string calculation
CFG_GIT_DIR := $(CFG_SRC_DIR).git
53
CFG_VERSION = prerelease
G
Graydon Hoare 已提交
54
ifneq ($(wildcard $(CFG_GIT)),)
55 56 57 58
ifneq ($(wildcard $(CFG_GIT_DIR)),)
    CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
                     --pretty=format:'(%h %ci)')
endif
G
Graydon Hoare 已提交
59
endif
60

61 62
ifdef CFG_DISABLE_VALGRIND
  $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
63 64
  CFG_VALGRIND :=
endif
65 66 67 68
ifdef CFG_BAD_VALGRIND
  $(info cfg: disabling valgrind due to its unreliability on this platform)
  CFG_VALGRIND :=
endif
69

G
Graydon Hoare 已提交
70 71 72 73 74 75 76 77 78 79
DOCS :=
ifeq ($(CFG_MAKEINFO),)
  $(info cfg: no makeinfo found, omitting doc/rust.html)
else
  DOCS += doc/rust.html
endif

ifeq ($(CFG_TEXI2PDF),)
  $(info cfg: no texi2pdf found, omitting doc/rust.pdf)
else
80 81 82 83 84
  ifeq ($(CFG_TEX),)
    $(info cfg: no tex found, omitting doc/rust.pdf)
  else
    DOCS += doc/rust.pdf
  endif
G
Graydon Hoare 已提交
85 86
endif

87 88 89 90
ifdef CFG_DISABLE_DOCS
  $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
  DOCS :=
endif
G
Graydon Hoare 已提交
91

92 93 94 95 96 97 98 99 100 101
######################################################################
# Target-and-rule "utility variables"
######################################################################

ifdef VERBOSE
  Q :=
  E =
else
  Q := @
  E = echo $(1)
102 103
endif

104 105 106 107 108 109 110
S := $(CFG_SRC_DIR)
X := $(CFG_EXE_SUFFIX)

# Look in doc and src dirs.
VPATH := $(S)doc $(S)src

# Compilers we build, we now know how to run.
111
STAGE0 := $(Q)$(call CFG_RUN_TARG,stage0,\
112
                stage0/rustc$(X) $(CFG_RUSTC_FLAGS))
113
STAGE1 := $(Q)$(call CFG_RUN_TARG,stage0, \
114
                $(CFG_VALGRIND_COMPILE) stage1/rustc$(X) \
115
                $(CFG_RUSTC_FLAGS))
116
STAGE2 := $(Q)$(call CFG_RUN_TARG,stage1, \
117
                $(CFG_VALGRIND_COMPILE) stage2/rustc$(X) \
118
                $(CFG_RUSTC_FLAGS))
119 120
STAGE3 := $(Q)$(call CFG_RUN_TARG,stage2, \
                $(CFG_VALGRIND_COMPILE) stage3/rustc$(X) \
121
                $(CFG_RUSTC_FLAGS))
122 123

# "Source" files we generate in builddir along the way.
G
Graydon Hoare 已提交
124
GENERATED :=
125 126 127 128 129 130 131 132

# Delete the built-in rules.
.SUFFIXES:
%:: %,v
%:: RCS/%,v
%:: RCS/%
%:: s.%
%:: SCCS/s.%
133

134 135 136 137
######################################################################
# Standard library variables
######################################################################

G
Graydon Hoare 已提交
138
STDLIB_CRATE := $(S)src/lib/std.rc
139
STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/lib/,*.rc *.rs */*.rs))
140 141

######################################################################
142
# rustc crate variables
143 144
######################################################################

G
Graydon Hoare 已提交
145
COMPILER_CRATE := $(S)src/comp/rustc.rc
146
COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/comp/, \
147
                                rustc.rc *.rs */*.rs */*/*.rs))
148

149
######################################################################
G
Graydon Hoare 已提交
150
# Main target dependency variables
151 152
######################################################################

153
LREQ := rt/$(CFG_RUNTIME) rustllvm/$(CFG_RUSTLLVM)
154 155
SREQ0 := stage0/rustc$(X) $(LREQ) rt/main.o stage0/glue.o \
         stage0/lib/$(CFG_STDLIB)
R
Rafael Ávila de Espíndola 已提交
156 157 158 159
SREQ1 := stage1/rustc$(X) $(LREQ) rt/main.o stage1/glue.o \
         stage1/lib/$(CFG_STDLIB)
SREQ2 := stage2/rustc$(X) $(LREQ) rt/main.o stage2/glue.o \
         stage2/lib/$(CFG_STDLIB)
160

G
Graydon Hoare 已提交
161

162 163 164 165 166
######################################################################
# Exports for sub-utilities
######################################################################

export CFG_SRC_DIR
167
export CFG_VERSION
168
export CFG_LLVM_ROOT
169

P
Patrick Walton 已提交
170 171 172 173
######################################################################
# Subprograms
######################################################################

174
LLVM_AS := $(CFG_LLVM_BINDIR)/llvm-as$(X)
P
Patrick Walton 已提交
175

176
LLC := $(CFG_LLVM_BINDIR)/llc$(X)
177

178 179 180
######################################################################
# Single-target rules
######################################################################
181

182 183
ifneq ($(CFG_IN_TRANSITION),)

184
CFG_INFO := $(info cfg:)
185 186
CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
187
CFG_INFO := $(info cfg:)
188 189 190

all: rt/$(CFG_RUNTIME)          \
     rustllvm/$(CFG_RUSTLLVM)   \
191
     stage0/lib/$(CFG_STDLIB)   \
192 193 194 195
     stage0/intrinsics.bc       \
     stage0/rustc$(X)           \
     $(GENERATED)               \
     $(DOCS)                    \
196
     stage1/lib/$(CFG_STDLIB)   \
197 198 199 200 201 202
     stage1/intrinsics.bc       \
     stage1/glue.o              \
     stage1/rustc$(X)           \

else

203
all: rt/$(CFG_RUNTIME)          \
204
     rustllvm/$(CFG_RUSTLLVM)   \
205
     stage0/lib/$(CFG_STDLIB)   \
P
Patrick Walton 已提交
206
     stage0/intrinsics.bc       \
207
     stage0/rustc$(X)           \
G
Graydon Hoare 已提交
208
     $(GENERATED)               \
209
     $(DOCS)                    \
210
     stage1/lib/$(CFG_STDLIB)   \
P
Patrick Walton 已提交
211
     stage1/intrinsics.bc       \
212 213
     stage1/glue.o              \
     stage1/rustc$(X)           \
214
     stage2/lib/$(CFG_STDLIB)   \
P
Patrick Walton 已提交
215
     stage2/intrinsics.bc       \
216
     stage2/glue.o              \
217
     stage2/rustc$(X)           \
218
     stage3/lib/$(CFG_STDLIB)   \
219
     stage3/glue.o              \
P
Patrick Walton 已提交
220
     stage3/intrinsics.bc       \
221
     stage3/rustc$(X)
222

223 224
endif

225 226 227 228 229

######################################################################
# Re-configuration
######################################################################

230
config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
231 232 233 234
	@$(call E, cfg: reconfiguring)
	$(S)configure $(CFG_CONFIGURE_ARGS)


235
######################################################################
236
# Primary-target makefiles
237 238
######################################################################

P
Patrick Walton 已提交
239
include $(CFG_SRC_DIR)/mk/intrinsics.mk
G
Graydon Hoare 已提交
240 241 242
include $(CFG_SRC_DIR)/mk/stage0.mk
include $(CFG_SRC_DIR)/mk/stage1.mk
include $(CFG_SRC_DIR)/mk/stage2.mk
243
include $(CFG_SRC_DIR)/mk/stage3.mk
G
Graydon Hoare 已提交
244 245 246
include $(CFG_SRC_DIR)/mk/rt.mk
include $(CFG_SRC_DIR)/mk/rustllvm.mk
include $(CFG_SRC_DIR)/mk/autodep.mk
247
include $(CFG_SRC_DIR)/mk/fuzzer.mk
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
include $(CFG_SRC_DIR)/mk/docs.mk


######################################################################
# Secondary makefiles, conditionalized for speed
######################################################################

ifneq ($(findstring dist,$(MAKECMDGOALS)),)
  include $(CFG_SRC_DIR)/mk/dist.mk
endif

ifneq ($(findstring snap,$(MAKECMDGOALS)),)
  include $(CFG_SRC_DIR)/mk/snap.mk
endif

ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
  include $(CFG_SRC_DIR)/mk/pp.mk
endif

ifneq ($(findstring check,$(MAKECMDGOALS)),)
  include $(CFG_SRC_DIR)/mk/tests.mk
else
  ifneq ($(findstring test,$(MAKECMDGOALS)),)
    include $(CFG_SRC_DIR)/mk/tests.mk
  endif
endif

ifneq ($(findstring clean,$(MAKECMDGOALS)),)
  include $(CFG_SRC_DIR)/mk/dist.mk
  include $(CFG_SRC_DIR)/mk/snap.mk
  include $(CFG_SRC_DIR)/mk/tests.mk
  include $(CFG_SRC_DIR)/mk/clean.mk
endif