forked from Sigmapitech/glados
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (77 loc) · 2.33 KB
/
Makefile
File metadata and controls
106 lines (77 loc) · 2.33 KB
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
97
98
99
100
101
102
103
104
105
106
.PHONY: all
all: glados
SELF := $(firstword $(MAKEFILE_LIST))
glados: .build/mk.cli\:cli
cp $(shell cabal -v0 list-bin exe:cli) $@
chmod +x $@
@ $(LOG_TIME) "Build $(C_CYAN)$(notdir $@)$(C_RESET)"
define mk-target
_name_$(strip $1) := $(subst \:library,,$(subst +,\:,$(strip $1)))
.PHONY: $$(_name_$(strip $1))
.build/mk.$$(_name_$(strip $1)): $$(shell git ls-files | grep ".*hs")
$$(call cabal-cmd-$($(strip $1)), $$(_name_$(strip $1)))
@ $$(LOG_TIME) "$$(C_CYAN)$$(_name_$(strip $1))$$(C_RESET)"
@ touch $$@
$$(_name_$(strip $1)): .build/mk.$$(_name_$(strip $1))
endef
cabal-cmd-lib = cabal build $(strip $1)
cabal-cmd-exe = cabal build $(strip $1)
cabal-cmd-test = cabal test $(strip $1)
ifneq ($(MAKECMDGOALS),fclean)
CABAL-EXTRACT := $(shell cabal -v0 list-bin exe:cabal-extract --dry-run)
all-targets +=
-include .build/types.mk
# $(foreach target, $(all-targets), \
$(info $(call mk-target, $(target))))
$(eval $(foreach target, $(all-targets), \
$(eval $(call mk-target, $(target)))))
endif
.build/types.mk: .build/layout.json $(SELF)
@ mkdir -p $(dir $@)
@ jq -r '.[] | "\(.name)=\(.type)"' .build/layout.json | tr ':' '+' > $@
@ grep -Po "^(.*)(?=[=])" $@ \
| xargs -i echo "all-targets += {}" >> $@
@ $(LOG_TIME) "Generated $(C_PURPLE)$@$(C_RESET)"
.build/layout.json: $(CABAL-EXTRACT)
@ mkdir -p $(dir $@)
@ cabal run cabal-extract -- . > $@
$(CABAL-EXTRACT): cabal-extract
@ cabal build cabal-extract
@ $(LOG_TIME) "Build $(C_CYAN)$(notdir $@)$(C_RESET)"
.PHONY: tests_run
tests_run:
@ cabal test all
.PHONY: clean
clean:
@ $(RM) .build/mk.*
.PHONY: fclean
fclean: clean
@ cabal clean
.NOTPARALLEL: re
.PHONY: re
re: fclean all
ifneq ($(shell command -v tput),)
ifneq ($(shell tput colors),0)
mk-color = \e[$(strip $1)m
C_BEGIN := \033[A
C_RESET := $(call mk-color, 00)
C_RED := $(call mk-color, 31)
C_GREEN := $(call mk-color, 32)
C_YELLOW := $(call mk-color, 33)
C_BLUE := $(call mk-color, 34)
C_PURPLE := $(call mk-color, 35)
C_CYAN := $(call mk-color, 36)
endif
endif
NOW = $(shell date +%s%3N)
STIME := $(shell date +%s%3N)
export STIME
define TIME_MS
$$( expr \( $$(date +%s%3N) - $(STIME) \))
endef
BOXIFY = "[$(C_BLUE)$(1)$(C_RESET)] $(2)"
ifneq ($(shell command -v printf),)
LOG_TIME = printf $(call BOXIFY, %6s , %b\n) "$(call TIME_MS)"
else
LOG_TIME = echo -e $(call BOXIFY, $(call TIME_MS) ,)
endif