CUR_REL_PATH := base/fileformats_lib

include ../../config.mk

TESTS = unit_test
APPS = $(TESTS)
INST_INCLUDES = fileformats_lib.h
LIB = libfileformats.a

APPS_OBJS = $(patsubst %,%.o,$(APPS))
PRE_CPPFLAGS += -I../include -I../user_lib -I../himath_lib
LDLIBS += -luser -ljpeg -lpng -ltiff -lgeotiff -lm

LIB_OBJS = read_gif.o \
	read_jpeg.o \
	read_tiff.o \
	read_pbm.o \
	read_picfile.o \
	write_bmp.o \
	write_gif.o \
	write_jpeg.o \
	write_png.o \
	write_tiff.o \
	write_ps.o \
	write_file_format.o \
	ColormapFromRgb.o \
	conv24to8.o \
	printer_func.o

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

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

test: $(TESTS)
	$(patsubst %,./%;,$(TESTS))
	unit_check

clean:
	rm -f *.o *~ *.a *.d $(APPS) $(LIB_DIR)/$(LIB) unit_test_results.*

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

uninstall:
	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

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

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

$(OBJS): Makefile

-include $(DEPS)
