towerops/c_src/Makefile

39 lines
790 B
Makefile

# Makefile for building towerops_nif.so
# Erlang NIF paths
ERL_INCLUDE_PATH ?= $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
# Detect OS
UNAME_S := $(shell uname -s)
# Compiler flags
CFLAGS = -O3 -std=c99 -fPIC -Wall -Wextra -Wno-unused-parameter
CFLAGS += -I$(ERL_INCLUDE_PATH)
# Linker flags
LDFLAGS = -lnetsnmp
ifeq ($(UNAME_S),Darwin)
# macOS specific flags
LDFLAGS += -dynamiclib -undefined dynamic_lookup
else
# Linux flags
LDFLAGS += -shared
endif
# Target
TARGET = ../priv/towerops_nif.so
# Source files
SRC = towerops_nif.c
all: $(TARGET)
$(TARGET): $(SRC)
@mkdir -p ../priv
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
clean:
rm -f $(TARGET)
.PHONY: all clean