#
# Makefile for simlib.o
#

CPP 		= 	/lib/cpp
CFLAGS 		= 	-g -D$(MACHINE)  $(DEC_HACK)
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$(INTERP)
LIBRARY_NAME 	= 	basic
FUNCTIONS 	= 	simfuncs
STRUCTURES 	= 	sim_struct.h
EXT_HEADER	=	sim_ext.h
TARGET_OBJ	= 	simlib.o

default: $(TARGET_OBJ) 

OBJECTS =	\
		sim_access.o \
		sim_action.o \
		sim_address.o \
		sim_attach.o \
		sim_base.o \
		sim_bindings.o \
		sim_buffer.o \
		sim_call.o \
		sim_check.o \
		sim_class.o \
		sim_clock.o \
		sim_connect.o \
		sim_copy.o \
		sim_create.o \
		sim_current.o \
		sim_delete.o \
		sim_detach.o \
		sim_element.o \
		sim_elemlist.o \
		sim_estack.o \
		sim_event.o \
		sim_fields.o \
		sim_file.o \
		sim_find.o \
		sim_get.o \
		sim_help.o \
		sim_index.o \
		sim_intgrt.o \
		sim_item.o \
		sim_list.o \
		sim_main.o \
		sim_malloc.o \
		sim_mask.o \
		sim_map.o \
		sim_move.o \
		sim_msg.o \
		sim_name.o \
		sim_notes.o \
		sim_object.o \
		sim_ops.o \
		sim_project.o \
		sim_position.o \
		sim_reset.o \
		sim_response.o \
		sim_save.o \
		sim_sched.o \
		sim_set.o \
		sim_simulate.o \
		sim_stack.o \
		sim_status.o \
		sim_show.o \
		sim_step.o \
		sim_strings.o \
		sim_tform.o \
		sim_tree.o \
		sim_tstack.o \
		sim_valid.o \
		sim_value.o \
		nsim_wildcard.o

HEADERS = 	\
		$(SYS)/header.h \
		$(SYS)/profile.h \
		sim_defs.h \
		sim_ext.h \
		sim_struct.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

SYMBOLTAB = $(LIBRARY_NAME)_d@.o $(LIBRARY_NAME)_f@.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)
