summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 18591d5894a012ded2dee6bef47594341c9e7ef4 (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
# This file is licensed under the Affero General Public License version 3 or
# later. See the COPYING file.
# @author Bernhard Posselt <dev@bernhard-posselt.com>
# @copyright Bernhard Posselt 2012, 2014

# Generic Makefile for building and packaging an ownCloud app
#
# Dependencies:
# * make
# * curl: if phpunit and composer are not installed to fetch the files from the web
# * tar: for building the archive
# * npm: for building and testing everything JS

app_name=$(notdir $(CURDIR))
build_directory=$(CURDIR)/build/artifacts/source
package_name=$(build_directory)/$(app_name)
npm=$(shell which npm)

all: build

# Fetches the PHP and JS dependencies and compiles the JS
.PHONY: build
build:
	make composer
	make npm

# Installs and updates the composer dependencies. If composer is not installed
# a copy is fetched from the web
.PHONY: composer
composer:
ifeq (, $(shell which composer 2> /dev/null))
	@echo "No composer command available, downloading a copy from the web"
	curl -sS https://getcomposer.org/installer | php
	php composer.phar install --prefer-dist
	php composer.phar update --prefer-dist
	rm -f composer.phar
else
	composer install --prefer-dist
	composer update --prefer-dist
endif

# Installs npm dependencies
.PHONY: npm
npm:
ifeq (,$(wildcard $(CURDIR)/package.json))
	cd js && $(npm) run build
else
	npm run build
endif

# Removes the appstore build
.PHONY: clean
clean:
	rm -rf ./build

# Same as clean but also removes dependencies installed by composer, bower and
# npm
.PHONY: distclean
distclean: clean
	rm -rf vendor
	rm -rf js/vendor
	rm -rf js/node_modules

# Builds the package for the app store
.PHONY: dist
dist:
	make clean
	make build
	make test
	mkdir -p $(build_directory)
	tar cvzf $(package_name).tar.gz ../$(app_name) \
	--exclude-vcs \
	--exclude=../$(app_name)/build \
	--exclude=../$(app_name)/js/node_modules \


# Command for running JS and PHP tests. Works for package.json files in the js/
# and root directory. If phpunit is not installed systemwide, a copy is fetched
# from the internet
.PHONY: test
test:
ifeq (,$(wildcard $(CURDIR)/package.json))
	cd js && $(npm) run test
else
	npm run test
endif
ifeq (, $(shell which phpunit 2> /dev/null))
	@echo "No phpunit command available, downloading a copy from the web"
	curl -sSOL https://phar.phpunit.de/phpunit.phar
	php phpunit.phar -c phpunit.xml
	php phpunit.phar -c phpunit.integration.xml
	rm -f phpunit.phar
else
	phpunit -c phpunit.xml
	phpunit -c phpunit.integration.xml
endif