#-----------------------------------------------------------------------------#
# vim: ts=8 sw=8 noexpandtab ft=make
#-----------------------------------------------------------------------------#
# Copyright (C) 2013 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 mfilterjavac tool.

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

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

-include Mmake.mfilterjavac.params

# Override the default rule in `mmake --use-mmc-make' that asks `mmc' to
# create a missing optional params file.
Mmake.mfilterjavac.params:

# Module-specific options should go in Mercury.options so they can be found
# by `mmc --make'. But this hasn't been used in this directory so far,
# so it is commented out.
# include Mercury.options

MAIN_TARGET = all

ALL_MODULES = mfilterjavac

MAIN_TARGET=all
MERCURY_MAIN_MODULES=$(ALL_MODULES)
DEPEND=$(patsubst %,%.depend,$(ALL_MODULES))
PDBS=$(patsubst %,%.pdb,$(ALL_MODULES))

VPATH = $(LIBRARY_DIR) $(SSDB_DIR)

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

MLFLAGS += --shared
MCFLAGS += --flags MFILTERJAVAC_FLAGS $(CONFIG_OVERRIDE)

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

# Tell the C# compiler where the stdlib assembly is.
#
ifneq ("$(filter csharp%,$(GRADE))","")
CSCFLAGS=-lib:../library -r:mer_std.dll
endif

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

ifneq ("$(filter csharp% java%,$(GRADE))","")
MLOBJS =
endif

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

.PHONY: nothing
nothing:

.PHONY: depend
depend:	$(DEPEND)

$(DEPEND): MFILTERJAVAC_FLAGS

.PHONY: all
all:	$(ALL_MODULES) $(TAGS_FILE_EXISTS)

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

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

ifeq ("$(filter csharp% java%,$(GRADE))","")
mfilterjavac: \
	$(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A \
	$(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
endif

$(cs_subdir)mfilterjavac.c:	$(UTIL_DIR)/mkinit$(EXT_FOR_EXE)

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

.PHONY: check
check:	DEPEND=$(patsubst %,%.check,$(ALL_MODULES))

.PHONY: ints
ints:	DEPEND=$(patsubst %,%.ints,$(ALL_MODULES))

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

# We need the shenanigans with .mfilterjavac_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:	.mfilterjavac_tags

.mfilterjavac_tags: $(MTAGS) $(wildcard *.m) $(wildcard $(LIBRARY_DIR)/*.m)
	$(MTAGS) *.m $(LIBRARY_DIR)/*.m
	@touch .mfilterjavac_tags

.PHONY: tags_file_exists
tags_file_exists:
	@if test ! -f tags; \
	then \
		echo making tags; \
		$(MTAGS) *.m $(LIBRARY_DIR)/*.m; \
		touch .mfilterjavac_tags; \
	fi

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

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

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

# The documentation of the reason for this set of rules
# can be found in library/Mmakefile.

.PHONY: os cs css javas
ifeq ($(MMAKE_USE_MMC_MAKE),yes)
os:     mfilterjavac.os
cs:     mfilterjavac.cs
css:    mfilterjavac.css
javas:  mfilterjavac.javas
else
ifneq ($(origin mfilterjavac.os),undefined)
os:     $(mfilterjavac.os)
cs:     $(mfilterjavac.cs)
css:    $(mfilterjavac.css)
javas:  $(mfilterjavac.javas)
else
os:
	mmake depend; mmake os

cs:
	mmake depend; mmake cs

css:
	mmake depend; mmake css

javas:
	mmake depend; mmake javas
endif
endif

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

realclean_local:
	rm -f .mfilterjavac_tags tags \
		MFILTERJAVAC_FLAGS MFILTERJAVAC_FLAGS.date $(PDBS) vc*.pdb

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

# Installation target.

# See the comment above the 'install_compiler' target in compiler/Mmakefile
# for the reasons why we handle the java grade specially here.
#
ifeq ($(findstring java,$(GRADE)),java)
INSTALL_PROGRAM=mfilterjavac.jar
else
INSTALL_PROGRAM=mfilterjavac$(EXT_FOR_EXE)
endif

install: mfilterjavac
	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
	cp `vpath_find $(INSTALL_PROGRAM)` $(INSTALL_MERC_BIN_DIR)/$(INSTALL_PROGRAM)

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

.PHONY: uninstall
uninstall:
	-rm -f $(INSTALL_MERC_BIN_DIR)/$(INSTALL_PROGRAM)

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