# ----------------------------------------------------
# Copyright (C) 1997, Ericsson Telecommunications
# Author: Lars Thorsen
# ----------------------------------------------------

AUTOCONF := $(ERL_TOP)/erts/autoconf
TARGET := $(shell $(AUTOCONF)/config.guess)
EBIN=../../ebin
include $(ERL_TOP)/internal_tools/make/$(TARGET)/otp.mk

# ----------------------------------------------------
# Application version
# ----------------------------------------------------
include ../../vsn.mk
VSN=$(ORBER_VSN)

# ----------------------------------------------------
# Release directory specification
# ----------------------------------------------------
RELEASE_PATH= ../../../release/$(TARGET)
RELSYSDIR = $(RELEASE_PATH)/lib/orber-$(VSN)
# ----------------------------------------------------
# Target Specs
# ----------------------------------------------------

MODULES = \
	OrberEventChannelAdmin_EventChannel_impl \
	CosEventChannelAdmin_SupplierAdmin_impl \
	CosEventChannelAdmin_ConsumerAdmin_impl \
	OrberEventChannelAdmin_ProxyPullConsumer_impl \
	OrberEventChannelAdmin_ProxyPullSupplier_impl \
	OrberEventChannelAdmin_ProxyPushConsumer_impl \
	OrberEventChannelAdmin_ProxyPushSupplier_impl \
	OrberEventChannel_EventChannelFactory_impl

ERL_FILES = $(MODULES:%=%.erl) 
HRL_FILES = event_service.hrl

GEN_ERL_FILES =  \
	oe_CosEventChannelAdmin.erl \
	oe_OrberEventChannelAdmin.erl \
	oe_event_channel_factory.erl \
	CosEventChannelAdmin_ConsumerAdmin.erl \
	CosEventChannelAdmin_EventChannel.erl \
	CosEventChannelAdmin_ProxyPullConsumer.erl \
	CosEventChannelAdmin_ProxyPullSupplier.erl \
	CosEventChannelAdmin_ProxyPushConsumer.erl \
	CosEventChannelAdmin_ProxyPushSupplier.erl \
	CosEventChannelAdmin_SupplierAdmin.erl \
	OrberEventChannelAdmin_EventChannel.erl \
	OrberEventChannelAdmin_ProxyPullConsumer.erl \
	OrberEventChannelAdmin_ProxyPullSupplier.erl \
	OrberEventChannelAdmin_ProxyPushConsumer.erl \
	OrberEventChannelAdmin_ProxyPushSupplier.erl \
	OrberEventChannel_EventChannelFactory.erl \
	CosEventChannelAdmin_AlreadyConnected.erl \
	CosEventChannelAdmin_TypeError.erl

GEN_HRL_FILES = \
	oe_CosEventChannelAdmin.hrl \
	oe_OrberEventChannelAdmin.hrl \
	oe_event_channel_factory.hrl \
	CosEventChannelAdmin.hrl \
	CosEventChannelAdmin_ConsumerAdmin.hrl \
	CosEventChannelAdmin_EventChannel.hrl \
	CosEventChannelAdmin_ProxyPullConsumer.hrl \
	CosEventChannelAdmin_ProxyPullSupplier.hrl \
	CosEventChannelAdmin_ProxyPushConsumer.hrl \
	CosEventChannelAdmin_ProxyPushSupplier.hrl \
	CosEventChannelAdmin_SupplierAdmin.hrl \
	OrberEventChannel.hrl \
	OrberEventChannelAdmin.hrl \
	OrberEventChannelAdmin_EventChannel.hrl \
	OrberEventChannelAdmin_ProxyPullConsumer.hrl \
	OrberEventChannelAdmin_ProxyPullSupplier.hrl \
	OrberEventChannelAdmin_ProxyPushConsumer.hrl \
	OrberEventChannelAdmin_ProxyPushSupplier.hrl \
	OrberEventChannel_EventChannelFactory.hrl

TARGET_FILES = \
	$(GEN_ERL_FILES:%.erl=$(EBIN)/%.$(EMULATOR)) \
	$(MODULES:%=$(EBIN)/%.$(EMULATOR)) 

GEN_FILES = $(GEN_HRL_FILES) $(GEN_ERL_FILES)

IDL_FILES = \
	CosEventChannelAdmin.idl \
	CosEventComm.idl \
	OrberEventChannelAdmin.idl \
	event_channel_factory.idl

APP_FILE = 
#APP_SRC = $(APP_FILE).src
#APP_TARGET = $(EBIN)/$(APP_FILE)

# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
ERL_FLAGS += -pa $(ERL_TOP)/libraries/orber/ebin -pa $(CC_ROOT)/libraries/ic/ebin
# The -pa option is just used temporary until erlc can handle 
# includes from other directories than ../include .
ERL_COMPILE_FLAGS += -I$(ERL_TOP)/libraries/orber/include \
	+'{parse_transform, sys_pre_attributes}' \
	+'{attribute, insert, vsn, "orber_$(ORBER_VSN)"}' 

YRL_FLAGS = 

# ----------------------------------------------------
# Targets
# ----------------------------------------------------
debug opt: $(TARGET_FILES) $(APP_TARGET)

clean:
	rm -f $(TARGET_FILES) $(GEN_FILES) $(APP_TARGET)
	rm -f errs core *~

$(APP_TARGET): $(APP_SRC)
	sed -e 's;%VSN%;$(VSN);' $(APP_SRC) > $(APP_TARGET)

docs:

# ----------------------------------------------------
# Special Build Targets
# ----------------------------------------------------
oe_CosEventChannelAdmin.erl: CosEventChannelAdmin.idl
	erlc $(ERL_FLAGS) +'{handle_info, "CosEventChannelAdmin::ConsumerAdmin"}' \
		+'{handle_info, "CosEventChannelAdmin::SupplierAdmin"}' \
		CosEventChannelAdmin.idl

#	echo "ic:gen('CosEventChannelAdmin', [{handle_info, \"CosEventChannelAdmin::ConsumerAdmin\"}, {handle_info, \"CosEventChannelAdmin::SupplierAdmin\"}]), halt()."| $(ERL) $(ERL_FLAGS)

oe_OrberEventChannelAdmin.erl: OrberEventChannelAdmin.idl
	erlc $(ERL_FLAGS) +'handle_info' \
		+'{this, "OrberEventChannelAdmin::EventChannel::for_consumers"}' \
		+'{this, "OrberEventChannelAdmin::EventChannel::for_suppliers"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPullConsumer::connect_pull_supplier"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPullConsumer::disconnect_pull_consumer"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPullSupplier::connect_pull_consumer"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPullSupplier::disconnect_pull_supplier"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPushConsumer::connect_push_supplier"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPushConsumer::disconnect_push_consumer"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPushSupplier::connect_push_consumer"}' \
		+'{this, "OrberEventChannelAdmin::ProxyPushSupplier::disconnect_push_supplier"}' \
		OrberEventChannelAdmin.idl

#	echo "ic:gen('OrberEventChannelAdmin', [handle_info, {this, \"OrberEventChannelAdmin::EventChannel::for_consumers\"}, {this, \"OrberEventChannelAdmin::EventChannel::for_suppliers\"}, {this, \"OrberEventChannelAdmin::ProxyPullConsumer::connect_pull_supplier\"}, {this, \"OrberEventChannelAdmin::ProxyPullConsumer::disconnect_pull_consumer\"}, {this, \"OrberEventChannelAdmin::ProxyPullSupplier::connect_pull_consumer\"}, {this, \"OrberEventChannelAdmin::ProxyPullSupplier::disconnect_pull_supplier\"}, {this, \"OrberEventChannelAdmin::ProxyPushConsumer::connect_push_supplier\"}, {this, \"OrberEventChannelAdmin::ProxyPushConsumer::disconnect_push_consumer\"}, {this, \"OrberEventChannelAdmin::ProxyPushSupplier::connect_push_consumer\"}, {this, \"OrberEventChannelAdmin::ProxyPushSupplier::disconnect_push_supplier\"}]), halt()."| $(ERL) $(ERL_FLAGS)

oe_event_channel_factory.erl: event_channel_factory.idl
	erlc $(ERL_FLAGS) event_channel_factory.idl

#	echo "ic:gen('event_channel_factory'), halt()." | $(ERL) $(ERL_FLAGS)


# ----------------------------------------------------
# Release Target
# ---------------------------------------------------- 
include $(ERL_TOP)/internal_tools/make/otp_release_targets.mk


release_spec: opt
	$(INSTALL_DIR) $(RELSYSDIR)/ebin
	$(INSTALL_DATA) $(TARGET_FILES) $(APP_TARGET) $(RELSYSDIR)/ebin
	$(INSTALL_DIR) $(RELSYSDIR)/COSS/CosEvent
	$(INSTALL_DATA) $(ERL_FILES) $(HRL_FILES) $(IDL_FILES) $(RELSYSDIR)/COSS/CosEvent
	$(INSTALL_DATA) $(GEN_HRL_FILES) $(GEN_ERL_FILES) $(RELSYSDIR)/COSS/CosEvent


release_docs_spec:


release_src_spec: release_spec
	$(INSTALL_DATA) Makefile $(RELSYSDIR)/COSS/CosEvent
