ifndef prefix
    export prefix=$(shell cd ../..;pwd)
endif

TARGET_STATIC  = libpslib.a
include ../Makefile.Globals
CFLAGS := $(CFLAGS_RELOC) -I. -I../sysUtils -I../collections -I.. -I../image -I..

SRC_OBJS = psStats.o  \
           psFunctions.o \
           psMatrix.o \
           psMatrixVectorArithmetic.o \
           psVectorFFT.o \
           psMinimize.o \
 
OBJS = $(addprefix makedir/,$(SRC_OBJS))
 
HEADERS = $(SRC_OBJS:.o=.h)
         
all: $(TARGET_STATIC)

psDataManipErrors.h: psDataManipErrors.dat
	perl ../parseErrorCodes.pl --data=$? $@

# force the creation of a psImage.i for psImage.o (to expand macros).
psMatrixVectorArithmetic.o: psMatrixVectorArithmetic.i

# Rule to make static library

libpslib.a:     $(OBJS)
# The ar option -r is to add/replace object and -s is to create
# a symbol table in the archive
	$(AR) rcs ../$@ $(OBJS)

# Define PHONY target "install" which will install necessary files
# XXX: Do the psConstants.h install.
install: $(TARGET_STATIC)
	install $(HEADERS) $(includedir)
	install psConstants.h $(includedir)


# Define PHONY target "distclean" which will cleanup the distribution
distclean:      clean
	$(RM) ../$(TARGET_STATIC)

# Define PHONY target "clean" which will cleanup the development area
clean:
	@echo "    Deleting intermediate files for 'sysUtils'"
	$(RM) $(OBJS) *.lint $(SRC_OBJS:.o=.i)

cleandep:
	$(RM) $(OBJS:.o=.d)

%.lint: %.c
	splint +posixlib -exportlocal -realcompare $(INCLUDE_GLOBAL) $? > $@; cat $@

%.i: %.c
	$(CC) -E $(CFLAGS) -o $@ $<

makedir/%.o: %.c
	$(CC) -c $(CFLAGS) -o $@ $<

makedir/%.d: %.c
	$(CC) -MM $(CFLAGS) $< > $@.tmp
	sed 's|\($*\)\.o[ :]*|\1.o $@ : |g' $@.tmp > $@
	$(RM) -f $@.tmp

include $(OBJS:.o=.d)
