ENV ?= dev
OS := $(shell uname)

ifneq (,$(findstring Ubuntu, $(shell uname -v)))
composer = $(shell which composer.phar)
endif
composer ?= ./composer.phar

.PHONY: all clean test assets init config
.IGNORE: all

all: | $(composer)
	@$(composer) self-update
	@$(composer) update
	@patch -p0 -Nls -i wrep.patch --no-backup-if-mismatch

init:
	@php app/check.php | grep ERROR || true
	@app/console doctrine:database:create --env=${ENV}
	@app/console doctrine:schema:update --force --env=${ENV}
	@app/console doctrine:schema:validate --env=${ENV}

config:
	git config user.name $(shell whoami)
	git config user.email rick1125@gmail.com
	git config pull.default simple
	git config push.default current

$(composer):
	@echo -n "Downloading composer.phar ... "
	@curl -s http://getcomposer.org/installer | php > /dev/null 2>&1
	@echo "OK"

assets:
	@app/console assets:install --symlink --env=${ENV}
	@app/console assetic:dump --env=${ENV}

test:
	phpunit -c app

clean:
	app/console cache:clear --env=${ENV}
remove wrep patch, seems like they fixed this bug, we don't need this patch anymore