-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
120 lines (95 loc) · 3.09 KB
/
makefile
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
107
108
109
110
111
112
113
114
115
116
117
118
########################################
# Informations
########################################
NOW := $(shell date +"%Y-%m-%dT%H:%M:%S%z")
VERSION ?= $(shell cat ./VERSION)
HS_A := sha1
HS_T := $(shell which sha1sum || which shasum)
I_ST := init
U_ST := update
########################################
# Outputs
########################################
OUTDIR := ./dist
FUNCTION_FILE := $(OUTDIR)/init_fct.sql
I_FL := $(OUTDIR)/$(I_ST)-$(VERSION).sql
I_HS := $(I_FL).$(HS_A)
U_FL := $(OUTDIR)/$(U_ST)-$(VERSION).sql
U_HS := $(U_FL).$(HS_A)
########################################
# Inputs
########################################
COREDIR := ./core
pre_init := $(COREDIR)/_pre_init.sql
init := \
$(COREDIR)/ddl/create_tables.sql \
$(COREDIR)/ddl/initial_data.sql
init_views := \
$(COREDIR)/ddl/create_mat_views.sql \
$(COREDIR)/ddl/create_views.sql
fixs := $(shell find -L $(COREDIR)/fixs/current -name '*.sql' | sort)
funcs_drop := $(COREDIR)/funcs/_pre_drop.sql
funcs := $(shell find $(COREDIR)/funcs -name '*.sql' | grep -v '_pre_drop.sql' | sort)
########################################
# Build
########################################
clean:
@echo "Cleaning $(OUTDIR)"
@rm -fr $(OUTDIR)
@echo "Cleaning $(COREDIR)/init.sql"
@rm -fr $(COREDIR)/init.sql
@echo "Cleaning $(COREDIR)/update.sql"
@rm -fr $(COREDIR)/update.sql
@echo "Cleaning docker unused"
@docker system prune -a
.PHONY: clean
$(I_HS): $(init) $(funcs_drop) $(funcs) $(init_views)
@mkdir -p $(OUTDIR)
@echo "[$(I_ST)] Generating hash: $(HS_A)"
@cat $^ | $(HS_T) | cut -f1 -d ' ' > $(I_HS)
$(I_FL): $(I_HS) $(pre_init) $(init) $(funcs_drop) $(funcs) $(init_views)
ifeq ("$(VERSION)", "")
@echo "Build failed, no valid version provided!"
else
@mkdir -p $(OUTDIR)
$(eval $@_hash=$(shell cat $(I_HS)))
@sed -e "s/{{VERSION}}/$(VERSION)/g" \
-e "s/{{SCRIPT_TYPE}}/$(I_ST)/g" \
-e "s/{{SCRIPT_HASH}}/$($@_hash)/g" \
-e "s/{{NOW}}/$(NOW)/g" $(pre_init) $(init) $(funcs_drop) $(funcs) $(init_views) > $(I_FL)
@echo "[$(I_ST)] Builded at $(NOW) ($(HS_A) hash: $($@_hash))"
@echo "[$(I_ST)] Generated file: $(I_FL) (Version: $(VERSION))"
endif
init: $(I_FL)
.PHONY: init
$(U_HS): $(fixs) $(funcs_drop) $(funcs)
@mkdir -p $(OUTDIR)
@echo "[$(U_ST)] Generating hash: $(HS_A)"
@cat $^ | $(HS_T) | cut -f1 -d ' ' > $(U_HS)
$(U_FL): $(U_HS) $(fixs) $(funcs_drop) $(funcs)
ifeq ("$(VERSION)", "")
@echo "Build failed, no valid version provided!"
else
@mkdir -p $(OUTDIR)
$(eval $@_hash=$(shell cat $(U_HS)))
@sed -e "s/{{VERSION}}/$(VERSION)/g" \
-e "s/{{SCRIPT_TYPE}}/$(U_ST)/g" \
-e "s/{{SCRIPT_HASH}}/$($@_hash)/g" \
-e "s/{{NOW}}/$(NOW)/g" $(fixs) $(funcs_drop) $(funcs) > $(U_FL)
@echo "[$(U_ST)] Builded at $(NOW) ($(HS_A) hash: $($@_hash))"
@echo "[$(U_ST)] Generated file: $(U_FL) (Version: $(VERSION))"
endif
update: $(U_FL)
.PHONY: update
### Funcs file only ###
funcs: $(funcs_drop) $(funcs)
@mkdir -p $(OUTDIR)
@echo "Generate funcs file only: $(FUNCTION_FILE)"
@cat $^ > $(FUNCTION_FILE)
.PHONY: funcs
build:
@make clean
@make init
@cp dist/init-beta-1.0.0.sql core/init.sql
@docker compose up
.PHONY: build