Makefile 8.24 KB
Newer Older
1 2 3 4
# Tools

PHPMD ?= phpmd
NPM ?= npm
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
MSGFMT ?= msgfmt
PHP ?= php
JAVA ?= java

# Variables

APACHECONF = kopano-webapp.conf
DESTDIR ?= deploy

# Javascript compiler

JSDEPLOY = $(DESTDIR)/client

JSCOMPILER ?= $(JAVA) -jar tools/lib/compiler.jar

JSOPTIONS = --externs client/externs.js \
21
	--compilation_level SIMPLE --warning_level VERBOSE --jscomp_off=es5Strict --strict_mode_input=false \
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
	--jscomp_off=globalThis --jscomp_off=misplacedTypeAnnotation --jscomp_off=nonStandardJsDocs \
	--jscomp_off=missingProperties --jscomp_off=invalidCasts --jscomp_off=checkTypes \
	--jscomp_warning=visibility --jscomp_warning=unknownDefines --jscomp_warning=undefinedVars \
	--jscomp_warning=strictModuleDepCheck --jscomp_warning=fileoverviewTags --jscomp_warning=deprecated \
	--jscomp_error=checkVars --jscomp_warning=checkRegExp --jscomp_warning=accessControls

# Server files

APACHECONFDEST = $(addprefix $(DESTDIR)/, $(APACHECONF))
DISTFILES = $(addprefix $(DESTDIR)/,config.php.dist debug.php.dist)
ROBOTS = $(addprefix $(DESTDIR)/, robots.txt)
HTACCESS = $(addprefix $(DESTDIR)/, .htaccess)
LANGTXT = $(wildcard server/language/*/language.txt)
LANGTXTDEST = $(addprefix $(DESTDIR)/, $(LANGTXT))
POS = $(wildcard server/language/*/LC_MESSAGES/zarafa_webapp.po)
MOS = $(patsubst %.po,$(DESTDIR)/%.mo,$(POS))
INCLUDES = $(shell find server/includes -name '*.php')
PHPFILES = $(filter-out $(DESTDIR)/config.php, $(filter-out $(DESTDIR)/debug.php, $(patsubst %.php,$(DESTDIR)/%.php,$(wildcard *.php) $(INCLUDES))))
SERVERROOTFILES = $(addprefix $(DESTDIR)/,server/.htaccess server/manifest.dtd)

# Client files

44
CSS = $(wildcard client/resources/css/*.* client/resources/css/*/*.* client/extjs/ux/css/ux-all.css client/extjs/resources/css/*.css)
45 46 47 48 49
CSSDEST = $(addprefix $(DESTDIR)/, $(CSS))
IMAGEDIR = client/resources/images
APPICONS = $(wildcard $(IMAGEDIR)/app-icons/*.*)
APPICONSSCSS = client/resources/scss/base/_icons.scss
APPICONSEXTENSIONSFILE = client/resources/images/app-icons.extensions.json
50 51
IMAGES = $(filter-out $(APPICONSEXTENSIONSFILE), $(wildcard $(IMAGEDIR)/*.* $(IMAGEDIR)/whatsnew/*.*))
IMAGESDEST = $(addprefix $(DESTDIR)/, $(IMAGES))
52 53 54 55 56 57 58 59
EXTJSMODFILES = $(wildcard client/extjs-mod/*.js)
ICONEXTENSIONSFILE = client/resources/iconsets/extensions.json
ICONSETS = $(notdir $(filter-out client/resources/iconsets/extensions.json, $(wildcard client/resources/iconsets/*)))
ICONS = $(foreach iconsetdir,$(ICONSETS),$(wildcard client/resources/iconsets/$(iconsetdir)/src/png/*/*.png))
ICONSETSDEST = $(addprefix $(DESTDIR)/client/resources/iconsets/, $(ICONSETS))
ICONSETSCSS = $(foreach iconsetdir,$(ICONSETS),client/resources/iconsets/$(iconsetdir)/$(iconsetdir)-icons.css)
ICONSETSCSSDEST = $(addprefix $(DESTDIR)/, $(ICONSETSCSS))
EXTJS = client/extjs/ext-base.js client/extjs/ext-all.js
60
THIRDPARTY = $(shell find client/third-party -name '*.js') client/third-party/tokenizr/tokenizr.js
61 62

