forked from jkubin/m4root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (86 loc) · 3.45 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
# __HEADER([Josef Kubin], [2019/10/09], [root_cz])
# ___DESCR([this handwritten Makefile automatically creates additional rules for creating target files])
# ___POINT([learning M4 using the examples in this series])
# ___USAGE([make h && make && make])
# <--- this is the form-feed character for Vim abbreviations, type: [[ to skip backward; type: ]] to skip forward
# keep secondary generated files
.SECONDARY:
SOURCE = $(wildcard *.mc)
DOC_FILE = brief_documentation.txt
DEBUG_FILE = debug.m4
ORDER_FILE = order.m4
VPATH = gfiles
SUBDIRS = gfiles hello_world preproc messages asm
EMPTY =
SPACE = $(EMPTY) $(EMPTY)
COMMA = ,
LANG_CODES = $(patsubst lang_%.m4,%,$(wildcard lang_*.m4))
REQ_LANGS = $(filter-out $(ex)$(exclude), $(LANG_CODES))
MAKE_HTML = $(patsubst %,html_%.mk,$(REQ_LANGS))
MAKE_FHTML = $(patsubst %,fhtml_%.mk,$(REQ_LANGS))
MAKE_REFS = $(patsubst %,refs_%.m4,$(REQ_LANGS))
REFS_ALL = $(patsubst %,refs_%.m4,$(LANG_CODES))
LANGS_ALL = $(subst $(SPACE),$(COMMA),$(LANG_CODES))
FILE_LIST = $(subst $(SPACE),$(COMMA),$(SOURCE))
CLSUBDIRS = $(SUBDIRS:%=clean-%)
-include $(wildcard *.mk)
#:all creates all files
.PHONY: all
all: src html $(TARGETS)
#:html creates rules to generate html
.PHONY: html
html: $(MAKE_HTML)
#:fhtml creates rules to generate html from frozen M4 files
.PHONY: fhtml
fhtml: $(MAKE_FHTML)
#:src generates files in all example folders
.PHONY: src
src: $(SUBDIRS)
#:debug/dbg/trunc/d truncates the debug file for M4 script development
.PHONY: debug dbg trunc d
debug dbg trunc d:
> $(DEBUG_FILE)
#:refs regenerate references
.PHONY: refs
refs: $(MAKE_REFS)
#:test/t this target is for M4 script development
.PHONY: test t
test t: debug dev
#:devel/dev this target is for M4 script development
.PHONY: devel dev
devel dev: rootb.m4
m4 $< test.m4
#:doc extracts headers from the source files and creates a brief documentation for a basic source file overview
.PHONY: doc
doc: $(DOC_FILE)
$(DOC_FILE): doc.m4 $(wildcard gfiles/*b.m4) $(shell find -name '*.sed' -o -name 'Makefile' -o -name '*.m4' ! -path './messages/*' ! -path './gfiles/*' ! -path './hello_world/*' ! -path './preproc/*' ! -path './asm/*')
m4 $+ > $@
$(ORDER_FILE): rootb.m4 toc.m4 toc_list.m4
m4 -DALL_LANGS='$(LANGS_ALL)' -DFILE_LIST='$(FILE_LIST)' $^ > $@
refs_%.m4: rootb.m4 lang_%.m4 toc.m4 $(ORDER_FILE) lang.m4 headings.m4 refs.m4
m4 -DLANG_CODE='$*' $^ $(SOURCE) > $@
html_%.mk: rootb.m4 $(ORDER_FILE) refs_%.m4 lang.m4 headings.m4 mk/html.m4
m4 -DREFS_FILES='$(MAKE_REFS)' -DLANG_CODE='$*' $^ > $@
fhtml_%.mk: rootb.m4 $(ORDER_FILE) refs_%.m4 lang.m4 headings.m4 mk/fhtml.m4
m4 -DREFS_FILES='$(MAKE_REFS)' -DLANG_CODE='$*' $^ > $@
.PHONY: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
.PHONY: $(CLSUBDIRS)
$(CLSUBDIRS):
$(MAKE) -C $(@:clean-%=%) clean
#:clean/cle/del/cl deletes all generated files
.PHONY: clean cle del cl
clean cle del cl:
$(RM) -r $(DEBUG_FILE) $(DOC_FILE) $(ORDER_FILE) $(REFS_ALL) $(FOLDERS) *.{mk,m4f}
#:distclean/dcl/cld/dc also deletes generated files also in all example folders
.PHONY: distclean dcl cld dc
distclean dcl cld dc: clean $(CLSUBDIRS)
#:mostlyclean/mcl/clm/cll/mc deletes only a subset of the generated files
.PHONY: mostlyclean mcl clm cll mc
mostlyclean mcl clm cll mc:
$(RM) -r $(FOLDERS) *.{mk,m4f}
#:help/he/hl/h prints help for this Makefile
.PHONY: help he hl h
help he hl h:
@sed -n '/^#:/{s//\x1b[7mmake /;s/\t/\x1b[m /;p}' Makefile $(wildcard *.mk) | sort -u # ]] <--- square brackets because of M4