Makefile.in 39.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
######################################################################
# Residual auto-configuration
######################################################################

include config.mk
MKFILES := Makefile config.mk

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

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

14 15 16 17 18 19 20 21 22 23 24
CFG_GCC_CFLAGS :=
CFG_GCC_LINK_FLAGS :=
CFG_BOOT_FLAGS := $(BOOT_FLAGS)
CFG_RUSTC_FLAGS := -nowarn

# On Darwin, we need to run dsymutil so the debugging information ends
# up in the right place.  On other platforms, it automatically gets
# embedded into the executable, so use a no-op command.
CFG_DSYMUTIL := true

ifeq ($(CFG_OSTYPE), FreeBSD)
25
  CFG_LIB_NAME=lib$(1).so
26 27 28 29 30 31 32
  CFG_GCC_CFLAGS += -fPIC -march=i686 -I/usr/local/include
  CFG_GCC_LINK_FLAGS += -shared -fPIC -lpthread -lrt
  ifeq ($(CFG_CPUTYPE), x86_64)
    CFG_GCC_CFLAGS += -m32
    CFG_GCC_LINK_FLAGS += -m32
  endif
  CFG_UNIXY := 1
33
  CFG_LDENV := LD_LIBRARY_PATH
34
  CFG_DEF_SUFFIX := .bsd.def
35 36 37
endif

ifeq ($(CFG_OSTYPE), Linux)
38
  CFG_LIB_NAME=lib$(1).so
39 40
  CFG_GCC_CFLAGS += -fPIC -march=i686
  CFG_GCC_LINK_FLAGS += -shared -fPIC -ldl -lpthread -lrt
41 42
  CFG_GCC_DEF_FLAG := -Wl,-whole-archive,--export-dynamic,--dynamic-list=
  CFG_GCC_POST_LIB_FLAGS := -Wl,-no-whole-archive
43 44 45 46 47
  ifeq ($(CFG_CPUTYPE), x86_64)
    CFG_GCC_CFLAGS += -m32
    CFG_GCC_LINK_FLAGS += -m32
  endif
  CFG_UNIXY := 1
48
  CFG_LDENV := LD_LIBRARY_PATH
49
  CFG_DEF_SUFFIX := .linux.def
50 51 52
endif

ifeq ($(CFG_OSTYPE), Darwin)
53
  CFG_LIB_NAME=lib$(1).dylib
54
  CFG_UNIXY := 1
55
  CFG_LDENV := DYLD_LIBRARY_PATH
56
  CFG_GCC_LINK_FLAGS += -dynamiclib -lpthread
57
  CFG_GCC_DEF_FLAG := -Wl,-exported_symbols_list,
58 59 60 61 62 63 64
  # Darwin has a very blurry notion of "64 bit", and claims it's running
  # "on an i386" when the whole userspace is 64-bit and the compiler
  # emits 64-bit binaries by default. So we just force -m32 here. Smarter
  # approaches welcome!
  CFG_GCC_CFLAGS += -m32
  CFG_GCC_LINK_FLAGS += -m32
  CFG_DSYMUTIL := dsymutil
65
  CFG_DEF_SUFFIX := .darwin.def
66 67 68 69 70 71
endif

ifneq ($(findstring MINGW,$(CFG_OSTYPE)),)
  CFG_WINDOWSY := 1
endif

72
CFG_LDPATH :=$(CFG_BUILD_DIR)/rt
73
CFG_LDPATH :=$(CFG_LDPATH):$(CFG_BUILD_DIR)/rustllvm
74

75 76 77 78 79
ifdef CFG_WINDOWSY
  CFG_INFO := $(info cfg: windows-y environment)

  CFG_EXE_SUFFIX := .exe
  CFG_LIB_NAME=$(1).dll
80 81
  CFG_LDPATH :=$(CFG_LDPATH):$(CFG_LLVM_BINDIR)
  CFG_LDPATH :=$(CFG_LDPATH):$$PATH
82 83
  CFG_RUN_TEST=PATH="$(CFG_LDPATH)" $(1)
  CFG_RUN_TARG=PATH="$(CFG_LDPATH)" $(1)
84

85 86
  CFG_PATH_MUNGE := $(strip perl -i.bak -p             \
                           -e 's@\\(\S)@/\1@go;'       \
87
                           -e 's@^/([a-zA-Z])/@\1:/@o;')
88 89 90 91 92
  ifdef CFG_FLEXLINK
    CFG_BOOT_NATIVE := 1
  endif
  CFG_GCC_CFLAGS += -march=i686
  CFG_GCC_LINK_FLAGS += -shared -fPIC
93
  CFG_DEF_SUFFIX := .def
94 95 96 97 98
endif

ifdef CFG_UNIXY
  CFG_INFO := $(info cfg: unix-y environment)

99
  CFG_PATH_MUNGE := true
100
  CFG_EXE_SUFFIX :=
101
  CFG_LDPATH :=$(CFG_LDPATH):$(CFG_LLVM_LIBDIR)
102
  CFG_RUN_TARG=$(CFG_LDENV)=$(CFG_LDPATH) $(1)
103
  CFG_RUN_TEST=\
104
      $(CFG_LDENV)=$(dir $(firstword $(1))):$(CFG_LDPATH) \
105
      $(CFG_VALGRIND) $(1)
106 107 108 109 110 111

  CFG_BOOT_NATIVE := 1

  ifdef MINGW_CROSS
    CFG_EXE_SUFFIX := .exe
    CFG_LIB_NAME=$(1).dll
112 113
    CFG_LDPATH :=$(CFG_LDPATH):$(CFG_LLVM_BINDIR)
    CFG_LDPATH :=$(CFG_LDPATH):$$PATH
114
    CFG_RUN_TARG=PATH=$(CFG_LDPATH) $(1)
115
    CFG_RUN_TEST=PATH=$(CFG_LDPATH) $(1)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

    CFG_INFO := $(info cfg: mingw-cross)
    CFG_GCC_CROSS := i586-mingw32msvc-
    CFG_BOOT_FLAGS += -t win32-x86-pe
    ifdef CFG_VALGRIND
      CFG_VALGRIND += wine
    endif
    CFG_GCC_CFLAGS := -march=i686
    CFG_GCC_LINK_FLAGS := -shared
    ifeq ($(CFG_CPUTYPE), x86_64)
      CFG_GCC_CFLAGS += -m32
      CFG_GCC_LINK_FLAGS += -m32
    endif
  endif
  ifdef CFG_VALGRIND
    CFG_VALGRIND += --leak-check=full \
                    --error-exitcode=1 \
                    --quiet --vex-iropt-level=0 \
134
                    --suppressions=$(CFG_SRC_DIR)src/etc/x86.supp
135 136 137 138
  endif
endif

CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
139
CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
140 141
CFG_STDLIB :=$(call CFG_LIB_NAME,std)

142
CFG_LLC_CFLAGS := -march=x86 -relocation-model=pic
G
Graydon Hoare 已提交
143

