1
+ # ## Makefile for mathport
2
+
3
+ # This is not a "real" makefile, i.e. it does not detect dependencies between targets.
4
+
5
+ # # Targets:
6
+ # `lean4-source`: clone `lean4`, patch `kernel/inductive.cpp`, compile, and `elan override`
7
+ # `mathbin-source`: clone mathlib3, and create `all.lean`
8
+ # `lean3-source`: clone lean3, and create `all.lean` (run after `mathbin-source`, to get the right commit)
9
+ # `lean3-predata`: create `.ast` and `.tlean` files from Lean3
10
+ # `mathbin-predata`: create `.ast` and `.tlean` files from mathlib3
11
+ # `build`: compile mathport
12
+ # `port-lean`: run mathport on Lean3
13
+ # `port-mathbin`: run mathport on mathlib3
14
+
15
+ # # Prerequisites:
16
+ # curl, git, cmake, elan, python3
17
+
18
+ # We make the following assumptions about versions:
19
+ #
20
+ # * `lean-toolchain` points to the same version of `lean4` as
21
+ # the branch/commit of `mathlib4` selected in `lakefile.lean`.
22
+ #
23
+ # It will automatically identify the version of `lean3` than `mathlib` currently uses.
24
+
1
25
all :
2
26
3
27
unport :
4
28
rm -rf Lib4 Logs/*
5
29
git checkout HEAD -- Lib4
6
30
31
+ # Select which commit of mathlib3 to use.
32
+ MATHBIN_COMMIT =master
33
+
34
+ # Unfortunately we can't use vanilla lean4: we need to cherrypick
35
+ # https://github.com/dselsam/lean4/commit/9228d3949bda8c1411e707b3e20650fa1fdb9b4d
36
+ lean4-source :
37
+ rm -rf sources/lean4
38
+ mkdir -p sources
39
+ cd sources && git clone --depth 1 --branch ` cat ../lean-toolchain | sed " s/.*://" ` https://github.com/leanprover/lean4-nightly/ lean4
40
+ cd sources/lean4 && git submodule update --init src/lake
41
+ cd sources/lean4 && patch -u src/kernel/inductive.cpp < ../../whnf-type-inductives.patch
42
+ cd sources/lean4 && rm -rf build && mkdir -p build/release && cd build/release && \
43
+ cmake ../.. && make -j` python -c ' import multiprocessing as mp; print(mp.cpu_count())' `
44
+ elan toolchain link lean4-mathport-cherrypick sources/lean4/build/release/stage1/
45
+ elan override set lean4-mathport-cherrypick
46
+
47
+ # Obtain the requested commit from `mathlib`, and create `all.lean`
48
+ mathbin-source :
49
+ mkdir -p sources
50
+ if [ ! -d " sources/mathlib" ]; then \
51
+ cd sources && git clone https://github.com/leanprover-community/mathlib.git; \
52
+ fi
53
+ cd sources/mathlib && git clean -xfd && git checkout $(MATHBIN_COMMIT )
54
+ cd sources/mathlib && leanpkg configure && ./scripts/mk_all.sh
55
+
56
+ # Obtain the commit from (community edition) Lean 3 which mathlib is using, and create `all.lean`.
57
+ lean3-source :
58
+ mkdir -p sources
59
+ if [ ! -d " sources/lean" ]; then \
60
+ cd sources && git clone https://github.com/leanprover-community/lean.git; \
61
+ fi
62
+ cd sources/lean && git clean -xfd && git checkout ` cd ../mathlib && lean --version | sed -e " s/.*commit \([0-9a-f]*\).*/\1/" `
63
+ mkdir -p sources/lean/build/release
64
+ # Run cmake, to create `version.lean` from `version.lean.in`.
65
+ cd sources/lean/build/release && cmake ../../src
66
+ # Create `all.lean`.
67
+ ./mk_all.sh sources/lean/library/
68
+
69
+ # Build .ast and .tlean files for Lean 3
70
+ lean3-predata : lean3-source
71
+ mkdir -p PreData
72
+ rm -rf PreData/Leanbin
73
+ find sources/lean/library -name " *.olean" -delete # ast only exported when oleans not present
74
+ # FIXME replace `stable` here with what mathlib is using?
75
+ cd sources/lean && elan override set stable
76
+ cd sources/lean && lean --make --recursive --ast --tlean library
77
+ cp -r sources/lean/library PreData/Leanbin
78
+ find PreData/ -name " *.lean" -delete
79
+ find PreData/ -name " *.olean" -delete
80
+
81
+ # Build .ast and .tlean files for Mathlib 3.
82
+ mathbin-predata : mathbin-source
83
+ rm -rf PreData/Mathbin
84
+ find sources/mathlib -name " *.olean" -delete # ast only exported when oleans not present
85
+ # By changing into the directory, `elan` automatically dispatches to the correct binary.
86
+ cd sources/mathlib && lean --make --recursive --ast --tlean src
87
+ cp -r sources/mathlib PreData/Mathbin
88
+ find PreData/ -name " *.lean" -delete
89
+ find PreData/ -name " *.olean" -delete
90
+
91
+ predata : lean3-predata mathbin-predata
92
+
7
93
init-logs :
8
94
mkdir -p Logs
9
95
@@ -12,57 +98,22 @@ MATHPORT_LIB=./build/lib
12
98
13
99
LEANBIN_LIB =./Lib4/leanbin/build/lib
14
100
MATHBIN_LIB =./Lib4/mathbin/build/lib
15
- LIQUIDBIN_LIB =./Lib4/liquidbin/build/lib
16
101
17
- port-lean : init-logs
18
- LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) time ./build/bin/mathport config.json Leanbin::all >> Logs/mathport.out 2> Logs/mathport.err
102
+ build :
103
+ lake build
104
+
105
+ port-lean : init-logs build
106
+ LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) ./build/bin/mathport config.json Leanbin::all >> Logs/mathport.out 2> Logs/mathport.err
19
107
LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) lean --o=$(LEANBIN_LIB ) /Leanbin.olean ./Lib4/leanbin/Leanbin.lean
20
108
cp lean-toolchain Lib4/leanbin
21
109
22
- port-mathlib : port-lean
23
- LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) time ./build/bin/mathport config.json Leanbin::all Mathbin::all >> Logs/mathport.out 2> Logs/mathport.err
110
+ port-mathbin : port-lean
111
+ LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) ./build/bin/mathport config.json Leanbin::all Mathbin::all >> Logs/mathport.out 2> Logs/mathport.err
24
112
LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) lean --o=$(MATHBIN_LIB ) /Mathbin.olean ./Lib4/mathbin/Mathbin.lean
25
113
cp lean-toolchain Lib4/mathbin
26
114
27
- port-liquid : port-mathlib
28
- LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) :$(LIQUIDBIN_LIB ) time ./build/bin/mathport config.json Leanbin::all Mathbin::all Liquidbin::all >> Logs/mathport.out 2> Logs/mathport.err
29
- LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) :$(LIQUIDBIN_LIB ) lean --o=$(LIQUIDBIN_LIB ) /Liquidbin.olean ./Lib4/liquidbin/Liquidbin.lean
30
- cp lean-toolchain Lib4/liquidbin
115
+ test :
116
+ LEAN_PATH=$(MATHPORT_LIB ) :$(MATHLIB4_LIB ) :$(LEANBIN_LIB ) :$(MATHBIN_LIB ) lean ./Test.lean
31
117
32
118
tar-lib4 :
33
119
tar --exclude ' lean_packages' -czvf mathport-release.tar.gz Lib4 Logs PreData
34
-
35
- lean3-predata :
36
- mkdir -p PreData
37
- rm -rf PreData/Leanbin
38
- find $(LEAN3_LIB ) -name " *.olean" -delete # ast only exported when oleans not present
39
- LEAN_PATH=$(LEAN3_LIB ) $(LEAN3_BIN ) /lean --make --recursive --ast --tlean $(LEAN3_LIB )
40
- LEAN_PATH=$(LEAN3_LIB ) :$(LEAN3_PKG ) $(LEAN3_BIN ) /lean --make --recursive --ast --tlean $(LEAN3_PKG )
41
- cp -r $(LEAN3_LIB ) PreData/Leanbin
42
- find PreData/ -name " *.lean" -delete
43
- find PreData/ -name " *.olean" -delete
44
-
45
- mathbin-predata : lean3-predata
46
- rm -rf PreData/Mathbin
47
- find $(MATHLIB3_SRC ) -name " *.olean" -delete # ast only exported when oleans not present
48
- LEAN_PATH=$(LEAN3_LIB ) :$(MATHLIB3_SRC ) $(LEAN3_BIN ) /lean --make --recursive --ast $(MATHLIB3_SRC )
49
- LEAN_PATH=$(LEAN3_LIB ) :$(MATHLIB3_SRC ) $(LEAN3_BIN ) /lean --make --recursive --tlean $(MATHLIB3_SRC )
50
- cp -r $(MATHLIB3_SRC ) PreData/Mathbin
51
- find PreData/ -name " *.lean" -delete
52
- find PreData/ -name " *.olean" -delete
53
-
54
- liquid-predata : mathbin-predata
55
- rm -rf PreData/Liquid
56
- find $(LIQUID3_SRC ) -name " *.olean" -delete # ast only exported when oleans not present
57
- LEAN_PATH=$(LEAN3_LIB ) :$(MATHLIB3_SRC ) :$(LIQUID3_SRC ) $(LEAN3_BIN ) /lean --make --recursive --ast --tlean $(LIQUID3_SRC )
58
- cp -r $(LIQUID3_SRC ) PreData/Liquidbin
59
- find PreData/ -name " *.lean" -delete
60
- find PreData/ -name " *.olean" -delete
61
-
62
- tmp-liquid-predata :
63
- rm -rf PreData/Liquid
64
- find $(LIQUID3_SRC ) -name " *.olean" -delete # ast only exported when oleans not present
65
- LEAN_PATH=$(LEAN3_LIB ) :$(MATHLIB3_SRC ) :$(LIQUID3_SRC ) $(LEAN3_BIN ) /lean --make --recursive --ast --tlean $(LIQUID3_SRC )
66
- cp -r $(LIQUID3_SRC ) PreData/Liquidbin
67
- find PreData/ -name " *.lean" -delete
68
- find PreData/ -name " *.olean" -delete
0 commit comments