-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
211 lines (181 loc) · 8.56 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
HSFILES=$(wildcard *.hs) $(wildcard app/*.hs) $(wildcard src/*/*.hs) $(wildcard src/*/*/*.hs) $(wildcard src/*/*/*/*.hs)
CPU_PLAT_RAW=$(shell stack ghc -- -e "(\(Just p) -> p) $$ lookup "'"'"Target platform"'"'" $$(stack ghc -- --info)" | tr -d \")
CPU_RAW=$(shell echo "$(CPU_PLAT_RAW)" | cut -d "-" -f 1)
CPU_x86_64=amd64
CPU_i386=i386
TARGET_CPU=$(CPU_$(CPU_RAW))
PLAT_RAW=$(shell echo "$(CPU_PLAT_RAW)" | cut -d "-" -f 2,3)
PLAT_unknown-linux=linux
PLAT_linux-gnu=linux
PLAT_unknown-mingw32=windows
PLAT_w64-mingw32=windows
TARGET_PLATFORM=$(PLAT_$(PLAT_RAW))
ifeq ($(OS),Windows_NT)
SMUDGE_EXE=smudge.exe
/=\\
PKGEXT=zip exe
RC_FILE=$(SMUDGE_BUILD_DIR)/Properties.o
CABAL_FLAGS+=--ghc-options $(RC_FILE)
else
SMUDGE_EXE=smudge
/=/
PKGEXT=tgz deb
DEBDIR=debian/$(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU)
endif
define cabal_query
$(shell grep "^$(1):" smudge.cabal | cut -d ':' -f 1 --complement | sed -e 's/^\s*//' -e 's/\s*$$//')
endef
PACKAGE=smudge
SMUDGE_BUILD_DIR_RAW=$(shell stack path --local-install-root)
SMUDGE_BUILD_DIR=$(subst \,/,$(SMUDGE_BUILD_DIR_RAW))
SMUDGE_RELEASE_SUBDIR=smudge
SMUDGE_RELEASE_STAGE_DIR=$(SMUDGE_BUILD_DIR)/$(SMUDGE_RELEASE_SUBDIR)
SMUDGE_TARGET=$(SMUDGE_BUILD_DIR)/bin/$(SMUDGE_EXE)
SMUDGE_VERSION=$(call cabal_query,version)
POUND=\\\#
COMMA=,
.PHONY: all tags build examples doc \
release stage package zip tgz exe deb \
newticket testticket todo clean distclean
all: build examples doc TAGS
tags: TAGS
echo ":ctags" | ghci -v0 `find . -iname \*\.hs | grep -v Setup.hs`
build: $(SMUDGE_TARGET) smudge
examples: build
$(MAKE) -C examples all
doc:
$(MAKE) -C docs$/tutorial tutorial.pdf
$(MAKE) -C docs$/definition all
smudge: $(SMUDGE_TARGET)
echo "#!/bin/sh" > smudge
echo "stack exec smudge -- \$$*" >> smudge
chmod +x smudge
$(SMUDGE_TARGET): smudge.cabal stack.yaml $(HSFILES) $(RC_FILE)
stack $(STACK_FLAGS) build $(CABAL_FLAGS)
$(RC_FILE):
@echo $(POUND)include \<winver.h\> > $(@:%.o=%.rc)
@echo VS_VERSION_INFO VERSIONINFO >> $(@:%.o=%.rc)
@echo FILEVERSION $(subst .,$(COMMA),$(SMUDGE_VERSION)) >> $(@:%.o=%.rc)
@echo PRODUCTVERSION $(subst .,$(COMMA),$(SMUDGE_VERSION)) >> $(@:%.o=%.rc)
@echo BEGIN >> $(@:%.o=%.rc)
@echo BLOCK \"StringFileInfo\" >> $(@:%.o=%.rc)
@echo BEGIN >> $(@:%.o=%.rc)
@echo BLOCK \"040904B0\" >> $(@:%.o=%.rc)
@echo BEGIN >> $(@:%.o=%.rc)
@echo VALUE \"FileVersion\", \"$(SMUDGE_VERSION)\" >> $(@:%.o=%.rc)
@echo VALUE \"ProductVersion\", \"$(SMUDGE_VERSION)\" >> $(@:%.o=%.rc)
@echo VALUE \"FileDescription\", \"Smudge\" >> $(@:%.o=%.rc)
@echo VALUE \"ProductName\", \"Smudge\" >> $(@:%.o=%.rc)
@echo VALUE \"InternalName\", \"Smudge\" >> $(@:%.o=%.rc)
@echo VALUE \"OriginalFilename\", \"$(SMUDGE_EXE)\" >> $(@:%.o=%.rc)
@echo VALUE \"LegalCopyright\", \"$(call cabal_query,copyright)\" >> $(@:%.o=%.rc)
@echo VALUE \"CompanyName\", \"$(call cabal_query,copyright)\" >> $(@:%.o=%.rc)
@echo VALUE \"License\", \"$(call cabal_query,license)\" >> $(@:%.o=%.rc)
@echo END >> $(@:%.o=%.rc)
@echo END >> $(@:%.o=%.rc)
@echo BLOCK \"VarFileInfo\" >> $(@:%.o=%.rc)
@echo BEGIN >> $(@:%.o=%.rc)
@echo VALUE \"Translation\", 0x0409, 0x04B0 >> $(@:%.o=%.rc)
@echo END >> $(@:%.o=%.rc)
@echo END >> $(@:%.o=%.rc)
windres -i $(@:%.o=%.rc) $@
manpage.in: README.md makeman.py
./makeman.py
docs/smudge.1: manpage.in build
help2man -o docs/smudge.1 --version-string=$(SMUDGE_VERSION) -N -s 1 -i manpage.in ./smudge
docs/tutorial/tutorial.pdf:
$(MAKE) -C docs$/tutorial tutorial.pdf
TAGS: $(HSFILES)
@if command -v hasktags >/dev/null 2>&1; then \
hasktags `find . -iname \*\.hs | grep -v Setup.hs`; \
fi
release:
@read -r -p "Is this release correctly versioned and tagged? [Yn] " REPLY; \
if [ "$$REPLY" = "n" ]; then echo "Well, do that, then!"; exit 1; fi
$(MAKE) package
stage: build docs/tutorial/tutorial.pdf
# Make sure it's a clean new release build.
rm -rf $(SMUDGE_RELEASE_STAGE_DIR)
mkdir -p $(SMUDGE_RELEASE_STAGE_DIR)
cp $(SMUDGE_TARGET) $(SMUDGE_RELEASE_STAGE_DIR)
$(MAKE) -C examples clean
cp -r examples $(SMUDGE_RELEASE_STAGE_DIR)
$(MAKE) -C docs$/tutorial docclean
cp -r docs/tutorial $(SMUDGE_RELEASE_STAGE_DIR)
cp CHANGES $(SMUDGE_RELEASE_STAGE_DIR)
cp LICENSE $(SMUDGE_RELEASE_STAGE_DIR)
cp README.md $(SMUDGE_RELEASE_STAGE_DIR)
package: $(foreach EXT,$(PKGEXT),$(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).$(EXT))
zip: $(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).zip
$(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).zip: stage
cd $(SMUDGE_BUILD_DIR) && \
if type zip >/dev/null 2>&1; then \
zip -r $@ $(SMUDGE_RELEASE_SUBDIR); \
elif type 7z >/dev/null 2>&1; then \
7z a $@ $(SMUDGE_RELEASE_SUBDIR); \
fi
mv $(SMUDGE_BUILD_DIR)/$@ .
$(SMUDGE_BUILD_DIR)/setup.iss: setup.iss.in smudge.cabal
@echo $(POUND)define MyAppName \"Smudge\" > $@
@echo $(POUND)define MyAppVersion \"$(SMUDGE_VERSION)\" >>$@
@echo $(POUND)define MyAppPublisher \"$(call cabal_query,copyright)\" >>$@
@echo $(POUND)define MyAppURL \"$(call cabal_query, location)\" >>$@
@echo $(POUND)define MyOutputDir \"$(SMUDGE_BUILD_DIR)\" >>$@
@echo $(POUND)define MySetupDir \"$(SMUDGE_RELEASE_STAGE_DIR)\" >>$@
@echo $(POUND)define MyOutputBase \"$(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU)\" >>$@
cat $< >>$@
exe: $(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).exe
$(PACKAGE)_$(SMUDGE_VERSION)-windows_$(TARGET_CPU).exe: $(SMUDGE_BUILD_DIR)/setup.iss stage
ISCC /Q $(SMUDGE_BUILD_DIR_RAW)\setup.iss
mv $(SMUDGE_BUILD_DIR)/$@ .
tgz: $(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).tgz
$(PACKAGE)_$(SMUDGE_VERSION)-linux_$(TARGET_CPU).tgz: stage docs/smudge.1
cp docs/smudge.1 $(SMUDGE_RELEASE_STAGE_DIR)
cd $(SMUDGE_BUILD_DIR) && \
fakeroot tar -czf $@ $(SMUDGE_RELEASE_SUBDIR)
mv $(SMUDGE_BUILD_DIR)/$@ .
deb: $(PACKAGE)_$(SMUDGE_VERSION)-$(TARGET_PLATFORM)_$(TARGET_CPU).deb
$(PACKAGE)_$(SMUDGE_VERSION)-linux_$(TARGET_CPU).deb: stage docs/smudge.1
mkdir -p $(DEBDIR)/DEBIAN
mkdir -p $(DEBDIR)/usr/bin
mkdir -p $(DEBDIR)/usr/share/doc/smudge/
mkdir -p $(DEBDIR)/usr/share/man/man1/
cp $(SMUDGE_BUILD_DIR)/smudge/smudge $(DEBDIR)/usr/bin
chrpath -d $(DEBDIR)/usr/bin/smudge
cp -r $(SMUDGE_BUILD_DIR)/$(SMUDGE_RELEASE_SUBDIR)/* $(DEBDIR)/usr/share/doc/smudge/
rm $(DEBDIR)/usr/share/doc/smudge/smudge # No need for extra binary
# Lintian wants the changelog to be called changelog.gz
mv $(DEBDIR)/usr/share/doc/smudge/CHANGES $(DEBDIR)/usr/share/doc/smudge/changelog
cp debian/changelog $(DEBDIR)/usr/share/doc/smudge/changelog.Debian
gzip --best -fn $(DEBDIR)/usr/share/doc/smudge/changelog.Debian
gzip --best -fn $(DEBDIR)/usr/share/doc/smudge/changelog
chmod -R a+rX $(DEBDIR)/usr/share/doc/smudge/*
cp docs/smudge.1 $(DEBDIR)/usr/share/man/man1/
gzip --best -fn $(DEBDIR)/usr/share/man/man1/smudge.1
# Note: the copyright file duplicates info from LICENSE.
cp debian/copyright $(DEBDIR)/usr/share/doc/smudge/
chmod 755 $(DEBDIR)/usr/bin/smudge
sed -e "s/__VERSION__/$(SMUDGE_VERSION)-linux/g" -e "s/__ARCH__/$(TARGET_CPU)/g" debian/control > $(DEBDIR)/DEBIAN/control
fakeroot dpkg --build $(DEBDIR)
mv $(DEBDIR).deb . # Whew, puns
newticket:
cd tickets && ./mkticket.sh "$(title)"
testticket:
@cd tickets && \
find -name $(TICKET) | xargs notangle > $(TICKET).smudge && \
stack exec smudge -- $(TICKET).smudge && \
rm $(TICKET).smudge
todo:
@find roadmap/$V | while read -r fn; do find -L tickets/ -xdev -samefile $$fn; done
clean:
stack clean
rm -rf TAGS tags
rm -f *.tgz *.deb
rm -rf $(DEBDIR)
$(MAKE) -C examples clean
$(MAKE) -C docs$/tutorial clean
$(MAKE) -C docs$/definition clean
rm -f smudge docs/smudge.1 manpage.in
distclean: clean
rm -rf .stack-work
rm -rf $(DEBDIR)