-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
269 lines (206 loc) · 8.7 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ---------------------------------------------------------------------------
#
# SAC Compiler Construction Framework
#
# ---------------------------------------------------------------------------
#
# SAC COPYRIGHT NOTICE, LICENSE, AND DISCLAIMER
#
# (c) Copyright 1994 - 2011 by
#
# SAC Development Team
# SAC Research Foundation
#
# http://www.sac-home.org
# email:info@sac-home.org
#
# All rights reserved
#
# ---------------------------------------------------------------------------
#
# The SAC compiler construction framework, all accompanying
# software and documentation (in the following named this software)
# is developed by the SAC Development Team (in the following named
# the developer) which reserves all rights on this software.
#
# Permission to use this software is hereby granted free of charge
# exclusively for the duration and purpose of the course
# "Compilers and Operating Systems"
# of the MSc programme Grid Computing at the University of Amsterdam.
# Redistribution of the software or any parts thereof as well as any
# alteration of the software or any parts thereof other than those
# required to use the compiler construction framework for the purpose
# of the above mentioned course are not permitted.
#
# The developer disclaims all warranties with regard to this software,
# including all implied warranties of merchantability and fitness. In no
# event shall the developer be liable for any special, indirect or
# consequential damages or any damages whatsoever resulting from loss of
# use, data, or profits, whether in an action of contract, negligence, or
# other tortuous action, arising out of or in connection with the use or
# performance of this software. The entire risk as to the quality and
# performance of this software is with you. Should this software prove
# defective, you assume the cost of all servicing, repair, or correction.
#
# ---------------------------------------------------------------------------
#
#######################################################################################
#
# general setup:
#
PROJECT_ROOT := .
include $(PROJECT_ROOT)/Makefile.Config
include $(PROJECT_ROOT)/Makefile.Targets
ALL_SOURCE_DIRS = $(addprefix src/,$(src))
SOURCE_DIRS = $(addprefix src/,$(TARGET))
BIN_DIR = $(PROJECT_ROOT)/bin
DOC_DIR = $(PROJECT_ROOT)/doc
TARGETS = $(addprefix src/,$(foreach target,$(TARGET),$(addprefix $(target)/,$($(target)))))
SOURCE_MAKEFILES = $(addsuffix /Makefile,$(ALL_SOURCE_DIRS))
INCS = $(patsubst %,-I%,$(ALL_SOURCE_DIRS))
XML_DIR = $(PROJECT_ROOT)/src/framework
XML_COMMONS = $(wildcard $(XML_DIR)/common-*.xsl)
AST_DIR = $(PROJECT_ROOT)/src/global
GENERATED_INCLUDE_FILES = $(patsubst %.xsl,%,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.h.xsl))) \
$(patsubst %.xsl,%,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.mac.xsl))) \
$(patsubst %.y,%.tab.h,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.y)))
GENERATED_SOURCE_FILES = $(patsubst %.xsl,%,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c.xsl))) \
$(patsubst %.y,%.tab.c,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.y))) \
$(patsubst %.l,%.lex.c,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.l))) \
GENERATED_HTML_FILES = $(patsubst %.xsl,%,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.html.xsl)))
GENERATED_PNG_FILES = $(patsubst %.xsl,%,$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.png.xsl)))
GENERATED_FILES = $(GENERATED_INCLUDE_FILES) $(GENERATED_SOURCE_FILES) $(GENERATED_HTML_FILES) $(GENERATED_PNG_FILES)
DEPENDENCY_FILES = $(patsubst %.o,%.d,$(TARGETS))
DEPS = $(foreach file,$(DEPENDENCY_FILES),$(dir $(file)).$(notdir $(file)))
###############################################################################
#
# Dummy rules
#
.PHONY: clean all devel make_devel %.track
.PHONY: check_os makefiles
.PHONY: %.go makesubdir
.PRECIOUS: %.c %.h %.o %.prod.o .%.d %.c %.mac %.lex.c %.tab.c %.tab.h
###############################################################################
#
# Start rules
#
all: make_devel
devel:
@$(MAKE) CHECK_DEPS="yes" make_devel
make_devel: makefiles civicc.go
makefiles: $(SOURCE_MAKEFILES)
src/%/Makefile: Makefile.Source
@$(ECHO) "Creating makefile: $@"
@cp -f $< $@
%.go:
@$(ECHO) ""
@$(ECHO) "************************************"
@$(ECHO) "* Making $*"
@$(ECHO) "************************************"
@touch make_track
@$(ECHO) ""
@$(ECHO) "Generating files in directory src/framework"
@cd $(XML_DIR); $(MAKE)
@$(MAKE) CHECK_DEPS="yes" MODE="$(suffix $*)" TARGET="$(src)" $*
civicc: $(TARGETS)
@$(ECHO) ""
@$(ECHO) "Linking civicc"
@$(ECHO) ""
@$(CC) $(CCLINKFLAGS) -o $(BIN_DIR)/$@ $(TARGETS) $(LIB) $(LIBS)
@$(RM) make_track
###############################################################################
#
# Rules for making subdirectories
#
makesubdir: $(TARGETS)
@$(ECHO) ""
###############################################################################
#
# Rules for cleaning directories
#
clean: makefiles $(addsuffix .clean,$(ALL_SOURCE_DIRS))
@$(RM) $(BIN_DIR)/civicc $(DOC_DIR)/ast.html $(DOC_DIR)/ast.png *~
%.clean:
@$(ECHO) "Cleaning directory $*"
@$(MAKE) CHECK_DEPS="no" -C $* clean
###############################################################################
#
# Pattern rules for compilation
#
%.o: %.c
@if [ ! -f make_track -o "$(dir $*)" != "`cat make_track`" ] ; \
then $(ECHO) "$(dir $*)" > make_track; \
$(ECHO) ""; \
$(ECHO) "Compiling files in directory $(dir $@)" ; \
fi
@$(ECHO) " Compiling code: $(notdir $<)"
@$(CC) $(CCFLAGS) $(CFLAGS) $(YYFLAGS) $(INCS) -o $@ -c $<
%.lex.c: %.l %.track
@$(ECHO) " Generating source code from LEX specification: $(notdir $<)"
@$(LEX) $<
@mv lex.yy.c $@
%.tab.c: %.y %.track
@$(ECHO) " Generating source code from YACC specification: $(notdir $<)"
@$(YACC) $<
@mv y.tab.c $@
@$(RM) y.tab.h
@mv y.output $(dir $@) 2>/dev/null
%.tab.h: %.y %.track
@$(ECHO) " Generating header file from YACC specification: $(notdir $<)"
@$(YACC) $<
@mv y.tab.h $@
@$(RM) y.tab.c
@mv y.output $(dir $@) 2>/dev/null
%.h: %.h.xsl $(AST_DIR)/ast.xml $(XML_COMMONS)
@$(ECHO) " Generating header file from XML specification: $(notdir $@)"
@$(XSLTENGINE) $< $(AST_DIR)/ast.xml | $(INDENT) >$@
%.c: %.c.xsl $(AST_DIR)/ast.xml $(XML_COMMONS)
@$(ECHO) " Generating source code from XML specification: $(notdir $@)"
@$(XSLTENGINE) $< $(AST_DIR)/ast.xml | $(INDENT) >$@
%.html: %.html.xsl $(AST_DIR)/ast.xml $(XML_COMMONS)
@$(ECHO) " Checking XML specification against schema: $(notdir $@)"
@xmllint --schema $(XML_DIR)/ast.xsd $(AST_DIR)/ast.xml > /dev/null
@$(ECHO) " Generating html file from XML specification: $(notdir $@)"
@$(XSLTENGINE) $< $(AST_DIR)/ast.xml > $(DOC_DIR)/$(notdir $@)
%.png: %.png.xsl $(AST_DIR)/ast.xml $(XML_COMMONS)
@if [ $(DOT) = "no" ];\
then \
$(ECHO) " Generating png file from XML specification: $(notdir $@) failed. Please install Graphviz" ;\
else \
$(ECHO) " Generating png file from XML specification: $(notdir $@)" ; \
$(XSLTENGINE) $< $(AST_DIR)/ast.xml > $(DOC_DIR)/ast.dot; \
dot $(DOC_DIR)/ast.dot -Tpng -o $(DOC_DIR)/$(notdir $@); \
rm $(DOC_DIR)/ast.dot; \
fi
%.track:
@if [ ! -f make_track -o "$(dir $*)" != "`cat make_track`" ] ; \
then $(ECHO) "$(dir $*)" > make_track; \
$(ECHO) ""; \
$(ECHO) "Generating files in directory $(dir $@)" ; \
fi
#######################################################################################
#
# Pattern rules for dependency tracking mechanism:
#
.%.d: %.c $(GENERATED_FILES)
@if [ ! -f make_track -o "$(dir $*)" != "`cat make_track`" ] ; \
then $(ECHO) "$(dir $*)" > make_track; \
$(ECHO) ""; \
$(ECHO) "Checking dependencies in directory $(dir $@)" ; \
fi
@$(ECHO) " Checking dependencies of source file: $(notdir $<)"
@if $(CC) $(CCDEPS_FLAGS) $(CFLAGS) $(INCS) $< > $@d ; \
then sed 's/\($(notdir $*)\)\.o[ :]*/$(subst /,\/,$*)\.o $(subst /,\/,$@)\: $$\(PROJECT_ROOT\)\/Makefile.Config /' <$@d >$@; \
$(RM) $@d ; \
else $(RM) $@d ; \
exit 1 ; \
fi
###############################################################################
#
# Includes for dependency tracking mechanism
#
ifeq ($(CHECK_DEPS),yes)
ifneq ($(DEPS),)
-include $(sort $(DEPS))
endif
endif