###############################################################################
##
##  Makefile:   sysUtils
##
##  $Revision: 1.22 $  $Name: not supported by cvs2svn $
##  $Date: 2004-09-09 22:21:00 $
##
##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
###############################################################################

# Define variable prefix to the top level project - psLib
# This is necessary for definition is Makefile.Globals uses prefix

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

# Define the two targets to be built

TARGET_STATIC  = libpslib.a

# Include the make global definitions for the project

include ../Makefile.Globals

# Set CFLAGS used by the implicit rule to compile .c

CFLAGS := $(CFLAGS_RELOC) -I../collections -I../dataManip -I../sysUtils -I../include -I..

# Define the source objects
 
SRC_OBJS = psMemory.o    \
           psError.o     \
           psTrace.o     \
           psLogMsg.o    \
           psAbort.o     \
           psString.o    \
           psErrorCodes.o 

OBJS = $(addprefix makedir/,$(SRC_OBJS))

HEADERS = $(SRC_OBJS:.o=.h) psType.h

# Define PHONY target "all" which will make all the necessary items

all: $(TARGET_STATIC)

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

psErrorCodes.c: ../psErrorCodes.dat
	perl ../parseErrorCodes.pl --data=$? $@

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


# 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

install: $(TARGET_STATIC) 
	install $(HEADERS) $(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

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

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

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)
