CUR_REL_PATH := base/himath_lib
PACKAGE := base-himath_lib

include ../shared/config.mk

ifdef ENABLE_NLS
  SUBDIRS = po
endif

INST_INCLUDES = convolute.h himath_lib.h numutil.h
APPS = map_test xypoly_test polyfittest iir_test
LIB = libhimath.a

APPS_OBJS = $(patsubst %,%.o,$(APPS))
LIB_OBJS =	\
		convolute.o \
		covsrt.o \
		fft.o \
		gaussj.o \
		himath_lib_nls_init.o \
		lfit.o \
		linefit.o \
		maproj.o \
		MapProjInt.o \
		matrix.o \
		mrqmin.o \
		poly.o \
		triangle.o \
		xypoly.o

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

PRE_CPPFLAGS += -I../include -I../user_lib
LDLIBS += -lhimath -luser -lm $(LSEARCH_BSD)

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

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

install: all $(IRIS_BIN) $(IRIS_LIB) $(IRIS_INCLUDE)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(LIB) $(IRIS_LIB)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(INST_INCLUDES) $(IRIS_INCLUDE)

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

uninstall:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	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)
