# ----------------------------------------------------
# Copyright (C) 1997, Ericsson Telecommunications
# Author: Lars Thorsen
# ----------------------------------------------------
CC_ROOT := $(shell pwd | sed 's/erts.*$$//')
AUTOCONF := $(CC_ROOT)/erts/autoconf
TARGET := $(shell $(AUTOCONF)/config.guess)
include $(CC_ROOT)/internal_tools/make/$(TARGET)/otp.mk

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

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

# ----------------------------------------------------
# Target Specs
# ----------------------------------------------------
MODULES =  \
	erl_mkbif \
	beam_listing \
	beam_compile \
	beam_optimize \
	beam_asm_int \
        beam_dict \
	beam_cleanup \
	sys_bifs \
	beam_opcodes \
	compile \
	jam_asm \
	jam_compile \
	jam_encode \
	jam_listing \
	jam_optimize \
	jam_yecc_pj \
	jam_listing \
	sys_pre_attributes \
	sys_pre_expand \
	sys_pre_pj

BEAM_H = $(wildcard ../priv/beam_h/*.h)

HRL_FILES=
ERL_FILES= $(MODULES:%=%.erl)
TARGET_FILES= beam_opcodes.hrl $(MODULES:%=$(EBIN)/%.$(EMULATOR)) $(APP_TARGET)

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

# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
ERL_FLAGS += 
ERL_COMPILE_FLAGS += -I../../stdlib/include -W

# ----------------------------------------------------
# Targets
# ----------------------------------------------------

debug opt: $(TARGET_FILES) 

docs:

clean:
	rm -f $(TARGET_FILES)
	rm -f core

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

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

BIF_TAB = $(CC_ROOT)erts/system/emulator/runtime/bif.tab
OP_TAB = $(CC_ROOT)erts/system/emulator/beam/ops.tab
BEAM_EMU := $(CC_ROOT)erts/system/emulator/beam

sys_bifs.erl: $(BIF_TAB)
	erlc -o $@ $(BIF_TAB)

beam_opcodes.erl beam_opcodes.hrl: 
	$(BEAM_EMU)/beam_makeops -compiler $(OP_TAB)

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

# Note: Source for the compiler should not be released.

release_spec:
	$(INSTALL_DIR) $(RELSYSDIR)/ebin
	$(INSTALL_DATA) $(TARGET_FILES) $(RELSYSDIR)/ebin

release_src_spec: opt
	$(INSTALL_DIR) $(RELSYSDIR)/ebin
	$(INSTALL_DATA) $(TARGET_FILES) $(RELSYSDIR)/ebin
	$(INSTALL_DIR) $(RELSYSDIR)/src
	$(INSTALL_DATA) $(ERL_FILES) $(RELSYSDIR)/src
	sed 's/^\(release_spec:\).*/\1/' Makefile > Makefile.dist
	$(INSTALL_DATA) Makefile.dist $(RELSYSDIR)/src/Makefile
	$(INSTALL_DATA) $(APP_SRC) beam_opcodes.hrl $(RELSYSDIR)/src
	$(INSTALL_DATA) ../Makefile ../vsn.mk $(RELSYSDIR)

release_docs_spec:
