#-----------------------------------------------------------------------------#

# Mmake - this is Mmake file for building the Mercury profiler

MERCURY_DIR=..
include $(MERCURY_DIR)/Mmake.common

MAIN_TARGET=mercury_profile

VPATH=$(LIBRARY_DIR)

#-----------------------------------------------------------------------------#

# Specify which compilers to use to compile the compiler.
# Don't change these without good reason - if you want to
# do a temporary change, change ../Mmake.params

MCD	=	MERCURY_INT_DIR=. $(MC) --generate-dependencies
MCI	=	MERCURY_INT_DIR=$(LIBRARY_DIR) $(MC) --make-interface
MCG	=	MERCURY_C_INCL_DIR=$(RUNTIME_DIR) \
		MERCURY_INT_DIR=$(LIBRARY_DIR) $(MC) --compile-to-c
MCS	=	MERCURY_C_INCL_DIR=$(RUNTIME_DIR) \
		MERCURY_INT_DIR=$(LIBRARY_DIR) $(MC) --split-c-files -c
MGNUC	=	MERCURY_C_INCL_DIR=$(RUNTIME_DIR) $(SCRIPTS_DIR)/mgnuc
MGNUCFLAGS =	-I$(BOEHM_GC_DIR) $(EXTRA_CFLAGS)
C2INIT =	\
MERCURY_MOD_LIB_MODS="$(RUNTIME_DIR)/runtime.init $(LIBRARY_DIR)/library.init" \
		MERCURY_MKINIT=$(UTIL_DIR)/mkinit $(SCRIPTS_DIR)/c2init
ML	=	MERCURY_C_LIB_DIR=. $(SCRIPTS_DIR)/ml
MLFLAGS =	--no-libs  $(EXTRA_MLFLAGS)
MLLIBS  =	$(EXTRA_MLLIBS) $(LIBRARY_DIR)/libmercury.a \
		$(RUNTIME_DIR)/libmer.a ` \
		    case $(GRADE) in \
			*.gc.prof) echo $(BOEHM_GC_DIR)/libgc_prof.a ;; \
			*.gc) echo $(BOEHM_GC_DIR)/libgc.a ;; \
		    esac \
		` -lm
MSL	=	MERCURY_SP_LIB_DIR=$(LIBRARY_DIR) $(SCRIPTS_DIR)/msl
MNLFLAGS =	-u 6000
MTAGS	=	$(SCRIPTS_DIR)/mtags

#-----------------------------------------------------------------------------#

.PHONY: depend
depend : mercury_profile.depend

.PHONY: all
all : mercury_profile

#-----------------------------------------------------------------------------#

# Add some additional dependencies, so that Mmake knows to remake the
# profiler if one of the libraries changes.

mercury_profile: $(RUNTIME_DIR)/libmer.a $(LIBRARY_DIR)/libmercury.a
# Should also depend on $(BOEHM_GC_DIR)/libgc(_prof).a, but only
# if in .gc(.prof) grade; GNU make does not support dynamic dependencies,
# so just leave it out.

mercury_profile_init.c: $(UTIL_DIR)/mkinit

#-----------------------------------------------------------------------------#

.PHONY: check
check		: mercury_profile.check

.PHONY: ints 
ints		: mercury_profile.ints

#-----------------------------------------------------------------------------#

tags		: $(MTAGS) $(mercury_profile.ms) $(LIBRARY_DIR)/*.m
	$(MTAGS) $(mercury_profile.ms) $(LIBRARY_DIR)/*.m

#-----------------------------------------------------------------------------#

.PHONY: dates
dates		:
	touch $(mercury_profile.dates)

#-----------------------------------------------------------------------------#

.PHONY: os cs
os: $(mercury_profile.os) mercury_profile_init.o
cs: $(mercury_profile.cs) mercury_profile_init.c

#-----------------------------------------------------------------------------#

realclean:
	rm -f tags

#-----------------------------------------------------------------------------#

# Installation targets

.PHONY: install
install: install_profiler

.PHONY: install_profiler
install_profiler: mercury_profile
	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
	cp `vpath_find mercury_profile` $(INSTALL_MERC_BIN_DIR)

#-----------------------------------------------------------------------------#
