#########################################################################
#
#    (c) Copyright 1992,1993,1994 by G & A Technical Software, Inc.,
#              28 Research Drive, Hampton, Virginia, 23666.
#
#  All Rights Reserved. No part of this software or publication may be
#  reproduced, stored in a retrieval system, or transmitted, in any form
#  or by any means, electronic, mechanical, photocopying, recording, or
#  otherwise without the prior written permission of G & A Technical
#  Software, Inc.
#
#########################################################################
#
# RCSID: $Id: Makefile,v 2.1 1994/07/08 17:52:19 jcburt Exp $
#
# Log: $Log: Makefile,v $
# Revision 2.1  1994/07/08  17:52:19  jcburt
# Updated typedefs, defines and function protypes to allow recursive
# parsing of pct files. Enabled use of sub-PDT files and scoping of
# datasets. Datasets used in a pct must be defined either in the
# associated pdt file or the pdt file associated with the direct
# ancestors of the current pct file.
#
# DataSet functions and subroutines now have an additional parameter
# passed to them, indicating the number of parameters passed in the
# dataset list, i.e. was: function(DataSet **dl)
#                    now: function(int nargs, DataSet **dl)
# Parameters passed to the dataset routines from the PCT level are all
# still contained in the dataset list, nargs is during the function or
# subroutine call from s3_exec_enode
#
# Revision 2.0.0.1  1994/06/28  18:48:26  jcburt
# S3 Version 2.0 Initial Source
#
#
#########################################################################
#
#  Makefile for the S3 software development system
#
#########################################################################
MAJOR	=	2
MINOR	=	1
PATCH	=	1

#
# Options for IBM RS/6000 AIX 3.2.0
#
#CC		= xlc
#LEX		= flex
#LFLAGS		=
#YACC		= bison
#YFLAGS		= -d
#OPTIONS		= -O
#INCLUDES	= -I../include
#LINCLUDES	=  -L. -L../lib -L/usr/local/lib -L/u/burton/lib
#LDFLAGS		= -ls3_2.0 -lm -lld
#SHLDFLAGS	= -lS3 -lm -ldl -lc
#DLOADFLAGS	= '"$(LINCLUDES) -lS3 -lm -lxlf"'
#SLOADFLAGS	= '"$(LINCLUDES) -lS3 -lld -lm -lxlf"'
#DEFINES		= -D_ALL_SOURCE -D_PARAMETERS_ON_STACK -D_HAVE_LOAD\
#		  -DD_LOADFLAGS=$(DLOADFLAGS) \
#		  -DS_LOADFLAGS=$(SLOADFLAGS)
#
# Options for IBM RS/6000 AIX 4.1
#
#CC		= xlc
#LEX		= flex
#LFLAGS		=
#YACC		= bison
#YFLAGS		= -d
#OPTIONS		= -O
#INCLUDES	= -I../include
#LINCLUDES	=  -L. -L../lib -L/usr/local/lib -L/u/burton/lib
#LDFLAGS		= -lS3 -lld -lm -lc
#SHLDFLAGS	= -lS3 -lm -lld -lc
#DLOADFLAGS	= '"$(LINCLUDES) -lS3 -lxlf90 -lxlf -lm -lc"'
#SLOADFLAGS	= '"$(LINCLUDES) -lS3 -lld -lxlf90 -lxlf -lm -lc"'
#DEFINES		= -D_ALL_SOURCE -D_PARAMETERS_ON_STACK -D_HAVE_LOAD -D_BROKEN_MAKE\
#		  -DD_LOADFLAGS=$(DLOADFLAGS) \
#		  -DS_LOADFLAGS=$(SLOADFLAGS)
#
# Options for LINUX 1.2.8
#
MAKE		= make
CC		= gcc
FC		= gfortran
LEX		= flex
LFLAGS		= -CF
#LFLAGS		= -d
YACC		= bison
YFLAGS		= -l -d
#OPTIONS		= -O3 -fPIC
OPTIONS		= -O -g 
INCLUDES	= -I../include
LINCLUDES	= -L./ 
#LDFLAGS		= 
LDFLAGS		=  -ldl
#SHLDFLAGS	= -lS3 -ldl -lm -lc
#SHLDFLAGS	= -ldl -lm -lc
DLOADFLAGS	= '"-lS3 -lgfortran -lstdc++ -lmm"'
#SLOADFLAGS	= '"-lS3 -lf2c -lgcc -lm -ldl -lc"'
DEFINES		= -DD_LOADFLAGS=$(DLOADFLAGS) \
          -D_ALL_SOURCE -D_PARAMETERS_ON_STACK -D_HAVE_DL \
		  -DC_COMPILER='"$(CC)"' -DF_COMPILER='"$(FC)"' \
		  -DMAKE_COMMAND='"$(MAKE)"' \
		  -DD_LOADFLAGS=$(DLOADFLAGS) \
		  -DS_LOADFLAGS=$(SLOADFLAGS)



