# Edison Design Group C++ Front End.
# Makefile for the front end proper (src directory).
# This makefile builds the front end three different ways:
#
#   edgcpfe: As an executable that uses its command-line options to compile
#            one or more translation units.
#   edgcpdisp: As an executable that reads an IL file optionally created by
#            edgcpfe and displays the IL in human-readable form.
#   edgcpfed: As a multi-threaded daemon that receives compilation requests
#             from cfe_daemon_client (built in the util directory).  This
#             configuration is supported only on POSIX-compatible operating
#             systems (through the pthread library).
#
# On Windows, if you have the front end configured to allow C++/CLI
# (see CPPCLI_ENABLING_POSSIBLE), you will need the alink.h header, which
# Microsoft makes available at http://code.msdn.microsoft.com/alink,
# and you will need to add a compilation of ms_metadata.cpp, as
# a C++ file.  You will also need to link with mscoree.lib and
# oleaut32.lib (see LLIBS below) and add a C++ compilation for
# ms_metadata.cpp.  See the msinfo.txt file for more information.
#
# This Makefile is for demonstration purposes only and uses GNU-specific
# features that may not be available in all versions of "make".

# Note that if you set your own value for CXXFLAGS you're not required to
# set IL_SHOULD_BE_WRITTEN_TO_FILE.  If you don't, the IL display program
# is built anyway, but you won't be able to use it because you won't be
# able to make the front end write out an IL file.
CXXFLAGS = -DIL_SHOULD_BE_WRITTEN_TO_FILE

LLIBS=

INSTALL_DIR = ../bin

OBJECTS = \
	attribute.o c_gen_be.o cfe.o cfe_daemon.o class_decl.o cmd_line.o \
	const_ints.o cp_gen_be.o debug.o decl_inits.o decl_spec.o \
	declarator.o decls.o def_arg.o disambig.o error.o expr.o \
	exprutil.o extasm.o fe_init.o fe_wrapup.o fixed_pt.o \
	float_pt.o floating.o folding.o func_def.o host_envir.o \
	ifc_map_functions.o ifc_map_functions_acc.o \
	ifc_map_functions_dbg.o ifc_map_functions_mut.o \
	ifc_map_functions_val.o ifc_modules.o \
	ifc_modules_read.o ifc_modules_templ.o ifc_modules_write.o \
	il.o il_alloc.o il_display.o il_read.o il_to_str.o \
	il_walk.o il_write.o inline.o interpret.o layout.o \
	lexical.o literals.o lookup.o lower_c99.o lower_eh.o \
	lower_il.o lower_init.o lower_name.o macro.o mem_manage.o \
	modules.o ms_attrib.o overload.o pch.o pragma.o preproc.o \
	scope_stk.o src_seq.o statements.o symbol_ref.o symbol_tbl.o \
	sys_predef.o target.o templates.o trans_copy.o trans_corresp.o \
	trans_unit.o types.o unicode_name_fsm.o

DISP_OBJECTS = const_ints.o debug.o error.o fe_init.o fixed_pt.o \
	float_pt.o floating.o host_envir.o il.o il_display.o il_read.o \
	il_to_str.o il_walk.o mem_manage.o src_seq.o target.o types.o

INCLUDES = \
	attribute.h basic_hdrs.h basics.h builtin_defs.h c_gen_be.h  \
	cfe_daemon_common.h checking.h class_decl.h cmd_line.h \
	const_ints.h cp_gen_be.h debug.h decl_hdrs.h decl_inits.h \
	decl_spec.h declarator.h decls.h def_arg.h defines.h \
	direct_allocator.h disambig.h error.h expr.h expr_hdrs.h \
	exprutil.h extasm.h fe_common.h fe_init.h fe_wrapup.h \
	fixed_pt.h float_pt.h float_type.h floating.h folding.h \
	func_def.h header_util.h host_envir.h host_util.h ifc_map.h \
	ifc_map_functions.h ifc_modules.h ifc_modules_inst.h \
	ifc_modules_internal.h ifc_modules_spec.h il.h il_alloc.h \
	il_def.h il_display.h il_file.h il_read.h il_to_str.h \
	il_walk.h il_write.h inline.h interpret.h lang_feat.h \
	layout.h lexical.h lint.h literals.h lookup.h lower_c99.h \
	lower_eh.h lower_hdrs.h lower_il.h lower_init.h  \
	lower_name.h macro.h mem_manage.h mem_tables.h modules.h  \
	ms_attrib.h ms_metadata.h overload.h pch.h pragma.h  \
	preproc.h scope_stk.h src_seq.h statements.h symbol_ref.h  \
	symbol_tbl.h sys_predef.h targ_def.h target.h target_cfg.h  \
	target_map.h templates.h trans_copy.h trans_corresp.h  \
	trans_unit.h types.h util.h version.h walk_entry.h

