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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-1999 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
# Mmake.rules - rules for building Mercury programs
# N.B. All the builtin rules must use $@ as the target, so that they work
# when $(VPATH) is set.
main_target: $(MAIN_TARGET)
#-----------------------------------------------------------------------------#
# Beware that the order of suffixes is significant.
.SUFFIXES: .m .nl .no .err \
.int0 .int .int2 .int3 .opt .trans_opt \
.dep .depend .dv .doit .ugly \
.date0 .date .date3 .optdate .trans_opt_date \
.c .nu .o .pic_o \
.i .s .pic_s \
.ql .pl \
.rlo
#-----------------------------------------------------------------------------#
#
# Code to set variables based on the setting of MMAKE_USE_SUBDIRS
# (i.e. --use-subdirs).
#
ifeq ($(MMAKE_USE_SUBDIRS),yes)
MCFLAGS += --use-subdirs
MSCFLAGS += --use-subdirs
MNCFLAGS += --use-subdirs
ALL_MGNUCFLAGS += -I.
endif
#-----------------------------------------------------------------------------#
.PRECIOUS: $(date0s_subdir)%.date0
.PRECIOUS: $(dates_subdir)%.date
.PRECIOUS: $(date3s_subdir)%.date3
.PRECIOUS: $(optdates_subdir)%.optdate
.PRECIOUS: $(trans_opt_dates_subdir)%.trans_opt_date
#-----------------------------------------------------------------------------#
#
# Rules for NU-Prolog and SICStus Prolog.
#
.m.pl:
sicstus_conv $<
.nl.pl:
sicstus_conv $<
$(nos_subdir)%.no : %.m
$(MNC) $(ALL_MNCFLAGS) -o $@ $<
$(nos_subdir)%.no : %.nl
$(MNC) $(ALL_MNCFLAGS) -o $@ $<
$(qls_subdir)%.ql : %.m
$(MSC) $(ALL_MSCFLAGS) -o $@ $<
$(qls_subdir)%.ql : %.nl
$(MSC) $(ALL_MSCFLAGS) -o $@ $<
#-----------------------------------------------------------------------------#
#
# Rules for building dependency files
#
# When creating the dependencies with `--use-subdirs' enabled,
# we need to create the `Mercury/dates' directories manually
# in order to get things started. This should not be necessary,
# but there is a bug in GNU Make with regard to directory caching.
# I have sent off a bug report to the GNU Make maintainers (19 March 1998).
# -fjh.
# beware the code for `%.depend' and `%.dep'/`%.dv' is duplicated
$(deps_subdir)%.dep $(deps_subdir)%.dv:
$(MCD) $(ALL_MCDFLAGS) $*
ifeq ($(MMAKE_USE_SUBDIRS),yes)
# the following mkdirs work around a bug in GNU Make
-[ -d Mercury/dates ] || mkdir Mercury/dates
-[ -d Mercury/date0s ] || mkdir Mercury/date0s
-[ -d Mercury/date3s ] || mkdir Mercury/date3s
-[ -d Mercury/optdates ] || mkdir Mercury/optdates
endif
# beware the code for `%.depend' and `%.dep'/`%.dv' is duplicated
.PHONY: %.depend
%.depend :
$(MCD) $(ALL_MCDFLAGS) $*
ifeq ($(MMAKE_USE_SUBDIRS),yes)
# the following mkdirs work around a bug in GNU Make
-[ -d Mercury/dates ] || mkdir Mercury/dates
-[ -d Mercury/date0s ] || mkdir Mercury/date0s
-[ -d Mercury/date3s ] || mkdir Mercury/date3s
-[ -d Mercury/optdates ] || mkdir Mercury/optdates
endif
# The `.doit' files are helpful when using Prolog.
%.doit : $(deps_subdir)%.dep $(deps_subdir)%.dv
sed -e ':a' -e '/\\/N' -e 's/\\\n //' -e 't a' $< | \
grep '\.ms *=' | \
sed -e 's/.*=/:-[ '\''nu_library.doit'\'', /' \
-e 's/\.m/,/g' \
-e 's/$$/ portray ]./' \
> $@
#-----------------------------------------------------------------------------#
#
# Rules for building interface files
# WARNING: any changes here will probably need to be
# duplicated in compiler/modules.m.
#
$(date0s_subdir)%.date0 : %.m
$(MCPI) $(ALL_MCPIFLAGS) $<
$(dates_subdir)%.date : %.m
$(MCI) $(ALL_MCIFLAGS) $<
$(date3s_subdir)%.date3 : %.m
$(MCSI) $(ALL_MCSIFLAGS) $<
$(optdates_subdir)%.optdate : %.m
$(MCOI) $(ALL_MCOIFLAGS) $<
$(trans_opt_dates_subdir)%.trans_opt_date : %.m
$(MCTOI) $(ALL_MCTOIFLAGS) $<
# Be very careful about changing the following rules.
# The `@:' is a silent do-nothing command.
# It is used to force GNU Make to recheck the timestamp
# on the target file. (It is a pity that GNU Make doesn't
# have a way of handling these sorts of rules in a nicer manner.)
$(int0s_subdir)%.int0 : $(date0s_subdir)%.date0
@:
$(ints_subdir)%.int : $(dates_subdir)%.date
@:
$(int2s_subdir)%.int2 : $(dates_subdir)%.date
@:
$(int3s_subdir)%.int3 : $(date3s_subdir)%.date3
@:
$(opts_subdir)%.opt : $(optdates_subdir)%.optdate
@:
$(trans_opts_subdir)%.trans_opt : $(trans_opt_dates_subdir)%.trans_opt_date
@:
#-----------------------------------------------------------------------------#
#
# Rules for compiling Mercury source files
# WARNING: any changes here will probably need to be
# duplicated in compiler/modules.m.
#
$(cs_subdir)%.c : %.m
rm -f $(cs_subdir)$*.c
$(MCG) $(ALL_GRADEFLAGS) $(ALL_MCGFLAGS) $< > $*.err 2>&1
$(rlos_subdir)%.rlo : %.m
rm -f $(rlos_subdir)$*.c
$(MCG) $(ALL_GRADEFLAGS) $(ALL_MCGFLAGS) --aditi-only $< > $*.err 2>&1
# If we are removing the .c files, we need to tell Make that we're
# generating the .o files directly from the .m files, but
# in order to avoid remaking the .c files if they're already there,
# we need to invoke mmake recursively for each .c file.
# This can be pretty inefficient.
ifneq ($(RM_C),:)
$(os_subdir)%.o : %.m
$(MMAKE_MAKE_CMD) $(MFLAGS) MC="$(MC)" ALL_MCFLAGS="$(ALL_MCFLAGS)" \
ALL_GRADEFLAGS="$(ALL_GRADEFLAGS)" $(cs_subdir)$*.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -c $(cs_subdir)$*.c -o $@
$(RM_C) $(cs_subdir)$*.c
$(os_subdir)%.pic_o : %.m
$(MMAKE_MAKE_CMD) $(MFLAGS) MC="$(MC)" ALL_MCFLAGS="$(ALL_MCFLAGS)" \
ALL_GRADEFLAGS="$(ALL_GRADEFLAGS)" $(cs_subdir)$*.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) $(CFLAGS_FOR_PIC) \
-c $(cs_subdir)$*.c -o $@
endif # RM_C != :
# For --split-c-files, we generate the .o files directly from the .m files.
# (One reason for this is that there's no easy of telling Make how many
# `.o' files it should make, since the number of them depends on what's
# in the source files.)
$(dirs_subdir)%.dir/*.o: %.m
rm -f $@
$(MCS) $(ALL_GRADEFLAGS) $(ALL_MCSFLAGS) $<
# The `touch' is necessary, since otherwise if
# the old .err file was of size zero and
# the new .err file is also of size zero,
# the time-stamp doesn't get updated!
# (Is that a bug in unix? In bash?)
.m.err:
$(MC) $(ALL_MCFLAGS) --errorcheck-only $< > $@ 2>&1
@touch $@
.m.ugly:
$(MC) --convert-to-mercury $(ALL_MCFLAGS) $<
#-----------------------------------------------------------------------------#
#
# Rules for compiling C files in the user's source directory.
#
.c.o:
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -c $< -o $@
.c.pic_o:
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) $(CFLAGS_FOR_PIC) \
-c $< -o $@
.c.s:
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -S $< -o $@
.c.pic_s:
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) $(CFLAGS_FOR_PIC) \
-S $< -o $@
.c.i:
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -E $< > $@
#-----------------------------------------------------------------------------#
#
# Rules for compiling C files in a subdirectory.
# Note that we need both these rules and the ones above,
# since even if the compiler generates all of its files in subdirectories,
# the user may have some C files of their own which need to be compiled.
#
ifneq ("$(cs_subdir)","")
$(os_subdir)%.o : $(cs_subdir)%.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -c $< -o $@
$(os_subdir)%.pic_o : $(cs_subdir)%.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) $(CFLAGS_FOR_PIC) \
-c $< -o $@
%.s: $(cs_subdir)%.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -S $< -o $@
%.pic_s: $(cs_subdir)%.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) $(CFLAGS_FOR_PIC) \
-S $< -o $@
%.i: $(cs_subdir)%.c
$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -E $< > $@
endif # $(cs_subdir) != ""
#-----------------------------------------------------------------------------#
#
# Code to handle dependencies on $(MLOBJS) and $(MLPICOBJS).
#
# The generated `.dep' files include rules for targets which may depend
# on $(MLOBJS) or $(MLPICOBJS). However, the definition of $(MLOBJS)
# or $(MLPICOBJS) is in the user's Mmakefile, and the `.dep' files get
# included *before* the Mmakefile. The `.dep' files cannot contain
# those dependency directly, because $(MLOBJS) and $(MLPICOBJS) variables
# have not yet been defined.
#
# Instead, the generated `.dep' files just add the appropriate targets to
# the $(MLOBJS_DEPS) or $(MLPICOBJS_DEPS) variables, and then we record the
# dependency of those files on $(MLOBJS) or $(MLPICOBJS) here in Mmake.rules,
# which gets included after the user's Mmakefile.
$(MLOBJS_DEPS) : $(MLOBJS)
$(MLPICOBJS_DEPS) : $(MLPICOBJS)
#-----------------------------------------------------------------------------#
#
# Targets for cleaning up.
#
# Note that the actions for most of these targets are in the
# automatically generated `.d' files.
#
.PHONY: clean realclean clean_nu clean_sicstus clean_prof_files
clean_prof_files:
-rm -f Prof.CallPair Prof.Counts Prof.Decl Prof.MemWords Prof.MemCells
#
# The `clean' and `realclean' targets are implemented via `clean_local'
# and `realclean_local'. This allows a user to add rules in their
# Mmakefile to do a recursive mmake clean, for example, while still being
# able to use the local versions in their original form.
#
.PHONY: clean_local realclean_local
realclean: realclean_local
clean: clean_local
realclean_local: clean_local
clean_local: clean_prof_files
#-----------------------------------------------------------------------------#
#
# Targets for building and installing libraries.
#
# Note: the `lib%.install_ints' rule is generated in each module's `.dep'
# file so it can be more easily customised based on the desired level of
# intermodule optimisation.
.PHONY: lib%.install
lib%.install: lib%.install_ints lib%.install_init lib%.install_library
$(MMAKE) lib$*.install_grades || { mercury_cleanup_install && exit 1; }
.PHONY: lib%.install_split
lib%.install_split: lib%.install_ints lib%.install_init \
lib%.install_split_library
$(MMAKE) lib$*.install_split_grades || \
{ mercury_cleanup_install && exit 1; }
.PHONY: lib%.install_init
lib%.install_init: %.init install_lib_dirs
cp `vpath_find $*.init` $(INSTALL_MODULE_DIR)
.PHONY: lib%.install_library
lib%.install_library: lib%.a lib%.$(EXT_FOR_SHARED_LIB) install_grade_dirs
cp `vpath_find lib$*.a lib$*.$(EXT_FOR_SHARED_LIB)` \
$(INSTALL_MERC_LIB_DIR)
lib%.install_split_library: %.split.a install_grade_dirs
cp `vpath_find $*.split.a` $(INSTALL_MERC_LIB_DIR)/lib$*.a
lib%.install_grades:
rm -rf tmp_dir && \
mkdir tmp_dir && \
{ mv -f $($*.cs) $($*.os) $($*.pic_os) *.a *.so tmp_dir || true; } && \
for grade in x $(ALL_LIBGRADES); do \
if [ "$$grade" != "x" ]; then \
$(MMAKE) GRADE=$$grade lib$*.install_library || \
exit 1; \
rm -f $($*.cs) $($*.os) $($*.pic_os) *.a *.so; \
fi; \
done && \
{ mv tmp_dir/*.c $(cs_subdir). ; \
mv tmp_dir/*.o $(os_subdir). ; \
mv tmp_dir/*.pic_o $(os_subdir). ; \
mv tmp_dir/* . ; rmdir tmp_dir ; true }
lib%.install_split_grades:
rm -rf tmp_dir && \
mkdir tmp_dir && \
{ mv -f $($*.dirs) *.a *.so tmp_dir || true; } && \
for grade in x $(ALL_LIBGRADES); do \
if [ "$$grade" != "x" ]; then \
$(MMAKE) GRADE=$$grade lib$*.install_split_library || \
exit 1; \
rm -rf $($*.dirs) *.a *.so; \
fi; \
done && \
{ mv tmp_dir/*.dir $(dirs_subdir). ; \
mv tmp_dir/* . ; rmdir tmp_dir ; true }
.PHONY: install_lib_dirs
install_lib_dirs:
-[ -d $(INSTALL_INT_DIR) ] || mkdir -p $(INSTALL_INT_DIR)
-[ -d $(INSTALL_INC_DIR) ] || mkdir -p $(INSTALL_INC_DIR)
-[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
# The following is needed to support the `--use-subdirs' option
-[ -d $(INSTALL_INT_DIR)/Mercury ] || \
mkdir -p $(INSTALL_INT_DIR)/Mercury
.PHONY: install_grade_dirs
install_grade_dirs: #install_lib_dirs
-[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
#-----------------------------------------------------------------------------#
|