This repository has been archived by the owner on Feb 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Makefile
371 lines (297 loc) · 12.1 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# Builds the Mac OS X installer for Haskell Platform
# NOTE: This process depends on much of the scripts and makefiles that go into
# producing the generic source tarball for Haskell Platform. If that process
# changes, then this will likely need changing too. See ../generic
all: help
# architecture to build
GHC_ARCH := i386
#GHC_ARCH := x86_64
# location where the build and assembly of the image is performed
BUILD := dist-$(GHC_ARCH)
DIRS := $(BUILD)
SPEC_CABAL := ../../haskell-platform.cabal
GHC_VERSION := $(subst ==,,$(word 3,$(shell grep '^tested-with:' $(SPEC_CABAL))))
PLATFORM_VERSION := $(word 2,$(shell grep '^version:' $(SPEC_CABAL)))
# Locations are paths to things that are installed. There are three versions
# of every location:
# TARGET_<foo> - a path in the installation on the target system (always absolute)
# IMAGE_<foo> - a path in the image of the target system, on this build system
# IMAGE_<foo>_ABS - absolute path to same
_REL_ROOT :=
TARGET_ROOT := /
IMAGE_ROOT := $(BUILD)/root
IMAGE_ROOT_ABS := $(abspath $(IMAGE_ROOT))
ROOT = $$(error Don't use ROOT as a variable. Use TARGET_ROOT, IMAGE_ROOT, or IMAGE_ROOT_ABS instead.)
DIRS += $(IMAGE_ROOT)
define location
# $1 = location name, used as base for variables names,
# $2 = location that this location is relative too, use ROOT for top
# $3 = relative path
_REL_$1 := $$(_REL_$2)/$3
TARGET_$1 := $$(_REL_$1)
IMAGE_$1 := $(IMAGE_ROOT)$$(_REL_$1)
IMAGE_$1_ABS := $(abspath $$(IMAGE_$1))
$1 = $$(error Don't use $1 as a variable. Use TARGET_$1, IMAGE_$1, or IMAGE_$1_ABS instead.)
endef
# The two main components that will be installed
$(eval $(call location,FRAMEWORKS,ROOT,Library/Frameworks))
$(eval $(call location,HASKELL,ROOT,Library/Haskell))
DIRS += $(IMAGE_FRAMEWORKS) $(IMAGE_HASKELL)
###
### Fetch GHC distribution, and unpack it
###
GHC_PKG_URL := http://haskell.org/ghc/dist/$(GHC_VERSION)/GHC-$(GHC_VERSION)-$(GHC_ARCH).pkg
GHC_PKG := $(BUILD)/GHC-$(GHC_VERSION)-$(GHC_ARCH).pkg
GHC_PACKAGE := $(BUILD)/GHC-package
GHC_PAYLOAD := $(GHC_PACKAGE)/ghc.pkg/Payload
$(eval $(call location,GHC_FRAMEWORK,FRAMEWORKS,GHC.framework))
$(eval $(call location,GHC_BIN,GHC_FRAMEWORK,Versions/Current/usr/bin))
$(eval $(call location,GHC_EXEC,GHC_BIN,ghc))
$(GHC_PKG):
curl $(GHC_PKG_URL) -o $@
$(GHC_PAYLOAD): | $(GHC_PKG)
-rm -rf $(GHC_PACKAGE)
pkgutil --expand $(GHC_PKG) $(GHC_PACKAGE)
$(IMAGE_GHC_FRAMEWORK): | $(GHC_PAYLOAD)
-rm -rf $(IMAGE_GHC_FRAMEWORK)
gunzip < $(GHC_PAYLOAD) | (cd $(IMAGE_FRAMEWORKS) && cpio -i)
ghc: dirs | $(IMAGE_GHC_FRAMEWORK)
clean-ghc:
-rm -rf $(IMAGE_GHC_FRAMEWORK)
-rm -rf $(GHC_PACKAGE)
clean: clean-ghc
.PHONY: ghc clean-ghc
.PRECIOUS: $(GHC_PKG)
###
### Rewrap GHC executables in versions of scripts that reference local dist.
### Rewrite GHC package database to one the references the local dist.
###
GHC_PROGS := ghc ghc-pkg haddock hsc2hs
$(eval $(call location,GHC_PACKAGE_DB,GHC_FRAMEWORK,Versions/Current/usr/lib/ghc-$(GHC_VERSION)/package.conf.d))
BUILD_PACKAGE_DB := $(BUILD)/package.conf.d
BUILD_BIN := $(BUILD)/bin
BUILD_PROGS :=
DIRS += $(BUILD_BIN) $(BUILD_PACKAGE_DB)
WITH_DB := GHC_PACKAGE_PATH=$(abspath $(BUILD_PACKAGE_DB))
WITH_PATH := PATH="$(abspath $(BUILD_BIN)):$$PATH"
define rewrap-prog # $1 = prog
$(BUILD_BIN)/$1: | $(IMAGE_GHC_FRAMEWORK)
sed -e 's:$(TARGET_GHC_FRAMEWORK):$(IMAGE_GHC_FRAMEWORK_ABS):' $(IMAGE_GHC_BIN)/$1 > $$@
chmod +x $$@
BUILD_PROGS += $(BUILD_BIN)/$1
endef
$(foreach prog,$(GHC_PROGS),\
$(eval $(call rewrap-prog,$(prog))))
$(BUILD_PACKAGE_DB)/package.cache: | $(IMAGE_GHC_FRAMEWORK)
for conf in $(IMAGE_GHC_PACKAGE_DB)/*.conf; do \
sed -e '/haddock-html/!s:$(TARGET_GHC_FRAMEWORK):$(IMAGE_GHC_FRAMEWORK_ABS):' $$conf > $(BUILD_PACKAGE_DB)/`basename $$conf`; \
done
$(BUILD_BIN)/ghc-pkg --package-conf $(BUILD_PACKAGE_DB) recache
rewrap: dirs ghc $(BUILD_PROGS) $(BUILD_PACKAGE_DB)/package.cache
clean-rewrap:
-rm -rf $(BUILD_BIN)
-rm -rf $(BUILD_PACKAGE_DB)
clean: clean-rewrap
.PHONEY: rewrap clean-rewrap
###
### Create a working copy of the base source image
###
GENERIC_SOURCE_TREE := ../generic/haskell-platform-$(PLATFORM_VERSION)
GENERIC_PACKAGE_LIST := $(GENERIC_SOURCE_TREE)/packages/platform.packages
BUILD_SOURCE_TREE := $(BUILD)/source
BUILD_SOURCE_PACKAGES := $(BUILD_SOURCE_TREE)/packages
BUILD_SOURCE_PACKAGES_ABS := $(abspath $(BUILD_SOURCE_PACKAGES))
BUILD_PACKAGE_LIST := $(BUILD_SOURCE_PACKAGES)/platform.packages
WITH_EXTRA := COPYFILE_DISABLE=true
$(GENERIC_PACKAGE_LIST):
cd ../generic && $(WITH_DB) $(WITH_PATH) $(WITH_EXTRA) sh prepare.sh
$(BUILD_PACKAGE_LIST): $(GENERIC_PACKAGE_LIST)
cp -r $(GENERIC_SOURCE_TREE)/ $(BUILD_SOURCE_TREE)
source: dirs $(BUILD_PACKAGE_LIST)
clean-source:
-rm -rf $(BUILD_SOURCE_TREE)
clean: clean-source
.PHONY: source clean-source
###
### Build the platform libraries
###
$(eval $(call location,PLATFORM_BASE,HASKELL,ghc-$(GHC_VERSION)))
$(eval $(call location,PLATFORM_LIB,PLATFORM_BASE,lib))
CONFIG_STATUS := $(BUILD_SOURCE_TREE)/config.status
CONFIG_OPTIONS += --disable-user-install
CONFIG_OPTIONS += --prefix=$(TARGET_PLATFORM_LIB)
CD_AND := cd $(BUILD_SOURCE_TREE) &&
SRC_RUN := $(CD_AND) $(WITH_DB) $(WITH_PATH)
$(CONFIG_STATUS): $(BUILD_PACKAGE_LIST)
$(SRC_RUN) ./configure $(CONFIG_OPTIONS)
config: rewrap source $(CONFIG_STATUS)
clean-config:
-rm $(CONFIG_STATUS)
clean: clean-config
.PHONY: config clean-config
BUILD_STAMP := $(BUILD_SOURCE_TREE)/build.stamp
CABAL_OPTS := --prefix=$(TARGET_PLATFORM_LIB)/\$$pkgid
CABAL_OPTS += --libsubdir=
CABAL_OPTS += --datasubdir=
CABAL_OPTS += --docdir=\$$prefix/doc
$(BUILD_STAMP): $(CONFIG_STATUS)
$(SRC_RUN) EXTRA_CONFIGURE_OPTS="${CABAL_OPTS}" scripts/build.sh
@touch $@
build: config $(BUILD_STAMP)
clean-build:
-rm $(BUILD_STAMP)
clean: clean-build
.PHONY: build clean-build
$(eval $(call location,PLATFORM_REGISTRATIONS,PLATFORM_LIB,registrations))
PACKAGE_STAMP := $(BUILD_SOURCE_TREE)/package.stamp
$(PACKAGE_STAMP): $(BUILD_STAMP)
-rm -rf $(IMAGE_PLATFORM_REGISTRATIONS)
-mkdir -p $(IMAGE_PLATFORM_REGISTRATIONS)
$(SRC_RUN) scripts/package.sh $(IMAGE_ROOT_ABS) $(IMAGE_PLATFORM_REGISTRATIONS_ABS)
@touch $@
package: build $(PACKAGE_STAMP)
clean-package:
-rm -rf $(IMAGE_PLATFORM_REGISTRATIONS) $(PACKAGE_STAMP)
clean: clean-package
.PHONY: package clean-package
###
### Scripts
###
HP_POST_SCRIPT = $(BUILD)/hp-postinstall.sh
$(HP_POST_SCRIPT):
echo "#!/bin/sh" > $@
echo "for conf in $(TARGET_PLATFORM_REGISTRATIONS)/*" >> $@
echo "do" >> $@
echo " /usr/bin/ghc-pkg register --force \$$conf" >> $@
echo "done" >> $@
echo "ln -sf $(TARGET_HASKELL)/bin/* /usr/bin" >> $@
echo "/usr/bin/uninstall-hs install-check" $(GHC_VERSION) " Installer" >> $@
chmod +x $@
scripts: $(HP_POST_SCRIPT)
clean-scripts:
-rm -rf $(HP_POST_SCRIPT)
clean: clean-scripts
.PHONY: scripts clean-scripts
###
### Build master haddock
###
$(eval $(call location,DOC_BASE,PLATFORM_BASE,doc))
$(eval $(call location,INDEX_HTML,DOC_BASE,index.html))
$(eval $(call location,START_HTML,DOC_BASE,start.html))
$(eval $(call location,GHC_DOC_BASE,GHC_FRAMEWORK,Versions/${GHC_VERSION}-$(GHC_ARCH)/usr/share/doc/ghc/html))
$(eval $(call location,GHC_API_BASE,GHC_DOC_BASE,libraries/ghc-${GHC_VERSION}))
define relpath # $1 from, $2 to
$(shell python -c "import os; print os.path.relpath('$1','$2')")
endef
PKGS_PLAT_REL := $(call relpath,$(IMAGE_PLATFORM_LIB),$(IMAGE_DOC_BASE))
PKGS_GHC_REL := $(call relpath,$(IMAGE_GHC_DOC_BASE),$(IMAGE_DOC_BASE))
PKGS_API_REL := $(call relpath,$(IMAGE_GHC_API_BASE),$(IMAGE_DOC_BASE))
DIRS += $(IMAGE_DOC_BASE)
$(IMAGE_INDEX_HTML): $(HP_POST_SCRIPT)
read="" ; \
for conf in $(IMAGE_PLATFORM_REGISTRATIONS)/*; do \
html=`grep haddock-html $$conf | cut -f 2 -d ' '` ; \
intf=`grep haddock-interfaces $$conf | cut -f 2 -d ' '` ; \
if [ -f ${IMAGE_ROOT}$$intf ] ; then \
read="$$read --read-interface=packages/$${html#${TARGET_PLATFORM_LIB}/},${IMAGE_ROOT}$$intf" ; \
fi ; \
done ; \
for pkg in `$(BUILD_BIN)/ghc-pkg list --package-conf=$(BUILD_PACKAGE_DB) --simple-output`; do \
html=`$(BUILD_BIN)/ghc-pkg field $$pkg haddock-html | cut -f 2 -d ' '` ; \
intf=`$(BUILD_BIN)/ghc-pkg field $$pkg haddock-interfaces | cut -f 2 -d ' '` ; \
if [ "$${pkg%-*}" \!= "ghc" -a -f ${IMAGE_ROOT}$$intf ] ; then \
read="$$read --read-interface=ghc-doc/$${html#${TARGET_GHC_DOC_BASE}/},${IMAGE_ROOT}$$intf" ; \
fi ; \
done ; \
./$(BUILD_BIN)/haddock --odir=${IMAGE_DOC_BASE} --gen-index --gen-contents \
$$read --title="Haskell Platform"
# These can't be symlink'd in the image as they cause PackageMaker fits
# So symlink them in the post install script
echo "ln -sf $(PKGS_PLAT_REL) $(TARGET_DOC_BASE)/packages" >> $(HP_POST_SCRIPT)
echo "ln -sf $(PKGS_GHC_REL) $(TARGET_DOC_BASE)/ghc-doc" >> $(HP_POST_SCRIPT)
echo "ln -sf $(PKGS_API_REL) $(TARGET_DOC_BASE)/ghc-api" >> $(HP_POST_SCRIPT)
$(IMAGE_START_HTML): start.html
cp $< $@
DOC_FIX_STAMP := $(BUILD_SOURCE_TREE)/docfix.stamp
SOURCE_LINK_PATTERN := $(BUILD_SOURCE_PACKAGES_ABS)/\([^/]*\)/dist/doc/html/[^/]*
TARGET_LINK_REPLACEMENT := $(TARGET_PLATFORM_LIB)/\1/doc/html
$(DOC_FIX_STAMP): $(PACKAGE_STAMP) $(IMAGE_INDEX_HTML)
find $(IMAGE_PLATFORM_BASE) -name '*.html' -print0 \
| xargs -0 -n 1 sed -i '' -e 's=$(SOURCE_LINK_PATTERN)=$(TARGET_LINK_REPLACEMENT)=g'
@touch $@
doc: ghc package scripts $(IMAGE_INDEX_HTML) $(IMAGE_START_HTML) $(DOC_FIX_STAMP)
clean-doc:
-rm -rf $(IMAGE_DOC_BASE) $(DOC_FIX_STAMP)
clean: clean-doc
.PHONY: doc clean-doc
###
### Final polish of the tree
###
$(eval $(call location,PLATFORM_BIN,PLATFORM_BASE,bin))
polish-bin:
-rm -rf $(IMAGE_PLATFORM_BIN)
mkdir -p $(IMAGE_PLATFORM_BIN)
cd $(IMAGE_PLATFORM_BIN) && ln -s ../lib/*/bin/* .
-rm $(IMAGE_PLATFORM_BIN)/*-tests
polish-cabal: polish-bin
mv $(IMAGE_PLATFORM_BIN)/cabal $(IMAGE_PLATFORM_BIN)/cabal.real
cp cabal.wrap $(IMAGE_PLATFORM_BIN)/cabal.wrap
chmod +x $(IMAGE_PLATFORM_BIN)/cabal.wrap
cd $(IMAGE_PLATFORM_BIN) && ln -s cabal.wrap cabal
UNINST_PROG = $(IMAGE_PLATFORM_BIN)/uninstall-hs
$(UNINST_PROG): polish-bin | UninstallHS.hs
$(WITH_DB) $(WITH_PATH) ghc --make -O -fforce-recomp -o $@ UninstallHS.hs
strip $@
PATCH_PROG = $(IMAGE_PLATFORM_BIN)/patch-ghc-settings
$(PATCH_PROG): polish-bin | PatchSettings.hs
$(WITH_DB) $(WITH_PATH) ghc --make -O -fforce-recomp -o $@ PatchSettings.hs
strip $@
polish-symlinks:
-rm $(IMAGE_HASKELL)/current $(IMAGE_HASKELL)/bin $(IMAGE_HASKELL)/doc
cd $(IMAGE_HASKELL) && ln -sf ghc-$(GHC_VERSION) current
cd $(IMAGE_HASKELL) && ln -sf current/bin bin
cd $(IMAGE_HASKELL) && ln -sf current/doc doc
polish: doc package polish-bin polish-cabal polish-symlinks $(UNINST_PROG) $(PATCH_PROG)
.PHONY: polish
###
### Build the installer package
###
INSTALLER_PACKAGE = dist/HaskellPlatform.pkg
$(INSTALLER_PACKAGE): Platform.pmdoc ghc scripts polish
#/Developer/usr/bin/packagemaker --doc Platform.pmdoc --verbose --out $@
@echo "About to change permissions of root. You will need to authorize:"
sudo chown -R -P root:admin $(IMAGE_ROOT)
sudo chmod -R go=u-w $(IMAGE_ROOT)
rm -rf dist
ln -s $(BUILD) dist
@echo "Build from PackageMaker please..."
rm -f Platform.pmdoc/*-contents.xml
open -a PackageMaker.app Platform.pmdoc
@echo "After building, sign & check with:"
@echo " productsign --sign 'Developer ID Installer: name' xxx.pkg xxx-signed.pkg"
@echo " spctl -a -v --type install xxx-signed.pkg"
installer: $(INSTALLER_PACKAGE)
clean-installer:
-rm $(INSTALLER_PACKAGE)
clean: clean-installer
.PHONY: installer clean-installer
###
### Misc
###
help:
@echo "make one of the following targets:"
@echo " ghc -- fetch and unpack ghc"
@echo " rewrap -- create working relocated ghc"
@echo " source -- create a working copy of the haskell platform source tree"
@echo " config -- config the working copy to use the unpacked ghc"
@echo " build -- build the packages in the working copy"
@echo " package -- install the packages in the root tree"
@echo " scripts -- create scripts needed for the installer"
@echo " doc -- build the master doc index"
@echo " polish -- various odds and ends to make the tree beautiful"
@echo " installler -- build the Mac installer package"
.PHONY: clean help
dirs: $(DIRS)
.PHONY: dirs
$(DIRS):
-mkdir -p $@