Stop writing Comment objects to g.cache
[reddit.git] / r2 / Makefile
blob91eb0aaf6ce46752a19ff2af7f3f285c18866bfa
1 # The contents of this file are subject to the Common Public Attribution
2 # License Version 1.0. (the "License"); you may not use this file except in
3 # compliance with the License. You may obtain a copy of the License at
4 # http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
5 # License Version 1.1, but Sections 14 and 15 have been added to cover use of
6 # software over a computer network and provide for limited attribution for the
7 # Original Developer. In addition, Exhibit A has been modified to be consistent
8 # with Exhibit B.
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
12 # the specific language governing rights and limitations under the License.
14 # The Original Code is reddit.
16 # The Original Developer is the Initial Developer. The Initial Developer of
17 # the Original Code is reddit Inc.
19 # All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
20 # Inc. All Rights Reserved.
21 ###############################################################################
23 SHELL=/bin/sh
24 PYTHON=python
25 SED=sed
26 CAT=cat
27 BUILD_DIR=build
29 .PHONY: clean
30 all: pyx static ini
31 clean: clean_pyx clean_i18n clean_static
33 DEFS_PY := Makefile.py
34 DEFS_FILE := Makefile.defs
35 .PHONY: $(DEFS_FILE)
36 $(shell $(PYTHON) $(DEFS_PY) > $(DEFS_FILE))
37 include $(DEFS_FILE)
38 ifdef DEFS_SUCCESS
39 $(info [+] including definitions from $(DEFS_PY))
40 else
41 $(error $(DEFS_PY) failed. aborting)
42 endif
44 #################### Generated code: Cython + Thrift
45 PYX_FILES := $(shell find . -name \*.pyx)
46 PYX_C_FILES := $(PYX_FILES:.pyx=.c)
47 PYX_SO_FILES := $(PYX_FILES:.pyx=.so)
49 .PHONY: pyx clean_pyx
51 pyx:
52 $(PYTHON) setup.py build
53 $(PYTHON) setup.py build_ext --inplace # copy the .so files from cython into the source tree
55 clean_pyx:
56 rm -f $(PYX_C_FILES) $(PYX_SO_FILES)
58 #################### i18n
59 STRINGS_FILE := r2/lib/generate_strings.py
60 GENERATED_STRINGS_FILE := r2/lib/generated_strings.py
62 .PHONY: i18n clean_i18n
64 # POTFILE is set by Makefile.py
65 i18n: $(GENERATED_STRINGS_FILE)
66 $(PYTHON) setup.py extract_messages --input-dirs=r2,$(PLUGIN_I18N_PATHS) -o $(POTFILE)
68 $(GENERATED_STRINGS_FILE): $(STRINGS_FILE)
69 $(PYTHON) $(STRINGS_FILE) > $(GENERATED_STRINGS_FILE)
71 clean_i18n:
72 rm -f $(GENERATED_STRINGS_FILE)
74 #################### ini files
75 UPDATE_FILES := $(wildcard *.update)
76 INIFILES := $(UPDATE_FILES:.update=.ini)
78 .PHONY: clean_ini
80 ini: $(INIFILES)
82 $(INIFILES): %.ini: %.update example.ini
83 ./updateini.py example.ini $< > $@ || rm $@
85 clean_ini:
86 rm $(INIFILES)
88 #################### CSS file lists
89 SPRITED_STYLESHEETS += reddit.less compact.css modtools.less
90 LESS_STYLESHEETS := wiki.less adminbar.less policies.less reddit-embed.less
91 OTHER_STYLESHEETS := mobile.css highlight.css
93 #################### Static Files
94 STATIC_ROOT := r2/public
95 STATIC_FILES := $(shell find $(STATIC_ROOT) -readable)
96 STATIC_BUILD_ROOT := $(BUILD_DIR)/public
97 STATIC_BUILD_DIR := $(STATIC_BUILD_ROOT)/static
98 STATIC_BUILDSTAMP := $(BUILD_DIR)/static-buildstamp
100 .PHONY: clean_static
102 static: plugin_static pyx css js names
104 clean_static:
105 rm -rf $(STATIC_BUILDSTAMP) $(STATIC_BUILD_DIR) $(PLUGIN_BUILDSTAMPS) $(MANGLE_BUILDSTAMP)
107 $(STATIC_BUILDSTAMP): $(STATIC_FILES)
108 cp -ruTL $(STATIC_ROOT) $(STATIC_BUILD_ROOT)
109 touch $@
111 #################### Plugin static files
112 PLUGIN_BUILDSTAMPS := $(foreach plugin,$(PLUGINS),$(BUILD_DIR)/plugin-$(plugin)-buildstamp)
114 plugin_static: $(PLUGIN_BUILDSTAMPS)
116 define PLUGIN_STATIC_TEMPLATE
117 $(BUILD_DIR)/plugin-$(1)-buildstamp: $(STATIC_BUILDSTAMP) $(shell find $(PLUGIN_PATH_$(1))/public)
118 if [ -f $(PLUGIN_PATH_$(1))/../Makefile ]; then \
119 $(MAKE) -C $(PLUGIN_PATH_$(1))/../ static; \
121 cp -r --preserve=timestamps $(PLUGIN_PATH_$(1))/public/* $(STATIC_BUILD_ROOT)/
122 touch $$@
124 $(info [+] adding make rules from plugin "$(1)")
125 -include $(PLUGIN_PATH_$(1))/../Makefile.plugin
126 endef
127 $(foreach plugin,$(PLUGINS),$(eval $(call PLUGIN_STATIC_TEMPLATE,$(plugin))))
129 #### Stylesheets
130 LESSC := lessc
131 CSS_COMPRESS := $(PYTHON) r2/lib/contrib/rcssmin.py
132 CSS_SOURCE_DIR := $(STATIC_BUILD_DIR)/css
134 PROCESSED_SPRITED_STYLESHEETS := $(addprefix $(STATIC_BUILD_DIR)/, $(SPRITED_STYLESHEETS:.less=.css))
135 SPRITES := $(addprefix $(STATIC_BUILD_DIR)/, $(patsubst %.css,sprite-%.png, $(SPRITED_STYLESHEETS:.less=.css)))
137 LESS_OUTPUTS := $(addprefix $(STATIC_BUILD_DIR)/, $(patsubst %.less,%.css, $(LESS_STYLESHEETS)))
139 MINIFIED_OTHER_STYLESHEETS := $(addprefix $(STATIC_BUILD_DIR)/, $(OTHER_STYLESHEETS))
141 PROCESSED_STYLESHEETS := $(PROCESSED_SPRITED_STYLESHEETS) $(MINIFIED_OTHER_STYLESHEETS) $(LESS_OUTPUTS)
143 CSS_OUTPUTS = $(PROCESSED_STYLESHEETS) $(SPRITES)
145 .PHONY: clean_css
147 css: $(STATIC_BUILDSTAMP) $(CSS_OUTPUTS)
150 # the LESSC invocation is separated so the recipe fails in case of LESS errors.
151 $(LESS_OUTPUTS): $(STATIC_BUILD_DIR)/%.css : $(CSS_SOURCE_DIR)/%.less
152 rm -f $@
153 $(LESSC) $< > $@.tmp
154 $(CSS_COMPRESS) < $@.tmp > $@
155 rm $@.tmp
157 $(MINIFIED_OTHER_STYLESHEETS): $(STATIC_BUILD_DIR)/%.css: $(CSS_SOURCE_DIR)/%.css
158 # when static file names are mangled, the original becomes a symlink to the mangled name
159 # remove the original file here in case it's a symlink so we don't just rewrite the old file
160 rm -f $@
161 $(CAT) $< | $(CSS_COMPRESS) > $@
163 $(STATIC_BUILD_DIR)/sprite-%.png $(STATIC_BUILD_DIR)/%.css: $(CSS_SOURCE_DIR)/%.less $(STATIC_BUILDSTAMP)
164 # see above
165 rm -f $(STATIC_BUILD_DIR)/sprite-$*.png $(STATIC_BUILD_DIR)/$*.css
166 $(PYTHON) r2/lib/nymph.py $(CSS_SOURCE_DIR)/$*.less $(STATIC_BUILD_DIR)/sprite-$*.png > $(CSS_SOURCE_DIR)/$*.less.tmp
167 $(LESSC) $(CSS_SOURCE_DIR)/$*.less.tmp > $(STATIC_BUILD_DIR)/$*.css.tmp
168 $(CSS_COMPRESS) < $(STATIC_BUILD_DIR)/$*.css.tmp > $(STATIC_BUILD_DIR)/$*.css
169 rm $(CSS_SOURCE_DIR)/$*.less.tmp $(STATIC_BUILD_DIR)/$*.css.tmp
171 # deprecated; remove once compact.scss has been converted to LESS
172 $(STATIC_BUILD_DIR)/sprite-%.png $(STATIC_BUILD_DIR)/%.css: $(CSS_SOURCE_DIR)/%.css $(STATIC_BUILDSTAMP)
173 # see above
174 rm -f $(STATIC_BUILD_DIR)/sprite-$*.png $(STATIC_BUILD_DIR)/$*.css
175 $(PYTHON) r2/lib/nymph.py $< $(STATIC_BUILD_DIR)/sprite-$*.png | $(CSS_COMPRESS) > $(STATIC_BUILD_DIR)/$*.css
177 clean_css:
178 rm -f $(CSS_OUTPUTS)
180 #### JS
182 .PHONY: clean_js
184 js: $(STATIC_BUILDSTAMP) $(JS_OUTPUTS)
186 define JS_MODULE_TEMPLATE
187 $(JS_MODULE_OUTPUTS_$(1)): $(JS_MODULE_DEPS_$(1)) r2/lib/js.py
188 # remove mangled output symlinks, similar to above.
189 rm -f $(JS_MODULE_OUTPUTS_$(1))
190 $(PYTHON) r2/lib/js.py build_module "$(1)"
191 touch $$@
192 endef
194 # apply the module template to each of the modules
195 # so they source their deps from js.py and build accordingly
196 $(foreach module,$(JS_MODULES),$(eval $(call JS_MODULE_TEMPLATE,$(module))))
198 clean_js:
199 rm -f $(STATIC_BUILD_DIR)/*.js
201 #### name mangling
202 MANGLEABLE_FILES := $(CSS_OUTPUTS) $(JS_OUTPUTS)
203 MANGLE_BUILDSTAMP := $(BUILD_DIR)/mangle-buildstamp
204 NAMES_FILE := $(STATIC_BUILD_DIR)/names.json
205 MANGLED_FILES := $(wildcard $(foreach file,$(MANGLEABLE_FILES),$(basename $(file)).*$(suffix $(file))))
207 .PHONY: clean_names
209 names: $(MANGLE_BUILDSTAMP)
211 $(MANGLE_BUILDSTAMP): $(MANGLEABLE_FILES)
212 $(PYTHON) r2/lib/static.py $(NAMES_FILE) $(MANGLEABLE_FILES)
213 touch $@
215 clean_names:
216 rm -f $(MANGLE_BUILDSTAMP) $(NAMES_FILE) $(MANGLEABLE_FILES) $(MANGLED_FILES)
218 $(shell rm -f $(DEFS_FILE))