#
# Makefile for emptylib.o
# Most of this need not be modified, except for changing the
# name 'empty' to something more appropriate.
#

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
SIMINCLUDE 	= 	-I. -I$(INSTALL_INCLUDE)
LIBRARY_NAME 	= 	empty
FUNCTIONS 	= 	emptyfuncs
STRUCTURES 	= 	empty_struct.h
EXT_HEADER	=	empty_ext.h
TARGET_OBJ	= 	emptylib.o

default: $(TARGET_OBJ) 

#
# This is where the user defines the files being compiled.
#

OBJECTS =	\
		empty.o 


HEADERS = 	\
		empty_ext.h \
		empty_struct.h

#
#
# The user need not modify anything beyond here
#
#

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

$(OBJECTS) : $(HEADERS)

# make the data structure section of the symbol table

$(LIBRARY_NAME)_d@.c : $(STRUCTURES) $(INSTALL_LIB)/code_sym
	- $(CPP) $(STRUCTURES) /tmp/$(STRUCTURES) $(SIMINCLUDE)
	- $(INSTALL_LIB)/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) $(INSTALL_LIB)/code_func
	- $(INSTALL_LIB)/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 $(INSTALL_LIB)/code_lib $(OBJECTS)
	 - $(INSTALL_LIB)/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 *.o *@.c)
