#-----------------------------------------------------------------------------#
# Copyright (C) 1995-1999 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.
#-----------------------------------------------------------------------------#

# 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

M_ENV	=	MERCURY_INT_DIR=$(LIBRARY_DIR)  \
		MERCURY_ALL_C_INCL_DIRS="\
			-I$(TRACE_DIR) \
			-I$(RUNTIME_DIR) \
			-I$(BOEHM_GC_DIR) \
			-I$(BOEHM_GC_DIR)/include \
		"
MCD	=	$(M_ENV) $(MC) --generate-dependencies
MCI	=	$(M_ENV) $(MC) --make-interface
MCPI	=	$(M_ENV) $(MC) --make-private-interface
MCSI	=	$(M_ENV) $(MC) --make-short-interface
MCOI	=	$(M_ENV) $(MC) --make-optimization-interface
MCTOI	=	$(M_ENV) $(MC) --make-transitive-optimization-interface
MCG	=	$(M_ENV) $(MC) --compile-to-c
MCS	=	$(M_ENV) $(MC) --split-c-files -c --cflags "$(ALL_CFLAGS)"
MGNUC	=	$(M_ENV) $(SCRIPTS_DIR)/mgnuc
C2INIT	=	MERCURY_MOD_LIB_MODS="$(BROWSER_DIR)/$(BROWSER_LIB_NAME).init $(LIBRARY_DIR)/$(STD_LIB_NAME).init $(RUNTIME_DIR)/$(RT_LIB_NAME).init" \
                MERCURY_MKINIT=$(UTIL_DIR)/mkinit $(SCRIPTS_DIR)/c2init
ML	=	MERCURY_C_LIB_DIR=. $(SCRIPTS_DIR)/ml
MLFLAGS =	--mercury-libs none
MLLIBS  =	$(TRACE_DIR)/lib$(TRACE_LIB_NAME).a \
		$(BROWSER_DIR)/lib$(BROWSER_LIB_NAME).a \
		$(LIBRARY_DIR)/lib$(STD_LIB_NAME).a \
		$(RUNTIME_DIR)/lib$(RT_LIB_NAME).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)/lib$(RT_LIB_NAME).a
mercury_profile: $(LIBRARY_DIR)/lib$(STD_LIB_NAME).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.

$(cs_subdir)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) $(os_subdir)mercury_profile_init.o
cs: $(mercury_profile.cs) $(cs_subdir)mercury_profile_init.c

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

realclean_local:
	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$(EXT_FOR_EXE)` $(INSTALL_MERC_BIN_DIR)

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