CUR_REL_PATH := base/antenna_lib
PACKAGE := base-antenna_lib

include ../shared/config.mk

ifdef ENABLE_NLS
  SUBDIRS = po
endif

INST_INCLUDES = antenna_lib.h antenna_int.h
EXES = ant_rcvd ant_xmtd antsim_rcvd antsim_xmtd ant_logd
APPS = $(EXES)

LIB = libantenna.a

APPS_OBJS = $(patsubst %,%.o,$(APPS))
LIB_OBJS =	ant_control.o \
		AntInsert.o \
		ant_iosubs.o \
		ant_misc.o \
		ant_model.o \
		ant_motion.o \
		ant_netrcv.o \
		ant_history.o \
		ant_xh.o \
		antenna_lib_nls_init.o \
		AntSet.o \
		antsim_control.o \
		antsim_misc.o \
		antsim_motion.o \
		bitsim_driver.o \
		iant_pwrp.o \
		iantsim_pwrp.o \
		bite_driver.o \
		sun_position.o

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

PRE_CPPFLAGS += -I../config_lib -I../exthdr_lib -I../include -I../user_lib
PRE_LDFLAGS += -L../lib
LDLIBS += -lconfig -luser -ldl -lm $(LSEARCH_BSD)

LDLIBS_ant_rcvd  = -lexthdr

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

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

install: all $(IRIS_INCLUDE) $(IRIS_BIN) $(IRIS_LIB) $(IRIS_CONFIG_TMPL_LOGROTATE)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(INST_INCLUDES) $(IRIS_INCLUDE)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(LIB) $(IRIS_LIB)
	install -m 0775 -o $(IRIS_USER) -g $(IRIS_GROUP) $(STRIP_OPT) $(EXES) $(IRIS_BIN)
	install -m 0644 -o ${IRIS_USER} -g ${IRIS_GROUP} sigmet-antlib $(IRIS_CONFIG_TMPL_LOGROTATE)

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

uninstall:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	if [ -d $(IRIS_BIN) ]; then cd $(IRIS_BIN) && rm -f $(EXES); fi
	if [ -d ${IRIS_CONFIG_TMPL_LOGROTATE} ]; then \
		cd ${IRIS_CONFIG_TMPL_LOGROTATE} && rm -f sigmet-antlib; fi
	rm -f $(IRIS_LIB)/$(LIB)
	if [ -d $(IRIS_INCLUDE) ]; then \
		cd $(IRIS_INCLUDE) && rm -f $(INST_INCLUDES); fi

$(APPS): $(LIB_DIR)/$(LIB)

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

$(OBJS): Makefile

-include $(DEPS)
