@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: bldapp.bat
rem Builds Windows VisualAge COBOL applications
rem Usage: bldapp prog_name [ db_name [ userid password ]]

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 If an embedded SQL program, precompile and bind it.
if not exist "%1.sqb" goto compile_step
call embprep %1 %2 %3 %4
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
if "%3" == "" goto case2
if "%4" == "" goto error
goto case3 

:case1
  set EXTRA_COMPFLAG=-q"SQL('database sample CALL_RESOLUTION DEFERRED')"
  goto compile_step
:case2
  set EXTRA_COMPFLAG=-q"SQL('database %2 CALL_RESOLUTION DEFERRED')"
  goto compile_step
:case3
  set EXTRA_COMPFLAG=-q"SQL('database %2 user %3 using %4 CALL_RESOLUTION DEFERRED')"
  goto compile_step

:compile_step
rem Compile the error-checking utility.
cob2 -qpgmname(mixed) -c -qlib -I"%DB2PATH%\include\cobol_a" checkerr.cbl
 
rem Compile the program.
cob2 -qpgmname(mixed) -c -qlib -I"%DB2PATH%\include\cobol_a" %1.cbl %EXTRA_COMPFLAG%
 
rem Link the program.
cob2 %1.obj checkerr.obj db2api.lib
goto exit

:error
echo Usage: bldapp prog_name [ db_name [ userid password ]]

:exit
@echo on