45 lines
1.8 KiB
Text
45 lines
1.8 KiB
Text
SHELL := /usr/bin/env bash -euo pipefail
|
|
|
|
# any absolute path to the stdlib breaks the Makefile
|
|
export LEAN_PATH=
|
|
|
|
# LEAN_OPTS: don't use native code (except for primitives) since it is from the previous stage
|
|
# MORE_DEPS: rebuild the stdlib whenever the compiler has changed
|
|
LEANMAKE_OPTS=\
|
|
LEAN="${CMAKE_CROSSCOMPILING_EMULATOR} ${PREV_STAGE}/bin/lean${CMAKE_EXECUTABLE_SUFFIX}"\
|
|
OUT="${LIB}"\
|
|
LIB_OUT="${LIB}/lean"\
|
|
OLEAN_OUT="${LIB}/lean"\
|
|
BIN_OUT="${CMAKE_BINARY_DIR}/bin"\
|
|
LEAN_OPTS+="${LEAN_EXTRA_MAKE_OPTS}"\
|
|
LEANC_OPTS+="${LEANC_OPTS}"\
|
|
LEAN_CXX="${CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER}"\
|
|
LEAN_AR="${CMAKE_AR}"\
|
|
MORE_DEPS+="${PREV_STAGE}/bin/lean${CMAKE_EXECUTABLE_SUFFIX}"\
|
|
CMAKE_LIKE_OUTPUT=1\
|
|
$(MORE_LEANMAKE_OPTS)
|
|
|
|
.PHONY: Init Std Lean leanshared Leanpkg
|
|
|
|
# These can be phony since the inner Makefile will have the correct dependencies and avoid rebuilds
|
|
Init:
|
|
# Use `+` to use the Make jobserver with `leanmake` for parallelized builds
|
|
+"${LEAN_BIN}/leanmake" lib PKG=Init $(LEANMAKE_OPTS)
|
|
|
|
Std: Init
|
|
+"${LEAN_BIN}/leanmake" lib PKG=Std $(LEANMAKE_OPTS)
|
|
|
|
Lean: Init Std
|
|
+"${LEAN_BIN}/leanmake" lib PKG=Lean $(LEANMAKE_OPTS)
|
|
|
|
# This target will always be remade, but then not trigger further builds downstream if the .a file did not change
|
|
${LIB}/lean/libLean.a: Lean
|
|
|
|
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libleanshared${CMAKE_SHARED_LIBRARY_SUFFIX}: ${LIB}/lean/libLean.a ${LIB}/lean/libleancpp.a ${CMAKE_BINARY_DIR}/runtime/libleanrt_initial-exec.a
|
|
@echo "[ ] Building $@"
|
|
"${LEAN_BIN}/leanc" -x none -shared -o $@ ${LEANSHARED_LINKER_FLAGS} ${LEANC_OPTS}
|
|
|
|
leanshared: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libleanshared${CMAKE_SHARED_LIBRARY_SUFFIX}
|
|
|
|
Leanpkg: Init Std Lean leanshared
|
|
+"${LEAN_BIN}/leanmake" bin PKG=Leanpkg BIN_NAME=leanpkg${CMAKE_EXECUTABLE_SUFFIX} $(LEANMAKE_OPTS) LINK_OPTS='-lleanshared ${CMAKE_EXE_LINKER_FLAGS_MAKE}'
|