#
# Makefile for userlib.o
#

LIBS 		=  	-lm
CPP 		= 	/lib/cpp
CFLAGS 		= 	-g -D$(MACHINE) $(DEC_HACK)
SIM 		= 	../sim
SYS 		= 	../sys
INTERP 		= 	../shell
INSTALL_DIR =	$(INSTALL)
INSTALL_LIB 	= 	$(INSTALL_DIR)/lib
INSTALL_INCLUDE	= 	$(INSTALL_DIR)/include
INSTALL_STARTUP	= 	$(INSTALL_DIR)/startup
SIMINCLUDE 	= 	-I. -I$(SYS) -I$(SIM) -I$(INTERP)
LIBRARY_NAME 	= 	segment
FUNCTIONS 	= 	segfuncs
STRUCTURES 	= 	seg_struct.h
EXT_HEADER	=	seg_ext.h
TARGET_OBJ	=	seglib.o

default : $(TARGET_OBJ)

OBJECTS = 	\
	 	Ca_concen.o \
		balance.o \
		channela.o \
		channelb.o \
		channelc.o \
		channelc2.o \
		compartment.o \
		leakage.o \
		manconduct.o \
		pc_apply.o \
		pc_init.o \
		pc_input.o \
		pc_thresh.o \
		pc_update.o \
		rcunit.o \
		site.o \
		symcompart.o \
		unit.o 	


HEADERS = 	\
		seg.h 		\
		seg_defs.h	\
		seg_struct.h	\
		seg_ext.h	

# $(OBJECTS) : $(HEADERS) 

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

# 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 -f *.o *@.c)