POFILES = $(wildcard server/language/*/*/*.po)
63
JSFILES = $(shell find client/zarafa -name '*.js')
64 65 66

# Build

67
.PHONY: deploy server client all
68

69 70 71
all: deploy

deploy: server client plugins
72 73 74 75

build: node_modules deploy
test: jstest

76 77
server: $(MOS) $(LANGTXTDEST) $(PHPFILES) $(DESTDIR)/$(APACHECONF) $(DISTFILES) $(ROBOTS) $(HTACCESS) $(DESTDIR)/version $(SERVERROOTFILES)

78
client: $(CSSDEST) $(ICONSETSDEST) $(IMAGESDEST) js
79 80 81
	cp -r client/resources/fonts $(DESTDIR)/client/resources/
	cp -r client/zarafa/core/themes $(DESTDIR)/client/
	rm -rf $(DESTDIR)/client/themes/*/js
82
	cp -r client/resources/scss $(DESTDIR)/client/resources/scss
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
	# TODO use separate targets

js: $(JSDEPLOY)/fingerprint.js $(JSDEPLOY)/resize.js $(TEMPATEJSDEST) $(JSDEPLOY)/kopano.js $(JSDEPLOY)/extjs-mod/extjs-mod.js $(JSDEPLOY)/extjs/ext-base-all.js $(DESTDIR)/client/third-party/ux-thirdparty.js
	cp -r client/tinymce $(DESTDIR)/client/
	cp -r client/tinymce-languages $(DESTDIR)/client/
	cp -r client/tinymce-plugins $(DESTDIR)/client/
	cp -r client/extjs $(DESTDIR)/client/
	rm $(DESTDIR)/client/extjs/ext-base.js
	rm $(DESTDIR)/client/extjs/ext-all.js
	rm $(DESTDIR)/client/extjs/resources/css/reset-min.css
	rm $(DESTDIR)/client/extjs/resources/css/xtheme-blue.css
	# TODO use separate targets

$(DESTDIR)/%.php: %.php
	php -l $<
	mkdir -p $$(dirname $@)
	cp $< $@

$(APACHECONFDEST): $(APACHECONF)
	cp $< $@

$(ROBOTS): robots.txt
	cp $< $@

$(HTACCESS): .htaccess
	cp $< $@

$(DESTDIR)/%.mo : %.po
	mkdir -p $$(dirname $@)
	$(MSGFMT) -v -o $@ $<

$(DESTDIR)/%: %
	mkdir -p $$(dirname $@)
	cp $< $@

$(DESTDIR)/version: version
	cp $< $@

$(DESTDIR)/client/extjs/ext-base-all.js: $(EXTJS)
	cat $+ > $@

$(JSDEPLOY)/fingerprint.js: client/fingerprint.js
	mkdir -p $(JSDEPLOY)
	cat client/fingerprint.js > $(JSDEPLOY)/fingerprint-debug.js
	$(JSCOMPILER) --js $< --js_output_file $@ $(JSOPTIONS)

$(JSDEPLOY)/kopano.js: $(JSFILES)
	$(PHP) tools/loadorder.php kopano $(@:.js=-debug.js)
	$(JSCOMPILER) --js $(@:.js=-debug.js) --js_output_file $@ \
		--source_map_location_mapping=$(JSDEPLOY)/\| \
		--output_wrapper="%output%//# sourceMappingURL=$(shell basename $@.map)" \
		--create_source_map $@.map \
		$(JSOPTIONS)

$(JSDEPLOY)/extjs-mod/extjs-mod.js: $(EXTJSMODFILES)
	mkdir -p $(JSDEPLOY)/extjs-mod
	$(PHP) tools/loadorder.php extjs $(@:.js=-debug.js)
	$(JSCOMPILER) --js $(@:.js=-debug.js) --js_output_file $@ \
		--source_map_location_mapping=$(JSDEPLOY)/extjs-mod/\| \
		--output_wrapper="%output%//# sourceMappingURL=$(shell basename $@.map)" \
		--create_source_map $@.map $(JSOPTIONS)

$(JSDEPLOY)/resize.js: client/resize.js
	mkdir -p $(JSDEPLOY)
	cat client/resize.js > $(JSDEPLOY)/resize-debug.js
	$(JSCOMPILER) --js $(@:.js=-debug.js) --js_output_file $@

150
$(JSDEPLOY)/third-party/ux-thirdparty.js: $(THIRDPARTY)
151
	mkdir -p $(JSDEPLOY)/third-party
152
	# concatenate using cat
153 154 155 156 157 158
	cat $^ > $(@:.js=-debug.js)
	$(JSCOMPILER) --js $(@:.js=-debug.js) --js_output_file $@ \
		--source_map_location_mapping=$(JSDEPLOY)/\| \
		--output_wrapper="%output%//# sourceMappingURL=$(shell basename $@.map)" \
		--create_source_map $@.map \
		$(JSOPTIONS) --jscomp_off=checkVars
159 160 161 162 163

$(JSDEPLOY)/third-party/TinyMceTextArea-debug.js: client/third-party/tinymce/TinyMceTextArea.js
	mkdir -p $(JSDEPLOY)/third-party
	cp $< $@
	$(JSCOMPILER) --js $< --js_output_file $@
164 165 166 167 168

config:
	cp $(DESTDIR)/config.php.dist $(DESTDIR)/config.php

# Test
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

.PHONY: lint
lint: vendor
	$(NPM) run lint -- --cache

.PHONY: lintci
lintci: vendor
	$(NPM) run lint -- --quiet -f junit -o eslint.xml client/zarafa/ || true

.PHONY: jstest
jstest: build
	$(NPM) run jsunit

.PHONY: jstestci
jstestci: build
	$(NPM) run jsunit -- --reporters junit

.PHONY: jstestcov
jstestcov: build
	$(NPM) run jsunit -- --reporters coverage

open-coverage: jstestcov
	${BROWSER} test/js/coverage/report-html/index.html

.PHONY: phplint
phplint:
	$(PHPMD) server text .phpmd.xml

.PHONY: phplintcli
phplintci:
	$(PHPMD) server xml .phpmd.xml --ignore-violations-on-exit | python tools/violations_to_junit.py > phpmd.xml

# NPM

.PHONY: vendor
vendor: node_modules

node_modules:
	$(NPM) install

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
# Icons

.SECONDEXPANSION:
$(ICONSETSDEST): $$(subst deploy/,,$$@)/iconset.json $$@/$$(notdir $$@)-icons.css
	mkdir -p $@
	cp $< $@

$(ICONSETSCSSDEST): $$(subst deploy/,,$$@)
	mkdir -p $(@D)
	cp $< $@

.PHONY: iconsets
iconsets: $(ICONS) node_modules
	$(NPM) run iconsets

# This rule should not be enabled until our build server supports nodejs.
# Just create the iconsets locally by running `npm run iconsets` whenever
# something has changed.
#$(ICONSETSCSS): $$(@D)/src/png/*/*.png $(ICONEXTENSIONSFILE) node_modules
#	$(NPM) run iconsets:$(notdir $(@D))

# this rule creates the file client/resources/scss/base/_icons.scss
# since the scss files are not compiled during the build (yet),
# this rule can only be used locally for now.
.PHONY: app-icons
app-icons: $(APPICONSSCSS)

$(APPICONSSCSS): $(APPICONS) $(APPICONSEXTENSIONSFILE) node_modules
	$(NPM) run app-icons

239 240 241 242 243 244 245 246 247 248 249 250
# Tokenizr library

# This rule should not be enabled until our build server supports nodejs.
# Just build the tokenizr library locally by running `make tokenizr` whenever
# something has changed. (i.e. the tokenizr lib has been updated)
#client/third-party/tokenizr/tokenizr.js: tokenizr
#	$(NPM) run build:tokenizr

.PHONY: tokenizr
tokenizr: node_modules
	$(NPM) run build:tokenizr

251 252 253 254 255 256
# Plugins

.PHONY: plugins
plugins:
	make -C plugins

257 258
.PHONY: clean
clean:
259
	make -C plugins clean
260 261
	@rm -rf deploy
	@rm -rf node_modules
262 263

print-%  :
264
	@echo $* = $($*)