summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorhorus_arch2015-03-19 13:39:37 +0100
committerhorus_arch2015-03-19 13:39:37 +0100
commitf334c93c0364d14a2b55641b155ad58f715a4b39 (patch)
tree63ffbfc845f441802bd59c07adf2d9fe2f86c4bc /Makefile
parent3c9bdbc66998075278f7d79fa10709e7fab5deb6 (diff)
downloadfreemail-f334c93c0364d14a2b55641b155ad58f715a4b39.tar.gz
Rewriting from scratch.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile133
1 files changed, 133 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4e92af6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,133 @@
+# Modify env.sh and uncomment to change config.
+include env.sh
+
+# Start the race detector with "TEST_RACE=1 make test" on the command line.
+ifdef TEST_RACE
+ RACE:=-race
+else
+ RACE:=
+endif
+
+# To be verbose while testing use TEST_VERBOSE=1.
+ifdef TEST_VERBOSE
+ VERBOSE:=-v
+else
+ VERBOSE:=
+endif
+
+IMPORT_FILE:=./import.go
+APP:=mailer
+
+# Include the sqlit3 database in archiv.
+ifeq ($(FREEMAIL_DB_DRIVER), sqlite3)
+ FREEMAIL_DB_DIR:=db
+else
+ FREEMAIL_DB_DIR:=
+endif
+
+# Start targets
+all: kill build run
+
+clean: kill
+ @(rm $(IMPORT_FILE) 2>/dev/null && echo "Removing import file..." ) || true
+ @(rm $(FREEMAIL_DB_CREDENTIALS) 2>/dev/null echo && "Removing sqlite3 database..." ) || true
+# @(rm ../$(APP).tar.gz 1>&2 2>/dev/null && echo "Removing tar archiv...") || true
+ @(rm _env.sh 1>&2 2>/dev/null && echo "Removing _env.sh...") || true
+ @(rm $(APP) 2>/dev/null && echo "Removing binary ($(APP))...") || true
+# @(rm ../start.sh 1>&2 2>/dev/null && echo "Removing startup script...") || true
+ @echo "Done."
+
+build: import
+ go build -o $(APP)
+
+run: _test_build
+ ./$(APP) &
+
+kill:
+ @echo "Killing running instances..."
+ @pkill $(APP) || true
+
+create_import:
+ @if [ ! -f $(IMPORT_FILE) ] ; \
+ then \
+ echo "package main" > $(IMPORT_FILE) ; \
+ fi
+
+import:
+ @if [ ! -f $(IMPORT_FILE) ] ; \
+ then \
+ echo "package main" > $(IMPORT_FILE) ; \
+ echo "import _ \"$(FREEMAIL_DB_IMPORT_DRIVER)\"" >> $(IMPORT_FILE) ; \
+ fi
+
+sqlite3: create_import
+ @echo "import _ \"github.com/mattn/go-sqlite3\"" >> $(IMPORT_FILE)
+
+mysql: create_import
+ @echo "import _ \"github.com/go-sql-driver/mysql\"" >> $(IMPORT_FILE)
+
+postgresql: create_import
+ @echo "import _ \"github.com/lib/pq\"" >> $(IMPORT_FILE)
+
+database_all: sqlite3 mysql postgresql
+ @echo "Created import file for all databases."
+
+pack: gen_config
+ @cd .. && \
+ echo "#!/bin/sh" > start.sh && \
+ echo "cd app && . ./_env.sh && ./$(APP)" >> start.sh && \
+ chmod +x start.sh && \
+ tar czf $(APP).tar.gz start.sh app/$(APP) app/_env.sh views static $(FREEMAIL_DB_DIR) 2>/dev/null && \
+ rm start.sh 2>/dev/null && \
+ echo "\n../$(APP).tar.gz is ready." || \
+ (echo "Run \"make build\" first." && exit 1)
+
+test: import
+ FREEMAIL_DB_CREDENTIALS=":memory:" go test $(RACE) $(VERBOSE) #-tags general
+ make clean
+
+test_all: import
+ FREEMAIL_DB_CREDENTIALS=":memory:" go test $(RACE) $(VERBOSE) -v -tags all
+
+test_dependencies: import
+ FREEMAIL_DB_CREDENTIALS=":memory:" go test $(RACE) $(VERBOSE) -tags dep
+
+benchmark:
+ FREEMAIL_DB_CREDENTIALS=":memory:" go test $(VERBOSE) -bench=".*" -tags general
+
+benchmark_dependencies: import
+ export DB_FREEMAIL_LOG=false
+ FREEMAIL_DB_CREDENTIALS=":memory:" go test $(VERBOSE) -bench=".*" -tags dep
+
+_test_build:
+ @if [ ! -f ./$(APP) ] || [ ! -x ./$(APP) ]; then \
+ echo "No executable binary found." 1>&2; \
+ echo "Run \"make build\" first." 1>&2; \
+ echo ""; \
+ exit 1; \
+ fi
+
+gen_config: _test_build
+ @echo "Generating config file!\n"
+ echo "#!/bin/sh" > _env.sh
+ @echo "# Database" >> _env.sh
+ echo "export FREEMAIL_DB_DRIVER=$(FREEMAIL_DB_DRIVER)" >> _env.sh
+ echo "export FREEMAIL_DB_CREDENTIALS=$(FREEMAIL_DB_CREDENTIALS)" >> _env.sh
+ echo "export FREEMAIL_DB_IMPORT_DRIVER=$(FREEMAIL_DB_IMPORT_DRIVER)" >> _env.sh
+ echo "export FREEMAIL_DB_LOG=$(FREEMAIL_DB_LOG)\n" >> _env.sh
+ @echo ""
+ @echo "# Redis" >> _env.sh
+ echo "export FREEMAIL_REDIS_SERVER=$(FREEMAIL_REDIS_SERVER)" >> _env.sh
+ echo "export FREEMAIL_REDIS_PORT=$(FREEMAIL_REDIS_PORT)\n" >> _env.sh
+ @echo ""
+ @echo "# Http" >> _env.sh
+ echo "export FREEMAIL_HTTP_IP=$(FREEMAIL_HTTP_IP)" >> _env.sh
+ echo "export FREEMAIL_HTTP_PORT=$(FREEMAIL_HTTP_PORT)" >> _env.sh
+ @echo ""
+ echo "export FREEMAIL_SECRET=$(FREEMAIL_SECRET)" >> _env.sh
+ @echo ""
+ @echo "# Smtp" >> _env.sh
+ echo "export FREEMAIL_SMTP_MAILER=$(FREEMAIL_SMTP_MAILER)" >> _env.sh
+ echo "export FREEMAIL_SMTP_PASSWORD=$(FREEMAIL_SMTP_PASSWORD)" >> _env.sh
+ echo "export FREEMAIL_SMTP_ADRESS=$(FREEMAIL_SMTP_ADRESS)" >> _env.sh
+ @chmod +x _env.sh