forked from sagemath/sage-windows-cygwin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
284 lines (212 loc) · 9.15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
TARGETS=env-build env-runtime cygwin-build cygwin-runtime sage-build \
sage-runtime cygwin-extras-runtime
.PHONY: all $(TARGETS) $(addprefix clean-,$(TARGETS)) clean-envs \
clean-installer clean-all
############################ Configurable Variables ###########################
# Can be x86 or x86_64
ARCH?=x86_64
# Set to 1 to build a test version of the installer for testing the installer
# itself itself; it excludes Sage but is faster to build and install
SAGE_TEST_INSTALLER?=0
SAGE_VERSION?=develop
SAGE_BRANCH?=$(SAGE_VERSION)
INSTALLER_VERSION=$(shell cat version.txt)
# Output paths
DIST?=dist
DOWNLOAD?=download
ENVS?=envs
STAMPS?=.stamps
# Path to the Inno Setup executable
ISCC?="/cygdrive/c/Program Files (x86)/Inno Setup 5/ISCC.exe"
PROGBASE?=sage
PROG?=sagemath
################################################################################
# Actual targets for the main build stages (the stamp files)
env-build=$(STAMPS)/env-build-$(SAGE_VERSION)-$(ARCH)
env-runtime=$(STAMPS)/env-runtime-$(SAGE_VERSION)-$(ARCH)
cygwin-build=$(STAMPS)/cygwin-build-$(SAGE_VERSION)-$(ARCH)
cygwin-runtime=$(STAMPS)/cygwin-runtime-$(SAGE_VERSION)-$(ARCH)
sage-build=$(STAMPS)/sage-build-$(SAGE_VERSION)-$(ARCH)
sage-runtime=$(STAMPS)/sage-runtime-$(SAGE_VERSION)-$(ARCH)
cygwin-runtime-extras=$(STAMPS)/cygwin-runtime-extras-$(SAGE_VERSION)-$(ARCH)
###############################################################################
# Resource paths
PATCHES?=patches
CYGWIN_EXTRAS?=cygwin_extras
RESOURCES?=resources
DOT_SAGE?=dot_sage
ICONS:=$(wildcard $(RESOURCES)/*.bmp) $(wildcard $(RESOURCES)/*.ico)
ENV_BUILD_DIR=$(ENVS)/build-$(SAGE_VERSION)-$(ARCH)
ENV_RUNTIME_DIR=$(ENVS)/runtime-$(SAGE_VERSION)-$(ARCH)
SAGE_GIT?=git://git.sagemath.org/sage.git
SAGE_ROOT=/opt/$(PROG)-$(SAGE_VERSION)
SAGE_ROOT_BUILD=$(ENV_BUILD_DIR)$(SAGE_ROOT)
SAGE_ROOT_RUNTIME=$(ENV_RUNTIME_DIR)$(SAGE_ROOT)
N_CPUS=$(shell cat /proc/cpuinfo | grep '^processor' | wc -l)
# TODO: These variables should be made dependent on the Sage version being
# built, as we may need to change this from version to version. In practice
# though we usually just care about building the latest version.
# NOTE: The latest version, 9.2, still does not work with system GMP.
# NOTE: The latest version, 9.2, defaults to Python 3.8 but works with
# Python 3.7 if we specify it.
override SAGE_CONFIGURE_FLAGS:=--with-mp=system --with-python=python3.7 $(SAGE_CONFIGURE_FLAGS)
# NOTE: Be very careful about quoting here; we need literal
# quotes or else they will be stripped when exec'ing bash
# NOTE: FFLAS_FFPACK_CONFIGURE is needed to work around a regression introduced
# in Sage 8.9: https://trac.sagemath.org/ticket/27444#comment:34
SAGE_ENVVARS:=\
SAGE_NUM_THREADS=$(N_CPUS) \
SAGE_INSTALL_CCACHE=yes \
CCACHE_DIR=\"$(HOME)/.ccache\" \
SAGE_FAT_BINARY=yes \
FFLAS_FFPACK_CONFIGURE=--disable-openmp \
MAKE=\"make -j$(N_CPUS)\"
SAGE_OPTIONAL_PACKAGES=bliss coxeter3 mcqd primecount tdlib
# Outputs representing success in the Sage build process
SAGE_CONFIGURE=$(SAGE_ROOT_BUILD)/configure
SAGE_MAKEFILE?=$(SAGE_ROOT_BUILD)/build/make/Makefile
SAGE_STARTED?=$(SAGE_ROOT_BUILD)/local/etc/$(PROGBASE)-started.txt
# Files used as input to ISCC
SAGEMATH_ISS?=SageMath.iss
SOURCES:=$(SAGEMATH_ISS) $(DOT_SAGE) $(ICONS)
# URL to download the Cygwin setup.exe
CYGWIN_SETUP_NAME=setup-$(ARCH).exe
CYGWIN_SETUP=$(DOWNLOAD)/$(CYGWIN_SETUP_NAME)
CYGWIN_SETUP_URL=https://www.cygwin.com/$(CYGWIN_SETUP_NAME)
CYGWIN_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/
CYGWIN_LOCAL_MIRROR=cygwin_mirror/
ifeq (,$(wildcard $(CYGWIN_LOCAL_MIRROR)))
CYGWIN_LOCAL_INSTALL_FLAGS=
else
CYGWIN_MIRROR=$(CYGWIN_LOCAL_MIRROR)
CYGWIN_LOCAL_INSTALL_FLAGS=--local-install --local-package-dir "$$(cygpath -w -a .)"
endif
SAGE_INSTALLER=$(DIST)/$(PROG)-$(SAGE_VERSION)-v$(INSTALLER_VERSION).exe
TOOLS=tools
SUBCYG=$(TOOLS)/subcyg
DIRS=$(DIST) $(DOWNLOAD) $(ENVS) $(STAMPS)
################################################################################
all: $(SAGE_INSTALLER)
$(SAGE_INSTALLER): $(SOURCES) $(env-runtime) | $(DIST)
cd $(CUDIR)
$(ISCC) /DSageName=$(PROG) /DSageVersion=$(SAGE_VERSION) /DSageArch=$(ARCH) /Q \
/DInstallerVersion=$(INSTALLER_VERSION) \
/DSageTestInstaller=$(SAGE_TEST_INSTALLER) \
/DEnvsDir="$(ENVS)" /DOutputDir="$(DIST)" $(SAGEMATH_ISS)
clean-installer:
rm -f $(SAGE_INSTALLER)
$(foreach target,$(TARGETS),$(eval $(target): $$($(target))))
$(env-runtime): $(cygwin-runtime) $(sage-runtime) $(cygwin-runtime-extras)
$(TOOLS)/fixup-symlinks $(ENV_RUNTIME_DIR) > $(ENV_RUNTIME_DIR)/etc/symlinks.lst
@touch $@
clean-env-runtime: clean-cygwin-runtime
rm -f $(env-runtime)
$(sage-runtime): $(SAGE_ROOT_RUNTIME)
@touch $@
clean-sage-runtime:
rm -rf $(SAGE_ROOT_RUNTIME)
rm -f $(sage-runtime)
SAGE_REBASE_CMD?="cd $(SAGE_ROOT) && local/bin/sage-rebaseall.sh local"
SAGE_FIXUP_DOC_CMD?=tools/sage-fixup-doc-symlinks "$(SAGE_ROOT_RUNTIME)/local/share/doc/sage/html"
$(SAGE_ROOT_RUNTIME): $(cygwin-runtime) $(sage-build)
[ -d $(dir $@) ] || mkdir $(dir $@)
cp -rp $(SAGE_ROOT_BUILD) $(dir $@)
# Prepare / compactify runtime environment
$(TOOLS)/$(PROGBASE)-prep-runtime "$(SAGE_ROOT_RUNTIME)" "$(SAGE_ROOT)"
# Re-rebase everything
#SHELL=/bin/dash $(SUBCYG) "$(ENV_RUNTIME_DIR)" \
$(SAGE_REBASE_CMD)
$(SAGE_FIXUP_DOC_CMD)
$(env-build): $(cygwin-build) $(sage-build)
@touch $@
clean-env-build: clean-sage-build clean-cygwin-build clean-installer
rm -f $(env-build)
SAGE_REBUILD_CMD?="cd $(SAGE_ROOT) && local/bin/sage-rebaseall.sh local"
SAGE_BUILD_DOC_CMD?="cd $(SAGE_ROOT) && $(SAGE_ENVVARS) make doc"
$(sage-build): $(cygwin-build) $(SAGE_STARTED)
SHELL=/bin/dash $(SUBCYG) "$(ENV_BUILD_DIR)" \
$(SAGE_REBUILD_CMD)
$(SUBCYG) "$(ENV_BUILD_DIR)" $(SAGE_BUILD_DOC_CMD)
@touch $@
clean-sage-build:
rm -rf $(SAGE_ROOT_BUILD)
rm -f $(sage-build)
$(cygwin-runtime-extras): $(cygwin-runtime)
$(TOOLS)/$(PROGBASE)-prep-runtime-extras "$(ENV_RUNTIME_DIR)" "$(CYGWIN_EXTRAS)" \
"$(SAGE_VERSION)"
# Set apt-cyg to use a non-local mirror in the runtime env
$(SUBCYG) "$(ENV_RUNTIME_DIR)" "apt-cyg mirror $(CYGWIN_MIRROR)"
@touch $@
# Right now the only effective way to roll back cygwin-runtime-extras
# is to clean the entire runtime cygwin environment
clean-cygwin-runtime-extras: clean-cygwin-runtime
$(STAMPS)/cygwin-%: | $(ENVS)/% $(STAMPS)
@touch $@
clean-cygwin-build:
rm -rf $(ENV_BUILD_DIR)
rm -f $(cygwin-build)
clean-cygwin-runtime: clean-sage-runtime
rm -rf $(ENV_RUNTIME_DIR)
rm -f $(cygwin-runtime)
rm -f $(cygwin-runtime-extras)
clean-envs: clean-env-runtime clean-env-build
clean-all: clean-envs clean-installer
.SECONDARY: $(ENV_BUILD_DIR) $(ENV_RUNTIME_DIR)
$(ENVS)/%-$(SAGE_VERSION)-$(ARCH): cygwin-$(PROGBASE)-%-$(ARCH).list $(CYGWIN_SETUP)
$(eval ENV_TMP := $(shell mktemp -d))
"$(CYGWIN_SETUP)" --site $(CYGWIN_MIRROR) \
$(CYGWIN_LOCAL_INSTALL_FLAGS) \
--root "$$(cygpath -w -a $(ENV_TMP))" \
--arch $(ARCH) --no-admin --no-shortcuts --quiet-mode \
--packages $$($(TOOLS)/setup-package-list $<) \
$(CYGWIN_SETUP_FLAGS)
# Move the tmpdir into the final environment location
mkdir -p $(ENVS)
mv $(ENV_TMP) $@
# Install symlinks for CCACHE
if [ -x $@/usr/bin/ccache ]; then \
ln -s /usr/bin/ccache $@/usr/local/bin/gcc; \
ln -s /usr/bin/ccache $@/usr/local/bin/g++; \
fi
# A bit of cleanup
rm -f $@/Cygwin*.{bat,ico}
# We should re-touch the relevant stamp file since the runtime
# environment may be updated
touch "$(STAMPS)/cygwin-$(subst $(ENVS)/,,$@)"
SAGE_START_CMD?="cd $(SAGE_ROOT) && $(SAGE_ENVVARS) make start"
SAGE_BUILD_PACKAGES?="cd $(SAGE_ROOT) && $(SAGE_ENVVARS) ./sage -i $(SAGE_OPTIONAL_PACKAGES) && make build"
$(SAGE_STARTED): $(SAGE_MAKEFILE)
$(SUBCYG) "$(ENV_BUILD_DIR)" $(SAGE_START_CMD)
# Install pre-installed optional packages and run make build again to
# intall sagelib optional extensions that use those packages
$(SUBCYG) "$(ENV_BUILD_DIR)" $(SAGE_BUILD_PACKAGES)
SAGE_RUN_CONFIGURE_CMD?="cd $(SAGE_ROOT) && ./configure $(SAGE_CONFIGURE_FLAGS)"
$(SAGE_MAKEFILE): $(SAGE_CONFIGURE)
$(SUBCYG) "$(ENV_BUILD_DIR)" $(SAGE_RUN_CONFIGURE_CMD)
SAGE_MAKE_CONFIGURE_CMD?="cd $(SAGE_ROOT) && make configure"
$(SAGE_CONFIGURE): | $(SAGE_ROOT_BUILD)
$(SUBCYG) "$(ENV_BUILD_DIR)" $(SAGE_MAKE_CONFIGURE_CMD)
$(SAGE_ROOT_BUILD): $(cygwin-build)
[ -d $(dir $(SAGE_ROOT_BUILD)) ] || mkdir $(dir $(SAGE_ROOT_BUILD))
# Get $(PROG) into the right place.
# If there exists neighbouring directory $(PROG)-$(SAGE_VERSION) e.g.
# gap-4.11.1, then use that version; move into $(SAGE_ROOT_BUILD).
# Else clone into $(SAGE_ROOT) using $(SAGE_GIT) & $(SAGE_BRANCH).
# Note that $(SAGE_ROOT) = $(SAGE_ROOT_BUILD)/$(PROG)-$(SAGE_VERSION).
if [ -d ../$(PROG)-$(SAGE_VERSION) ]; then \
mv ../$(PROG)-$(SAGE_VERSION) $(SAGE_ROOT_BUILD); \
else \
$(SUBCYG) "$(ENV_BUILD_DIR)" "cd /opt && git clone --single-branch --branch $(SAGE_BRANCH) $(SAGE_GIT) $(SAGE_ROOT)"; \
fi
# Apply patches
if [ -d $(PATCHES)/$(SAGE_BRANCH) ]; then \
for patch in $(PATCHES)/$(SAGE_BRANCH)/*.patch; do \
patch="$$(pwd)/$$patch"; \
(cd $(SAGE_ROOT_BUILD) && patch -p1 < $$patch); \
done; \
fi
$(CYGWIN_SETUP): | $(DOWNLOAD)
(cd $(DOWNLOAD) && wget "$(CYGWIN_SETUP_URL)")
chmod +x $(CYGWIN_SETUP)
$(DIRS):
mkdir "$@"