cobcd.bat 3.15 KB
Newer Older
1
2
@ECHO OFF
SETLOCAL
3
4
5
6
7
8
9
10
11
12
13
14
15
::
:: Make sure cobc can run, using the default environment if one has
:: not already been set up
::
if not defined COB_CONFIG_DIR (
    call cobenv --setenv >NUL
    )

::
:: Bust up the input parameters into one that come before the single
:: COBOL source module we know how to handle, the COBOL module itself,
:: and the ones after
::
16

17
18
19
20
set BEFORESOURCE=
set SOURCEFILE=
set BASENAME=
set AFTERSOURCE=
21
22
set XorM=-m

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
:parameter_loop

    IF "%1"=="-x" (
        SET XorM=-x
        )
    IF /i "%~x1"==".cbl" (
        set SOURCEFILE=%1
        set BASENAME=%~n1
        goto parameter_continue
        )
    IF /i "%~x1"==".cob" (
        set SOURCEFILE=%1
        set BASENAME=%~n1
        goto parameter_continue
        )
    IF "%SOURCEFILE%"=="" (
        set BEFORESOURCE=%BEFORESOURCE% %1
        ) ELSE (
        set AFTERSOURCE=%AFTERSOURCE% %1
        )
:parameter_continue
    shift
    if not "%~1"=="" goto parameter_loop

:: echo BEFORESOURCE %BEFORESOURCE%
:: echo SOURCEFILE %SOURCEFILE%
:: echo AFTERSOURCE %AFTERSOURCE%
:: echo BASENAME %BASENAME%
:: echo XorM %XorM%
52
53
54
55
56
57
58
59

if "%BASENAME%"=="" (
    echo No input files
    goto :eof
    )

:: 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
60
61
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
62
63

:: Do a -c compile to create the .h, .i, and .lst file that COBST needs
64
65
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
66
67
68

:: Get rid of the .o file we won't be using, just to avoid possible confusion
erase %BASENAME%.o
69
IF NOT ERRORLEVEL 0 GOTO bail
70
71
72

:: Run COBST to create basename.sym.c
cobst -q %BASENAME%
73
IF NOT ERRORLEVEL 0 GOTO bail
74
75
76
77

:: Compile basename.sym.c to create basename.sym.o
set COB_CFLAGS=
cobc -c -o %BASENAME%.sym.o %BASENAME%.sym.c
78
IF NOT ERRORLEVEL 0 GOTO bail
79
80
81

:: Use SFIX to modify the basename.s file
sfix -q %BASENAME%.s %BASENAME%-2.s %BASENAME%.c %SOURCEFILE%
82
IF NOT ERRORLEVEL 0 GOTO bail
83
84
85

:: Assemble the modified .s file
cobc -c -o %BASENAME%.o %BASENAME%-2.s
86
IF NOT ERRORLEVEL 0 GOTO bail
87
88
89

:: Link the two .o modules together
IF "%XorM%"=="-x" (
90
91
    cobc -x %BASENAME%.o %BASENAME%.sym.o %AFTERSOURCE%
    IF NOT ERRORLEVEL 0 GOTO bail
92
    ) ELSE (
93
94
    gcc -shared -o %BASENAME%.dll %BASENAME%.o %BASENAME%.sym.o -lcob %AFTERSOURCE%
    IF NOT ERRORLEVEL 0 GOTO bail
95
96
97
98
99
100
101
102
103
104
105
    )

SET CPRINTPY=
for %%I in (cprint.py) do SET CPRINTPY=%%~$PATH:I

if "%CPRINTPY%"=="" (
    echo Couldn't find a copy of cprint.py on the PATH
    ) ELSE (
    copy %CPRINTPY% %BASENAME%-gdb.py >NUL
    )

106
107
:bail

108
109
110
111
if "%COBCDNOCLEAN%"=="" (
    erase /Q %BASENAME%.c %BASENAME%.s %BASENAME%*.h %BASENAME%.i %BASENAME%.lst ^
    %BASENAME%.cbl.lst %BASENAME%.full.tab %BASENAME%.tab %BASENAME%.o ^
    %BASENAME%.cbl.o %BASENAME%-2.lst %BASENAME%.sym.c %BASENAME%.sym.o ^
112
    %BASENAME%-2.s %BASENAME%.o  %BASENAME%-2.o
113
114
    )

115
ENDLOCAL