144 145 146 147 148 149
ifdef CFG_GCC
  CFG_INFO := $(info cfg: using gcc)
  CFG_GCC_CFLAGS += -Wall -Werror -fno-rtti -fno-exceptions -g
  CFG_GCC_LINK_FLAGS += -g
  CFG_COMPILE_C = $(CFG_GCC_CROSS)g++ $(CFG_GCC_CFLAGS) -c -o $(1) $(2)
  CFG_DEPEND_C = $(CFG_GCC_CROSS)g++ $(CFG_GCC_CFLAGS) -MT "$(1)" -MM $(2)
150
  CFG_LINK_C = $(CFG_GCC_CROSS)g++ $(CFG_GCC_LINK_FLAGS) -o $(1) \
151
               $(CFG_GCC_DEF_FLAG)$(3) $(2)
152 153 154 155
else
  CFG_ERR := $(error please try on a system with gcc)
endif

156
ifdef CFG_OCAMLC_OPT
157
  $(info cfg: have ocaml native compiler)
158 159
  OPT=.opt
else
160
  $(info cfg: have only ocaml bytecode compiler)
161 162
endif

163 164 165
ifdef BOOT_PROFILE
  $(info cfg: forcing native bootstrap compiler (BOOT_PROFILE))
  CFG_BOOT_NATIVE := 1
166 167 168
  CFG_OCAMLOPT_PROFILE_FLAGS := -p
endif

169 170 171
ifdef BOOT_DEBUG
  $(info cfg: forcing bytecode bootstrap compiler (DEBUG))
  CFG_BOOT_NATIVE :=
172 173
endif

174
ifdef CFG_BOOT_NATIVE
175 176 177 178 179 180
  $(info cfg: building native bootstrap compiler)
else
  $(info cfg: building bytecode bootstrap compiler)
endif

ifdef NO_VALGRIND
181 182 183 184
  $(info cfg: disabling valgrind (NO_VALGRIND))
  CFG_VALGRIND :=
endif

G
Graydon Hoare 已提交
185 186 187 188 189 190 191 192 193 194
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
195 196 197 198 199
  ifeq ($(CFG_TEX),)
    $(info cfg: no tex found, omitting doc/rust.pdf)
  else
    DOCS += doc/rust.pdf
  endif
G
Graydon Hoare 已提交
200 201 202
endif


203 204 205 206 207 208 209 210 211 212
######################################################################
# Target-and-rule "utility variables"
######################################################################

ifdef VERBOSE
  Q :=
  E =
else
  Q := @
  E = echo $(1)
213 214
endif

215 216 217 218 219 220 221
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.
222
BOOT := $(Q)OCAMLRUNPARAM="b1" boot/rustboot$(X) $(CFG_BOOT_FLAGS) -L boot
223 224 225 226
STAGE0 := $(Q)$(call CFG_RUN_TARG,\
                stage0/rustc$(X) $(CFG_RUSTC_FLAGS) -L stage0)
STAGE1 := $(Q)$(call CFG_RUN_TARG,\
                stage1/rustc$(X) $(CFG_RUSTC_FLAGS) -L stage1)
227 228 229 230 231 232 233 234 235 236 237

# "Source" files we generate in builddir along the way.
GENERATED := boot/fe/lexer.ml boot/version.ml

# Delete the built-in rules.
.SUFFIXES:
%:: %,v
%:: RCS/%,v
%:: RCS/%
%:: s.%
%:: SCCS/s.%
238 239 240 241 242 243 244 245 246 247

######################################################################
# Bootstrap compiler variables
######################################################################

# We must list them in link order.
# Nobody calculates the link-order DAG automatically, sadly.

BOOT_MLS :=                                              \
    $(addsuffix .ml,                                     \
248 249
        boot/version                                     \
        $(addprefix boot/util/, fmt common bits)         \
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
        $(addprefix boot/driver/, session)               \
        $(addprefix boot/fe/, ast token lexer parser     \
          extfmt pexp item cexp fuzz)                    \
        $(addprefix boot/be/, asm il abi)                \
        $(addprefix boot/me/, walk semant resolve alias  \
          simplify type dead layer effect typestate      \
         loop layout transutil trans dwarf)              \
        $(addprefix boot/be/, x86 ra pe elf macho)       \
        $(addprefix boot/driver/, lib glue main))        \

BOOT_CMOS := $(BOOT_MLS:.ml=.cmo)
BOOT_CMXS := $(BOOT_MLS:.ml=.cmx)
BOOT_OBJS := $(BOOT_MLS:.ml=.o)
BOOT_CMIS := $(BOOT_MLS:.ml=.cmi)

G
Graydon Hoare 已提交
265
BS := $(S)src/boot
266 267 268 269 270 271 272 273

BOOT_ML_DEP_INCS := -I $(BS)/fe   -I $(BS)/me      \
                    -I $(BS)/be   -I $(BS)/driver  \
                    -I $(BS)/util -I boot

BOOT_ML_INCS    :=  -I boot/fe   -I boot/me      \
                    -I boot/be   -I boot/driver  \
                    -I boot/util -I boot
274

275 276 277
BOOT_ML_LIBS        := unix.cma  nums.cma  bigarray.cma
BOOT_ML_NATIVE_LIBS := unix.cmxa nums.cmxa bigarray.cmxa
BOOT_OCAMLC_FLAGS   := -g $(BOOT_ML_INCS) -w Ael -warn-error Ael
278 279
BOOT_OCAMLOPT_FLAGS := -g $(BOOT_ML_INCS) -w Ael -warn-error Ael

280 281 282 283
ifdef CFG_FLEXLINK
  BOOT_OCAMLOPT_FLAGS += -cclib -L/usr/lib
endif

284 285 286
######################################################################
# Runtime (C++) library variables
######################################################################
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
RUNTIME_CS := rt/sync/timer.cpp \
              rt/sync/sync.cpp \
              rt/sync/lock_and_signal.cpp \
              rt/rust.cpp \
              rt/rust_builtin.cpp \
              rt/rust_run_program.cpp \
              rt/rust_crate.cpp \
              rt/rust_crate_cache.cpp \
              rt/rust_crate_reader.cpp \
              rt/rust_comm.cpp \
              rt/rust_dom.cpp \
              rt/rust_task.cpp \
              rt/rust_task_list.cpp \
              rt/rust_proxy.cpp \
              rt/rust_chan.cpp \
              rt/rust_port.cpp \
              rt/rust_upcall.cpp \
              rt/rust_log.cpp \
              rt/rust_message.cpp \
              rt/rust_timer.cpp \
              rt/circular_buffer.cpp \
              rt/isaac/randport.cpp \
              rt/rust_srv.cpp \
              rt/rust_kernel.cpp \
              rt/memory_region.cpp \
              rt/test/rust_test_harness.cpp \
              rt/test/rust_test_runtime.cpp \
              rt/test/rust_test_util.cpp

RUNTIME_HDR := rt/globals.h \
               rt/rust.h \
               rt/rust_dwarf.h \
               rt/rust_internal.h \
               rt/rust_util.h \
               rt/rust_chan.h \
               rt/rust_port.h \
               rt/rust_dom.h \
               rt/rust_task.h \
               rt/rust_task_list.h \
               rt/rust_proxy.h \
               rt/rust_log.h \
               rt/rust_message.h \
               rt/circular_buffer.h \
               rt/util/array_list.h \
               rt/util/indexed_list.h \
               rt/util/synchronized_indexed_list.h \
               rt/util/hash_map.h \
               rt/sync/sync.h \
               rt/sync/timer.h \
