CUR_REL_PATH := "rda/netcards_lib"
PACKAGE := rda-netcards_lib

include ../../config.mk

ifdef ENABLE_NLS
  SUBDIRS = po
endif

FW_IMAGES = rvp9wr-elf.srec rvp9wr-sof.srec rcp9orda-elf.srec rcp9orda-sof.srec rcp9asr-elf.srec rcp9asr-sof.srec

LIB = libnetcards.a
APPS = netflash

APPS_OBJS = $(patsubst %,%.o,$(APPS))
LW_RPC_OBJS =	lwrpc.o \
		netcards_lib_nls_init.o
RVP9WR_OBJS =	rvp9wr_netio_cli.o \
		rvp9wr_net.o       \
		rvp9wr_misc.o      \
		rvp9wr_rx.o        \
		rvp9wr_tx.o        \
		wsr98d_diags.o     \
                netcards_diagio.o  \
		rcp9asr_net.o       \
		rcp9asr_netio_cli.o \
		rcp9orda_net.o       \
		rcp9orda_netio_cli.o \
                asr9rim_api.o
RVP9IFD_OBJS= srecord.o flashmem.o progresstxt.o netio.o


OBJS = $(LW_RPC_OBJS) $(RVP9WR_OBJS) $(RVP9IFD_OBJS) $(APPS_OBJS)

PRE_CPPFLAGS += -I../include -I../rdasubs_lib -I../pcicards -I../softplane
LIB_OBJS =  $(LW_RPC_OBJS) $(RVP9WR_OBJS)

LDLIBS += -luser -lpthread  -lm

LDLIBS_netflash =  -lpopt

DEPS = $(patsubst %.o,%.d,$(OBJS))

all: $(APPS) $(LIB_DIR) $(LIB_DIR)/$(LIB) $(FW_IMAGES) testsizes
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

$(LIB_DIR):
	install -d $(LIB_DIR)

install: all $(IRIS_BIN) $(IRIS_RDA_LIB)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	install -m 0775 -o $(IRIS_USER) -g $(IRIS_GROUP) $(STRIP_OPT) $(APPS) $(IRIS_BIN)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(FW_IMAGES) $(IRIS_BIN)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(LIB) $(IRIS_RDA_LIB)

test:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

uninstall:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	if [ -d $(IRIS_BIN) ]; then \
		cd $(IRIS_BIN) && rm -f $(APPS) $(FW_IMAGES); fi
	rm -f $(IRIS_RDA_LIB)/$(LIB)

clean: clean_testsizes
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	rm -f $(APPS) core t_lwrpc *.o *.bak *~ *.d *.srec $(LIB_DIR)/$(LIB)

$(APPS): 

$(LIB): $(LIB_OBJS)
	rm -f $@; $(AR) -rsc $@ $^

$(OBJS): Makefile

netflash: netflash.o $(RVP9IFD_OBJS) $(LW_RPC_OBJS)

# Test program for low level LwRPC socket interface
#
CPPFLAGS_t_lwrpc = -DMAKETEST
LDLIBS_t_lwrpc = -lnetcards -lrdasubs -lconfig -lm

t_lwrpc.o: lwrpc.c
	$(COMPILE.c) $(OUTPUT_OPTION) $<

t_lwrpc: $(LIB_DIR)/$(LIB)

# Test program to verify LwRPC structure sizes are consistent
#
CPPFLAGS_t_sizes_gpp = -DT_TRYNEW=1
CPPFLAGS_t_sizes_gcc = -DT_TRYNEW=1
CPPFLAGS_t_sizes_old = -DT_TRYNEW=0

t_sizes_gpp.C : t_sizes.c
	cp t_sizes.c t_sizes_gpp.C
t_sizes_gcc.c : t_sizes.c
	cp t_sizes.c t_sizes_gcc.c
t_sizes_old.c : t_sizes.c
	cp t_sizes.c t_sizes_old.c

testsizes : t_sizes_gpp t_sizes_gcc t_sizes_old
	./t_sizes_gpp | sort -u > sizes_gpp
	./t_sizes_gcc | sort -u > sizes_gcc
	./t_sizes_old | sort -u > sizes_old
	diff sizes_master sizes_gcc
	diff sizes_master sizes_gpp
	touch testsizes

clean_testsizes :
	rm -f t_sizes_gpp.C t_sizes_gcc.c t_sizes_old.c
	rm -f t_sizes_gpp   t_sizes_gcc   t_sizes_old
	rm -f   sizes_gpp     sizes_gcc     sizes_old  testsizes

-include $(DEPS)
