
ERL_TOP = /opt/erlang/current/lib/erlang

EI_ROOT = $(ERL_TOP)/lib/erl_interface-3.5.5.2

EI_INCLUDE = -I$(ERL_TOP)/usr/include -I$(EI_ROOT)/include

EI_LIB = -L$(EI_ROOT)/lib -lei

OUR_C_FLAGS =  -g -Wall -fpic $(EI_INCLUDE)
CFLAGS += $(OUR_C_FLAGS)
CXXFLAGS += $(OUR_C_FLAGS)

EBIN_DIR = .
ERLC = $(ERL_TOP)/bin/erlc
ERLC_FLAGS = -W

TARGETS = drv.beam drv.so

all: $(TARGETS)

clean:
	rm -f $(TARGETS) *.o
	rm -f core erl_crash.dump
	rm -f *~

%.so: %.cc
	$(CXX) $(CXXFLAGS) $< -shared -o $@

%.so: %.o
	$(CC) $(CFLAGS) -shared $< $(EI_LIB) -o $@

%: %.cc
	$(CXX) $(CXXFLAGS) $< -o $@

%.beam: %.erl
	$(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