G
Graydon Hoare 已提交
337
               rt/sync/lock_and_signal.h \
338 339 340 341 342 343 344 345 346
               rt/sync/lock_free_queue.h \
               rt/rust_srv.h \
               rt/rust_kernel.h \
               rt/memory_region.h \
               rt/memory.h \
               rt/test/rust_test_harness.h \
               rt/test/rust_test_runtime.h \
               rt/test/rust_test_util.h

347
RUNTIME_DEF := rt/rustrt$(CFG_DEF_SUFFIX)
348 349
RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash
RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o)
350
RUNTIME_LIBS := $(CFG_GCC_POST_LIB_FLAGS)
351 352

######################################################################
353
# rustc LLVM-extensions (C++) library variables
354 355
######################################################################

356
RUSTLLVM_CS := $(addprefix rustllvm/, \
357
                MachOObjectFile.cpp Object.cpp RustWrapper.cpp)
358

359
RUSTLLVM_HDR := rustllvm/include/llvm-c/Object.h
360
RUSTLLVM_DEF := rustllvm/rustllvm$(CFG_DEF_SUFFIX)
361

362 363 364
RUSTLLVM_INCS := -iquote $(CFG_LLVM_INCDIR) \
                 -iquote $(S)src/rustllvm/include
RUSTLLVM_OBJS := $(RUSTLLVM_CS:.cpp=.o)
365 366
RUSTLLVM_LIBS := $(CFG_LLVM_LDFLAGS) $(CFG_LLVM_LIBS) \
                 $(CFG_GCC_POST_LIB_FLAGS)
367

368 369 370 371
######################################################################
# Standard library variables
######################################################################

G
Graydon Hoare 已提交
372
STDLIB_CRATE := $(S)src/lib/std.rc
373
STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/lib/,*.rc *.rs */*.rs))
374 375

######################################################################
376
# rustc crate variables
377 378
######################################################################

G
Graydon Hoare 已提交
379
COMPILER_CRATE := $(S)src/comp/rustc.rc
380
COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/comp/, \
381 382
                                rustc.rc *.rs */*.rs))

383
######################################################################
G
Graydon Hoare 已提交
384
# Test dependency variables
385 386
######################################################################

387
LREQ := rt/$(CFG_RUNTIME) rustllvm/$(CFG_RUSTLLVM)
388 389 390 391
BREQ := boot/rustboot$(X) boot/$(CFG_STDLIB)
SREQ0 := stage0/rustc$(X) $(LREQ)
SREQ1 := stage1/rustc$(X) $(LREQ)

G
Graydon Hoare 已提交
392

393 394 395
######################################################################
# Single-target rules
######################################################################
396

397
all: boot/rustboot$(X)          \
398
     boot/$(CFG_STDLIB)         \
399
     rt/$(CFG_RUNTIME)          \
400
     rustllvm/$(CFG_RUSTLLVM)   \
401
     stage0/rustc$(X)           \
G
Graydon Hoare 已提交
402
     stage0/glue.o              \
403
     stage0/$(CFG_STDLIB)       \
G
Graydon Hoare 已提交
404 405
     $(GENERATED)               \
     $(DOCS)
406

407
rt/$(CFG_RUNTIME): $(RUNTIME_OBJS) $(MKFILES) $(RUNTIME_HDR) $(RUNTIME_DEF)
408
	@$(call E, link: $@)
409
	$(Q)$(call CFG_LINK_C,$@,$(RUNTIME_LIBS) $(RUNTIME_OBJS),$(RUNTIME_DEF))
410

411 412
rustllvm/$(CFG_RUSTLLVM): $(RUSTLLVM_OBJS) $(MKFILES) $(RUSTLLVM_HDR) \
                          $(RUSTLLVM_DEF)
413
	@$(call E, link: $@)
414
	$(Q)$(call CFG_LINK_C,$@,$(RUSTLLVM_LIBS) $(RUSTLLVM_OBJS) \
415
          $(CFG_LLVM_LIBS) $(CFG_LLVM_LDFLAGS),$(RUSTLLVM_DEF))
416 417

ifdef CFG_BOOT_NATIVE
418
boot/rustboot$(X): $(BOOT_CMXS) $(MKFILES)
419 420
	@$(call E, link: $@)
	$(Q)ocamlopt$(OPT) -o $@ $(BOOT_OCAMLOPT_FLAGS) $(BOOT_ML_NATIVE_LIBS) \
421 422
        $(BOOT_CMXS)
else
423
boot/rustboot$(X): $(BOOT_CMOS) $(MKFILES)
424
	@$(call E, link: $@)
425
	$(Q)ocamlc$(OPT) -o $@ $(BOOT_OCAMLC_FLAGS) $(BOOT_ML_LIBS) $(BOOT_CMOS)
426 427
endif

428 429
boot/version.ml: $(MKFILES)
	@$(call E, git: $@)
430 431
	$(Q)(cd $(S) && git log -1 \
      --pretty=format:'let version = "prerelease (%h %ci)";;') >$@ || exit 1
432

G
Graydon Hoare 已提交
433

434

G
Graydon Hoare 已提交
435
boot/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \
436
                    boot/rustboot$(X) $(MKFILES)
437 438 439
	@$(call E, compile: $@)
	$(BOOT) -shared -o $@ $<

440
stage0/std.bc: $(STDLIB_CRATE) $(STDLIB_INPUTS) stage0/rustc$(X) $(MKFILES)
G
Graydon Hoare 已提交
441 442 443
	@$(call E, compile: $@)
	$(STAGE0) -shared -o $@ $<

444 445 446 447 448 449
stage0/$(CFG_STDLIB): stage0/std.o stage0/glue.o
	@$(call E, link: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage0/glue.o $(CFG_GCC_LINK_FLAGS) -o $@ $< \
		-Lstage0 -Lrt -lrustrt

stage1/std.bc: $(STDLIB_CRATE) $(STDLIB_INPUTS) stage1/rustc$(X) $(MKFILES)
450 451 452
	@$(call E, compile: $@)
	$(STAGE1) -shared -o $@ $<

453 454 455 456 457 458
stage1/$(CFG_STDLIB): stage1/std.o stage1/glue.o
	@$(call E, link: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage1/glue.o $(CFG_GCC_LINK_FLAGS) -o $@ $< \
		-Lstage1 -Lrt -lrustrt

stage2/std.bc: $(STDLIB_CRATE) $(STDLIB_INPUTS) stage2/rustc$(X) $(MKFILES)
459 460 461
	@$(call E, compile: $@)
	$(STAGE2) -shared -o $@ $<

462 463 464 465 466
stage2/$(CFG_STDLIB): stage2/std.o stage2/glue.o
	@$(call E, link: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage2/glue.o $(CFG_GCC_LINK_FLAGS) -o $@ $< \
		-Lstage2 -Lrt -lrustrt

467

G
Graydon Hoare 已提交
468

G
Graydon Hoare 已提交
469
stage0/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) \
470
                  $(BREQ)
471 472 473 474
	@$(call E, compile: $@)
	$(BOOT) -minimal -o $@ $<
	$(Q)chmod 0755 $@

G
Graydon Hoare 已提交
475
stage1/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) \
476
                  $(SREQ0) stage0/$(CFG_STDLIB)
G
Graydon Hoare 已提交
477 478 479 480
	@$(call E, compile: $@)
	$(STAGE0) -o $@ $<
	$(Q)chmod 0755 $@

G
Graydon Hoare 已提交
481
stage2/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) \
482 483 484 485 486 487
                  $(SREQ1) stage1/$(CFG_STDLIB)
	@$(call E, compile: $@)
	$(STAGE1) -o $@ $<
	$(Q)chmod 0755 $@