#CC		= gcc
#LEX		= flex
#LFLAGS		=
#YACC		= bison
#YFLAGS		= -d
#OPTIONS		= -g
#DEFINES		= -D_HAVE_DLD -D_PARAMETERS_ON_STACK
#INCLUDES	= -I../include
#LINCLUDES	=  -L. -L../lib -L/usr/local/lib 
#LDFLAGS		= -ls3_2.0 -lm -ldld -lc
#
# DEC Alpha OSF/1
#
#CC		= cc
#LEX		= flex
#LFLAGS		=
#YACC		= bison
#YFLAGS		= -d
#OPTIONS		= -O3
#DEFINES		= -D_ALL_SOURCE -D_PARAMETERS_ON_STACK -D_HAVE_DL
#INCLUDES	= -I../include
#LINCLUDES	=  -L. -L../lib -L/usr/local/lib 
#LDFLAGS		= -ls3_2.0 -lm -lc



LIB		= libS3.$(MAJOR).$(MINOR).$(PATCH).a
LIBMAJ		= libS3.a
SHLIB		= libS3.so.$(MAJOR).$(MINOR).$(PATCH)
SHLIBMAJ	= libS3.so.$(MAJOR)
LLIB		= ../lib/$(LIB)
LIBDIR		= ../../../lib
BINDIR		= ../../../bin
#LIBDIR		= /u/burton/lib
#BINDIR		= /u/burton/bin
PROG		= s3exec
MAIN		= s3_main.c

CFLAGS		= $(OPTIONS) $(DEFINES) $(INCLUDES)

DEFS = 	../include/s3_defines.h \
	../include/s3_typedefs.h \
	../include/s3_externals.h \
	../include/s3_globals.h \
	../include/s3_machdep.h

OBJS	=	$(LIB)(s3_callcr.o) \
		$(LIB)(s3_callfr.o) \
		$(LIB)(s3_callr.o) \
		$(LIB)(s3_dlfcn.o) \
		$(LIB)(s3_dml.o) \
		$(LIB)(s3_dml_dl.o) \
		$(LIB)(s3_error.o) \
		$(LIB)(s3_executive.o) \
		$(LIB)(s3_globals.o) \
		$(LIB)(s3_idl_rpc.o) \
		$(LIB)(s3_link_executables.o) \
		$(LIB)(s3_memory.o) \
		$(LIB)(s3_parser.o) \
		$(LIB)(s3_lexer.o) \
		$(LIB)(s3_parser_funcs.o) \
		$(LIB)(s3_emt_parse_funcs.o) \
		$(LIB)(s3_create_libraries.o) \
		$(LIB)(s3_parser_pct.o) \
		$(LIB)(s3_parser_pdt.o) \
		$(LIB)(s3_to_f77.o) \
		$(LIB)(s3_setup_static.o) \
		$(LIB)(s3_static.o) \
		$(LIB)(s3_static_main.o) \
		$(LIB)(s3_symboltable.o) \
		$(LIB)(s3_utilities.o)
#		$(LIB)(s3_parser_emt.o) \

#make:	$(LIB) $(PROG)

#s3_dml.o:	s3_dml_load.c s3_dml_dl.c s3_dml_dld.c

