blob: fd4bd317067ea65e330a219701d0e9a217912117 [file] [log] [blame]
Graydon Hoare9c6e7e62011-03-16 16:17:321######################################################################
2# Residual auto-configuration
3######################################################################
4
5include config.mk
6MKFILES := Makefile config.mk
7
8ifneq ($(MAKE_RESTARTS),)
9CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
10endif
11
12CFG_INFO := $(info cfg: building on $(CFG_OSTYPE) $(CFG_CPUTYPE))
13
14ifdef CFG_OCAMLC_OPT
15 $(info cfg: using ocaml native compiler)
16 OPT=.opt
17else
18 $(info cfg: using ocaml bytecode compiler)
19endif
20
21ifdef PROFILE_BOOT
22 $(info cfg: building bootstrap compiler with profiling (forcing native))
23 CFG_NATIVE_BOOT := 1
24 CFG_OCAMLOPT_PROFILE_FLAGS := -p
25endif
26
27ifdef DEBUG
28 $(info cfg: forcing bytecode bootstrap compiler)
29 CFG_NATIVE_BOOT :=
30endif
31
32ifdef CFG_NATIVE_BOOT
33 $(info cfg: building native bootstrap compiler)
34else
35 $(info cfg: building bytecode bootstrap compiler)
36endif
37
38ifdef NO_VALGRIND
39 CFG_VALGRIND :=
40endif
41
42
43######################################################################
44# Bootstrap compiler variables
45######################################################################
46
47# We must list them in link order.
48# Nobody calculates the link-order DAG automatically, sadly.
49
50BOOT_MLS := \
51 $(addsuffix .ml, \
52 $(addprefix boot/util/, version fmt common bits) \
53 $(addprefix boot/driver/, session) \
54 $(addprefix boot/fe/, ast token lexer parser \
55 extfmt pexp item cexp fuzz) \
56 $(addprefix boot/be/, asm il abi) \
57 $(addprefix boot/me/, walk semant resolve alias \
58 simplify type dead layer effect typestate \
59 loop layout transutil trans dwarf) \
60 $(addprefix boot/be/, x86 ra pe elf macho) \
61 $(addprefix boot/driver/, lib glue main)) \
62
63BOOT_CMOS := $(BOOT_MLS:.ml=.cmo)
64BOOT_CMXS := $(BOOT_MLS:.ml=.cmx)
65BOOT_OBJS := $(BOOT_MLS:.ml=.o)
66BOOT_CMIS := $(BOOT_MLS:.ml=.cmi)
67
68ML_DEP_INCS := -I $(S)boot/fe -I $(S)boot/me -I $(S)boot/be \
69 -I $(S)boot/driver -I $(S)boot/util
70
71ML_INCS := $(ML_DEP_INCS)
72ML_LIBS := unix.cma nums.cma bigarray.cma
73ML_NATIVE_LIBS := unix.cmxa nums.cmxa bigarray.cmxa
74OCAMLC_FLAGS := -g $(ML_INCS) -w Ael -warn-error Ael
75
76
77######################################################################
78# Target-and-rule "utility variables"
79######################################################################
80
81ifdef VERBOSE
82 Q :=
83 E =
84else
85 Q := @
86 E = echo $(1)
87endif
88
89S := $(CFG_SRC_DIR)
90X := $(CFG_EXE_SUFFIX)
91
92# Look in src dir.
93VPATH := $(CFG_SRC_DIR)
94
95# Delete the built-in rules.
96.SUFFIXES:
97%:: %,v
98%:: RCS/%,v
99%:: RCS/%
100%:: s.%
101%:: SCCS/s.%
102
103######################################################################
104# Targets and rules
105######################################################################
106
107all: rustboot$(X)
108
109ifdef CFG_NATIVE_BOOT
110rustboot$(X): $(BOOT_CMXS) $(MKFILES)
111 @$(call E, compile: $@)
112 $(Q)ocamlopt$(OPT) -o $@ $(OCAMLOPT_FLAGS) $(ML_NATIVE_LIBS) \
113 $(BOOT_CMXS)
114else
115rustboot$(X): $(BOOT_CMOS) $(MKFILES)
116 @$(call E, compile: $@)
117 $(Q)ocamlc$(OPT) -o $@ $(OCAMLC_FLAGS) $(ML_LIBS) $(BOOT_CMOS)
118endif
119
120
121boot/util/version.ml: $(MKFILES)
122 $(Q)git log -1 \
123 --pretty=format:'let version = "prerelease (%h %ci)";;' >$@ || exit 1
124
125%.cmo: %.ml $(MKFILES)
126 @$(call E, compile: $@)
127 $(Q)ocamlc$(OPT) -c -o $@ $(OCAMLC_FLAGS) $<
128
129%.cmo: %.cmi $(MKFILES)