Subversion Repositories wpwmm4

Rev

Rev 22 | Rev 25 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 zsolt 1
include config.mk
2
 
10 zsolt 3
COMMON_DIR?=/home/zsolt/progs/wpwmm4/
13 zsolt 4
INCLUDE_DIR?=include/
2 zsolt 5
M4_DEFINITIONS=00_defines.m4
6
 
7
# If there are unset we're using default values
8
M4?=m4
16 zsolt 9
M4_FLAGS?=-P -I ${COMMON_DIR} -I ${INCLUDE_DIR} \
2 zsolt 10
		  -D_SRC_DIR=${SRC_DIR} -D_LAYOUT_DIR=${LAYOUT_DIR}
11
CAT?=cat
12
MKDIR=@mkdir -p
13
 
14
MSG=@echo "==>"
15
MSG1=@echo "  ==>"
16
MSG2=@echo "    ==>"
17
 
10 zsolt 18
INCL=${CAT} ${COMMON_DIR}${M4_DEFINITIONS}
2 zsolt 19
 
20
# Working Targets
21
# Prepend the ${DEST_DIR}
22
WTARGETS=${TARGETS:S/^/${DEST_DIR}/}
23
 
24
# Target directories
25
# Remove the filenames
26
TDIR=${WTARGETS:H:u}
27
 
28
.for CATEG in ${VIRTUALS}
29
TDIR+=${DEST_DIR}${VIRTUALDIR_${CATEG}}
24 zsolt 30
TDIR:=${TDIR}
2 zsolt 31
.endfor
32
 
33
all: assets ${WTARGETS} virtual
34
 
35
# Create directories inside ${DEST_DIR}
36
${TDIR:u}: pre-everything
37
	${MKDIR} -p ${TDIR:u}
38
 
39
# Create files using ${SRC_DIR}/*.m4 in ${DEST_DIR}/*.html
40
# Pass the directory of source file to m4 as `_DIRECTORY' and
41
# the created filename without path and extension as `_FILE'.
42
.for T in ${TARGETS}
24 zsolt 43
CT:=${DEST_DIR}${T}
44
DEP:=${GREQ} ${TDIR} ${T:S/^/${SRC_DIR}/:S/html$/m4/} ${${T}_REQ}
45
REQUIREMENT_${CT}:=${DEP}
46
ALLTARGET+=${CT}
47
ALLTARGET:=${ALLTARGET}
48
${CT}: ${DEP}
2 zsolt 49
	${MSG1} Building ${.TARGET}
50
	@${INCL} ${.TARGET:S/${DEST_DIR}/${SRC_DIR}/:R}.m4 | \
51
	  ${M4} ${M4_FLAGS} \
19 zsolt 52
	  -D_DIRECTORY=${.TARGET:H:S/${DEST_DIR}//} \
2 zsolt 53
	  -D_FILE=${.TARGET:S/${DEST_DIR}//:R} \
54
	   > ${.TARGET}
55
.endfor
56
 
57
# Looping all ${VIRTUALS}
58
.for CATEG in ${VIRTUALS}
59
VIRTUAL_FILES+=${VIRTUALOUT_${CATEG}:S/^/${DEST_DIR}${VIRTUALDIR_${CATEG}}/}
24 zsolt 60
VIRTUAL_FILES:=${VIRTUAL_FILES}
3 zsolt 61
VIRTUALREQRULE_${CATEG}?=C,.*,,
2 zsolt 62
 
63
# Create files from ${VIRTUALS} using ${VIRT_DIR}/*.m4
64
# Pass the directory as `_DIRECTORY' and create filename
65
# without extension as `_FILE'
3 zsolt 66
.for VOUT in ${VIRTUALOUT_${CATEG}}
24 zsolt 67
CT:=${DEST_DIR}${VIRTUALDIR_${CATEG}}${VOUT}
68
DEP:=${GREQ} \
5 zsolt 69
  ${DEST_DIR}${VIRTUALDIR_${CATEG}} \
2 zsolt 70
  ${VIRT_DIR}${VIRTUALTEMPLATE_${CATEG}}.m4 \
3 zsolt 71
  ${VIRTUALREQ_${CATEG}} \
72
  ${VOUT:${VIRTUALREQRULE_${CATEG}}}
24 zsolt 73
REQUIREMENT_${CT}:=${DEP}
74
ALLTARGET+=${CT}
75
ALLTARGET:=${ALLTARGET}
76
${CT}: ${DEP}
2 zsolt 77
	${MSG} Virtual ${VIRTUALTEMPLATE_${CATEG}}: ${.TARGET}
78
	${MKDIR} ${VIRTUALOUT_${CATEG}:H:S/^/${DEST_DIR}${VIRTUALDIR_${CATEG}}/}
79
	@${INCL} ${VIRT_DIR}${VIRTUALTEMPLATE_${CATEG}}.m4 | \
80
	  ${M4} ${M4_FLAGS} \
81
	  -D_DIRECTORY=${.TARGET:S/${DEST_DIR}//:H} \
4 zsolt 82
	  -D_FILE=${.TARGET:S/${DEST_DIR}//:C/.*\///:R} \
2 zsolt 83
	  > ${.TARGET}
84
.endfor
3 zsolt 85
.endfor
15 zsolt 86
# End of looping ${VIRTUALS}
2 zsolt 87
 
88
assets::
21 zsolt 89
.ifdef ASSETS_DIR
2 zsolt 90
	@cp -r ${ASSETS_DIR} ${DEST_DIR}
21 zsolt 91
.endif
2 zsolt 92
 
93
virtual: pre-everything ${VIRTUAL_FILES}
94
 
6 zsolt 95
clean: clean-other
2 zsolt 96
	rm -rf ${DEST_DIR}
97
 
14 zsolt 98
.for VAR in ASSETS_DIR COMMON_DIR DEST_DIR INCLUDE_DIR LAYOUT_DIR SRC_DIR VIRT_DIR
99
VARIABLES:=${VARIABLES}${VAR} = ${${VAR}}${.newline}
100
.endfor
101
 
102
.for VAR in ${VIRTUALS:O}
103
VIRTVARS:=${VIRTVARS}*** ${VAR} ***${.newline}\
104
TEMPLATE: ${VIRTUALTEMPLATE_${VAR}}${.newline}\
105
OUT: ${VIRTUALOUT_${VAR}}${.newline}\
106
REQ: ${VIRTUALREQ_${VAR}}${.newline}\
107
REQRULE: ${VIRTUALREQRULE_${VAR}}${.newline}\
108
${.newline}
109
.endfor
110
 
111
show-config:
112
	@echo "${VARIABLES}"
113
 
24 zsolt 114
show-targets:
115
	@echo ${ALLTARGET} | tr ' ' '\n'
116
 
117
show-req:
118
.for T in ${ALLTARGET}
119
	@echo
120
	@echo ${T}:
121
	@printf "  %s\n" ${REQUIREMENT_${T}}
122
.endfor
123
 
14 zsolt 124
show-virtuals:
125
	@echo "${VIRTVARS}"
126
 
2 zsolt 127
.if !target(pre-everything)
128
pre-everything:
129
.endif
6 zsolt 130
.if !target(clean-other)
131
clean-other:
132
.endif
2 zsolt 133
 
24 zsolt 134
.PHONY: all assets clean clean-other pre-everything show-config show-targets show-req show-virtuals virtual
2 zsolt 135
.MAIN: all