@echo off
rem (c) Copyright IBM Corp. 2007 All rights reserved.
rem 
rem The following sample of source code ("Sample") is owned by International 
rem Business Machines Corporation or one of its subsidiaries ("IBM") and is 
rem copyrighted and licensed, not sold. You may use, copy, modify, and 
rem distribute the Sample in any form without payment to IBM, for the purpose of 
rem assisting you in the development of your applications.
rem 
rem The Sample code is provided to you on an "AS IS" basis, without warranty of 
rem any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR 
rem IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
rem MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do 
rem not allow for the exclusion or limitation of implied warranties, so the above 
rem limitations or exclusions may not apply to you. IBM shall not be liable for 
rem any damages you suffer as a result of using, copying, modifying or 
rem distributing the Sample, even if IBM has been advised of the possibility of 
rem such damages.

rem BATCH FILE: bldrtn.bat
rem Builds Windows VisualAge COBOL routines (stored procedures)
rem Usage: bldrtn prog_name [ db_name ]
 
set IBMCOB_PRECOMP=
set EXTRA_COMPFLAG=

rem To use the IBM COBOL precompiler, uncomment the following line.
rem set IBMCOB_PRECOMP=true

rem If using the IBM COBOL precompiler
if "%IBMCOB_PRECOMP%" == "true" goto IBMCOB_precompile_step
 
rem Using the default DB2 precompiler,
rem Precompile and bind the program.
call embprep %1 %2
goto compile_step

:IBMCOB_precompile_step
rem Using the IBM COBOL precompiler,
rem Copy the <prog_name>.sqb file to <prog_name>.cbl.
if exist "%1.sqb" cp -f %1.sqb %1.cbl
rem Assign input parameters to the EXTRA_COMPFLAG variable
if "%1" == "" goto error
if "%2" == "" goto case1

set EXTRA_COMPFLAG=-q"SQL('database %2 CALL_RESOLUTION DEFERRED')"
goto compile_step

:case1
  set EXTRA_COMPFLAG=-q"SQL('database sample CALL_RESOLUTION DEFERRED')"
  goto compile_step
  
:compile_step
rem  Compile the stored procedure.
cob2 -qpgmname(mixed) -c -qlib -I"%DB2PATH%\include\cobol_a" %1.cbl %EXTRA_COMPFLAG%
 
rem  Link the stored procedure and create a shared library.
ilib /nol /gi:%1 %1.obj
ilink /free /nol /dll db2api.lib %1.exp %1.obj iwzrwin3.obj
 
rem Copy stored procedure to the %DB2PATH%\function directory.
copy %1.dll "%DB2PATH%\function"
goto exit

:error
echo Usage: bldrtn prog_name [ db_name ] 

:exit
@echo on