-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
171 lines (141 loc) · 4.18 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
CONFIGMK= config.mk
include ${CONFIGMK}
COMMON_DIR?=/home/zsolt/progs/wpwmm4/
INCLUDE_DIR?=include/
FLAG_DIR?=flags/
HOOK_PRE_HTML?=${MSG1} Building ${.TARGET}
HOOK_POST_HTML?=
HOOK_PRE_VHTML?=${MSG1} Building virtual ${.TARGET}
HOOK_POST_VHTML?=
M4_DEFINITIONS=00_defines.m4
FLAG_MKDIR=create-dirs
# If there are unset we're using default values
M4?=m4
M4_FLAGS?=-P -I ${COMMON_DIR} -I ${INCLUDE_DIR} \
-D_SRC_DIR=${SRC_DIR} -D_LAYOUT_DIR=${LAYOUT_DIR}
CAT?=cat
MKDIR=@mkdir -p
MSG=@echo "==>"
MSG1=@echo " ==>"
MSG2=@echo " ==>"
ASSETS_CP?= @cp -r
ASSETS_DEST_DIR?= ${DEST_DIR}
INCL=${CAT} ${COMMON_DIR}${M4_DEFINITIONS}
# Working Targets
# Prepend the ${DEST_DIR}
TARGETS?=
WTARGETS:=${TARGETS:S,^,${DEST_DIR},}
# Working Manual Targets
# Prepend the ${DEST_DIR}
TARGETS_MANUAL?=
WMTARGETS:=${TARGETS_MANUAL:S,^,${DEST_DIR},}
# Target directories
# Remove the filenames
TDIR=${WTARGETS:H:u}
.for CATEG in ${VIRTUALS}
TDIR+=${DEST_DIR}${VIRTUALDIR_${CATEG}}
TDIR:=${TDIR}
.endfor
all: ${FLAG_DIR}${FLAG_MKDIR} assets ${WTARGETS} ${WMTARGETS} virtual
${FLAG_DIR}${FLAG_MKDIR}: ${CONFIGMK} ${MKDIR_REQ}
${MSG} "Creating directory structure... (flagfile: ${.TARGET})"
@${MKDIR} ${FLAG_DIR}
@${MKDIR} ${TDIR:u}
@echo ${TDIR:u} | tr ' ' '\n' | sort > ${FLAG_DIR}${FLAG_MKDIR}
create-dirs: ${FLAG_DIR}${FLAG_MKDIR}
# Create files using ${SRC_DIR}/*.m4 in ${DEST_DIR}/*.html
# Pass the directory of source file to m4 as `_DIRECTORY' and
# the created filename without path and extension as `_FILE'.
.for T in ${TARGETS}
CT:=${DEST_DIR}${T}
DEP:=${GREQ} ${T:S/^/${SRC_DIR}/:S/html$/m4/} ${${T}_REQ}
REQUIREMENT_${CT}:=${DEP}
ALLTARGET+=${CT}
ALLTARGET:=${ALLTARGET}
${CT}: ${CONFIGMK} ${DEP}
${HOOK_PRE_HTML}
@${INCL} ${.TARGET:S/${DEST_DIR}/${SRC_DIR}/:R}.m4 | \
${M4} ${M4_FLAGS} \
-D_DIRECTORY=${.TARGET:S/${DEST_DIR}//:H} \
-D_FILE=${.TARGET:S/${DEST_DIR}//:R} \
> ${.TARGET}
${HOOK_POST_HTML}
.endfor
# Looping all ${VIRTUALS}
.for CATEG in ${VIRTUALS}
.ifndef VIRTUALOUT_${CATEG}
.error VIRTUALOUT_${CATEG} variable is not defined!
.endif
VIRTUAL_FILES+=${VIRTUALOUT_${CATEG}:S/^/${DEST_DIR}${VIRTUALDIR_${CATEG}}/}
VIRTUAL_FILES:=${VIRTUAL_FILES}
VIRTUALREQRULE_${CATEG}?=C,.*,,
# Create files from ${VIRTUALS} using ${VIRT_DIR}/*.m4
# Pass the directory as `_DIRECTORY' and create filename
# without extension as `_FILE'
.for VOUT in ${VIRTUALOUT_${CATEG}}
CT:=${DEST_DIR}${VIRTUALDIR_${CATEG}}${VOUT}
DEP:=${GREQ} \
${VIRT_DIR}${VIRTUALTEMPLATE_${CATEG}}.m4 \
${VIRTUALREQ_${CATEG}} \
${VOUT:${VIRTUALREQRULE_${CATEG}}} \
${${VIRTUALDIR_${CATEG}}${VOUT}_REQ}
REQUIREMENT_${CT}:=${DEP}
ALLTARGET+=${CT}
ALLTARGET:=${ALLTARGET}
${CT}: ${CONFIGMK} ${DEP}
${HOOK_PRE_VHTML}
${MKDIR} ${VIRTUALOUT_${CATEG}:H:S/^/${DEST_DIR}${VIRTUALDIR_${CATEG}}/}
@${INCL} ${VIRT_DIR}${VIRTUALTEMPLATE_${CATEG}}.m4 | \
${M4} ${M4_FLAGS} \
-D_DIRECTORY=${.TARGET:S/${DEST_DIR}//:H} \
-D_FILE=${.TARGET:S/${DEST_DIR}//:C/.*\///:R} \
> ${.TARGET}
${HOOK_POST_VHTML}
.endfor
.endfor
# End of looping ${VIRTUALS}
assets::
.ifdef ASSETS_DIR
$(MSG) Copy ${ASSETS_DIR} to ${ASSETS_DEST_DIR}
$(ASSETS_CP) ${ASSETS_DIR} ${ASSETS_DEST_DIR}
.endif
virtual: pre-everything ${VIRTUAL_FILES}
clean: clean-other
rm -rf ${DEST_DIR}
rm -rf ${FLAG_DIR}
.for VAR in ASSETS_DIR COMMON_DIR DEST_DIR INCLUDE_DIR LAYOUT_DIR M4 M4_FLAGS SRC_DIR VIRT_DIR
VARIABLES:=${VARIABLES}${VAR} = ${${VAR}}${.newline}
.endfor
.for VAR in ${VIRTUALS:O}
VIRTVARS:=${VIRTVARS}*** ${VAR} ***${.newline}\
TEMPLATE: ${VIRTUALTEMPLATE_${VAR}}${.newline}\
OUT: ${VIRTUALOUT_${VAR}}${.newline}\
REQ: ${VIRTUALREQ_${VAR}}${.newline}\
REQRULE: ${VIRTUALREQRULE_${VAR}}${.newline}\
${.newline}
.endfor
show-config:
@echo "${VARIABLES}"
show-hooks:
.for hook in PRE_HTML POST_HTML PRE_VHTML POST_VHTML
@printf "HOOK_${hook} = "
@$(MAKE) -VHOOK_${hook}
.endfor
show-targets:
@echo ${ALLTARGET} | tr ' ' '\n'
show-req:
.for T in ${ALLTARGET}
@echo
@echo ${T}:
@printf " %s\n" ${REQUIREMENT_${T}}
.endfor
show-virtuals:
@echo "${VIRTVARS}"
.if !target(pre-everything)
pre-everything:
.endif
.if !target(clean-other)
clean-other:
.endif
.PHONY: all assets clean clean-other pre-everything show-config show-hooks show-targets show-req show-virtuals virtual
.MAIN: all