Makefile.in 8.1 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
CFG_STDLIB :=$(call CFG_LIB_NAME,std)
50
CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
51

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

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

G
Graydon Hoare 已提交
71 72 73 74 75 76 77 78 79 80
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
81 82 83 84 85
  ifeq ($(CFG_TEX),)
    $(info cfg: no tex found, omitting doc/rust.pdf)
  else
    DOCS += doc/rust.pdf
  endif
G
Graydon Hoare 已提交
86 87
endif

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

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

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

105 106 107 108 109 110 111
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.
112
STAGE0 := $(Q)$(call CFG_RUN_TARG,stage0,\
113
                stage0/rustc$(X) $(CFG_RUSTC_FLAGS))
114
STAGE1 := $(Q)$(call CFG_RUN_TARG,stage0, \
115
                $(CFG_VALGRIND_COMPILE) stage1/rustc$(X) \
116
                $(CFG_RUSTC_FLAGS))
117
STAGE2 := $(Q)$(call CFG_RUN_TARG,stage1, \
118
                $(CFG_VALGRIND_COMPILE) stage2/rustc$(X) \
119
                $(CFG_RUSTC_FLAGS))
120 121
STAGE3 := $(Q)$(call CFG_RUN_TARG,stage2, \
                $(CFG_VALGRIND_COMPILE) stage3/rustc$(X) \
122
                $(CFG_RUSTC_FLAGS))
123 124

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

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

135 136 137 138
######################################################################
# Standard library variables
######################################################################

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

######################################################################
143
# rustc crate variables
144 145
######################################################################

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

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

154
LREQ := rt/$(CFG_RUNTIME) rustllvm/$(CFG_RUSTLLVM)
155 156
SREQ0 := stage0/rustc$(X) $(LREQ) rt/main.o stage0/glue.o \
         stage0/lib/$(CFG_STDLIB)
R
Rafael Ávila de Espíndola 已提交
157 158 159 160
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)
161

G
Graydon Hoare 已提交
162

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

export CFG_SRC_DIR
168
export CFG_VERSION
169
export CFG_LLVM_ROOT
170
export CFG_ENABLE_MINGW_CROSS
171

P
Patrick Walton 已提交
172 173 174 175
######################################################################
# Subprograms
######################################################################

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

178
LLC := $(CFG_LLVM_BINDIR)/llc$(X)
179

180 181 182
######################################################################
# Single-target rules
######################################################################
183

184 185
ifneq ($(CFG_IN_TRANSITION),)

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

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

else

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

225 226
endif

227 228 229 230 231

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

232
config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
233
	@$(call E, cfg: reconfiguring)
G
Graydon Hoare 已提交
234
	$(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
235 236


237
######################################################################
238
# Primary-target makefiles
239 240
######################################################################

P
Patrick Walton 已提交
241
include $(CFG_SRC_DIR)/mk/intrinsics.mk
G
Graydon Hoare 已提交
242 243 244
include $(CFG_SRC_DIR)/mk/stage0.mk
include $(CFG_SRC_DIR)/mk/stage1.mk
include $(CFG_SRC_DIR)/mk/stage2.mk
245
include $(CFG_SRC_DIR)/mk/stage3.mk
G
Graydon Hoare 已提交
246 247 248
include $(CFG_SRC_DIR)/mk/rt.mk
include $(CFG_SRC_DIR)/mk/rustllvm.mk
include $(CFG_SRC_DIR)/mk/autodep.mk
249
include $(CFG_SRC_DIR)/mk/fuzzer.mk
250 251 252 253 254 255 256
include $(CFG_SRC_DIR)/mk/docs.mk


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

G
Graydon Hoare 已提交
257 258 259 260 261
ifneq ($(strip $(findstring dist,$(MAKECMDGOALS))   \
               $(findstring check,$(MAKECMDGOALS))  \
               $(findstring test,$(MAKECMDGOALS))   \
               $(findstring clean,$(MAKECMDGOALS))),)
  CFG_INFO := $(info cfg: including dist rules)
262 263 264
  include $(CFG_SRC_DIR)/mk/dist.mk
endif

G
Graydon Hoare 已提交
265 266 267
ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))   \
               $(findstring clean,$(MAKECMDGOALS))),)
  CFG_INFO := $(info cfg: including snap rules)
268 269 270 271
  include $(CFG_SRC_DIR)/mk/snap.mk
endif

ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
G
Graydon Hoare 已提交
272
  CFG_INFO := $(info cfg: including reformat rules)
273 274 275
  include $(CFG_SRC_DIR)/mk/pp.mk
endif

G
Graydon Hoare 已提交
276 277 278 279
ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
               $(findstring test,$(MAKECMDGOALS))  \
               $(findstring tidy,$(MAKECMDGOALS))),)
  CFG_INFO := $(info cfg: including test rules)
280 281 282 283
  include $(CFG_SRC_DIR)/mk/tests.mk
endif

ifneq ($(findstring clean,$(MAKECMDGOALS)),)
G
Graydon Hoare 已提交
284
  CFG_INFO := $(info cfg: including clean rules)
285 286
  include $(CFG_SRC_DIR)/mk/clean.mk
endif