#########################################################################
#
#  Target for converting a lex file to C code, then compiling and
#  adding it to an archive file
#
#########################################################################
#
#.l.a:
#	$(LEX) $(LFLAGS) $<
#	mv lex.yy.c $*.c
#	$(CC) -c $(CFLAGS) -o $*.o lex.yy.c
#	$(AR) $(ARFLAGS) $@ $*.o
#	rm -f $*.o
#	rm -f $*.c

#########################################################################
#
#  Target for converting a yacc grammar file to C code, then compiling 
#  and adding it to an archive file
#
#########################################################################

#.y.c:
#	$(YACC) $(YFLAGS) $<
#	mv $*.tab.c $*.c
#
#.y.o:
#	$(YACC) $(YFLAGS) $<
#	mv $*.tab.c $*.c
#	$(CC) -c $(CFLAGS) $*.c
#
#.y.a:
#	$(YACC) $(YFLAGS) $<
#	mv $*.tab.c $*.c
#	$(CC) -c $(CFLAGS) $*.c
#	$(AR) $(ARFLAGS) $@ $*.o
#	rm -f $*.o
#	rm -f $*.c


$(LIB):	$(OBJS) $(DEFS)
	ranlib $(LIB)
#	ln -sf $(LIB) $(LIBMAJ)
#	install $(LIB) $(LIBDIR)
#	(cd $(LIBDIR) && ln -sf $(LIB) $(LIBMAJ) )
#	$(CC) $(LINCLUDES) -shared -Wl,-soname,$(SHLIBMAJ) -o $(SHLIB) ./tmpso/*.o $(LDFLAGS)
#	rm -rf ./tmpso


lib: 	init
#	$(LIB)

#$(SHLIB): $(LIB)
#	mkdir tmpso; cd tmpso; ar x ../$(LIB)
#	$(CC) $(LINCLUDES) -shared -Wl,-soname,$(SHLIBMAJ) -o $(SHLIB) ./tmpso/*.o 
#	ln -sf $(SHLIB) $(SHLIBMAJ)
#	ar rv $(SHLIB) libs3.o
#	rm libs3.o


#$(PROG): $(LIB) $(MAIN)
#	$(CC) $(CFLAGS) -o $@ $(MAIN) $(LINCLUDES) $(LDFLAGS)
#	$(CC) $(CFLAGS) -o $@sh $(MAIN) $(LINCLUDES) -lS3

$(PROG): $(MAIN) $(LIB)
#	$(CC) $(CFLAGS) -o $@ $(MAIN) $(LINCLUDES) $(SHLDFLAGS)
	$(CC) $(CFLAGS) -o $@ $(MAIN) $(LDFLAGS) $(LINCLUDES) $(LIB)

#install: $(PROG) 
#	install $(PROG) $(BINDIR)
#	install $(LIB) $(LIBDIR)
#	(cd $(LIBDIR) && ln -sf $(LIB) $(LIBMAJ) )

#	rm $(BINDIR)/$(PROGS) $(LIBDIR)/$(LIB) $(LIBDIR)/$(SHLIB)
#	cp $(BINDIR)/$(PROG) $(BINDIR)/$(PROG).old
#	cp $(LIBDIR)/$(LIB) $(LIBDIR)/$(LIB).old
#	cp $(LIBDIR)/$(SHLIB) $(LIBDIR)/$(SHLIB).old
#	cp $(PROG) $(BINDIR)/$(PROG)
#	cp $(PROG)sh $(BINDIR)/$(PROG)sh
#	cp $(LIB) $(LIBDIR)/$(LIB)
#	ln -sf $(LIBDIR)/$(LIB) $(LIBDIR)/$(LIBMAJ)
#	cp $(SHLIB) $(LIBDIR)/$(SHLIB)
#	ln -sf $(LIBDIR)/$(SHLIB) $(LIBDIR)/$(SHLIBMAJ)
#	/sbin/ldconfig


clean:
	$(MAKE) -C src clean
#-rm -f *.o *.a $(PROG) 

init:	
	$(MAKE) -C src install
