Skip to content

Commit

Permalink
Start splitting up Makefile.in
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed May 1, 2011
1 parent d887767 commit 40624e3
Show file tree
Hide file tree
Showing 14 changed files with 1,062 additions and 1,033 deletions.
1,051 changes: 18 additions & 1,033 deletions Makefile.in

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions mk/autodep.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
######################################################################
# 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: $@)
$(BOOT) -o $(patsubst %.d,%$(X),$@) -shared -rdeps $< >$@.tmp
$(Q)$(CFG_PATH_MUNGE) $@.tmp
$(Q)rm -f $@.tmp.bak
$(Q)mv $@.tmp $@

%.d: %.rc $(MKFILES) boot/rustboot$(X)
@$(call E, dep: $@)
$(BOOT) -o $(patsubst %.d,%$(X),$@) -rdeps $< >$@.tmp
$(Q)$(CFG_PATH_MUNGE) $@.tmp
$(Q)rm -f $@.tmp.bak
$(Q)mv $@.tmp $@

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

depend: boot/rustboot$(X) $(CRATE_DEPFILES) $(ML_DEPFILES) $(C_DEPFILES)
98 changes: 98 additions & 0 deletions mk/boot.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
######################################################################
# Bootstrap compiler variables and rules
######################################################################

ifdef CFG_BOOT_PROFILE
$(info cfg: forcing native bootstrap compiler (CFG_BOOT_PROFILE))
CFG_BOOT_NATIVE := 1
CFG_OCAMLOPT_PROFILE_FLAGS := -p
endif

ifdef CFG_BOOT_DEBUG
$(info cfg: forcing bytecode bootstrap compiler (CFG_BOOT_DEBUG))
CFG_BOOT_NATIVE :=
endif

ifdef CFG_BOOT_NATIVE
$(info cfg: building native bootstrap compiler)
else
$(info cfg: building bytecode bootstrap compiler)
endif

GENERATED := boot/fe/lexer.ml boot/version.ml


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

BOOT_MLS := \
$(addsuffix .ml, \
boot/version \
$(addprefix boot/util/, fmt common bits) \
$(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 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)

BS := $(S)src/boot

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

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
BOOT_OCAMLOPT_FLAGS := -g $(BOOT_ML_INCS) -w Ael -warn-error Ael

ifdef CFG_FLEXLINK
BOOT_OCAMLOPT_FLAGS += -cclib -L/usr/lib
endif

BOOT := $(Q)OCAMLRUNPARAM="b1" boot/rustboot$(X) $(CFG_BOOT_FLAGS) -L stage0


ifdef CFG_BOOT_NATIVE
boot/rustboot$(X): $(BOOT_CMXS) $(MKFILES)
@$(call E, link: $@)
$(Q)ocamlopt$(OPT) -o $@ $(BOOT_OCAMLOPT_FLAGS) $(BOOT_ML_NATIVE_LIBS) \
$(BOOT_CMXS)
else
boot/rustboot$(X): $(BOOT_CMOS) $(MKFILES)
@$(call E, link: $@)
$(Q)ocamlc$(OPT) -o $@ $(BOOT_OCAMLC_FLAGS) $(BOOT_ML_LIBS) $(BOOT_CMOS)
endif

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

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

%.cmo: %.cmi $(MKFILES)

%.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 $@ $<

44 changes: 44 additions & 0 deletions mk/clean.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
######################################################################
# Cleanup
######################################################################

.PHONY: clean

tidy:
@$(call E, check: formatting)
$(Q)echo \
$(filter-out $(GENERATED) $(addprefix $(S)src/, $(GENERATED)) \
$(addprefix $(S)src/, $(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
$(RUSTLLVM_HDR) $(PKG_3RDPARTY)) \
$(S)src/etc/%, $(PKG_FILES)) \
| xargs -n 10 python $(S)src/etc/tidy.py

clean:
@$(call E, cleaning)
$(Q)rm -f $(RUNTIME_OBJS) $(RUNTIME_DEF)
$(Q)rm -f $(RUSTLLVM_LIB_OBJS) $(RUSTLLVM_OBJS_OBJS) $(RUSTLLVM_DEF)
$(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)
$(Q)rm -f stage1/rustc$(X) stage1/$(CFG_STDLIB) stage1/glue*
$(Q)rm -f stage2/rustc$(X) stage2/$(CFG_STDLIB) stage2/glue*
$(Q)rm -f stage3/rustc$(X) stage3/$(CFG_STDLIB) stage3/glue*
$(Q)rm -f rustllvm/$(CFG_RUSTLLVM) rustllvm/rustllvmbits.a
$(Q)rm -f rt/$(CFG_RUNTIME)
$(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 -f $(foreach ext,o a d bc s exe,$(wildcard stage*/*.$(ext)))
$(Q)rm -Rf $(foreach ext,out out.tmp \
boot$(X) stage0$(X) stage1$(X) stage2$(X) \
bc o s exe dSYM, \
$(wildcard test/*/*.$(ext) test/bench/*/*.$(ext)))
$(Q)rm -Rf $(foreach ext, \
aux cp fn ky log pdf html pg toc tp vr cps, \
$(wildcard doc/*.$(ext)))
$(Q)rm -Rf doc/version.texi
62 changes: 62 additions & 0 deletions mk/dist.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
######################################################################
# Distribution
######################################################################

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

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) \
$(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
$(RUSTLLVM_HDR) \
$(PKG_3RDPARTY)) \
$(GENERATED) \
$(S)src/boot/fe/lexer.ml \
$(COMPILER_INPUTS) \
$(STDLIB_INPUTS) \
$(ALL_TEST_INPUTS) \
$(GENERATED)

dist: $(PKG_TAR)

$(PKG_TAR): $(GENERATED)
@$(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)
$(Q)rm -Rf dist
$(Q)mkdir -p dist
@$(call E, unpacking $(PKG_TAR) in dist/$(PKG_DIR))
$(Q)cd dist && tar -xzf ../$(PKG_TAR)
@$(call E, configuring in dist/$(PKG_DIR)-build)
$(Q)mkdir -p dist/$(PKG_DIR)-build
$(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 -----------------------------------------------


16 changes: 16 additions & 0 deletions mk/docs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
######################################################################
# Doc variables and rules
######################################################################

doc/version.texi: $(MKFILES) rust.texi
(cd $(S) && git log -1 \
--pretty=format:'@macro gitversion%n%h %ci%n@end macro%n') >$@

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
Loading

0 comments on commit 40624e3

Please sign in to comment.