#
VPATH = ./priv

ifeq ($(BOOSTINCLUDE),)
BOOSTINCLUDE := /usr/local/include
endif
ifeq ($(BOOSTLIB),)
BOOSTLIB := /usr/local/lib
endif

ERLANG_PATH = $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
CFLAGS = -I$(ERLANG_PATH) -I$(BOOSTINCLUDE) -fPIC -g -O3 -flto -mtune=generic -Wno-write-strings
LDFLAGS = -shared -undefined dynamic_lookup $(BOOSTLIB)/libboost_math_c99.a $(BOOSTLIB)/libboost_random.a

CC = g++

SRCS = boostnif.c
OBJS = $(SRCS:.c=.o)

priv/libboostnif.so: $(OBJS)
	find / -name 'libboost*.a' -ls
	$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)

.PHONY: clean

clean:
	rm -f priv/libboostnif.so