ERROR_FILES = err_codes.h err_data.h

# Object files used to build edgcpdisp and edgcpfed executables are kept in
# the "disp" and "daemon" subdirectories respectively (and are compiled with
# a different set of options).
DISP_OBJECTS := $(patsubst %,disp/%,$(DISP_OBJECTS))
EDGCPFED_OBJECTS := $(patsubst %,daemon/%,$(OBJECTS))

# Configuration macros that are specific to the edgcpdisp and edgcpfed
# executables:
DISP_OPTIONS = -DSTANDALONE_IL_DISPLAY
EDGCPFED_OPTIONS = -DEDG_FRONT_END_DAEMON -DMAKE_FRONT_END_CALLABLE \
		   -DMULTIPLE_THREAD_COMPILATION -DCUSTOM_DEFAULT_OUTPUT_FILES

# Specific rules for compiling edgcpdisp and edgcpfed objects must precede
# the more general rule:
disp/%.o: %.c
	$(CXX) -c $(CXXFLAGS) $(DISP_OPTIONS) -o $@ $<
daemon/%.o: %.c
	$(CXX) -c $(CXXFLAGS) $(EDGCPFED_OPTIONS) -o $@ $<
.c.o:
	$(CXX) -c $(CXXFLAGS) $*.c

default: edgcpfe disp/edgcpdisp daemon/edgcpfed

dirs:
	mkdir -p daemon disp

edgcpfe: $(OBJECTS)
	$(CXX) -o edgcpfe $(LDFLAGS) *.o $(LLIBS)

disp/edgcpdisp: dirs $(DISP_OBJECTS)
	$(CXX) -o disp/edgcpdisp $(LDFLAGS) $(DISP_OBJECTS) $(LLIBS)

daemon/edgcpfed: dirs $(EDGCPFED_OBJECTS)
	$(CXX) -o daemon/edgcpfed $(LDFLAGS) $(EDGCPFED_OBJECTS) $(LLIBS) -lpthread

error_files: $(ERROR_FILES)

$(ERROR_FILES): ../misc/mk_errinfo error_msg.txt error_tag.txt
	../misc/mk_errinfo error_msg.txt error_tag.txt err_codes.h err_data.h

../misc/mk_errinfo: ../misc/mk_errinfo.c
	@(cd ../misc; $(MAKE) "CXX=$(CXX)" "CXXFLAGS=$(CXXFLAGS)" "LDFLAGS=$(LDFLAGS)" mk_errinfo)

$(OBJECTS): defines.h $(ERROR_FILES)
$(DISP_OBJECTS): defines.h $(ERROR_FILES)
$(EDGCPFED_OBJECTS): defines.h $(ERROR_FILES)

fe_init.o: $(INCLUDES)

il_walk.o: walk_entry.h

$(INSTALL_DIR)/edgcpfe: edgcpfe
	rm -f $(INSTALL_DIR)/edgcpfe
	cp edgcpfe $(INSTALL_DIR)
	chmod -w $(INSTALL_DIR)/edgcpfe

$(INSTALL_DIR)/edgcpdisp: disp/edgcpdisp
	rm -f $(INSTALL_DIR)/edgcpdisp
	cp disp/edgcpdisp $(INSTALL_DIR)
	chmod -w $(INSTALL_DIR)/edgcpdisp

$(INSTALL_DIR)/edgcpfed: daemon/edgcpfed
	rm -f $(INSTALL_DIR)/edgcpfed
	cp daemon/edgcpfed $(INSTALL_DIR)
	chmod -w $(INSTALL_DIR)/edgcpfed

install: $(INSTALL_DIR)/edgcpfe $(INSTALL_DIR)/edgcpdisp $(INSTALL_DIR)/edgcpfed

clean:
	rm -f core a.out include/* *.o err_codes.h err_data.h
	rm -fr disp daemon

clobber: clean
	rm -f edgcpfe disp/edgcpdisp daemon/edgcpfed

all: clobber default
