forked from neopragma/cobol-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·76 lines (62 loc) · 2.03 KB
/
compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#================================================================================
# Build ZUTZCPC.CBL - Z390 compatible unit test framework for batch COBOL.
#================================================================================
. envvars
export COBCPY="$MAINCPY:$TESTCPY"
function show_help {
echo 'GNU COBOL compile script'
echo "Version $VERSION"
echo 'Usage: compile [options] program-name-without-suffix [subprogram-names]'
echo ' -c | --clean Delete the existing executable before compiling'
echo ' -h | --help Display usage help (this text) and exit'
echo ' -t | --test Source is in the project test directory (not main)'
echo ' -s | --subprogram Generate a callable subprogram (not an executable)'
}
CLEAN=false
TEST=false
SUBPROGRAM=false
TEMP=`getopt -o chst --long clean,help,subprogram,test \
-n 'javawrap' -- "$@"`
if [ $? != 0 ] ; then show_help >&2 ; exit 0 ; fi
eval set -- "$TEMP"
while [ $# -gt 0 ]; do
case "$1" in
-c | --clean ) CLEAN=true; shift ;;
-h | --help ) show_help; exit 0 ;;
-s | --subprogram ) SUBPROGRAM=true; shift ;;
-t | --test ) TEST=true; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ $# -eq 0 ]
then
show_help
exit 0
fi
mkdir -p "$TARGET"
if [ $TEST == true ]; then # compile test source
SOURCE="$TESTSRC"
else
SOURCE="$MAINSRC" # compile production source
fi
if [ $SUBPROGRAM == true ]; then # make a dynamic link module
SUFFIX='.so'
COBOPTS='-m'
else # make an executable
SUFFIX=
COBOPTS='-x'
fi
# remove existing output file, if any
if [ $CLEAN == true ] && [ -e "$TARGET/${1}${SUFFIX}" ]; then
rm "$TARGET/${1}${SUFFIX}"
fi
cobc "$COBOPTS" -std=ibm "$SOURCE/$1.CBL" # compile, assemble, link w/ selected options
if [ $? -eq 0 ] # copy output file to target directory
then
mv "${1}${SUFFIX}" "$TARGET/."
exit 0
else
exit 1
fi