This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
forked from docker-archive/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
229 lines (165 loc) · 7.08 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
TARGETS=env-build env-runtime cygwin-build cygwin-runtime sage-build \
sage-runtime cygwin-extras-runtime
.PHONY: all $(TARGETS) $(addprefix clean-,$(TARGETS)) clean-installer
############################ 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)
# 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"
################################################################################
# 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
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/sagemath-$(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)
# Note: Be very careful about quoting here; we need literal
# quotes or else they will be stripped when exec'ing bash
SAGE_ENVVARS:=\
SAGE_NUM_THREADS=$(N_CPUS) \
SAGE_INSTALL_CCACHE=yes \
CCACHE_DIR=\"$(HOME)/.ccache\" \
SAGE_FAT_BINARY=yes \
SAGE_ATLAS_LIB=/lib \
MAKE=\"make -j$(N_CPUS)\"
# 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/sage-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://cygwin.com/$(CYGWIN_SETUP_NAME)
CYGWIN_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/
SAGE_INSTALLER=$(DIST)/SageMath-$(SAGE_VERSION).exe
TOOLS=tools
SUBCYG=$(TOOLS)/subcyg
DIRS=$(DIST) $(DOWNLOAD) $(ENVS) $(STAMPS)
################################################################################
all: $(SAGE_INSTALLER)
$(SAGE_INSTALLER): $(SOURCES) $(env-runtime) | $(DIST)
cd $(CUDIR)
$(ISCC) /DSageVersion=$(SAGE_VERSION) /DSageArch=$(ARCH) \
/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)
(cd $(ENV_RUNTIME_DIR) && find . -type l) > $(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_ROOT_RUNTIME): $(cygwin-runtime) $(sage-build)
[ -d $(dir $@) ] || mkdir $(dir $@)
cp -rp $(SAGE_ROOT_BUILD) $(dir $@)
(cd $@ && rm -rf bootstrap config.* logs \
upstream local/var/tmp/sage/build/* local/var/lock/* \
src/build local/share/doc/sage/doctrees .git*)
# This shouldn't be necessary but it seems to help ensure that the
# main Makefile is newer than its prerequisites
touch "$(SAGE_ROOT_RUNTIME)/build/make/Makefile"
SHELL=/bin/dash $(SUBCYG) "$(ENV_RUNTIME_DIR)" \
"(cd $(SAGE_ROOT) && local/bin/sage-rebaseall.sh local)"
tools/sage-fixup-doc-symlinks "$(SAGE_ROOT_RUNTIME)/local/share/doc/sage/html"
$(env-build): $(cygwin-build) $(sage-build)
@touch $@
clean-env-build: clean-sage-build clean-cygwin-build
rm -f $(env-build)
$(sage-build): $(cygwin-build) $(SAGE_STARTED)
SHELL=/bin/dash $(SUBCYG) "$(ENV_BUILD_DIR)" \
"(cd $(SAGE_ROOT) && local/bin/sage-rebaseall.sh local)"
$(SUBCYG) "$(ENV_BUILD_DIR)" \
"(cd $(SAGE_ROOT) && $(SAGE_ENVVARS) make doc)"
@touch $@
clean-sage-build:
rm -rf $(SAGE_ROOT_BUILD)
rm -f $(sage-build)
$(cygwin-runtime-extras): $(cygwin-runtime)
cp -r $(CYGWIN_EXTRAS)/* $(ENV_RUNTIME_DIR)
echo "SAGE_VERSION=$(SAGE_VERSION)" > $(ENV_RUNTIME_DIR)/etc/sage-version
echo 'none /tmp usertemp binary,posix=0 0 0' >> $(ENV_RUNTIME_DIR)/etc/fstab
echo 'db_home: /home/sage' >> $(ENV_RUNTIME_DIR)/etc/nsswitch.conf
# Set the package download cache to something sensible; otherwise it
# will hard-code the package download cache used when building the
# environment in the installer, which is not what we want
# See https://github.com/sagemath/sage-windows/issues/24
sed -i '/^last-cache/{n;s|.*|\t/tmp|;}' "$(ENV_RUNTIME_DIR)"/etc/setup/setup.rc
@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)
.SECONDARY: $(ENV_BUILD_DIR) $(ENV_RUNTIME_DIR)
$(ENVS)/%-$(SAGE_VERSION)-$(ARCH): cygwin-sage-%-$(ARCH).list $(CYGWIN_SETUP)
"$(CYGWIN_SETUP)" --site $(CYGWIN_MIRROR) \
--local-package-dir "$$(cygpath -w -a $(DOWNLOAD))" \
--root "$$(cygpath -w -a $@)" \
--arch $(ARCH) --no-admin --no-shortcuts --quiet-mode \
--packages $$($(TOOLS)/setup-package-list $<)
# 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_STARTED): $(SAGE_MAKEFILE)
$(SUBCYG) "$(ENV_BUILD_DIR)" \
"(cd $(SAGE_ROOT) && $(SAGE_ENVVARS) make start)"
$(SAGE_MAKEFILE): $(SAGE_CONFIGURE)
$(SUBCYG) "$(ENV_BUILD_DIR)" "(cd $(SAGE_ROOT) && ./configure --with-blas=atlas)"
$(SAGE_CONFIGURE): | $(SAGE_ROOT_BUILD)
$(SUBCYG) "$(ENV_BUILD_DIR)" "(cd $(SAGE_ROOT) && make configure)"
$(SAGE_ROOT_BUILD): $(cygwin-build)
[ -d $(dir $(SAGE_ROOT_BUILD)) ] || mkdir $(dir $(SAGE_ROOT_BUILD))
$(SUBCYG) "$(ENV_BUILD_DIR)" "(cd /opt && git clone --single-branch --branch $(SAGE_BRANCH) $(SAGE_GIT) $(SAGE_ROOT))"
$(CYGWIN_SETUP): | $(DOWNLOAD)
(cd $(DOWNLOAD) && wget "$(CYGWIN_SETUP_URL)")
chmod +x $(CYGWIN_SETUP)
$(DIRS):
mkdir "$@"