aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile58
1 files changed, 37 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 068f872..d214a85 100644
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,47 @@
-SLUG ?= $(shell git rev-parse --short HEAD)
-LDFLAGS := "-X 'git.gabrielgio.me/cerrado/templates.Slug=.$(SLUG)' -s -w"
+GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
+LDFLAGS := "-X 'git.gabrielgio.me/cerrado/templates.Slug=.$(GIT_COMMIT)' -s -w"
+GO_SRC := $(shell find . -name '*.go')
-build: sass-slug tmpl
- go build \
- -ldflags=$(LDFLAGS) \
- -o bin/cerrado
+BIN ?= cerrado
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+
+TEMPLATES_DIR := templates
+TEMPLATES := $(wildcard $(TEMPLATES_DIR)/*.qtpl)
+GO_TEMPLATES_FILES := $(TEMPLATES:.qtpl=.qtpl.go)
+
+SASS_DIR := scss
+CSS_DIR := static
+OUTPUT_CSS := $(CSS_DIR)/main.$(GIT_COMMIT).css
+SASS_FILES := $(wildcard $(SASS_DIR)/*.scss)
+
+build: $(BIN)
+
+$(BIN): $(GO_SRC) $(OUTPUT_CSS) $(GO_TEMPLATES_FILES)
+ go build -ldflags=$(LDFLAGS) -o $(BIN)
+
+install:
+ install -Dm755 $(BIN) $(BINDIR)/$(BIN)
run: sass tmpl
- go run .
+ go run -ldflags=$(LDFLAGS) .
test:
go test -v --tags=unit ./...
-# this is meant for "prod" build
-sass-slug:
- mkdir -p static
- sassc \
- --style compressed \
- -I scss scss/main.scss static/main.$(SLUG).css
+sass: $(OUTPUT_CSS)
+
+$(OUTPUT_CSS): $(SASS_FILES)
+ @mkdir -p $(CSS_DIR)
+ sassc --style compressed $(SASS_DIR)/main.scss $(OUTPUT_CSS)
+
+tmpl: $(GO_TEMPLATES_FILES)
-sass:
- mkdir -p static
- sassc \
- -I scss scss/main.scss static/main.css
+$(TEMPLATES_DIR)/%.qtpl.go: $(TEMPLATES_DIR)/%.qtpl
+ qtc $(TEMPLATES_DIR)/$*.qtpl
-tmpl:
- cd ./templates && \
- qtc *
+clean:
+ -rm $(OUTPUT_CSS)
+ -rm $(BIN)
-.PHONY: sass
+.PHONY: sass tmpl