-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
325 lines (302 loc) · 11.4 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
##---------------------------------------------------------------------
# Makefile for python (supporting multiple versions)
##---------------------------------------------------------------------
Project = python
VERSIONERDIR = /usr/local/versioner
# Look for /usr/local/versioner in $(SDKROOT), defaulting to /usr/local/versioner
SDKVERSIONERDIR := $(or $(wildcard $(SDKROOT)$(VERSIONERDIR)),$(VERSIONERDIR))
FIX = $(SRCROOT)/fix
DEFAULT = 2.7
KNOWNVERSIONS = 2.7
BOOTSTRAPPYTHON =
VERSIONS = $(sort $(KNOWNVERSIONS) $(BOOTSTRAPPYTHON))
OTHERVERSIONS = $(filter-out $(DEFAULT),$(VERSIONS))
ORDEREDVERS := $(DEFAULT) $(OTHERVERSIONS)
REVERSEVERS := $(OTHERVERSIONS) $(DEFAULT)
PYFRAMEWORK = /System/Library/Frameworks/Python.framework
PYFRAMEWORKVERSIONS = $(PYFRAMEWORK)/Versions
VERSIONERFLAGS = -std=gnu99 -Wall -mdynamic-no-pic -I$(DSTROOT)$(VERSIONERDIR)/$(Project) -I$(FIX) -framework CoreFoundation
RSYNC = rsync -rlpt
PWD = $(shell pwd)
ifeq ($(MAKECMDGOALS),)
MAKECMDGOALS = build
endif
ifneq ($(filter build install,$(MAKECMDGOALS)),)
ifndef DSTROOT
ifdef DESTDIR
export DSTROOT = $(shell mkdir -p '$(DESTDIR)' && echo '$(DESTDIR)')
else
export DSTROOT = /
endif
endif
ifndef OBJROOT
export OBJROOT = $(shell mkdir -p '$(PWD)/OBJROOT' && echo '$(PWD)/OBJROOT')
RSYNC += --exclude=OBJROOT
endif
ifndef SYMROOT
export SYMROOT = $(shell mkdir -p '$(PWD)/SYMROOT' && echo '$(PWD)/SYMROOT')
RSYNC += --exclude=SYMROOT
endif
endif
ifndef SRCROOT
export SRCROOT = $(PWD)
endif
ifndef RC_ARCHS
export RC_ARCHS = $(shell arch)
export RC_$(RC_ARCHS) = YES
endif
ifndef RC_CFLAGS
export RC_CFLAGS = $(foreach A,$(RC_ARCHS),-arch $(A)) $(RC_NONARCH_CFLAGS)
endif
ifndef RC_NONARCH_CFLAGS
export RC_NONARCH_CFLAGS = -pipe
endif
ifndef RC_ProjectName
export RC_ProjectName = $(Project)
endif
##---------------------------------------------------------------------
# Before, we used the versioned gcc (e.g., gcc-4.2) because newer compiler
# would occasionally be incompatible with the compiler flags that python
# records. With clang, it doesn't use names with versions, so we just go
# back to using plain cc and c++. With 11952207, we will automatically
# get xcrun support.
##---------------------------------------------------------------------
export MY_CC = cc
export MY_CXX = c++
##---------------------------------------------------------------------
# The "strip" perl script, works around a verification error caused by a
# UFS bug (stripping a multi-link file breaks the link, and sometimes causes
# the wrong file to be stripped/unstripped). By using the "strip" perl script,
# it not only causes the correct file to be stripped, but also preserves the
# link.
##---------------------------------------------------------------------
export PATH:=$(OBJROOT)/bin:$(PATH)
TESTOK := -f $(shell echo $(foreach vers,$(VERSIONS),$(OBJROOT)/$(vers)/.ok) | sed 's/ / -a -f /g')
include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
VERSIONVERSIONS = $(VERSIONERDIR)/$(Project)/versions
VERSIONHEADER = $(VERSIONERDIR)/$(Project)/versions.h
VERSIONBINLIST = $(VERSIONERDIR)/$(Project)/usr-bin.list
VERSIONMANLIST = $(VERSIONERDIR)/$(Project)/usr-share-man.list
VERSIONERFIX = dummy.py scriptvers.ed
build::
$(RSYNC) '$(SRCROOT)/' '$(OBJROOT)'
@set -x && \
for vers in $(VERSIONS); do \
mkdir -p "$(SYMROOT)/$$vers" && \
mkdir -p "$(OBJROOT)/$$vers/DSTROOT" && \
(echo "######## Building $$vers:" `date` '########' > "$(SYMROOT)/$$vers/LOG" 2>&1 && \
{ [ "$$vers" != $(DEFAULT) ] || export PYTHON_DEFAULT=YES; } && \
TOPSRCROOT='$(SRCROOT)' \
$(MAKE) -C "$(OBJROOT)/$$vers" install \
SRCROOT="$(SRCROOT)/$$vers" \
OBJROOT="$(OBJROOT)/$$vers" \
DSTROOT="$(OBJROOT)/$$vers/DSTROOT" \
SYMROOT="$(SYMROOT)/$$vers" \
RC_ARCHS='$(RC_ARCHS)' >> "$(SYMROOT)/$$vers/LOG" 2>&1 && \
touch "$(OBJROOT)/$$vers/.ok" && \
echo "######## Finished $$vers:" `date` '########' >> "$(SYMROOT)/$$vers/LOG" 2>&1 \
) & \
done && \
wait && \
install -d $(DSTROOT)$(VERSIONERDIR)/$(Project)/fix && \
(cd $(FIX) && rsync -pt $(VERSIONERFIX) $(DSTROOT)$(VERSIONERDIR)/$(Project)/fix) && \
for a in $(VERSIONERFIX); do \
chmod g-w "$(DSTROOT)$(VERSIONERDIR)/$(Project)/fix/$${a}"; \
done && \
echo DEFAULT = $(DEFAULT) > $(DSTROOT)$(VERSIONVERSIONS) && \
for vers in $(KNOWNVERSIONS); do \
mkdir -p $(DSTROOT)/Library/Python/$$vers/site-packages; \
install $(SRCROOT)/$$vers/fix/Extras.pth $(DSTROOT)/Library/Python/$$vers/site-packages/Extras.pth; \
echo $$vers >> $(DSTROOT)$(VERSIONVERSIONS) || exit 1; \
done && \
for vers in $(VERSIONS); do \
cat $(SYMROOT)/$$vers/LOG && \
rm -f $(SYMROOT)/$$vers/LOG || exit 1; \
done && \
if [ $(TESTOK) ]; then \
$(MAKE) merge; \
else \
echo '#### error detected, not merging'; \
exit 1; \
fi
mkdir -p $(DSTROOT)$(PYFRAMEWORK)/Modules
install $(SRCROOT)/module.modulemap $(DSTROOT)$(PYFRAMEWORK)/Modules/module.modulemap
merge: mergebegin mergedefault mergeversions mergeplist mergebin mergeman fixsmptd legacySymLinks
mergebegin:
@echo ####### Merging #######
MERGEBIN = /usr/bin
# This causes us to replace the versioner stub with the default version of perl.
# Since we are now only shipping one version (2.7) and one slice (x86_64), there
# is no need for the re-exec stub. We are leaving the infrastructure in place
# in case we ever ship a new version or a new architecture in the future.
ifeq ($(OTHERVERSIONS),)
mergebin:
install -d $(DSTROOT)$(MERGEBIN)
pbin=$(PYFRAMEWORKVERSIONS)/$(DEFAULT)/bin && \
cd $(DSTROOT)$$pbin && \
if [ -e 2to3 ]; then \
mv 2to3 2to3$(DEFAULT) && \
ln -s 2to3$(DEFAULT) 2to3 && \
sed -e 's/@SEP@//g' -e "s/@VERSION@/$(DEFAULT)/g" $(FIX)/scriptvers.ed | ed - 2to3$(DEFAULT); \
fi && \
for f in `find . -type f | sed 's,^\./,,'`; do \
f0=`echo $$f | sed "s/$(DEFAULT)//"` && \
ln -sf ../..$$pbin/$$f $(DSTROOT)$(MERGEBIN)/$$f && \
ln -sf ../..$$pbin/$$f $(DSTROOT)$(MERGEBIN)/$$f0 && \
if file $$f | head -1 | fgrep -q script; then \
sed -e 's/@SEP@//g' -e "s/@VERSION@/$(DEFAULT)/g" $(FIX)/scriptvers.ed | ed - $$f; \
fi || exit 1; \
done; \
ln -sf ../..$$pbin/python2.7 $(DSTROOT)$(MERGEBIN)/python2
$(OBJROOT)/wrappers:
touch $(OBJROOT)/wrappers
else
TEMPWRAPPER = $(MERGEBIN)/.versioner
mergebin: $(DSTROOT)$(VERSIONHEADER) $(OBJROOT)/wrappers
cc $(RC_CFLAGS) $(VERSIONERFLAGS) $(SDKVERSIONERDIR)/versioner.c -o $(DSTROOT)$(TEMPWRAPPER)
@set -x && \
for w in `sort -u $(OBJROOT)/wrappers`; do \
ln -f $(DSTROOT)$(TEMPWRAPPER) $(DSTROOT)$(MERGEBIN)/$$w || exit 1; \
done
rm -f $(DSTROOT)$(TEMPWRAPPER)
cd $(DSTROOT)$(MERGEBIN) && ls | sort > $(DSTROOT)$(VERSIONBINLIST)
DUMMY = dummy.py
$(OBJROOT)/wrappers:
install -d $(DSTROOT)$(MERGEBIN)
install $(FIX)/$(DUMMY) $(DSTROOT)$(MERGEBIN)
@set -x && \
touch $(OBJROOT)/wrappers && \
for vers in $(ORDEREDVERS); do \
pbin=$(PYFRAMEWORKVERSIONS)/$$vers/bin && \
cd $(DSTROOT)$$pbin && \
if [ -e 2to3 ]; then \
mv 2to3 2to3$$vers && \
ln -s 2to3$$vers 2to3 && \
sed -e 's/@SEP@//g' -e "s/@VERSION@/$$vers/g" $(FIX)/scriptvers.ed | ed - 2to3$$vers; \
fi && \
for f in `find . -type f | sed 's,^\./,,'`; do \
f0=`echo $$f | sed "s/$$vers//"` && \
ln -sf ../..$$pbin/$$f $(DSTROOT)$(MERGEBIN)/$$f && \
if file $$f | head -1 | fgrep -q script; then \
sed -e 's/@SEP@//g' -e "s/@VERSION@/$$vers/g" $(FIX)/scriptvers.ed | ed - $$f && \
if [ ! -e $(DSTROOT)$(MERGEBIN)/$$f0 ]; then \
ln -f $(DSTROOT)$(MERGEBIN)/$(DUMMY) $(DSTROOT)$(MERGEBIN)/$$f0; \
fi; \
else \
echo $$f0 >> $@; \
fi || exit 1; \
done || exit 1; \
done
rm -f $(DSTROOT)$(MERGEBIN)/$(DUMMY)
endif
$(DSTROOT)$(VERSIONHEADER):
@set -x && ( \
echo '#define DEFAULTVERSION "$(DEFAULT)"' && \
echo '#define NVERSIONS (sizeof(versions) / sizeof(const char *))' && \
echo '#define PROJECT "$(Project)"' && \
printf '#define UPROJECT "%s"\n' `echo $(Project) | tr a-z A-Z` && \
echo 'static const char *versions[] = {' && \
touch $(OBJROOT)/versions && \
for vers in $(VERSIONS); do \
echo $$vers >> $(OBJROOT)/versions || exit 1; \
done && \
for vers in `sort -u $(OBJROOT)/versions`; do \
printf ' "%s",\n' $$vers || exit 1; \
done && \
echo '};' ) > $@
MERGEDEFAULT = \
usr/local/OpenSourceLicenses
mergedefault:
cd $(OBJROOT)/$(DEFAULT)/DSTROOT && rsync -Ra $(MERGEDEFAULT) $(DSTROOT)
MERGEMAN = /usr/share/man
mergeman: domergeman listman
# When merging man pages from the multiple versions, allow the man pages
# to be compressed (.gz suffix) or not.
domergeman:
@set -x && \
for vers in $(ORDEREDVERS); do \
cd $(OBJROOT)/$$vers/DSTROOT$(MERGEMAN) && \
for d in man*; do \
cd $$d && \
for f in `find . -type f -name '*.*' | sed 's,^\./,,'`; do \
ff=`echo $$f | sed -E "s/\.[^.]*(.gz)?$$/$$vers&/"` && \
ditto $$f $(DSTROOT)$(MERGEMAN)/$$d/$$ff && \
if [ ! -e $(DSTROOT)$(MERGEMAN)/$$d/$$f ]; then \
ln -fs $$ff $(DSTROOT)$(MERGEMAN)/$$d/$$f; \
fi || exit 1; \
done && \
cd .. || exit 1; \
done || exit 1; \
done
# When adding custom python.1 and pythonw.1 man pages, autodetect if we are
# compressing man pages, and if so, compress these custom man pages as well
CUSTOMTEMP = .temp.1
customman: $(OBJROOT)/wrappers
@set -x && \
cp -f $(FIX)/$(Project).1 $(DSTROOT)$(MERGEMAN)/man1/$(CUSTOMTEMP) && \
cd $(DSTROOT)$(MERGEMAN)/man1 && \
suffix='' && \
if ls | grep -q '\.gz$$'; then suffix='.gz'; fi && \
if [ "$${suffix}" ]; then gzip $(CUSTOMTEMP); fi && \
for w in `sort -u $(OBJROOT)/wrappers`; do \
rm -f $${w}.1$${suffix} && \
ln -f $(CUSTOMTEMP)$${suffix} $${w}.1$${suffix} || exit 1; \
done && \
rm -f $(CUSTOMTEMP)$${suffix}
listman:
cd $(DSTROOT)$(MERGEMAN) && find . ! -type d | sed 's,^\./,,' | sort > $(DSTROOT)$(VERSIONMANLIST)
OPENSOURCEVERSIONS = /usr/local/OpenSourceVersions
PLIST = $(OPENSOURCEVERSIONS)/$(Project).plist
mergeplist:
mkdir -p $(DSTROOT)/$(OPENSOURCEVERSIONS)
echo '<plist version="1.0">' > $(DSTROOT)/$(PLIST)
echo '<array>' >> $(DSTROOT)/$(PLIST)
@set -x && \
for vers in $(VERSIONS); do \
sed -e '/^<\/*plist/d' -e '/^<\/*array/d' -e 's/^/ /' $(OBJROOT)/$$vers/DSTROOT/$(PLIST) >> $(DSTROOT)/$(PLIST) || exit 1; \
done
echo '</array>' >> $(DSTROOT)/$(PLIST)
echo '</plist>' >> $(DSTROOT)/$(PLIST)
chmod 644 $(DSTROOT)/$(PLIST)
MERGEVERSIONSCONDITIONAL = \
Developer/Applications
MERGEVERSIONS = \
Library \
usr/include \
usr/lib
MERGEREVERSEVERSIONS = \
System
mergeversions:
@set -x && \
for vers in $(VERSIONS); do \
cd $(OBJROOT)/$$vers/DSTROOT && \
rsync -Ra $(MERGEVERSIONS) $(DSTROOT) && \
for c in $(MERGEVERSIONSCONDITIONAL); do \
if [ -e "$$c" ]; then \
rsync -Ra "$$c" $(DSTROOT); \
fi || exit 1; \
done || exit 1; \
done
for vers in $(REVERSEVERS); do \
cd $(OBJROOT)/$$vers/DSTROOT && \
rsync -Ra $(MERGEREVERSEVERSIONS) $(DSTROOT) || exit 1; \
done
fixsmptd:
set -x && \
cd $(DSTROOT)/usr/bin && \
mv -f smtpd.py smtpd.py.bak && \
cp -pf smtpd.py.bak smtpd.py && \
rm -f smtpd.py.bak && \
for i in smtpd*.py; do \
ed - $$i < $(FIX)/smtpd.py.ed || exit 1; \
done
# We're symlinking 2.3, 2.5, and 2.6 to 2.7 so apps that link against them don't crash on launch.
# Yes this is a bad idea, but it's the least bad from the customer's perspective.
legacySymLinks:
set -x && \
fwdst=$(DSTROOT)/$(PYFRAMEWORKVERSIONS) && \
cd $$fwdst && \
ln -s 2.7 2.3 && \
ln -s 2.7 2.5 && \
ln -s 2.7 2.6 && \
set +x