#
#  Generic make commands for rebuilding a library from source files
#  For GNU make; will not work with most other make programs
#
#  Usage:
#	SOURCES = a.c b.c ...
#	LIBNAME = libtsp	# default libtsp (cc) or libuti (f77)
#       HEADERS = a.h
#	include Make_lib
#
#  Optional make variables:
#	DEFS = ...		# passed to C-preprocessor
#	libdir = ...		# library directory
#	includedir = ...	# include file directory
#
#  Environment variable:
#	tspdir			# root directory for lib and include
#				#   (default /usr/local)

# $Id: Make_lib 1.19 1997/05/21 libtsp-v3r0 $

include Make_kernel

# Object modules
OBJ_1 = $(SOURCES:.c=.o)
OBJ_2 = $(OBJ_1:.f=.o)
OBJECTS = $(OBJ_2:.F=.o)

LIB_MODULES = $(LIB)($(OBJECTS))

.PRECIOUS: $(LIB)
.PHONY:	lint test clean

# Default target: update the library
$(LIB):	$(LIB_MODULES)
	ranlib $(LIB)
	@echo $(LIB) updated

ifdef HEADERS
$(LIB_MODULES):	$(HEADERS)
endif

# run test programs
test:
	@-test -d test && cd test && $(MAKE) test

# run lint
lint:	$(SOURCES)
	$(LINT) -I$(includedir) $(LINTFLAGS) $(DEFS) $?

# clean up object files
clean:
	rm -f $(OBJECTS)

# implicit C compile rule with include directory and DEFS
# implicit Fortran (with preprocessor) compile rule with DEFS
.c.o:
	$(CC) -c -I$(includedir) $(CFLAGS) $(CPPFLAGS) $(DEFS) $< -o $@
.F.o:
	$(FC) -c $(FFLAGS) $(CPPFLAGS) $(DEFS) $< -o $@
