#
# Makefile for toollib.o
#

CPP 		= 	/lib/cpp
CFLAGS 		= 	-g -D$(MACHINE) $(DEC_HACK)
INSTALL_DIR	= 	$(INSTALL)
INSTALL_LIB 	= 	$(INSTALL_DIR)/lib
INSTALL_INCLUDE	= 	$(INSTALL_DIR)/include
INSTALL_STARTUP	= 	$(INSTALL_DIR)/startup
OLF_INCLUDE 	=	../olf
SS_INCLUDE 	=	../ss
SYS	 	=	../sys
SEG_INC 	=	../segment
HH_INC 		=	../hh
BUF_INC 	=	../buffer
SHELL_INCLUDE 	=	../shell
SIMINCLUDE 	= 	-I. -I$(SYS) -I$(SHELL_INCLUDE) -I../sim -I$(OLF_INCLUDE) -I$(SS_INCLUDE) -I$(SEG_INC) -I$(HH_INC) -I$(BUF_INC)
LIBRARY_NAME 	= 	tools
FUNCTIONS 	= 	toolfuncs
STRUCTURES 	= 	tool_struct.h
EXT_HEADER	=	tool_ext.h
TARGET_OBJ	= 	toollib.o

default: $(TARGET_OBJ)

OBJECTS =	\
		cell_parser.o \
		cell_parms.o \
		traverse.o \
		coord_geom.o \
		script_hack.o \
		cell_sheet.o \
		conn_3d.o \
		curvefit3.o \
		readplot.o \
		spike_parms3.o \
		rall_calc.o \
		mrqmin.o \
		mrqcof.o \
		gaussj.o \
		nrutil.o \
		covsrt.o \
		spline.o \
		brent.o \
		zbrent.o \
		moment.o 

HEADERS = 	\
		tools.h 

.c.o:
	$(CC) $(CFLAGS) $(SIMINCLUDE) $< -c 

# $(OBJECTS) : $(HEADERS)

# make the data structure section of the symbol table

$(LIBRARY_NAME)_d@.c : $(STRUCTURES) $(SYS)/code_sym
	- $(CPP) $(STRUCTURES) /tmp/$(STRUCTURES) $(SIMINCLUDE)
	- $(SYS)/code_sym /tmp/$(STRUCTURES) $(LIBRARY_NAME) \
	  -I $(EXT_HEADER) -NI -o $(LIBRARY_NAME)_d@.c
	- rm /tmp/$(STRUCTURES)

# make the function list section of the symbol table

$(LIBRARY_NAME)_f@.c : $(FUNCTIONS) $(SYS)/code_func
	- $(SYS)/code_func $(FUNCTIONS) $(LIBRARY_NAME) \
	  > $(LIBRARY_NAME)_f@.c

# make the library header function
$(LIBRARY_NAME)_l@.c : $(LIBRARY_NAME)_f@.c $(LIBRARY_NAME)_d@.c $(SYS)/code_lib $(OBJECTS)
	 - $(SYS)/code_lib $(LIBRARY_NAME) -o $(LIBRARY_NAME)_l@.c



SYMBOLTAB = $(LIBRARY_NAME)_d@.o $(LIBRARY_NAME)_f@.o $(LIBRARY_NAME)_l@.o

$(TARGET_OBJ): $(OBJECTS) $(SYMBOLTAB)
	ld -r -o $(TARGET_OBJ) $(OBJECTS) $(SYMBOLTAB)

install: $(TARGET_OBJ)
	-(cp $(TARGET_OBJ) $(INSTALL_LIB))
	-(cp *.h $(INSTALL_INCLUDE))
	-(cp *.g $(INSTALL_STARTUP))

clean:
	-(rm -rf *.o *@.c)
