MAKEFLAGS    += -r -R

C_FLAGS      := $(CFLAGS) -DNDEBUG -Wall -Wno-error -O2 \
	-ggdb -fPIC -D_GNU_SOURCE \
	-I$(STAGING_DIR)/usr/include/dy_utils \
	-I$(STAGING_DIR)/usr/include/hiredis

LD_FLAGS     := $(LDFLAGS) -ldyutils -lubox \
	-lipc_helper -lpthread -lhiredis -lubuslog -lmodbus
SOURCES      := $(wildcard *.c)
OBJECTS      := $(SOURCES:.c=.o)
ifneq ($(findstring mips32,$(CFLAGS)),)
# fix linking error for mips target
LD_FLAGS     += -latomic
endif

TARGETS       = modbus_tcp_slave $(OBJECTS)

.PHONY: all clean
all: $(TARGETS)

modbus_tcp_slave: main.o modbus_tcp_slave.o
	$(CC) -o $@ $^ $(LD_FLAGS)

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

clean:
	rm -rf *.o $(TARGETS)
