CC=gcc

PROG = ethmngr
SRC_DIR = src

OBJS = $(addprefix $(SRC_DIR)/, ethmngr.o helper.o ethernet.o dmlayer.o vendor_ethernet.o)

-include Makefile.diag.inc

PROG_CFLAGS = $(CFLAGS) $(DIAG_CFLAGS) -Werror -fstrict-aliasing -fPIC -g

ifeq ($(filter -DBBF_VENDOR_PREFIX=%,$(PROG_CFLAGS)),)
PROG_CFLAGS += -DBBF_VENDOR_PREFIX=\"X_IOWRT_EU_\"
endif

# MUSL has the following issue in snprintf, so it is ignored:
PROG_CFLAGS += -Wno-format-nonliteral

PROG_LDFLAGS = $(LDFLAGS)
PROG_LIBS += -luci -lubus -lubox -ljson-c -lblobmsg_json -lbbfdm-ubus -lbbfdm-api \
	     -lnl-genl-3 -lnl-3 -leasy -lethernet

%.o: %.c
	$(CC) $(PROG_CFLAGS) -c -o $@ $<

.PHONY: all clean

all: $(PROG)

$(PROG): $(OBJS)
	$(CC) $(PROG_LDFLAGS) -o $@ $^ $(PROG_LIBS)

clean:
	rm -rf *.o $(PROG) $(addprefix $(SRC_DIR)/, *.o)
