# $Id: Makefile,v 1.9 1997/08/12 19:27:35 dhb Exp $
# $Log: Makefile,v $
# Revision 1.9  1997/08/12 19:27:35  dhb
# Removed unset NCDFDIR from the call to the interface makefile.  Was
# returning non-zero status causing AIX make to abort.
#
# Revision 1.8  1997/08/08 00:16:19  dhb
# Added define for MACHINE to CFLAGS
#
# Revision 1.7  1997/08/03 19:43:44  dhb
# Commented potentially recursive macros
#
# Revision 1.6  1997/08/01 21:35:23  dhb
# Fixed comment leader to use Makefiel comment char
#
# Revision 1.5  1997/07/29 18:26:20  venkat
# Added RCS Log and Id headers

#####################################################################
# The macros passed down from the machine-specific top-level Makefile
#####################################################################

# Since almost all of these macros are set directly on the make
# command line, we shouldn't need to set them here and should not
# as a macro like this can result in recursive macro errors with
# some makes

# OS = $(OS)

# CC = $(CC)
CFLAGS = $(COPT) -D$(OS) -D$(MACHINE)
# CPP = $(CPP)
# LD = $(LD) 
# LDFLAGS = $(LDFLAGS) 
# AR = $(AR)
# RANLIB = $(RANLIB)

INSTALL_DIR = $(INSTALL)


LIBRARY_NAME 	= 	diskio
STARTUP		=	diskiolib.g
STRUCTURES 	= 	diskio_struct.h
EXT_HEADER	= 	diskio_ext.h
TARGET_OBJ	=	diskiolib.o

OBJECTS = gen_diskio.o gen_variable.o gen_metadata.o diskio_utilfunc.o copyrights.o
INTERFACE_OBJECTS = interface/fflib.o


# ============================================
# everything below here should maintain itself
# ============================================

SHELL		=	/bin/sh

# GENINST is passed in from the Usermake makefile.  If you're not
# using Usermake, either edit your top level makefile to pass it
# in or hard code the GENESIS 2.0 installation directory here.

GENESIS_INCLUDE	= 	-I. -I../sim -I../sys -I../ss -I../shell 
HEADERS 	=  	$(STRUCTURES)
INCDIRS		=  	-I. -I..	

default : $(TARGET_OBJ)

$(OBJECTS) : $(HEADERS) 


$(INTERFACE_OBJECTS) : interfacelib

interfacelib:
	@(for subdir in interface; do echo cd $$subdir; cd $$subdir; make INCDIRS_IN="$(INCDIRS)" CC_IN="$(CC)" CFLAGS_IN="$(CFLAGS)" CPP_IN="$(CPP)" LD_IN="$(LD)" LDFLAGS_IN="$(LDFLAGS)"; cd ..;done)
	

$(LIBRARY_NAME)_g@.c $(LIBRARY_NAME)_g@.h: $(STARTUP)
	- ../sys/code_g $(STARTUP) $(EXT_HEADER) $(LIBRARY_NAME) \
	-cstartup copyright_fileformats

# make the data structure section of the symbol table

$(LIBRARY_NAME)_d@.c : $(STRUCTURES) ../sys/code_sym
	- $(CPP) $(STRUCTURES) /tmp/$(STRUCTURES) $(GENESIS_INCLUDE)
	- ../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) ../lib/code_func
	- ../sys/code_func $(FUNCTIONS) $(LIBRARY_NAME) \
	  > $(LIBRARY_NAME)_f@.c

# make the library header function

$(LIBRARY_NAME)_l@.c: $(LIBRARY_NAME)_g@.c $(LIBRARY_NAME)_d@.c $(FSYMBOLTAB_C) ../sys/code_lib $(OBJECTS)
	- ../sys/code_lib $(LIBRARY_NAME) -o $(LIBRARY_NAME)_l@.c

SYMBOLTAB = $(LIBRARY_NAME)_d@.o $(LIBRARY_NAME)_g@.o $(FSYMBOLTAB) $(LIBRARY_NAME)_l@.o

$(TARGET_OBJ): $(OBJECTS) $(INTERFACE_OBJECTS) $(SYMBOLTAB) 
	$(LD) $(LDFLAGS) -r -o $(TARGET_OBJ) $(OBJECTS) $(INTERFACE_OBJECTS) $(SYMBOLTAB) 

clean:
	@(for i in interface; do echo cd $$i; cd $$i; make clean; cd ..; done)
	-(rm -rf *.o; rm -rf *@.[ch])

install:
	@(for i in interface; do echo cd $$i; cd $$i; make INSTALL_IN="$(INSTALL_DIR)" RANLIB_IN="$(RANLIB)" install; cd ..; done)
	cp diskiolib.o $(INSTALL_DIR)/lib
	


# =========================================
	
#	Suffix rules 

# =========================================

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