G
Graydon Hoare 已提交
488

489
stage0/glue.bc: stage0/rustc$(X) boot/$(CFG_STDLIB) \
490
                rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)
491 492
	@$(call E, generate: $@)
	$(STAGE0) -o $@ -glue
493

494
stage1/glue.bc: stage1/rustc$(X) stage0/$(CFG_STDLIB) \
495
                rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)
G
Graydon Hoare 已提交
496 497 498
	@$(call E, generate: $@)
	$(STAGE1) -o $@ -glue

499
stage2/glue.bc: stage2/rustc$(X) stage1/$(CFG_STDLIB) \
500
                rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)
501 502 503
	@$(call E, generate: $@)
	$(STAGE2) -o $@ -glue

504
######################################################################
505
# Library and boot rules
506 507 508 509 510 511
######################################################################

rt/%.o: rt/%.cpp $(MKFILES)
	@$(call E, compile: $@)
	$(Q)$(call CFG_COMPILE_C, $@, $(RUNTIME_INCS)) $<

512
rustllvm/%.o: rustllvm/%.cpp $(MKFILES)
513
	@$(call E, compile: $@)
514
	$(Q)$(call CFG_COMPILE_C, $@, $(CFG_LLVM_CXXFLAGS) $(RUSTLLVM_INCS)) $<
515

516 517
%.cmo: %.ml $(MKFILES)
	@$(call E, compile: $@)
518
	$(Q)ocamlc$(OPT) -c -o $@ $(BOOT_OCAMLC_FLAGS) $<
519 520

%.cmo: %.cmi $(MKFILES)
521

522 523 524 525 526 527 528
%.cmx %.o: %.ml $(MKFILES)
	@$(call E, compile: $@)
	$(Q)ocamlopt$(OPT) -c -o $@ $(BOOT_OCAMLOPT_FLAGS) $<

%.ml: %.mll $(MKFILES)
	@$(call E, lex-gen: $@)
	$(Q)ocamllex$(OPT) -q -o $@ $<
529

530

531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
%.linux.def:    %.def.in $(MKFILES)
	@$(call E, def: $@)
	$(Q)echo "{" > $@
	$(Q)sed 's/.$$/&;/' $< >> $@
	$(Q)echo "};" >> $@

%.darwin.def:	%.def.in $(MKFILES)
	@$(call E, def: $@)
	$(Q)sed 's/^./_&/' $< > $@

ifdef CFG_WINDOWSY
%.def:	%.def.in $(MKFILES)
	@$(call E, def: $@)
	$(Q)echo LIBRARY $* > $@
	$(Q)echo EXPORTS >> $@
	$(Q)sed 's/^./    &/' $< >> $@
endif

G
Graydon Hoare 已提交
549 550 551 552 553
######################################################################
# Doc rules
######################################################################

doc/version.texi: $(MKFILES) rust.texi
554 555
	(cd $(S) && git log -1 \
      --pretty=format:'@macro gitversion%n%h %ci%n@end macro%n') >$@
G
Graydon Hoare 已提交
556 557 558 559 560 561 562 563 564 565 566

doc/%.pdf: %.texi doc/version.texi
	texi2pdf -I doc -o $@ --clean $<

doc/%.html: %.texi doc/version.texi
	makeinfo -I doc --html --ifhtml --force --no-split --output=$@ $<

docsnap: doc/rust.pdf
	mv $< doc/rust-$(shell date +"%Y-%m-%d")-snap.pdf


G
Graydon Hoare 已提交
567 568 569 570
######################################################################
# Testing variables
######################################################################

571 572
# Float doesn't work in boot

573
FLOAT_XFAILS := $(S)src/test/run-pass/float.rs \
574 575
                $(S)src/test/run-pass/float2.rs \
                $(S)src/test/run-pass/float-signature.rs
576

G
Graydon Hoare 已提交
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
# Temporarily xfail tests broken by the nominal-tags change.

NOMINAL_TAG_XFAILS := $(S)src/test/run-pass/mlist.rs

# Temporarily xfail tests broken by the constant-tags change.

CONST_TAG_XFAILS := $(S)src/test/run-pass/generic-tag.rs

# Temporarily xfail some of the task tests, while debugging the
# overhauled inter-domain messaging system.

TASK_XFAILS := $(addprefix $(S)src/test/run-pass/, \
                 task-comm-8.rs \
                 task-comm-10.rs \
                 task-comm-15.rs \
                 task-comm-12.rs \
                 task-comm-2.rs \
                 task-comm-9.rs \
595
                 task-comm-chan-nil.rs \
G
Graydon Hoare 已提交
596 597 598 599 600 601 602
                 task-life-0.rs \
                 alt-type-simple.rs \
                 many.rs)

TEST_XFAILS_BOOT := $(TASK_XFAILS) \
                    $(NOMINAL_TAG_XFAILS) \
                    $(CONST_TAG_XFAILS) \
603
                    $(FLOAT_XFAILS) \
G
Graydon Hoare 已提交
604 605 606 607 608 609 610 611 612 613
                    $(addprefix $(S)src/test/run-pass/, \
                      arith-unsigned.rs \
                      box-compare.rs \
                      child-outlives-parent.rs \
                      clone-with-exterior.rs \
                      constrained-type.rs \
                      destructor-ordering.rs \
                      obj-as.rs \
                      vec-slice.rs \
                      fn-lval.rs \
G
Graydon Hoare 已提交
614
                      empty-mutable-vec.rs \
G
Graydon Hoare 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
                      generic-bind-2.rs \
                      generic-fn-box.rs \
                      generic-tup.rs \
                      iter-ret.rs \
                      leak-tag-copy.rs \
                      lib-io.rs \
                      maybe-mutable.rs \
                      mlist-cycle.rs \
                      obj-as.rs \
                      seq-compare.rs \
                      task-comm.rs \
                      task-comm-3.rs \
                      vec-slice.rs \
                      while-and-do-while.rs) \
                    $(addprefix $(S)src/test/run-fail/, \
                      task-comm-14.rs) \
                    $(addprefix $(S)src/test/compile-fail/, \
                      bad-expr-path.rs \
                      import.rs \
                      import2.rs \
                      import3.rs \
                      import4.rs \
                      bad-recv.rs \
                      bad-send.rs \
                      infinite-vec-type-recursion.rs \
                      tail-non-call.rs \
                      writing-through-read-alias.rs)

