aboutsummaryrefslogtreecommitdiff
path: root/contexts/build.mk
blob: 0e55997eadede33e9c20abb09f0b39f3b9404399 (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
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

# Source Info ##################################################################

# source and resources
data-dir := $(path)/data

# fiveui source directory
fiveui-dir := $(data-dir)/fiveui

lib-dir := $(data-dir)/lib

# packaged extension directory
bin-dir  := $(data-dir)/target


# Extension Staging ############################################################
#
# The purpose of this step is to setup all the compiled scripts necessary for
# both plugins in a common tree.  From this state, we can pick and choose what
# goes into each extension.

stage-dir  := $(build-dir)/stage
target-dir := $(stage-dir)/data/target

define stage-files-from
$(stage-dir)/$1/$2: | $(stage-dir)/$1
	$$(call cmd,mkdir)

$(stage-dir)/$1/$2/%: $(path)/$1/$2/% | $(stage-dir)/$1/$2
	$$(call cmd,cp)
endef

$(eval $(call stage-files-from,data/fiveui,images))
$(eval $(call stage-files-from,data/fiveui,chrome))
$(eval $(call stage-files-from,data/fiveui,injected))
$(eval $(call stage-files-from,data/lib,codemirror))
$(eval $(call stage-files-from,data/lib,jquery))
$(eval $(call stage-files-from,data/lib,jshash))



$(eval $(call stage-files-from,data/fiveui/firefox,test))
$(eval $(call stage-files-from,data/fiveui,firefox))

$(eval $(call stage-files-from,data,fiveui))
$(eval $(call stage-files-from,data,lib))


$(target-dir): | $(stage-dir)/data
	$(call cmd,mkdir)

$(stage-dir)/data: | $(stage-dir)
	$(call cmd,mkdir)

$(stage-dir): | $(build-dir)
	$(call cmd,mkdir)


stage-path = $(patsubst $(path)/%,$(stage-dir)/%,$1)
stage-all  = $(call stage-path,$(wildcard $(path)/$1/*))


# Javascript "Compilation" #####################################################
#
# In order to turn a number of different javascript modules into a single one,
# we just concatenate them all together.  This should be fine, as all of the
# modules we define just provide functions, or register callbacks.

quiet_cmd_compilejs = JSC        $(call drop-prefix,$@)
      cmd_compilejs = cat $^ > $@

# generic background script dependencies
background-deps :=                \
  $(addprefix $(fiveui-dir)/,     \
    set.js                        \
    background.js                 \
    url-pat.js                    \
    settings.js                   \
    messenger.js                  \
    state.js                      \
    rules.js)

# generic options page dependencies
options-deps := $(addprefix $(fiveui-dir)/,\
  settings.js \
  chan.js \
  messenger.js \
  options.js \
  update-manager.js \
  utils.js \
  entry.js \
  rules.js \
  url-pat.js )


# CSS Staging ##################################################################

css-bundle := $(topdir)/tools/bin/css-bundle.py

quiet_cmd_cssbundle = CSSC       $(call drop-prefix,$@)
      cmd_cssbundle = ( cd $(dir $(TARGET)) && \
                        $(css-bundle) $(notdir $(TARGET)) $@ $(redir) )

$(stage-dir)/data/target/bundled.css: TARGET := $(lib-dir)/jquery/css/ui-lightness/jquery-ui.css
$(stage-dir)/data/target/bundled.css:                                      \
    $(wildcard $(lib-dir)/jquery/css/ui-lightness/*.css)        \
    $(wildcard $(lib-dir)/jquery/css/ui-lightness/images/*.png) \
  | $(stage-dir)/data
	$(call cmd,cssbundle)

$(stage-dir)/data/target/injected.css: TARGET := $(fiveui-dir)/injected/injected.css
$(stage-dir)/data/target/injected.css:       \
    $(fiveui-dir)/injected/injected.css      \
    $(fiveui-dir)/images/errorCircle.png     \
    $(fiveui-dir)/images/warningTriangle.png \
    $(fiveui-dir)/images/right-arrow.png     \
    $(fiveui-dir)/images/down-arrow.png      \
  | $(stage-dir)/data/target
	$(call cmd,cssbundle)



# Both Extensions ##############################################################

jquery := $(addprefix $(path)/data/lib/jquery/,\
	jquery-1.8.3.js           \
	jquery-ui-1.9.2.custom.js)

$(stage-dir)/data/underscore.js: $(lib-dir)/underscore.js
	$(call cmd,cp)

$(stage-dir)/data/backbone.js: $(lib-dir)/backbone.js
	$(call cmd,cp)

all: $(stage-dir)/data/fiveui/options.html                         \
     $(stage-dir)/data/fiveui/options.css                          \
     $(stage-dir)/data/fiveui/entry.css                            \
     $(stage-dir)/data/fiveui/ffcheck.js                           \
     $(stage-dir)/data/target/injected.css                         \
     $(stage-dir)/data/target/bundled.css                          \
     $(call stage-all,data/fiveui/images)                          \
     $(call stage-all,data/lib/codemirror)                         \
     $(call stage-path,$(jquery))                                  \
     $(call stage-all,data/lib/jshash)                             \
     $(stage-dir)/data/fiveui/injected/prelude.js                  \
     $(stage-dir)/data/fiveui/injected/jquery-plugins.js           \
     $(stage-dir)/data/fiveui/injected/fiveui-injected-compute.js  \
     $(stage-dir)/data/fiveui/injected/fiveui-injected-ui.js       \
     $(stage-dir)/data/underscore.js                               \
     $(stage-dir)/data/backbone.js

# Chrome Extension #############################################################
#
# Use the staged artifacts to build the chrome extension in contexts/fiveui.crx

chrome-dir := $(path)/chrome

all: $(topdir)/fiveui.crx

clean::
	$(RM) $(topdir)/fiveui.crx

$(topdir)/fiveui.crx: $(build-dir)/fiveui.crx
	$(call cmd,cp)

# Create the chrome extension
$(build-dir)/fiveui.crx:                                        \
  $(target-dir)/chrome-background.js                            \
  $(target-dir)/chrome-options.js                               \
  $(stage-dir)/manifest.json                                    \
  $(stage-dir)/data/fiveui/chrome/background.html               \
  $(stage-dir)/data/fiveui/chrome/chrome-port.js                \
  $(stage-dir)/data/fiveui/chrome/chrome-injected-compute.js    \
  $(stage-dir)/data/fiveui/chrome/chrome-injected-ui.js
	$(call label,MAKECRX    $(call drop-prefix,$@)) ( cd $(build-dir)   \
	&& $(topdir)/tools/bin/makecrx stage                                \
	       $(topdir)/contexts/chrome/fiveui.pem fiveui                  \
	   $(redir) )


# install the extension manifest in the stage directory
$(stage-dir)/manifest.json: $(path)/manifest.json | $(stage-dir)
	$(call cmd,cp)

chrome-src := $(fiveui-dir)/chrome

# the chrome-specific background javascript
$(target-dir)/chrome-background.js: $(background-deps)           \
                                    $(chrome-src)/background.js  \
                                    $(chrome-src)/chrome-port.js \
                                  | $(target-dir)
	$(call cmd,compilejs)


# the chrome-specific options javascript
$(target-dir)/chrome-options.js: $(options-deps)                 \
                                 $(chrome-src)/ajax.js           \
                                 $(chrome-src)/chrome-options.js \
                               | $(target-dir)
	$(call cmd,compilejs)


# Firefox Compilation ##########################################################

firefox-dir := $(fiveui-dir)/firefox

addon-sdk := $(topdir)/tools/addon-sdk

all: $(topdir)/fiveui.xpi

clean::
	$(RM) $(topdir)/fiveui.xpi

$(topdir)/fiveui.xpi: $(build-dir)/fiveui.xpi
	$(call cmd,cp)


# wrapper for setting up the environment for the running the cfx command
cfx = ( cd $(addon-sdk) $(redir) && \
        . bin/activate  $(redir) && \
        cd $1           $(redir) && \
        cfx $2          $(redir) )

run-firefox: $(build-dir)/fiveui.xpi
	$(call cfx,$(stage-dir),run)

test-firefox: $(build-dir)/fiveui.xpi                    \
              $(stage-dir)/data/fiveui/firefox/test      \
              $(call stage-all,data/fiveui/firefox/test) \
            | $(topdir)/profiles/firefox
	$(call cfx,$(stage-dir),test -v -p $(topdir)/profiles/firefox)

# build the actual extension
$(build-dir)/fiveui.xpi:                                                       \
    $(stage-dir)/package.json                                                  \
    $(target-dir)/firefox-main.js                                              \
    $(target-dir)/firefox-options.js                                           \
    $(call stage-path,$(path)/data/fiveui/firefox/firefox-injected-compute.js) \
    $(call stage-path,$(path)/data/fiveui/firefox/firefox-injected-ui.js)      \
    $(call stage-path,$(path)/data/fiveui/firefox/icon-content.html)           \
    $(call stage-path,$(path)/data/fiveui/firefox/icon-script.js)              \
    $(call stage-path,$(path)/data/fiveui/firefox/options-icon.html)           \
    $(call stage-path,$(path)/data/fiveui/firefox/options-script.js)           \
    $(call stage-path,$(path)/data/fiveui/firefox/firefox-options.js)          \
  | $(topdir)/profiles/firefox
	$(call label,XPI        $(call drop-prefix,$@))\
	  $(call cfx,$(build-dir),xpi -p $(topdir)/profiles/firefox \
	                 --pkgdir=$(stage-dir) )

# stage the package description
$(stage-dir)/package.json: $(path)/package.json | $(stage-dir)
	$(call cmd,cp)

# build the main script
$(target-dir)/firefox-main.js:       \
    $(firefox-dir)/main.js           \
    $(firefox-dir)/storage.js        \
    $(firefox-dir)/tabIds.js         \
    $(firefox-dir)/ajax.js           \
    $(fiveui-dir)/settings.js        \
    $(fiveui-dir)/messenger.js       \
    $(fiveui-dir)/rules.js           \
    $(fiveui-dir)/background.js      \
    $(fiveui-dir)/utils.js           \
    $(fiveui-dir)/set.js             \
    $(fiveui-dir)/state.js           \
    $(fiveui-dir)/url-pat.js         \
  | $(target-dir)
	$(call cmd,compilejs)


# the chrome-specific options javascript
$(target-dir)/firefox-options.js:        \
    $(lib-dir)/jquery/jquery-1.8.3.js    \
    $(lib-dir)/underscore.js             \
    $(lib-dir)/backbone.js               \
    $(options-deps)                      \
    $(firefox-dir)/firefox-options.js    \
  | $(target-dir)
	$(call cmd,compilejs)