CUR_REL_PATH := base/user_lib
PACKAGE := base-user_lib

include ../shared/config.mk

ifdef ENABLE_NLS
  SUBDIRS = po
endif

PRE_CPPFLAGS += -I../misc_lib -I../himath_lib -I../include
INST_INCLUDES = user_lib.h nlscommon.h messages.h
LIB = libuser.a

TESTS = test_c \
	test_data \
	test_shmem \
	test_signal \
	test_sphere \
	test_time \
	trtvec


OBJS =	angle.o \
	AngleNames.o \
	byteops.o \
	c_cmd_lookup.o \
	ClassifierNames.o \
	compress.o \
	DataConvert.o \
	DataConvertClass.o \
	DataNames.o \
	data_types.o \
	dft.o \
	dspcustom.o \
	EarthCurve.o \
	error_report.o \
	fambiguous_range.o \
	fileops.o \
	fnyquist_vel.o \
	help.o \
	KiloCount.o \
	lowmath.o \
	mapio.o \
	message_support.o \
	msgque.o \
	process.o \
	ProjectionNames.o \
	rtvec.o \
	schedule.o \
	semaphore.o \
	shmem.o \
	sig_microSleepExact.o \
	sig_subs.o \
	sig_system.o \
	SocketConnect.o \
	SocketIo.o \
	SocketSupport.o \
	sphere.o \
	str_subs.o \
	swap.o \
	TimeNames.o \
	timesubs.o \
	ttyio.o \
	UdpSupport.o \
	unlevelize.o \
	user_lib_nls_init.o \
	username.o \
	VaxData.o \
	window.o

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

LDLIBS += -luser -lm $(LSEARCH_BSD)

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

check: test_c test_run

test_run: test_c
	test_c ; touch test_run

trtvec.o:  rtvec.c
	$(COMPILE.c) -DSELFTEST $(OUTPUT_OPTION) $<

#trtvec: trtvec.o

prtvec: trtvec
	rm -f trtvec.dat ; ./trtvec > trtvec.dat
	echo 'set grid ;' \
	     'plot "trtvec.dat" using 1:2 title "All Data" with points ps 2,' \
	     '     "trtvec.dat" using 1:3 title "Drop One" with points ps 1,' \
	     '     "trtvec.dat" using 1:4 title "Drop Two" with points ps 0,' \
	     '     "trtvec.dat" using 1:5 title "Original" with points pt 3 ps 3 ;' \
	     'pause 1200 "Hit ^C to exit "' | gnuplot

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

install: all $(IRIS_INCLUDE) $(IRIS_BIN) $(IRIS_LIB)
	$(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)

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

uninstall:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	if [ -d $(IRIS_LIB) ]; then cd $(IRIS_LIB) && rm -f $(LIB); fi
	if [ -d $(IRIS_INCLUDE) ]; then \
		cd $(IRIS_INCLUDE) && rm -f $(INST_INCLUDES); fi


tests: $(TESTS) trtvec

$(TESTS) trtvec: $(LIB_DIR)/$(LIB)

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

$(OBJS): Makefile

-include $(DEPS)
