-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
177 lines (130 loc) · 6.11 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
## ------------------------------------------------------------------------ ##
$(shell set -x)
# Since we rely on paths relative to the makefile location,
# abort if make isn't being run from there.
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
THIS_FILE := $(lastword $(MAKEFILE_LIST))
## ------------------------------------------------------------------------ ##
## Build Project ##
## ------------------------------------------------------------------------ ##
## Suppress display of executed commands
$(VERBOSE).SILENT:
.EXPORT_ALL_VARIABLES:
.IGNORE:
.ONESHELL:
## ======================================================================== ##
# Set environment variables for the build
## ======================================================================== ##
# The shell in which to execute make rules
SHELL = /bin/bash
# The CMake executable
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters
EQUALS = =
# The top-level source directory on which CMake was run
# CMAKE_SOURCE_DIR = /opt/git/tobbot/bin/td
# The top-level build directory on which CMake was run
# CMAKE_BINARY_DIR = /opt/git/tobbot/bin/td/build
## ======================================================================== ##
# $(shell [ -f ./NODE_ENV ] || cp -prv config/.NODE_ENV "./";) ;
$(shell if [ ! -f ./.env ] 2>/dev/null; then cp -prv src/.env ./ ; fi;)
$(shell if [ ! -f ./.bowerrc ] 2>/dev/null; then cp -prv config/.bowerrc ./ ; fi;)
## ------------------------------------------------------------------------ ##
APP_NAME := cmdb-rtm
APP_SLOG := "CMDB - RTM"
APP_LOGO := ./assets/BANNER
APP_REPO := $(shell git ls-remote --get-url)
GIT_COMMIT := $(shell git rev-list --remove-empty --remotes --max-count=1 --date-order --reverse)
CODE_VERSION := $(shell cat ./VERSION)
DT = $(shell date +'%Y%m%d%H%M%S')
WD := $(shell pwd -P)
BD := $(WD)/bin
## ------------------------------------------------------------------------ ##
include $(BD)/Colors
## ------------------------------------------------------------------------ ##
## Shorthands
## ------------------------------------------------------------------------ ##
ARGS = $(shell echo '$@' | tr [:upper:] [:lower:])
STG = $(shell echo '$@' | tr [:lower:] [:upper:])
DAT = [${Gray}$(DT)${NC}]
BEGIN = $(Yellow)$(On_Blue)BEGIN$(NC) TARGET
RESULT = $(White)$(On_Purple)RESULT$(NC)
DONE = $(Cyan)$(On_Green)DONE$(NC) TARGET
FINE = $(Yellow)$(On_Green)FINISHED GOAL$(NC)
TARG = [$(Orange) $@ $(NC)]
THIS = [$(Red) $(THIS_FILE) $(NC)]
OKAY = [$(White) OK $(NC)]
## ------------------------------------------------------------------------ ##
## ENVIRONMENT ##
## ------------------------------------------------------------------------ ##
APP_ENV := $(shell grep NODE_ENV ./.env | cut -d "=" -f 2)
ifeq ($(APP_ENV),)
$(info $(DAT) $(Orange)APP_ENV$(NC) is $(Yellow)$(On_Red)NOT DETECTED$(NC)!)
endif
## ------------------------------------------------------------------------ ##
## COMMIT information
## ------------------------------------------------------------------------ ##
$(file > COMMIT,$(GIT_COMMIT));
$(info $(DAT) Created file [$(Yellow)COMMIT$(NC):$(Gray)$(GIT_COMMIT)$(NC)]);
## ------------------------------------------------------------------------ ##
## PATHS ##
## ------------------------------------------------------------------------ ##
DIR_SRC := $(WD)/src
DIR_BUILD := $(WD)/build-${CODE_VERSION}
DIR_DIST := $(WD)/dist-${CODE_VERSION}
DIR_COMMIT := $(GIT_COMMIT)
DIR_WEB := $(WD)/web
APP_DIRS := $(addprefix ${WD}/,build-* dist-* web)
## ------------------------------------------------------------------------ ##
## Query the default goal
## ------------------------------------------------------------------------ ##
ifeq ($(.DEFAULT_GOAL),)
.DEFAULT_GOAL := _default
endif
$(info $(DAT) $(Yellow)$(On_Purple)GOALS$(NC));
$(info $(DAT) \-- $(Orange)DEFAULT$(NC): [$(White)$(.DEFAULT_GOAL)$(NC)]);
$(info $(DAT) \-- $(Orange)CURRENT$(NC): [$(Blue)$(MAKECMDGOALS)$(NC)]);
## ------------------------------------------------------------------------ ##
## INCLUDES ##
## ------------------------------------------------------------------------ ##
include $(BD)/*.mk
## ------------------------------------------------------------------------ ##
## SET DEFAULT GOAL ##
## ------------------------------------------------------------------------ ##
PHONY := _default
_default: all ;
## ------------------------------------------------------------------------ ##
PHONY += test
test: banner state help banner ;
@ NODE_ENV=${APP_ENV}; npm run test
## ------------------------------------------------------------------------ ##
PHONY += setup build deploy
setup: ;
@ npm i --verbose
@ bower i --verbose
build: banner ;
@ NODE_ENV=${APP_ENV} ;
deploy: banner ;
@ cp -prvf ${DIR_SRC}/* ${DIR_SRC}/.env ./ \
&& sudo chmod a+x app/bin/*.sh ;
## ------------------------------------------------------------------------ ##
# .PHONY: rebuild redeploy
PHONY += rebuild redeploy
rebuild: build ;
redeploy: rebuild deploy ;
## ------------------------------------------------------------------------ ##
# .PHONY: all full cycle dev
PHONY += all full cycle dev
#* means the word "all" doesn't represent a file name in this Makefile;
#* means the Makefile has nothing to do with a file called "all" in the same directory.
all: banner clean rights cycle ;
full: clean-all all ;
cycle: setup build deploy ;
dev: redeploy banner ;
## ------------------------------------------------------------------------ ##
## Declare the contents of the .PHONY variable as phony. We keep that
## information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
## ------------------------------------------------------------------------ ##