-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (66 loc) · 2.25 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
# Makefile
SWIFT_RESOURCE_SCRIPT = ./rsrc2swift.sh
PACKAGE_NAME=jQuery
jQuery_RESOURCE_FILES = \
$(wildcard Upstream/*.min.js)
all : package-as-swift
swift build
clean :
swift package clean
rm -f Sources/$(PACKAGE_NAME)/ResourceMap.swift \
Sources/$(PACKAGE_NAME)/Resources.swift
distclean : clean
rm -rf .build Package.resolved
package-dir : Makefile
mkdir -p Sources/$(PACKAGE_NAME)
package-as-swift : Sources/$(PACKAGE_NAME)/ResourceMap.swift \
Sources/$(PACKAGE_NAME)/Resources.swift
Sources/$(PACKAGE_NAME)/Resources.swift: $($(PACKAGE_NAME)_RESOURCE_FILES) Makefile package-dir
@echo "// Generated on `date`" > $@
@echo "//" >> $@
@echo "" >> $@
@echo "import struct Foundation.Data" >> $@
@echo >> $@
@echo "public enum $(PACKAGE_NAME) {" >> $@
@for file in $($(PACKAGE_NAME)_RESOURCE_FILES); do \
tfile=$$(mktemp /tmp/foo.XXXXXXXXX); \
$(SWIFT_RESOURCE_SCRIPT) $$file $$tfile; \
cat $$tfile >> $@; \
rm $$tfile; \
done
@echo "}" >> $@
Sources/$(PACKAGE_NAME)/ResourceMap.swift: $($(PACKAGE_NAME)_RESOURCE_FILES) Makefile package-dir
@echo "// Generated on `date`" > $@
@echo "//" >> $@
@echo >> $@
@echo "import struct Foundation.Data" >> $@
@echo >> $@
@echo "public extension $(PACKAGE_NAME) {" >> $@
@echo >> $@
@echo " /**" >> $@
@echo " * Lookup a $(PACKAGE_NAME) resource. The returned Data" >> $@
@echo " * contains the gzip compressed resource." >> $@
@echo " *" >> $@
@echo " * Available resource names:" >> $@
@echo " *" >> $@
@for file in $($(PACKAGE_NAME)_RESOURCE_FILES); do \
origname="`echo $$file | sed 's|Upstream/||'`"; \
nicename="`basename $$file | sed 's/\\./_/g' | sed 's/\\-/_/g'`"; \
echo " * - \"$${origname}\"" >> $@; \
done
@echo " *" >> $@
@echo " */" >> $@
@echo " static func resourceNamed(_ name: String) -> Data? {" >> $@
@echo " switch name {" >> $@
@echo >> $@;
@for file in $($(PACKAGE_NAME)_RESOURCE_FILES); do \
origname="`echo $$file | sed 's|Upstream/||'`"; \
nicename="`basename $$file | sed 's/\\./_/g' | sed 's/\\-/_/g'`"; \
echo " case \"$${origname}\":" >> $@; \
echo " return data_$${nicename}" >> $@; \
echo >> $@; \
done
@echo " default: return nil" >> $@
@echo " }" >> $@
@echo " }" >> $@
@echo "}" >> $@