643 644
TEST_XFAILS_STAGE0 := $(FLOAT_XFAILS) \
                      $(addprefix $(S)src/test/run-pass/, \
G
Graydon Hoare 已提交
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
                        acyclic-unwind.rs \
                        alt-pattern-drop.rs \
                        alt-type-simple.rs \
                        basic-1.rs \
                        basic-2.rs \
                        basic.rs \
                        child-outlives-parent.rs \
                        clone-with-exterior.rs \
                        comm.rs \
                        constrained-type.rs \
                        destructor-ordering.rs \
                        iter-ret.rs \
                        lazychan.rs \
                        lib-bitv.rs \
                        lib-deque.rs \
                        lib-int.rs \
                        lib-io.rs \
                        lib-map.rs \
                        lib-rand.rs \
                        lib-sha1.rs \
                        lib-sort.rs \
                        lib-str.rs \
                        lib-str-buf.rs \
                        lib-task.rs \
                        lib-uint.rs \
                        lib-vec-str-conversions.rs \
                        lib-vec.rs \
                        many.rs \
                        mlist-cycle.rs \
                        mlist.rs \
                        mutable-alias-vec.rs \
                        obj-as.rs \
                        obj-dtor.rs \
                        pred.rs \
                        preempt.rs \
                        rt-circular-buffer.rs \
                        size-and-align.rs \
                        spawn-fn.rs \
                        spawn-module-qualified.rs \
                        spawn.rs \
                        str-append.rs \
                        syntax-extension-fmt.rs \
                        syntax-extension-shell.rs \
                        task-comm-0.rs \
                        task-comm-1.rs \
                        task-comm-10.rs \
                        task-comm-11.rs \
                        task-comm-12.rs \
                        task-comm-13-thread.rs \
                        task-comm-13.rs \
                        task-comm-15.rs \
                        task-comm-2.rs \
                        task-comm-3.rs \
                        task-comm-4.rs \
                        task-comm-5.rs \
                        task-comm-6.rs \
                        task-comm-7.rs \
                        task-comm-8.rs \
                        task-comm-9.rs \
                        task-comm.rs \
                        task-killjoin.rs \
                        task-life-0.rs \
                        threads.rs \
                        type-sizes.rs \
                        typestate-cfg-nesting.rs \
710
						use.rs \
711
                        use-import-export.rs \
G
Graydon Hoare 已提交
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
                        user.rs \
                        utf8.rs \
                        vec-alloc-append.rs \
                        vec-append.rs \
                        vec-slice.rs \
                        while-with-break.rs \
                        yield.rs \
                        yield2.rs \
                        multi.rc \
                        native-mod.rc \
                        native.rc \
                        ) \
                     $(filter-out \
                      $(addprefix $(S)src/test/compile-fail/, \
                        alt-tag-nullary.rs \
                        alt-tag-unary.rs \
                        arg-count-mismatch.rs \
                        arg-type-mismatch.rs \
                        bad-expr-path.rs \
                        bad-expr-path2.rs \
                        bogus-tag.rs \
                        fru-extra-field.rs \
                        import.rs \
                        import2.rs \
                        import3.rs \
                        import4.rs \
                        import-loop.rs \
                        import-loop-2.rs \
                        multiline-comment-line-tracking.rs \
                        output-type-mismatch.rs \
                        rec-missing-fields.rs \
                        reserved-dec.rs \
                        reserved-f128.rs \
                        reserved-f16.rs \
                        reserved-f80.rs \
                        reserved-m128.rs \
                        reserved-m32.rs \
                        reserved-m64.rs \
                        tail-non-call.rs \
                        tail-typeck.rs \
                        type-shadow.rs \
                        while-type-error.rs \
                        wrong-ret-type.rs \
                        ), \
                     $(wildcard $(S)src/test/*fail/*.rs test/*fail/*.rc)) \
                     $(S)src/test/bench/shootout/fannkuchredux.rs \
                     $(S)src/test/bench/shootout/fasta.rs \
                     $(S)src/test/bench/shootout/binarytrees.rs \
                     $(wildcard $(S)src/test/bench/99-bottles/*rs)

ifdef MINGW_CROSS
TEST_XFAILS_BOOT += $(S)src/test/run-pass/native-mod.rc
TEST_XFAILS_STAGE0 += $(S)src/test/run-pass/native-mod.rc
endif
ifdef CFG_WINDOWSY
TEST_XFAILS_BOOT += $(S)src/test/run-pass/native-mod.rc
TEST_XFAILS_STAGE0 += $(S)src/test/run-pass/native-mod.rc
endif

BENCH_RS := $(wildcard $(S)src/test/bench/shootout/*.rs) \
            $(wildcard $(S)src/test/bench/99-bottles/*.rs)
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs) $(BENCH_RS)
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)

ifdef CHECK_XFAILS
TEST_RPASS_CRATES_BOOT := $(filter $(TEST_XFAILS_BOOT), $(RPASS_RC))
TEST_RPASS_CRATES_STAGE0 := $(filter $(TEST_XFAILS_STAGE0), $(RPASS_RC))
TEST_RPASS_SOURCES_BOOT := $(filter $(TEST_XFAILS_BOOT), $(RPASS_RS))
TEST_RPASS_SOURCES_STAGE0 := $(filter $(TEST_XFAILS_STAGE0), $(RPASS_RS))
else
TEST_RPASS_CRATES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(RPASS_RC))
TEST_RPASS_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RPASS_RC))
TEST_RPASS_SOURCES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(RPASS_RS))
TEST_RPASS_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RPASS_RS))
endif

TEST_RPASS_EXES_BOOT := \
793 794
  $(subst $(S)src/,,$(TEST_RPASS_CRATES_BOOT:.rc=.boot$(X))) \
  $(subst $(S)src/,,$(TEST_RPASS_SOURCES_BOOT:.rs=.boot$(X)))
G
Graydon Hoare 已提交
795
TEST_RPASS_EXES_STAGE0 := \
796 797
  $(subst $(S)src/,,$(TEST_RPASS_CRATES_STAGE0:.rc=.stage0$(X))) \
  $(subst $(S)src/,,$(TEST_RPASS_SOURCES_STAGE0:.rs=.stage0$(X)))
G
Graydon Hoare 已提交
798 799

TEST_RPASS_OUTS_BOOT  := \
800
  $(TEST_RPASS_EXES_BOOT:.boot$(X)=.boot.out)
G
Graydon Hoare 已提交
801
TEST_RPASS_OUTS_STAGE0 := \
802
  $(TEST_RPASS_EXES_STAGE0:.stage0$(X)=.stage0.out)
G
Graydon Hoare 已提交
803 804 805 806

TEST_RPASS_TMPS_BOOT  := \
  $(TEST_RPASS_EXES_BOOT:.boot$(X)=.boot$(X).tmp)
TEST_RPASS_TMPS_STAGE0 := \
807
  $(TEST_RPASS_EXES_STAGE0:.stage0$(X)=.stage0$(X).tmp)
G
Graydon Hoare 已提交
808 809 810 811 812 813 814 815


TEST_RFAIL_CRATES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(RFAIL_RC))
TEST_RFAIL_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RFAIL_RC))
TEST_RFAIL_SOURCES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(RFAIL_RS))
TEST_RFAIL_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RFAIL_RS))

TEST_RFAIL_EXES_BOOT := \
816 817
  $(subst $(S)src/,,$(TEST_RFAIL_CRATES_BOOT:.rc=.boot$(X))) \
  $(subst $(S)src/,,$(TEST_RFAIL_SOURCES_BOOT:.rs=.boot$(X)))
G
Graydon Hoare 已提交
818
TEST_RFAIL_EXES_STAGE0 := \
819 820
  $(subst $(S)src/,,$(TEST_RFAIL_CRATES_STAGE0:.rc=.stage0$(X))) \
  $(subst $(S)src/,,$(TEST_RFAIL_SOURCES_STAGE0:.rs=.stage0$(X)))
G
Graydon Hoare 已提交
821 822

TEST_RFAIL_OUTS_BOOT  := \
823
  $(TEST_RFAIL_EXES_BOOT:.boot$(X)=.boot.out)
G
Graydon Hoare 已提交
824
TEST_RFAIL_OUTS_STAGE0 := \
825
  $(TEST_RFAIL_EXES_STAGE0:.stage0$(X)=.stage0.out)
G
Graydon Hoare 已提交
826 827 828 829

TEST_RFAIL_TMPS_BOOT  := \
  $(TEST_RFAIL_EXES_BOOT:.boot$(X)=.boot$(X).tmp)
TEST_RFAIL_TMPS_STAGE0 := \
830
  $(TEST_RFAIL_EXES_STAGE0:.stage0$(X)=.stage0$(X).tmp)
G
Graydon Hoare 已提交
831 832 833 834 835 836 837 838


TEST_CFAIL_CRATES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(CFAIL_RC))
TEST_CFAIL_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(CFAIL_RC))
TEST_CFAIL_SOURCES_BOOT := $(filter-out $(TEST_XFAILS_BOOT), $(CFAIL_RS))
TEST_CFAIL_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(CFAIL_RS))

TEST_CFAIL_EXES_BOOT := \
839 840
  $(subst $(S)src/,,$(TEST_CFAIL_CRATES_BOOT:.rc=.boot$(X))) \
  $(subst $(S)src/,,$(TEST_CFAIL_SOURCES_BOOT:.rs=.boot$(X)))
G
Graydon Hoare 已提交
841
TEST_CFAIL_EXES_STAGE0 := \
842
  $(subst $(S)src/,,$(TEST_CFAIL_CRATES_STAGE0:.rc=.stage0$(X))) \
843
  $(subst $(S)src/,,$(TEST_CFAIL_SOURCES_STAGE0:.rs=.stage0$(X)))
G
Graydon Hoare 已提交
844 845

TEST_CFAIL_OUTS_BOOT := \
846
  $(TEST_CFAIL_EXES_BOOT:.boot$(X)=.boot.out)
G
Graydon Hoare 已提交
847
TEST_CFAIL_OUTS_STAGE0 := \
848
  $(TEST_CFAIL_EXES_STAGE0:.stage0$(X)=.stage0.out)
G
Graydon Hoare 已提交
849 850 851 852

TEST_CFAIL_TMPS_BOOT := \
  $(TEST_CFAIL_EXES_BOOT:.boot$(X)=.boot$(X).tmp)
TEST_CFAIL_TMPS_STAGE0 := \
853
  $(TEST_CFAIL_EXES_STAGE0:.stage0$(X)=.stage0$(X).tmp)
G
Graydon Hoare 已提交
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895


ALL_TEST_CRATES := $(TEST_CFAIL_CRATES_BOOT) \
                   $(TEST_RFAIL_CRATES_BOOT) \
                   $(TEST_RPASS_CRATES_BOOT) \
                   $(TEST_CFAIL_CRATES_STAGE0) \
                   $(TEST_RFAIL_CRATES_STAGE0) \
                   $(TEST_RPASS_CRATES_STAGE0)

ALL_TEST_SOURCES := $(TEST_CFAIL_SOURCES_BOOT) \
                    $(TEST_RFAIL_SOURCES_BOOT) \
                    $(TEST_RPASS_SOURCES_BOOT) \
                    $(TEST_CFAIL_SOURCES_STAGE0) \
                    $(TEST_RFAIL_SOURCES_STAGE0) \
                    $(TEST_RPASS_SOURCES_STAGE0)

ALL_TEST_INPUTS := $(wildcard $(S)src/test/*/*.rs   \
                              $(S)src/test/*/*/*.rs \
                              $(S)src/test/*/*.rc)

# The test suite currently relies on logging to validate results so
# make sure that logging uses the default configuration
unexport RUST_LOG


check_nocompile: $(TEST_CFAIL_OUTS_BOOT) \
                 $(TEST_CFAIL_OUTS_STAGE0)

check: tidy \
       $(TEST_RPASS_EXES_BOOT) $(TEST_RFAIL_EXES_BOOT) \
       $(TEST_RPASS_OUTS_BOOT) $(TEST_RFAIL_OUTS_BOOT) \
       $(TEST_CFAIL_OUTS_BOOT) \
       $(TEST_RPASS_EXES_STAGE0) $(TEST_RFAIL_EXES_STAGE0) \
       $(TEST_RPASS_OUTS_STAGE0) $(TEST_RFAIL_OUTS_STAGE0) \
       $(TEST_CFAIL_OUTS_STAGE0)


compile-check: tidy \
       $(TEST_RPASS_EXES_BOOT) $(TEST_RFAIL_EXES_BOOT) \
       $(TEST_RPASS_EXES_STAGE0) $(TEST_RFAIL_EXES_STAGE0)


896 897 898 899
######################################################################
# Testing rules
######################################################################

900
%.stage0$(X): %.stage0.o rt/$(CFG_RUNTIME) stage0/glue.o
901 902
	@$(call E, link [gcc]: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage0/glue.o -o $@ $< -Lstage0 -Lrt -lrustrt
903 904 905
	@# dsymutil sometimes fails or prints a warning, but the
	@# program still runs.  Since it simplifies debugging other
	@# programs, I\'ll live with the noise.
G
Graydon Hoare 已提交
906
	-$(Q)$(CFG_DSYMUTIL) $@
907

908
%.stage1(X): %.stage1.o rt/$(CFG_RUNTIME) stage1/glue.o
909 910
	@$(call E, link [gcc]: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage1/glue.o -o $@ $< -Lstage1 -Lrt -lrustrt
911 912 913
	@# dsymutil sometimes fails or prints a warning, but the
	@# program still runs.  Since it simplifies debugging other
	@# programs, I\'ll live with the noise.
G
Graydon Hoare 已提交
914
	-$(Q)$(CFG_DSYMUTIL) $@
915

916
%.stage2$(X): %.stage2.o rt/$(CFG_RUNTIME) stage2/glue.o
917 918
	@$(call E, link [gcc]: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) stage2/glue.o -o $@ $< -Lstage2 -Lrt -lrustrt
919 920 921
	@# dsymutil sometimes fails or prints a warning, but the
	@# program still runs.  Since it simplifies debugging other
	@# programs, I\'ll live with the noise.
G
Graydon Hoare 已提交
922
	-$(Q)$(CFG_DSYMUTIL) $@
923 924 925 926 927 928 929 930 931 932 933



%.boot$(X): %.rs $(BREQ)
	@$(call E, compile [boot]: $@)
	$(BOOT) -o $@ $<

%.boot$(X): %.rc $(BREQ)
	@$(call E, compile [boot]: $@)
	$(BOOT) -o $@ $<

934 935 936 937 938 939 940 941
%.stage0.bc: %.rc $(SREQ0)
	@$(call E, compile [stage0]: $@)
	$(STAGE0) -o $@ $<

%.stage0.bc: %.rs $(SREQ0)
	@$(call E, compile [stage0]: $@)
	$(STAGE0) -o $@ $<

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
%.stage1.bc: %.rc $(SREQ1)
	@$(call E, compile [stage1]: $@)
	$(STAGE1) -o $@ $<

%.stage1.bc: %.rs $(SREQ1)
	@$(call E, compile [stage1]: $@)
	$(STAGE1) -o $@ $<

%.stage2.bc: %.rc $(SREQ2)
	@$(call E, compile [stage2]: $@)
	$(STAGE2) -o $@ $<

%.stage2.bc: %.rs $(SREQ2)
	@$(call E, compile [stage2]: $@)
	$(STAGE2) -o $@ $<



G
Graydon Hoare 已提交
960 961 962 963 964 965 966 967 968 969 970 971
%.o: %.s
	@$(call E, assemble [llvm]: $@)
	$(Q)gcc $(CFG_GCC_CFLAGS) -o $@ -c $<

%.ll: %.bc
	@$(call E, dis [llvm]: $@)
	$(Q)$(CFG_LLVM_BINDIR)/llvm-dis -o $@ $<

%.s: %.bc
	@$(call E, compile [llvm]: $@)
	$(Q)$(CFG_LLVM_BINDIR)/llc $(CFG_LLC_CFLAGS) -o $@ $<

972 973 974 975 976 977
# Cancel the implicit .out rule in GNU make.
%.out: %

%.out: %.out.tmp
	$(Q)mv $< $@

G
Graydon Hoare 已提交
978
test/run-pass/%.out.tmp: test/run-pass/%$(X) rt/$(CFG_RUNTIME)
979 980
	$(Q)rm -f $<.tmp
	@$(call E, run: $@)
981
	$(Q)$(call CFG_RUN_TEST, $<) > $@
982 983 984 985 986

test/bench/shootout/%.out.tmp: test/bench/shootout/%$(X) \
                               rt/$(CFG_RUNTIME)
	$(Q)rm -f $<.tmp
	@$(call E, run: $@)
987
	$(Q)$(call CFG_RUN_TEST, $<) > $@
988 989 990 991 992

test/bench/99-bottles/%.out.tmp: test/bench/99-bottles/%$(X) \
                                 rt/$(CFG_RUNTIME)
	$(Q)rm -f $<.tmp
	@$(call E, run: $@)
993
	$(Q)$(call CFG_RUN_TEST, $<) > $@
994 995 996 997 998 999 1000

test/run-fail/%.out.tmp: test/run-fail/%$(X) \
                         rt/$(CFG_RUNTIME)
	$(Q)rm -f $<.tmp
	@$(call E, run: $@)
	$(Q)grep -q error-pattern $(S)src/test/run-fail/$(basename $*).rs
	$(Q)rm -f $@
1001
	$(Q)$(call CFG_RUN_TEST, $<) >$@ 2>&1 ; X=$$? ; \
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
      if [ $$X -eq 0 ] ; then exit 1 ; else exit 0 ; fi
	$(Q)grep --text --quiet \
      "$$(grep error-pattern $(S)src/test/run-fail/$(basename $*).rs \
        | cut -d : -f 2- | tr -d '\n\r')" $@

test/compile-fail/%.boot.out.tmp: test/compile-fail/%.rs $(BREQ)
	@$(call E, compile [boot]: $@)
	$(Q)grep -q error-pattern $<
	$(Q)rm -f $@
	$(BOOT) -o $(@:.out=$(X)) $< >$@ 2>&1; test $$? -ne 0
	$(Q)grep --text --quiet \
      "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@

test/compile-fail/%.stage0.out.tmp: test/compile-fail/%.rs $(SREQ0)
	@$(call E, compile [stage0]: $@)
	$(Q)grep -q error-pattern $<
	$(Q)rm -f $@
	$(STAGE0) -o $(@:.out=$(X)) $< >$@ 2>&1; test $$? -ne 0
	$(Q)grep --text --quiet \
      "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

######################################################################
# Auto-dependency
######################################################################

ML_DEPFILES := $(BOOT_MLS:%.ml=%.d)
C_DEPFILES := $(RUNTIME_CS:%.cpp=%.d) $(RUSTLLVM_CS:%.cpp=%.d)

rt/%.d: rt/%.cpp $(MKFILES)
	@$(call E, dep: $@)
	$(Q)$(call CFG_DEPEND_C, $@ \
      $(subst $(S)src/,,$(patsubst %.cpp, %.o, $<)), \
      $(RUNTIME_INCS)) $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1037
	$(Q)rm -f $@.tmp.bak
1038 1039 1040 1041 1042 1043 1044 1045
	$(Q)mv $@.tmp $@

rustllvm/%.d: rustllvm/%.cpp $(MKFILES)
	@$(call E, dep: $@)
	$(Q)$(call CFG_DEPEND_C, $@ \
      $(subst $(S)src/,,$(patsubst %.cpp, %.o, $<)), \
      $(CFG_LLVM_CXXFLAGS) $(RUSTLLVM_INCS)) $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1046
	$(Q)rm -f $@.tmp.bak
1047 1048 1049 1050 1051 1052
	$(Q)mv $@.tmp $@

%.d: %.ml $(MKFILES)
	@$(call E, dep: $@)
	$(Q)ocamldep$(OPT) -slash $(BOOT_ML_DEP_INCS) $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1053 1054 1055
	$(Q)rm -f $@.tmp.bak
	$(Q)perl -i.bak -pe "s@$(S)src/@@go" $@.tmp
	$(Q)rm -f $@.tmp.bak
1056 1057 1058 1059 1060 1061
	$(Q)mv $@.tmp $@

%.d: %.mli $(MKFILES)
	@$(call E, dep: $@)
	$(Q)ocamldep$(OPT) -slash $(BOOT_ML_DEP_INCS) $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1062 1063 1064
	$(Q)rm -f $@.tmp.bak
	$(Q)perl -i.bak -pe "s@$(S)src/@@go" $@.tmp
	$(Q)rm -f $@.tmp.bak
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	$(Q)mv $@.tmp $@

ifneq ($(MAKECMDGOALS),clean)
-include $(ML_DEPFILES) $(C_DEPFILES)
endif

RUSTBOOT_PROBE := $(wildcard boot/rustboot$(X))

ifneq ($(RUSTBOOT_PROBE),)
CFG_INFO := $(info cfg: using built boot/rustboot$(X) for rust deps)
CRATE_DEPFILES := $(subst $(S)src/,,$(ALL_TEST_CRATES:%.rc=%.d)) \
                  boot/$(CFG_STDLIB).d \
                  stage0/rustc$(X).d \
                  stage0/$(CFG_STDLIB).d

boot/$(CFG_STDLIB).d: $(STDLIB_CRATE) $(STDLIB_INPUTS) \
                      $(MKFILES) boot/rustboot$(X)
	@$(call E, dep: $@)
	$(BOOT) -o $(patsubst %.d,%,$@) -shared -rdeps $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1085
	$(Q)rm -f $@.tmp.bak
1086 1087 1088 1089 1090 1091 1092
	$(Q)mv $@.tmp $@

stage0/rustc$(X).d: $(COMPILER_CRATE) $(COMPILER_INPUTS) \
                    $(STDLIB_CRATE) $(MKFILES) boot/rustboot$(X)
	@$(call E, dep: $@)
	$(BOOT) -o $(patsubst %.d,%,$@) -shared -rdeps $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1093
	$(Q)rm -f $@.tmp.bak
1094 1095 1096 1097 1098 1099
	$(Q)mv $@.tmp $@

%.d: %.rc $(MKFILES) boot/rustboot$(X)
	@$(call E, dep: $@)
	$(BOOT)  -o $(patsubst %.d,%,$@) -rdeps $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
1100
	$(Q)rm -f $@.tmp.bak
1101 1102 1103 1104 1105 1106 1107 1108 1109
	$(Q)mv $@.tmp $@

ifneq ($(MAKECMDGOALS),clean)
-include $(CRATE_DEPFILES)
endif
endif

depend: boot/rustboot$(X) $(CRATE_DEPFILES) $(ML_DEPFILES) $(C_DEPFILES)

1110 1111 1112 1113 1114 1115 1116 1117 1118
######################################################################
# Distribution
######################################################################

PKG_NAME := rust
PKG_VER  = $(shell date +"%Y-%m-%d")-snap
PKG_DIR = $(PKG_NAME)-$(PKG_VER)
PKG_TAR = $(PKG_DIR).tar.gz

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
PKG_3RDPARTY := rt/valgrind.h rt/memcheck.h \
                rt/isaac/rand.h rt/isaac/standard.h \
                rt/uthash/uthash.h rt/uthash/utlist.h \
                rt/bigint/bigint.h rt/bigint/bigint_int.cpp \
                rt/bigint/bigint_ext.cpp rt/bigint/low_primes.h

PKG_FILES :=\
    $(wildcard $(S)src/etc/*.*)                \
    $(S)LICENSE.txt $(S)README                 \
    $(S)configure $(S)Makefile.in              \
    $(addprefix $(S)src/,                      \
      README boot/README comp/README           \
      $(filter-out $(GENERATED), $(BOOT_MLS))  \
      $(RUNTIME_CS) $(RUNTIME_HDR)             \
1133
      $(RUSTLLVM_CS) $(RUSTLLVM_HDR)           \
1134
      $(PKG_3RDPARTY))                         \
G
Graydon Hoare 已提交
1135 1136
    $(GENERATED)                               \
    $(S)src/boot/fe/lexer.ml                   \
1137 1138 1139 1140 1141 1142 1143
    $(COMPILER_INPUTS)                         \
    $(STDLIB_INPUTS)                           \
    $(ALL_TEST_INPUTS)                         \
    $(GENERATED)

dist: $(PKG_TAR)

G
Graydon Hoare 已提交
1144
$(PKG_TAR): $(GENERATED)
1145 1146 1147 1148 1149 1150 1151 1152
	@$(call E, making dist dir)
	$(Q)rm -Rf dist
	$(Q)mkdir -p dist/$(PKG_DIR)
	$(Q)tar -c $(PKG_FILES) | tar -x -C dist/$(PKG_DIR)
	$(Q)tar -czf $(PKG_TAR) -C dist $(PKG_DIR)
	$(Q)rm -Rf dist

distcheck: $(PKG_TAR)
G
Graydon Hoare 已提交
1153 1154 1155 1156
	$(Q)rm -Rf dist
	$(Q)mkdir -p dist
	@$(call E, unpacking $(PKG_TAR) in dist/$(PKG_DIR))
	$(Q)cd dist && tar -xzf ../$(PKG_TAR)
1157
	@$(call E, configuring in dist/$(PKG_DIR)-build)
G
Graydon Hoare 已提交
1158
	$(Q)mkdir -p dist/$(PKG_DIR)-build
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
	$(Q)cd dist/$(PKG_DIR)-build && ../$(PKG_DIR)/configure
	@$(call E, making 'check' in dist/$(PKG_DIR)-build)
	$(Q)make -C dist/$(PKG_DIR)-build check
	@$(call E, making 'clean' in dist/$(PKG_DIR)-build)
	$(Q)make -C dist/$(PKG_DIR)-build clean
	$(Q)rm -Rf dist
	@echo
	@echo -----------------------------------------------
	@echo $(PKG_TAR) ready for distribution
	@echo -----------------------------------------------

1170 1171 1172 1173 1174 1175 1176

######################################################################
# Cleanup
######################################################################

.PHONY: clean

1177 1178
tidy:
	@$(call E, check: formatting)
1179
	$(Q)echo \
G
Graydon Hoare 已提交
1180
      $(filter-out $(GENERATED) $(addprefix $(S)src/, $(GENERATED)) \
1181 1182
        $(addprefix $(S)src/, $(RUSTLLVM_CS) $(RUSTLLVM_HDR) \
          $(PKG_3RDPARTY)) \
1183 1184
        $(S)src/etc/%, $(PKG_FILES)) \
    | xargs -n 10 python $(S)src/etc/tidy.py
1185

1186 1187
clean:
	@$(call E, cleaning)
1188
	$(Q)rm -f $(RUNTIME_OBJS)
1189
	$(Q)rm -f $(RUSTLLVM_OBJS)
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
	$(Q)rm -f $(BOOT_CMOS) $(BOOT_CMIS) $(BOOT_CMXS) $(BOOT_OBJS)
	$(Q)rm -f $(ML_DEPFILES) $(C_DEPFILES) $(CRATE_DEPFILES)
	$(Q)rm -f $(ML_DEPFILES:%.d=%.d.tmp)
	$(Q)rm -f $(C_DEPFILES:%.d=%.d.tmp)
	$(Q)rm -f $(CRATE_DEPFILES:%.d=%.d.tmp)
	$(Q)rm -f $(GENERATED)
	$(Q)rm -f boot/rustboot$(X) boot/$(CFG_STDLIB)
	$(Q)rm -f stage0/rustc$(X) stage0/$(CFG_STDLIB) stage0/glue*
	$(Q)rm -f stage1/rustc$(X) stage1/$(CFG_STDLIB) stage1/glue*
	$(Q)rm -f stage2/rustc$(X) stage2/$(CFG_STDLIB) stage2/glue*
1200
	$(Q)rm -f rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)
1201 1202 1203 1204 1205 1206
	$(Q)rm -Rf $(PKG_NAME)-*.tar.gz dist
	$(Q)rm -f $(foreach ext,cmx cmi cmo cma bc o a d exe,\
                        $(wildcard boot/*/*.$(ext) boot/*/*/*.$(ext)))
	$(Q)rm -Rf $(foreach ext,out out.tmp                               \
                             boot$(X) stage0$(X) stage1$(X) stage2$(X) \
                             bc o s exe dSYM,                          \
G
Graydon Hoare 已提交
1207
                        $(wildcard test/*/*.$(ext) test/bench/*/*.$(ext)))
G
Graydon Hoare 已提交
1208
	$(Q)rm -Rf $(foreach ext, \
1209
                 aux cp fn ky log pdf html pg toc tp vr cps texi, \
G
Graydon Hoare 已提交
1210
                 $(wildcard doc/*.$(ext)))