aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 9206ed24a8d3001eb0a9c14c23d7f86fe2d4c398 (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
include config.mk

BINARY_PATH=./bin
APP_NAME=grilist
IMPORTER_FILES = $(shell find tools/importer/ -type f -name '*.go')

CSS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/css/ -type f -name '*.css'))
LESS_FILES = $(patsubst assets_src/%.less, assets/%.css, $(shell find assets_src/css/ -type f -name '*.less'))
JS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/js/ -maxdepth 1 -type f -name '*.js'))
DEPFILES = $(patsubst assets/%, assets_src/%, $(JS_FILES:.js=.d))

BROWSERIFY := ./node_modules/browserify/bin/cmd.js
LESSC := ./node_modules/less/bin/lessc

-include $(DEPFILES)

all: assets app

print_info:
	@echo $(CSS_FILES)
	@echo $(LESS_FILES)
	@echo $(JS_FILES)
	@echo $(DEPFILES)

app:
	go build -o $(BINARY_PATH)/$(APP_NAME)

.npm_update: package.json
	touch $@
	npm install

package.json: package.json.tpl config.mk
	export NAME=$(NAME) &&\
	export VERSION=$(VERSION) &&\
	$(BINARY_PATH)/template.awk < $< | sh > $@

assets: $(CSS_FILES) $(LESS_FILES) $(JS_FILES)

assets/css/%.css: assets_src/css/%.css
	@mkdir -p $(@D)
	cp $< $@

assets/css/%.css: assets_src/css/%.less .npm_update
	mkdir -p $(@D)
	@echo lessc $< > $@
	@$(LESSC) $< > $@

assets_src/js/%.d: assets_src/js/%.js
	@$(BINARY_PATH)/generate-dependencies $(patsubst assets_src/%, assets/%, $<) $< $@

assets/js/%.js: assets_src/js/%.js assets_src/js/%.d .babelrc .npm_update
	@echo browserify $< -o $@
	@$(BROWSERIFY) --debug $< -o $@ -t babelify

clean:
	-rm -- $(BINARY_PATH)/$(APP_NAME)
	-rm -- $(CSS_FILES)
	-rm -- $(LESS_FILES)
	-rm -- $(JS_FILES)
	-rm -- $(DEPFILES)
	-rm -- importer

superclean: clean
	-rm -- .npm_update
	-rm -- package.json

ultraclean: superclean
	-rm -r -- node_modules

run: assets
	go run *.go

importer: $(IMPORTER_FILES)
	go build -o importer tools/importer/*.go

.PHONY: all assets app print_info clean superclean ultraclean run