aboutsummaryrefslogtreecommitdiff
path: root/mk/autodep.mk
blob: b2a785db1fff4ce03a85004e8a619f8fdfdb282b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
######################################################################
# Auto-dependency
######################################################################

ML_DEPFILES := $(BOOT_MLS:%.ml=%.d)
C_DEPFILES := $(RUNTIME_CS:%.cpp=%.d) $(RUSTLLVM_LIB_CS:%.cpp=%.d) \
              $(RUSTLLVM_OBJS_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
	$(Q)rm -f $@.tmp.bak
	$(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
	$(Q)rm -f $@.tmp.bak
	$(Q)mv $@.tmp $@

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

%.d: %.mli $(MKFILES)
	@$(call E, dep: $@)
	$(Q)ocamldep$(OPT) -slash $(BOOT_ML_DEP_INCS) $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
	$(Q)rm -f $@.tmp.bak
	$(Q)perl -i.bak -pe "s@$(S)src/@@go" $@.tmp
	$(Q)rm -f $@.tmp.bak
	$(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,%$(X),$@) -shared -rdeps $< >$@.tmp
	$(Q)$(CFG_PATH_MUNGE) $@.tmp
	$(Q)rm -f $@.tmp.bak
	$(Q)mv $@.tmp $@

stage0/rustc$(X).d: $(COMPILER_CRATE) $(COMPILER_INPUTS) \
                    $(STDLIB_CRATE) $(MKFILES) boot/rustboot$(X)
	@$(call E, dep: $@)
	$(Q)touch $@

%.d: %.rc $(MKFILES)
	@$(call E, dep: $@)
	$(Q)touch $@

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

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