summaryrefslogtreecommitdiff
path: root/Makefile
blob: 6bf337b0c81b4703be04a92997d75146ebd8d4c6 (plain)
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
SCSS = scss
CORDOVA = cordova
GSED = sed
WGET = wget -c --no-use-server-timestamp

pdfjs = https://github.com/mozilla/pdf.js/releases/download/v1.4.20/pdfjs-1.4.20-dist.zip
frc_safety_manual = http://www.firstinspires.org/sites/default/files/uploads/resource_library/frc/team-resources/safety/2016/frc-team-safety-manual.pdf

platforms = android browser

sources = \
	www/FIRST_Safety_Manual.pdf \
	www/pdfjs \
	www/css/index.css \
	www/MSDS.html

browser-targets = platforms/browser/build/package.zip

android-targets = platforms/android/build/outputs/apk/android-debug.apk

android-resources = \
	platforms/android/res/drawable/icon.png \
	platforms/android/res/drawable-ldpi/icon.png \
	platforms/android/res/drawable-mdpi/icon.png \
	platforms/android/res/drawable-hdpi/icon.png \
	platforms/android/res/drawable-xhdpi/icon.png \
	\
	platforms/android/res/drawable-land-ldpi/screen.png \
	platforms/android/res/drawable-land-mdpi/screen.png \
	platforms/android/res/drawable-land-hdpi/screen.png \
	platforms/android/res/drawable-land-xhdpi/screen.png \
	\
	platforms/android/res/drawable-port-ldpi/screen.png \
	platforms/android/res/drawable-port-mdpi/screen.png \
	platforms/android/res/drawable-port-hdpi/screen.png \
	platforms/android/res/drawable-port-xhdpi/screen.png

targets = $(foreach platform,$(platforms),$($(platform)-targets))
resources = $(foreach platform,$(platforms),$($(platform)-resources))

all: build

sources: PHONY $(sources)
resources: PHONY $(resources)
build: $(targets)

clean-sources: PHONY
	rm -rf -- www/pdfjs
	rm -f -- $(sources)
clean-resources: PHONY
	rm -f -- $(resources)
clean: PHONY clean-sources clean-resources
	rm -f -- info.txt www/css/*.map pdfjs-*.zip hs_err_pid*.log
distclean: PHONY clean
	rm -rf -- platforms plugins

$(foreach platform,$(platforms),\
          $(eval clean-$(platform)-resources: PHONY; rm -f -- $$($(platform)-resources)) \
          $(eval $(platform)-resources: PHONY $$($(platform)-resources)) \
          $(eval build-$(platform): PHONY $$($(platform)-targets)))

upload: PHONY build
	git push
	rsync -rv --delete -e ssh platforms/browser/www/ lukeshu@lukeshu.com:/srv/frc/app/web
	rsync -v -e ssh platforms/android/build/outputs/apk/android-debug.apk lukeshu@lukeshu.com:/srv/frc/app/releases/SafetyApp-latest.apk


DEP_DIR = $1 $(shell find $1)

platforms/browser/build/package.zip: platforms/browser config.xml $(sources) $(call DEP_DIR,www)
	rm -f -- $@
	$(CORDOVA) build browser
	test -f $@

platforms/android/build/outputs/apk/android-debug.apk: platforms/android config.xml $(sources) $(call DEP_DIR,www)
	rm -f -- $@
	$(CORDOVA) build android
	test -f $@

platforms/%:
	$(CORDOVA) platform add $*

www/FIRST_Safety_Manual.pdf:
	$(WGET) -O $@ $(frc_safety_manual)

$(notdir $(pdfjs)):
	$(WGET) $(pdfjs)

www/pdfjs: $(notdir $(pdfjs))
	rm -rf -- $@
	mkdir -- $@ && bsdtar -xf $(abspath $<) -C $@ --exclude '*.pdf' || rm -rf -- $@

www/MSDS.html: www/MSDS.html.in www/MSDS Makefile
	ls www/MSDS | $(GSED) 'p;s/_/ /g' | $(GSED) -r 'N;s,^(.*)\n(.*)\.pdf,<a href="pdfjs/web/viewer.html?file=../../MSDS/\1">\2</a>,' | $(GSED) $$'/@list@/{ s/@list@//; r/dev/stdin\n}' www/MSDS.html.in > $@


platforms/android/res/drawable/icon.png: www/img/logo.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 96x96 $@
platforms/android/res/drawable-ldpi/icon.png: www/img/logo.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 36x36 $@
platforms/android/res/drawable-mdpi/icon.png: www/img/logo.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 48x48 $@
platforms/android/res/drawable-hdpi/icon.png: www/img/logo.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 72x72 $@
platforms/android/res/drawable-xhdpi/icon.png: www/img/logo.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 96x96 $@

platforms/android/res/drawable-land-ldpi/screen.png: www/img/screen-landscape.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 320x200 $@
platforms/android/res/drawable-land-mdpi/screen.png: www/img/screen-landscape.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 480x320 $@
platforms/android/res/drawable-land-hdpi/screen.png: www/img/screen-landscape.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 800x480 $@
platforms/android/res/drawable-land-xhdpi/screen.png: www/img/screen-landscape.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 1280x720 $@

platforms/android/res/drawable-port-ldpi/screen.png: www/img/screen-portrait.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 200x320 $@
platforms/android/res/drawable-port-mdpi/screen.png: www/img/screen-portrait.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 320x480 $@
platforms/android/res/drawable-port-hdpi/screen.png: www/img/screen-portrait.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 480x800 $@
platforms/android/res/drawable-port-xhdpi/screen.png: www/img/screen-portrait.png | platforms/android
	mkdir -p $(@D)
	convert $< -resize 720x1280 $@


%.css: %.scss
	$(SCSS) $< $@


.PHONY: PHONY FORCE
.DELETE_ON_ERROR:
.SECONDARY: