# TODO: Is it possible to change code so that we use any CAN bus card 
# (at least from  Kvaser) with the same binary image?
 
# Use this settings, if Kvaser USBcanII is used.
CANBUS_IFACE = kvaser
CANBUS_LIB = canlib
# Use this settings, if PEAK-system's PCAN-PCI is used.
# CANBUS_IFACE = peak_pci
# CANBUS_LIB = pcan

CUR_REL_PATH := "rda/rcp8/open"

include ../../../config.mk

ifdef PROFILE_RCP8
LDFLAGS += -pg
CFLAGS += -pg -D__PROFILING
endif

NRP_LIBS = -lnrp -lrsnrpz
ifdef KILL_RS_POWERMETER
CFLAGS += -DKILL_RS_POWERMETER
NRP_LIBS = 
endif

LIB = librcp8_open.a

CFLAGS += $(GPIBFLAG)

PRE_CPPFLAGS += -I../../pcicards -I../../rdasubs_lib -I../../netcards_lib -I../../softplane
PRE_LDFLAGS = -L${SB_RDA_LIB}
LDFLAGS  += -L${IRIS_RDA_LIB} -L$(IRIS_DYN_LIB)

LDLIBS = -lrcp8_core -lrcp8_open -lrcp8_site -lsoftplane -lpcicards -lnetcards \
	    -lrdasubs -lantenna -lconfig -lhimath -luser -lpthread $(LGPIB) \
	    -l$(CANBUS_LIB) $(NRP_LIBS) -lrt -lm

#Needed for 3rd party builds:
LDLIBS += $(EXTRA_LIBS)

OPEN_C_OBJS =	andrew_acu_main.o \
		appsys_main.o \
		ara_acu3_main.o \
		canbus_main.o \
		can_$(CANBUS_IFACE).o \
		dau_main.o \
		dcu_main.o \
		dehydrator.o \
		dualsys.o \
		gigacom_main.o \
		eec_ddc_main.o \
		rpm_ped_main.o \
		klystron_main.o \
		power_monitor.o \
		hpib_main.o \
		kavouras_tcu_main.o \
		melco_tky01.o \
		orbit_main.o \
		ps_tr1163.o \
		rcp_limits.o \
		rcp8_lib_nls_init.o \
		seapath_inu_main.o \
		shaft_sim.o \
		ShaftAutoCal.o \
		subs_monitor.o \
		subs_open.o \
		subs_setup.o \
		tdrs_ped_rcv_main.o \
		tdrs_ped_xmt_main.o \
		tsc_twt_main.o \
		build_date.o

ROOTEXES = rcp8

CONFS = rcp8.conf rcp8_eec_ddc_token_config.conf

INCLUDE_FILES = rcp8.h rcp8main.h

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

all: $(LIB_DIR) $(ROOTEXES) $(LIB_DIR)/$(LIB) test_inu

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

rcp8: rcp8.o $(LIB_DIR)/$(LIB)

test_inu: test_inu.o $(LIB_DIR)/$(LIB)

build_date.c:
	echo "const char *rcp8OpenDate_c = \"`date`\" ;" > build_date.c

${LIB}: $(OPEN_C_OBJS)
	rm -f $@; $(AR) -rsc $@ $(OPEN_C_OBJS) build_date.o

install: all $(IRIS_BIN) $(IRIS_RDA_LIB) $(IRIS_CONFIG_TMPL) $(IRIS_CONFIG_TMPL_RCD) $(IRIS_INCLUDE) $(SYS_INIT_D)
	install -m 6775 -o root -g $(IRIS_GROUP) $(STRIP_OPT) $(ROOTEXES) $(IRIS_BIN)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(LIB) $(IRIS_RDA_LIB)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) rcp8.rc $(IRIS_CONFIG_TMPL_RCD)/rcp8
	install -m 0755 -o root         -g root          rcp8.rc $(SYS_INIT_D)/rcp8
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(CONFS) $(IRIS_CONFIG_TMPL)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(INCLUDE_FILES) $(IRIS_INCLUDE)

test:

uninstall:
	if [ -d $(IRIS_BIN) ]; then cd $(IRIS_BIN) && rm -f $(ROOTEXES); fi
	rm -f $(IRIS_RDA_LIB)/$(LIB)
	if [ -d $(IRIS_CONFIG_TMPL_RCD) ]; then cd $(IRIS_CONFIG_TMPL_RCD) && rm -f rcp8; fi
	if [ -d $(SYS_INIT_D) ]; then cd $(SYS_INIT_D) && rm -f rcp8; fi
	if [ -d $(IRIS_CONFIG_TMPL) ]; then cd $(IRIS_CONFIG_TMPL) && rm -f $(CONFS); fi
	if [ -d $(IRIS_INCLUDE) ]; then cd $(IRIS_INCLUDE) && rm -f $(INCLUDE_FILES); fi

clean:
	rm -f core $(ROOTEXES) test_inu *.o *.a *~ *.d *.d.bak $(LIB_DIR)/$(LIB) build_date.c

$(OBJS): Makefile

-include $(DEPS)
