# 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 SRCS = $(shell find . -name '*.lean') OBJS = $(SRCS:.lean=.olean) DEPS = $(SRCS:.lean=.depend) OPTS = @LEAN_EXTRA_MAKE_OPTS@ STAGE0_DIR = ../src/stage0 STAGE1_DIR = ../src/stage1 ifndef STAGE1_OUT $(error "`STAGE1_OUT` must be set (use cmake)") endif CS = $(addprefix $(STAGE1_DIR)/,$(patsubst %.lean,%.c,$(SRCS))) # ensure deterministic ordering CS_CORE=$(sort $(patsubst %.lean,%.c,$(SRCS))) 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 @mkdir -p $(STAGE1_DIR)/$(@D) $(LEAN) $(OPTS) --make --c="$(STAGE1_DIR)/$*.c.tmp" $< # create the .c file atomically mv "$(STAGE1_DIR)/$*.c.tmp" "$(STAGE1_DIR)/$*.c" # make sure the .olean file is newer than the .depend file to prevent infinite make cycles @touch $*.olean clean: find . -name *.olean -delete find . -name *.depend -delete -rm -r "$(STAGE1_DIR)" "$(STAGE1_OUT)" $(STAGE1_DIR)/%.c: %.olean @ $(STAGE1_OUT)/%.o: $(STAGE1_DIR)/%.c @mkdir -p "$(@D)" ../bin/leanc -c -o $@ $< $(LEANC_OPTS) $(STAGE1_OUT)/libleanstdlib.a: $(addprefix $(STAGE1_OUT)/,$(patsubst %.lean,%.o,$(SRCS))) @rm -f $@ @ar rcs $@ $^ update-stage0: rm -r $(STAGE0_DIR)/init cp -R $(STAGE1_DIR)/init $(STAGE0_DIR)/init echo "add_library (stage0 OBJECT $(CS_CORE))" > $(STAGE0_DIR)/CMakeLists.txt .PRECIOUS: %.depend $(STAGE1_DIR)/%.c include $(DEPS)