#!/home/users/mhesslin/regina/src/rexx
/* change the above to point to your rexx executable */
tempfile = '/tmp/configure_rexxsql'
Say ''
Say 'This configuration utility will create a Makefile based on the Oracle'
Say 'supplied $ORACLE_HOME/proc/lib/proc.mk and the makefile used to build'
Say 'Regina.  This configuration utility assumes that the proc.mk file resides'
Say 'in the above directory and is readble by the user.  This utility also'
Say 'assumes that the environment variable; ORACLE_HOME is set.'
Say ''
oracle_version = ''
Do 3
   Say 'Enter the version of Oracle you are using - 6.0, 7.0, 7.1 :[7.0]'
   Parse Pull oracle_version
   Select
     When oracle_version = '6.0' Then 
       Do
         use_ocildlibs = 'YES'
         Leave
       End
     When oracle_version = '7.0' Then 
       Do
         use_ocildlibs = 'YES'
         Leave
       End
     When oracle_version = '7.1' Then 
       Do
         use_ocildlibs = 'NO'
         Leave
       End
     Otherwise oracle_version = ''
   End
End
If oracle_version = '' Then
  Do
    Say 'Configuration aborted after 3 attempts at setting Oracle version...'
    Exit 1
  End
Say ''
Say 'Enter the full path to the Regina src directory:[]'
Parse Pull regina_src
Say 'Enter the full filename of the Regina makefile directory:['||regina_src||'/Makefile]'
Parse Pull regina_makefile
If regina_makefile = '' Then regina_makefile = regina_src||'/Makefile'
Say 'Enter the full filename of the Regina library; libregina.a:[/usr/local/lib/libregina.a]'
Parse Pull regina_lib
If regina_lib = '' Then regina_lib = '/usr/local/lib/libregina.a'
Say 'Building Makefile in current directory...'
macros = 'LL CC CEXTRA EEXTRA DYN_LINK SHL_TYPE DYN_LD ELIBS DYN_COMP MISCDEFS',
         'DEBUG PROF OPTIMIZE COPT LINKOPT LIBS LDEXTRA'
aa.1 = ''
aa.2 = 'SQLOBJS = rexxsql.o orasql.o hash.o'
aa.3 = 'ORAOBJS = rexxora.o oraora.o hash.o'
aa.4 = 'CCFLAGS = -DUNIX -I'||regina_src '$(OPT) -c'
aa.5 = ''
aa.6 = 'rexxsql: $(SQLOBJS)'
aa.7 = '	$(CC) $(LINKOPT) $(LDFLAGS) -o rexxsql $(SQLOBJS)' regina_lib '$(LIBS) $(OCILDLIBS)'
aa.8 = '	$(LDEXTRA) rexxsql'
aa.9 = ''
aa.10 = 'rexxora: $(ORAOBJS)'
aa.11 = '	$(CC) -DUNIX $(LINKOPT) $(LDFLAGS) -o rexxora $(ORAOBJS)' regina_lib '$(LIBS) $(OCILDLIBS)'
aa.12 = '	$(LDEXTRA) rexxora'
aa.13 = ''
aa.14 = 'hash.o: ../hash.c ../hash.h'
aa.15 = '	$(CC) $(CCFLAGS) -ohash.o ../hash.c'
aa.16 = ''
aa.17 = 'rexxsql.o: ../rexxsql.c ../oci.h ../rexxsql.h'
aa.18 = '	$(CC) $(CCFLAGS) -orexxsql.o ../rexxsql.c'
aa.19 = 'rexxora.o: ../rexxsql.c ../oci.h ../rexxsql.h'
aa.20 = '	$(CC) $(CCFLAGS) -DORA_PREFIX -orexxora.o ../rexxsql.c'
aa.21 = ''
aa.22 = 'orasql.o: ../orasql.c ../oci.h ../rexxsql.h'
aa.23 = '	$(CC) $(CCFLAGS) -oorasql.o ../orasql.c'
aa.24 = 'oraora.o: ../orasql.c ../oci.h ../rexxsql.h'
aa.25 = '	$(CC) $(CCFLAGS) -DORA_PREFIX -ooraora.o ../orasql.c'
extra_lines = 25
oracle_home = Value('ORACLE_HOME',,'SYSTEM')
proc_file = oracle_home||'/proc/lib/proc.mk'
Call putline '#******************************************************************'
Call putline '#  The following lines added for REXX/SQL'
Call putline '#******************************************************************'
If use_ocildlibs = 'NO' Then
  Do
    Call putline
    Call putline 'OCILDLIBS=$(LIBOCIC) $(PROLDLIBS)'
  End
Do While(Lines(regina_makefile)>0)
  line = Linein(regina_makefile)
  Do i = 1 To Words(macros)
    If Substr(line,1,Length(Word(macros,i))) = Word(macros,i) Then 
      Do
        Call putline(line)
        Leave
      End
  End
End
Do i = 1 To extra_lines
  Call putline aa.i
End
Address System 'rm -f Makefile'
Address System 'cat' proc_file tempfile '> Makefile'
Address System 'rm -f' tempfile
Return

putline: Procedure Expose tempfile
Parse Arg line
rc = Lineout(tempfile,line)
Return
