Commit d29e5bbb authored by rdubner's avatar rdubner

Augment cobcd.bat with COBC flexibility and dynamic GCC and COB_CFLAGS determination

parent 8e5347bc
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
::
::###########################################################################
::## The version number in the next line is updated by a Linux bash script. #
......@@ -5,10 +7,86 @@
::## Don't mess with it! #
::###########################################################################
::
::# [Version 3.3]
set VERSION=[Version 3.3]
::
::
set argC=0
for %%x in (%*) do Set /A argC+=1
IF "%argC%"=="0" (
echo This is cobcd %VERSION%
echo It is a wrapper for GnuCOBOL cobc
echo
echo Use environment variables COBCD_COBC or COBC to specify the cobc executable
goto :eof
)
IF NOT "%COBCD_COBC%"=="" (
set COBC=%COBCD_COBC%
) ELSE (
IF "%COBC%"=="" (
set COBC=cobc
)
)
FOR /F "tokens=* USEBACKQ" %%F IN (`%COBC% --info`) DO (
set COBC_INFO=!COBC_INFO! %%F
)
set GCC=
set ORIGINAL_COB_CFLAGS=
set IN_GCC=0
set IN_OCC=0
set EXTRACTOR="%COBC_INFO%"
:do_it_again
FOR /F "tokens=1,*" %%F IN (%EXTRACTOR%) DO (
set EXTRACTOR="%%G"
IF "%%F"=="COB_CFLAGS" (
SET IN_GCC=3
SET IN_OCC=1
goto do_it_again
)
IF "%%F"=="COB_LDFLAGS" (
SET IN_OCC=3
goto do_it_again
)
IF "%IN_GCC%"=="2" (
SET GCC=!GCC! %%F
)
IF "%IN_GCC%"=="1" (
IF "%%F"==":" (
set IN_GCC=2
)
)
IF "%IN_GCC%"=="0" (
IF "%%F"=="COB_CC" (
set IN_GCC=1
)
)
IF "%IN_OCC%"=="2" (
set ORIGINAL_COB_CFLAGS=!ORIGINAL_COB_CFLAGS! %%F
)
IF "%IN_OCC%"=="1" (
IF "%%F"==":" (
set IN_OCC=2
)
)
IF "%IN_OCC%"=="0" (
IF "%%F"=="COB_CFLAGS" (
set IN_OCC=1
)
)
goto do_it_again
)
::echo GCC is %GCC%
::echo ORIGINAL_COB_CFLAGS is %ORIGINAL_COB_CFLAGS%
::
@ECHO OFF
SETLOCAL
::
:: Make sure cobc can run, using the default environment if one has
:: not already been set up
......@@ -65,12 +143,12 @@ if "%BASENAME%"=="" (
)
:: Do a -S compile to create the .s file
set COB_CFLAGS=-fPIC -Wa,-L,-anchls=%BASENAME%.lst -I/mingw32/include -Wno-unused -fsigned-char -Wno-pointer-sign -D__USE_MINGW_ANSI_STDIO=1 -I/mingw32/include -march=i686 -mtune=generic -pipe -pipe
cobc -S -d -g %XorM% --fgen-c-line-directives --fgen-c-labels -T %BASENAME%.cbl.lst --tlines=0 --tsymbols %BEFORESOURCE% %SOURCEFILE%
set COB_CFLAGS=-fPIC -Wa,-L,-anchls=%BASENAME%.lst %ORIGINAL_COB_CFLAGS%
%COBC% -S -d -g %XorM% --fgen-c-line-directives --fgen-c-labels -T %BASENAME%.cbl.lst --tlines=0 --tsymbols %BEFORESOURCE% %SOURCEFILE%
IF NOT ERRORLEVEL 0 GOTO bail
:: Do a -c compile to create the .h, .i, and .lst file that COBST needs
cobc -c -d -g %XorM% --fgen-c-line-directives --fgen-c-labels -T %BASENAME%.cbl.lst --tlines=0 --tsymbols %BEFORESOURCE% %SOURCEFILE%
%COBC% -c -d -g %XorM% --fgen-c-line-directives --fgen-c-labels -T %BASENAME%.cbl.lst --tlines=0 --tsymbols %BEFORESOURCE% %SOURCEFILE%
IF NOT ERRORLEVEL 0 GOTO bail
:: Get rid of the .o file we won't be using, just to avoid possible confusion
......@@ -82,8 +160,8 @@ cobcd-st -q %BASENAME%
IF NOT ERRORLEVEL 0 GOTO bail
:: Compile basename.sym.c to create basename.sym.o
set COB_CFLAGS=
cobc -c -o %BASENAME%.sym.o %BASENAME%.sym.c
set COB_CFLAGS=%ORIGINAL_COB_CFLAGS%
%COBC% -c -o %BASENAME%.sym.o %BASENAME%.sym.c
IF NOT ERRORLEVEL 0 GOTO bail
:: Use SFIX to modify the basename.s file
......@@ -91,12 +169,12 @@ cobcd-sfix -q %BASENAME%.s %BASENAME%-2.s %BASENAME%.c %SOURCEFILE%
IF NOT ERRORLEVEL 0 GOTO bail
:: Assemble the modified .s file
cobc -c -o %BASENAME%.o %BASENAME%-2.s
%COBC% -c -o %BASENAME%.o %BASENAME%-2.s
IF NOT ERRORLEVEL 0 GOTO bail
:: Link the two .o modules together
IF "%XorM%"=="-x" (
cobc -x %BASENAME%.o %BASENAME%.sym.o %AFTERSOURCE%
%COBC% -x %BASENAME%.o %BASENAME%.sym.o %AFTERSOURCE%
IF NOT ERRORLEVEL 0 GOTO bail
) ELSE (
gcc -shared -o %BASENAME%.dll %BASENAME%.o %BASENAME%.sym.o -lcob %AFTERSOURCE%
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment