forked from GaloisInc/ICryptol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
183 lines (154 loc) · 5.63 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
HERE := $(dir $(lastword $(MAKEFILE_LIST)))
UNAME := $(shell uname -s)
ARCH := $(shell uname -m)
REV ?= $(shell git rev-parse --short=7 HEAD || echo "unknown")
VERSION := $(shell grep -i ^Version ICryptol.cabal | awk '{ print $$2}')
SYSTEM_DESC ?= ${UNAME}-${ARCH}_${REV}
PKG := ICryptol-${VERSION}-${SYSTEM_DESC}
CABAL := cabal
CABAL_BUILD := $(CABAL) build $(CABAL_BUILD_FLAGS)
CABAL_INSTALL := $(CABAL) install $(CABAL_INSTALL_FLAGS)
CS := $(HERE)/.cabal-sandbox
CS_BIN := $(CS)/bin
# Used only for windows, to find the right Program Files.
PROGRAM_FILES = Program\ Files\ \(x86\)
# Windows installer tools; assumes running on Cygwin and using WiX 3.8
WiX := /cygdrive/c/${PROGRAM_FILES}/WiX\ Toolset\ v3.8
CANDLE := ${WiX}/bin/candle.exe
HEAT := ${WiX}/bin/heat.exe
LIGHT := ${WiX}/bin/light.exe
# Windows-specific stuff
ifneq (,$(findstring _NT,${UNAME}))
DIST := ${PKG}.msi
EXE_EXT := .exe
adjust-path = '$(shell cygpath -w $1)'
PREFIX ?=
# For a systemwide distribution .msi, use:
# PREFIX ?= ${PROGRAM_FILES}/Galois/Cryptol\ ${VERSION}
# split this up because `cabal copy` strips drive letters
PREFIX_ABS := /cygdrive/c/${PREFIX}
# since Windows installs aren't overlapping like /usr/local, we
# don't need this extra prefix
PREFIX_SHARE :=
# goes under the share prefix
PREFIX_DOC := /doc
PKG_PREFIX := ${PKG}/${PREFIX}
ROOT_PATH := /cygdrive/c
else
DIST := ${PKG}.tar.gz ${PKG}.zip
EXE_EXT :=
adjust-path = '$1'
PREFIX ?=
# For a systemwide distribution like an .rpm or .pkg, use something like:
# PREFIX ?= /usr/local
PREFIX_ABS := ${PREFIX}
PREFIX_SHARE := /share
# goes under the share prefix
PREFIX_DOC := /doc/ICryptol
PKG_PREFIX := ${PKG}${PREFIX}
ROOT_PATH := /
endif
ICRYPTOL_EXE := ./dist/build/cryptol/icryptol-kernel${EXE_EXT}
ICRYPTOL_SRC := \
$(shell find src \
\( -name \*.hs -or -name \*.x -or -name \*.y \) \
-and \( -not -name \*\#\* \) -print)
${ICRYPTOL_EXE}: ${ICRYPTOL_SRC} dist/setup-config
${CABAL_BUILD}
# TODO: piece this apart a bit more; if right now if something fails
# during initial setup, you have to invoke this target again manually
${CS}:
$(CABAL) sandbox init
${CS_BIN}/alex: | ${CS}
$(CABAL_INSTALL) alex
${CS_BIN}/happy: | ${CS} ${CS_BIN}/alex
$(CABAL_INSTALL) happy
# We do things differently based on whether we have a PREFIX set by
# the user. If we do, then we know the eventual path it'll wind up in
# (useful for stuff like RPMs or Homebrew). If not, we try to be as
# relocatable as possible.
ifneq (,${PREFIX})
PREFIX_ARG := --prefix=$(call adjust-path,${PREFIX_ABS})
DESTDIR_ARG := --destdir=${PKG}
CONFIGURE_ARGS := --docdir=$(call adjust-path,${PREFIX_SHARE}/${PREFIX_DOC})
else
# This is kind of weird: 1. Prefix argument must be absolute; Cabal
# doesn't yet fully support relocatable packages. 2. We have to
# provide *some* prefix here even if we're not using it, otherwise
# `cabal copy` will make a mess in the PKG directory.
PREFIX_ARG := --prefix=$(call adjust-path,${ROOT_PATH})
DESTDIR_ARG := --destdir=${PKG}
CONFIGURE_ARGS := --docdir=$(call adjust-path,${PREFIX_SHARE}/${PREFIX_DOC})
endif
dist/setup-config: ICryptol.cabal Makefile | ${CS_BIN}/alex ${CS_BIN}/happy
$(CABAL_INSTALL) --only-dependencies --max-backjumps=999999
$(CABAL) configure ${PREFIX_ARG} --datasubdir=ICryptol ${CONFIGURE_ARGS}
.PHONY: all
all: ${ICRYPTOL_EXE}
.PHONY: dist
dist: ${DIST}
.PHONY: tarball
tarball: ${PKG}.tar.gz
.PHONY: zip
zip: ${PKG}.zip
.PHONY: msi
msi: ${PKG}.msi
.PHONY: notebook
notebook: ${PKG}
mkdir -p $(CURDIR)/.ipython
IPYTHONDIR=$(CURDIR)/.ipython \
PATH=$(call adjust-path,${CURDIR}/${PKG_BIN}):$$PATH \
${PKG_BIN}/icryptol --notebook-dir=$(call adjust-path,${PKG_EXAMPLES})
PROFILE_CRYPTOL_SRC := ipython/kernels/cryptol/kernel.json \
ipython/kernels/cryptol/logo-64x64.png
profile.tar: ${PROFILE_CRYPTOL_SRC}
tar -C ipython -cvf profile.tar kernels
PKG_BIN := ${PKG_PREFIX}/bin
PKG_SHARE := ${PKG_PREFIX}${PREFIX_SHARE}
PKG_ICRY := ${PKG_SHARE}/ICryptol
PKG_DOC := ${PKG_SHARE}${PREFIX_DOC}
PKG_EXAMPLES := ${PKG_DOC}/examples
PKG_EXAMPLE_FILES := examples/AES.ipynb
${PKG}: ${ICRYPTOL_EXE} icryptol profile.tar LICENSE \
${PKG_EXAMPLE_FILES}
$(CABAL) copy --destdir=${PKG}
# script not included in the copy
cp icryptol ${PKG_BIN}
# don't want to bundle the cryptol library in the binary distribution
rm -rf ${PKG_PREFIX}/lib
mkdir -p ${PKG_ICRY}
mkdir -p ${PKG_DOC}
mkdir -p ${PKG_EXAMPLES}
cp LICENSE ${PKG_DOC}
for EXAMPLE in ${PKG_EXAMPLE_FILES}; do \
cp $$EXAMPLE ${PKG_EXAMPLES}; done
cp -r profile.tar ${PKG_ICRY}
${PKG}.tar.gz: ${PKG}
tar -czvf $@ $<
${PKG}.zip: ${PKG}
zip -r $@ $<
${PKG}.msi: ${PKG} win32/ICryptol.wxs
${HEAT} dir ${PKG_PREFIX} -o allfiles.wxs -nologo -var var.pkg \
-ag -wixvar -cg ALLFILES -srd -dr INSTALLDIR -sfrag
${CANDLE} -ext WixUIExtension -ext WixUtilExtension \
-dversion=${VERSION} -dpkg=${PKG_PREFIX} win32/ICryptol.wxs
${CANDLE} -ext WixUIExtension -ext WixUtilExtension \
-dversion=${VERSION} -dpkg=${PKG_PREFIX} allfiles.wxs
${LIGHT} -ext WixUIExtension -ext WixUtilExtension \
-sval -o $@ ICryptol.wixobj allfiles.wixobj
rm -f allfiles.wxs
rm -f *.wixobj
rm -f *.wixpdb
.PHONY: clean
clean:
cabal clean
rm -rf ICryptol-${VERSION}*/
rm -rf ICryptol-${VERSION}*.tar.gz
rm -rf ICryptol-${VERSION}*.zip
rm -rf ICryptol-${VERSION}*.msi
rm -rf .ipython
rm -rf profile.tar
.PHONY: squeaky
squeaky: clean
-$(CABAL) sandbox delete
rm -rf dist