/
Mmakefile
253 lines (200 loc) · 8.68 KB
/
Mmakefile
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
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-2009 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
# This is the Mmakefile for building the Mercury deep profiler.
MERCURY_DIR=..
LINK_STATIC=yes
include $(MERCURY_DIR)/Mmake.common
#----------------------------------------------------------------------------#
# Override some settings from ../Mmake.workspace so that in debugging grades
# we do not include mer_mdbcomp.init when creating the _init.c files in
# this directory. We copy the mdbcomp modules into this directory so if we
# do include mer_mdbcomp.init we will end up with duplicate entries in the
# _init.c files.
C2INITFLAGS = --trace-init-file $(BROWSER_DIR)/$(BROWSER_LIB_NAME).init
#----------------------------------------------------------------------------#
-include Mmake.deep.params
# Override the default rule in `mmake --use-mmc-make' that asks `mmc' to
# create a missing optional params file.
Mmake.deep.params:
# Module-specific options should go in Mercury.options so they
# can be found by `mmc --make'.
include Mercury.options
MAIN_TARGET = all
ALL_DEEP_MODULES = \
mdprof_cgi \
mdprof_test \
mdprof_dump \
mdprof_feedback \
mdprof_procrep
# Always compile the deep profiler, even if it is not enabled.
#
MAIN_TARGET=all
MERCURY_MAIN_MODULES=$(ALL_DEEP_MODULES)
DEPEND=$(patsubst %,%.depend,$(ALL_DEEP_MODULES))
ifeq ("$(ENABLE_DEEP_PROFILER)","yes")
INSTALL=install_cgi_progs
else
INSTALL=nothing
endif
VPATH = $(LIBRARY_DIR) $(SSDB_DIR)
#-----------------------------------------------------------------------------#
MDBCOMP_MODULES = \
feedback.m \
mdbcomp.m \
prim_data.m \
program_representation.m \
rtti_access.m \
slice_and_dice.m \
trace_counts.m
MDBCOMP_ORIG_MODULES = $(patsubst %,$(MDBCOMP_DIR)/%,$(MDBCOMP_MODULES))
#-----------------------------------------------------------------------------#
MLFLAGS += --shared
MCFLAGS += --flags DEEP_FLAGS $(CONFIG_OVERRIDE)
#-----------------------------------------------------------------------------#
.PHONY: nothing
nothing:
.PHONY: depend
depend: $(MDBCOMP_MODULES) $(DEPEND)
$(DEPEND): DEEP_FLAGS $(MDBCOMP_MODULES)
.PHONY: all
all: $(MDBCOMP_MODULES) $(ALL_DEEP_MODULES) $(TAGS_FILE_EXISTS)
# We need to start by turning write permission on for each copied file
# in case some exist, but we need to ignore errors in case some don't exist.
# The exit 0 is to prevent make itself from printing a message about the
# (ignored) failure of an action.
#
# We could modify the action here to copy only the changed files.
$(MDBCOMP_MODULES): $(MDBCOMP_ORIG_MODULES)
-@chmod a+w $(MDBCOMP_MODULES) > /dev/null 2>&1; exit 0
cp $(MDBCOMP_ORIG_MODULES) .
@chmod a-w $(MDBCOMP_MODULES)
#-----------------------------------------------------------------------------#
# Add some additional dependencies, so that Mmake knows to remake the
# profiler if one of the libraries changes.
ifeq ("$(filter il% java% erlang%,$(GRADE))","")
mdprof_cgi: $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
mdprof_cgi: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
mdprof_test: $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
mdprof_test: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
mdprof_dump: $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
mdprof_dump: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
mdprof_feedback: $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
mdprof_feedback: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
mdprof_procrep: $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
mdprof_procrep: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
# XXX Should also depend on $(BOEHM_GC_DIR)/libgc(_prof).$A, but only
# if in .gc(.prof) grade.
endif
$(cs_subdir)mdprof_cgi_init.c: $(UTIL_DIR)/mkinit
$(cs_subdir)mdprof_test_init.c: $(UTIL_DIR)/mkinit
$(cs_subdir)mdprof_dump_init.c: $(UTIL_DIR)/mkinit
$(cs_subdir)mdprof_feedback_init.c: $(UTIL_DIR)/mkinit
$(cs_subdir)mdprof_procrep_init.c: $(UTIL_DIR)/mkinit
#-----------------------------------------------------------------------------#
.PHONY: check
check: DEPEND=$(patsubst %,%.check,$(ALL_DEEP_MODULES))
.PHONY: ints
ints: DEPEND=$(patsubst %,%.ints,$(ALL_DEEP_MODULES))
#-----------------------------------------------------------------------------#
# We need the shenanigans with .deep_tags to avoid situations in which an
# "mmake tags" in this directory does nothing even in the absence of a tags
# file in this directory, because mmake uses VPATH to find ../library/tags
# and believes it to be the tags file we are asking for.
.PHONY: tags
tags: .deep_tags
DEEP_MS = \
$(mdprof_cgi.ms) \
$(mdprof_test.ms) \
$(mdprof_dump.ms) \
$(mdprof_feedback.ms) \
$(mdprof_procrep.ms)
.deep_tags: $(MTAGS) $(DEEP_MS) \
$(wildcard $(MDBCOMP_DIR)/*.m) \
$(wildcard $(LIBRARY_DIR)/*.m)
$(MTAGS) $(DEEP_MS) $(MDBCOMP_DIR)/*.m $(LIBRARY_DIR)/*.m
@touch .deep_tags
.PHONY: tags_file_exists
tags_file_exists:
@if test ! -f tags; then echo making tags; \
$(MTAGS) $(DEEP_MS) $(MDBCOMP_DIR)/*.m $(LIBRARY_DIR)/*.m; \
touch .deep_tags; \
fi
#-----------------------------------------------------------------------------#
.PHONY: dates
dates:
touch $(mdprof_cgi.dates) $(mdprof_test.dates) $(mdprof_dump.dates) \
$(mdprof_feedback.dates) $(mdprof_procrep.dates)
#-----------------------------------------------------------------------------#
.PHONY: os cs
os: $(mdprof_cgi.os) $(os_subdir)mdprof_cgi_init.o
os: $(mdprof_test.os) $(os_subdir)mdprof_test_init.o
os: $(mdprof_dump.os) $(os_subdir)mdprof_dump_init.o
os: $(mdprof_feedback.os) $(os_subdir)mdprof_feedback_init.o
os: $(mdprof_procrep.os) $(os_subdir)mdprof_procrep_init.o
cs: $(mdprof_cgi.cs) $(cs_subdir)mdprof_cgi_init.c
cs: $(mdprof_test.cs) $(cs_subdir)mdprof_test_init.c
cs: $(mdprof_dump.cs) $(cs_subdir)mdprof_dump_init.c
cs: $(mdprof_feedback.cs) $(cs_subdir)mdprof_feedback_init.c
cs: $(mdprof_procrep.cs) $(cs_subdir)mdprof_procrep_init.c
#-----------------------------------------------------------------------------#
realclean_local:
rm -f .deep_tags tags DEEP_FLAGS DEEP_FLAGS.date \
$(MDBCOMP_MODULES) mdbcomp.*.err
#-----------------------------------------------------------------------------#
# Installation targets
.PHONY: install
install: $(INSTALL)
# We don't install mdprof_test, since it is not for users.
# The code of the install_cgi_progs target is duplicated in
# bindist/bindist.Makefile.in, though the two rules refer to mdprof_cgi
# by different paths.
.PHONY: install_cgi_progs
install_cgi_progs: mdprof_cgi mdprof_dump mdprof_test mdprof_feedback
# $(INSTALL_CGI_DIR) is likely to be writeable only by root or
# the www system administrator, which is why we don't consider a
# failure of this action to be an error. If the command fails,
# the install action in ../Mmakefile will remind the user to do
# the copy later.
#
# The mv before the cp is there in case the executable is being
# executed when we do the install. The mv is of course expected to
# fail during a first-time installation. The rm is before the move
# in case this is the third or later installation.
-if test $(ENABLE_DEEP_PROFILER) = yes ; then \
if test -w $(INSTALL_CGI_DIR) ; then \
rm -f $(INSTALL_CGI_DIR)/mdprof_cgi.was ; \
mv -f $(INSTALL_CGI_DIR)/mdprof_cgi \
$(INSTALL_CGI_DIR)/mdprof_cgi.was ; \
cp mdprof_cgi $(INSTALL_CGI_DIR) ; \
else \
echo "cannot install mdprof_cgi: " \
"$(INSTALL_CGI_DIR) is not writeable"; \
fi \
fi
# We also install mdprof_cgi in $(INSTALL_MERC_BIN_DIR).
# This is done just so that it can easily get put in the binary
# distribution (even if the step above failed). It is useful for
# mdprof_test and mdprof_dump to be available when debugging problems
# with the deep profiler, so we install them as well.
-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
cp `vpath_find mdprof_cgi$(EXT_FOR_EXE)` \
$(INSTALL_MERC_BIN_DIR)/mdprof_cgi
cp `vpath_find mdprof_test$(EXT_FOR_EXE)` \
$(INSTALL_MERC_BIN_DIR)/mdprof_test
cp `vpath_find mdprof_dump$(EXT_FOR_EXE)` \
$(INSTALL_MERC_BIN_DIR)/mdprof_dump
cp `vpath_find mdprof_feedback$(EXT_FOR_EXE)` \
$(INSTALL_MERC_BIN_DIR)/mdprof_feedback
uninstall:
# We try to uninstall mdprof_cgi, but failure to do so is not an
# error for two reasons: because we may simply lack permission to
# update the directory, and because the deep profiler installation
# may not have been enabled in the first place. (Looking at the current
# value of $(ENABLE_DEEP_PROFILER) to check for the latter wouldn't
# necessarily do any good, since its setting may have changed since
# the original install.)
-rm -f $(INSTALL_CGI_DIR)/mdprof_cgi
#-----------------------------------------------------------------------------#