66 lines
2 KiB
Makefile
66 lines
2 KiB
Makefile
# Copyright (c) 2018 Simon Hudon. All rights reserved.
|
|
# Released under Apache 2.0 license as described in the file LICENSE.
|
|
# Authors: Simon Hudon, Sebastian Ullrich, Leonardo de Moura
|
|
LEAN ?= ../../bin/lean
|
|
LEANC ?= ../../bin/leanc
|
|
LEAN_ROOT ?= .
|
|
# Even though we copy the sources into a new directory for stage2/3, we
|
|
# read the list of files to compile from the original directory to avoid
|
|
# issues with stale copied files
|
|
SRCS = $(shell cd $(LEAN_ROOT); find . -name '*.lean')
|
|
DEPS = $(addprefix $(LEAN_ROOT)/,$(SRCS:.lean=.depend))
|
|
OPTS = @LEAN_EXTRA_MAKE_OPTS@
|
|
STAGE0_DIR = ../../stage0
|
|
C_OUT ?= .
|
|
ifndef OUT
|
|
$(error "`OUT` must be set (use cmake)")
|
|
endif
|
|
OBJS = $(SRCS:.lean=.olean)
|
|
# ensure deterministic ordering
|
|
CS_CORE=$(addprefix Init/,$(sort $(SRCS:.lean=.c)))
|
|
|
|
SHELL = /usr/bin/env bash -eo pipefail
|
|
|
|
.PHONY: all clean
|
|
|
|
all: $(OBJS)
|
|
|
|
depends: $(DEPS)
|
|
|
|
%.depend: %.lean
|
|
# use separate assignment to ensure failure propagation
|
|
@deps=`$(LEAN) --deps $< | python relative.py`; echo $(<:.lean=.olean): $$deps > $@
|
|
|
|
%.olean: %.lean %.depend $(MORE_DEPS)
|
|
@echo "[ ] Building $<"
|
|
@mkdir -p $(C_OUT)/$(*D)
|
|
$(LEAN) $(OPTS) --make --c="$(C_OUT)/$*.c.tmp" $<
|
|
# create the .c file atomically
|
|
mv "$(C_OUT)/$*.c.tmp" "$(C_OUT)/$*.c"
|
|
# make sure the .olean file is newer than the .depend file to prevent infinite make cycles
|
|
@touch $@
|
|
|
|
$(C_OUT)/%.c: %.olean
|
|
@
|
|
|
|
$(OUT)/%.o: $(C_OUT)/%.c
|
|
@echo "[ ] Building $<"
|
|
@mkdir -p "$(@D)"
|
|
$(LEANC) -c -o $@ $< $(LEANC_OPTS)
|
|
|
|
$(OUT)/libleanstdlib.a: $(addprefix $(OUT)/,$(SRCS:.lean=.o))
|
|
@rm -f $@
|
|
@ar rcs $@ $^
|
|
|
|
update-stage0:
|
|
-rm -r $(STAGE0_DIR)
|
|
-mkdir -p $(STAGE0_DIR)/stdlib
|
|
for f in $(SRCS:.lean=.c); do mkdir -p `dirname $(STAGE0_DIR)/stdlib/Init/$$f`; cp $(C_OUT)/$$f $(STAGE0_DIR)/stdlib/Init/$$f; done
|
|
echo "add_library (stage0 OBJECT $(CS_CORE))" > $(STAGE0_DIR)/stdlib/CMakeLists.txt
|
|
# don't copy untracked crap
|
|
cd ..; git ls-files -z . | xargs -0 -I '{}' bash -c 'mkdir -p `dirname ../stage0/src/{}` && cp {} ../stage0/src/{}'
|
|
-git add $(STAGE0_DIR)
|
|
|
|
.PRECIOUS: %.depend $(C_OUT)/%.c
|
|
|
|
include $(DEPS)
|