# ``The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
# compliance with the License. You should have received a copy of the
# Erlang Public License along with this software. If not, it can be
# retrieved via the world wide web at http://www.erlang.org/.
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# The Initial Developer of the Original Code is Ericsson Utvecklings AB.
# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
# AB. All Rights Reserved.''
# 
#     $Id$
#
include $(ERL_TOP)/make/target.mk

ifeq ($(TYPE),debug)
ERL_COMPILE_FLAGS += -Ddebug -W
endif

include $(ERL_TOP)/make/$(TARGET)/otp.mk

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

# ----------------------------------------------------
# Release directory specification
# ----------------------------------------------------
RELSYSDIR = $(RELEASE_PATH)/lib/orber-$(VSN)

# ----------------------------------------------------
# Target Specs
# ----------------------------------------------------

MODULES= \
	orber \
	corba \
	corba_boa \
	corba_object \
	any \
	iop_ior \
	orber_tc \
	orber_typedefs \
	orber_request_number \
	orber_objectkeys \
	orber_policy_server \
	orber_initial_references \
	orber_bootstrap \
	cdrlib \
	cdr_encode \
	cdr_decode \
	orber_iiop \
	orber_iiop_net \
	orber_iiop_net_accept \
	orber_iiop_insup \
	orber_iiop_inproxy \
	orber_iiop_inrequest \
	orber_iiop_pm \
	orber_iiop_outsup \
	orber_iiop_outproxy \
	orber_iiop_outrequest \
	orber_iiop_socketsup \
	orber_socket \
	orber_ifr \
	orber_ifr_aliasdef \
	orber_ifr_arraydef \
	orber_ifr_attributedef \
	orber_ifr_constantdef \
	orber_ifr_contained \
	orber_ifr_container \
	orber_ifr_enumdef \
	orber_ifr_exceptiondef \
	orber_ifr_idltype \
	orber_ifr_interfacedef \
	orber_ifr_irobject \
	orber_ifr_moduledef \
	orber_ifr_operationdef \
	orber_ifr_orb \
	orber_ifr_primitivedef \
	orber_ifr_repository \
	orber_ifr_sequencedef \
	orber_ifr_stringdef \
	orber_ifr_structdef \
	orber_ifr_typecode \
	orber_ifr_typedef \
	orber_ifr_uniondef \
	orber_ifr_utils 
#	orber_imr

EXTERNAL_HRL_FILES= ../include/corba.hrl \
	../include/ifr_types.hrl

INTERNAL_HRL_FILES = \
	orber_debug.hrl \
	orber_iiop.hrl \
	ifr_objects.hrl \
	orber_ifr.hrl

ERL_FILES= $(MODULES:%=%.erl)	

GEN_ERL_FILES1 =  \
	oe_erlang.erl \
	erlang_pid.erl \
	erlang_port.erl \
	erlang_ref.erl

GEN_ERL_FILES2 =  \
	oe_CORBA.erl \
	CORBA_Policy.erl

GEN_ERL_FILES =  $(GEN_ERL_FILES1) $(GEN_ERL_FILES2)

GEN_HRL_FILES1 = \
	oe_erlang.hrl \
	erlang.hrl

GEN_HRL_FILES2 = \
	CORBA.hrl \
	oe_CORBA.hrl \
	CORBA_Policy.hrl \

GEN_HRL_FILES = $(GEN_HRL_FILES1) $(GEN_HRL_FILES2)


GEN_FILES = \
	$(GEN_ERL_FILES) \
	$(GEN_HRL_FILES)

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

APPUP_FILE = orber.appup
APPUP_SRC = $(APPUP_FILE).src
APPUP_TARGET = $(EBIN)/$(APPUP_FILE)

APP_FILE = orber.app
APP_SRC = $(APP_FILE).src
APP_TARGET = $(EBIN)/$(APP_FILE)

# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
ERL_FLAGS += -pa $(ERL_TOP)/lib/orber/ebin -pa $(ERL_TOP)/lib/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)/lib/orber/include \
	+'{parse_transform, sys_pre_attributes}' \
	+'{attribute, insert, app_vsn, "orber_$(ORBER_VSN)"}' 

# ----------------------------------------------------
# Targets
# ----------------------------------------------------
debug:
	@${MAKE} TYPE=debug opt

opt: $(TARGET_FILES) $(APP_TARGET) $(APPUP_TARGET)

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

$(APP_TARGET): $(APP_SRC) ../vsn.mk
	sed -e 's;%VSN%;$(VSN);' $< > $@

$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk
	sed -e 's;%VSN%;$(VSN);' $< > $@

docs:

# ----------------------------------------------------
# Special Build Targets
# ----------------------------------------------------

$(GEN_ERL_FILES1) $(GEN_HRL_FILES1): $(ERL_TOP)/lib/ic/include/erlang.idl
	erlc $(ERL_FLAGS) $(ERL_TOP)/lib/ic/include/erlang.idl

$(GEN_ERL_FILES2) $(GEN_HRL_FILES2): CORBA.idl
	erlc $(ERL_FLAGS) CORBA.idl


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


release_spec: opt
	$(INSTALL_DIR) $(RELSYSDIR)/ebin
	$(INSTALL_DATA) $(TARGET_FILES) $(APP_TARGET) $(APPUP_TARGET) $(RELSYSDIR)/ebin
	$(INSTALL_DIR) $(RELSYSDIR)/src
	$(INSTALL_DATA) $(ERL_FILES) $(YRL_FILE) $(INTERNAL_HRL_FILES) $(RELSYSDIR)/src
	$(INSTALL_DIR) $(RELSYSDIR)/include
	$(INSTALL_DATA) $(EXTERNAL_HRL_FILES) $(GEN_HRL_FILES) $(RELSYSDIR)/include


release_docs_spec:


