COBOL with LLVM and Clang

OpenCOBOL successfully builds with and then compiles using LLVM Clang. clang throughout the build process, including make check and tests/cobol85/make test. …

Well met,

It worked first try, well second, to correct some unit tests. OpenCOBOL builds with export CC=clang, then utilizes clang for later .cob compiles.


$ sudo yum install llvm clang clang-analyzer clang-devel
$ export CC=clang
$ ./configure
OpenCOBOL Configuration:

CC clang
COB_CC clang
CFLAGS -O2
COB_CFLAGS -I/usr/local/include
COB_EXTRA_FLAGS
LDFLAGS
COB_LDFLAGS
COB_LIBS -L${exec_prefix}/lib -lcob -lm -lgmp -lncurses -ldb
COB_CONFIG_DIR ${prefix}/share/open-cobol/config
COB_COPY_DIR ${prefix}/share/open-cobol/copy
COB_LIBRARY_PATH ${exec_prefix}/lib/open-cobol
COB_MODULE_EXT so
COB_SHARED_OPT -shared
COB_PIC_FLAGS -fPIC -DPIC
COB_EXPORT_DYN -Wl,--export-dynamic
COB_STRIP_CMD strip --strip-unneeded
Dynamic loading System

$ scan-build make

scan-build: Removing directory '/tmp/scan-build-2012-05-23-2' because it contains no reports.


$ make check

# I had to make one change to cobc/cobc.c to remove -fno-gcse to avoid a bunch of make check 'failures' due to a warning about unused -fno-gcse

$ sudo make install
$ sudo ldconfig

cobc is built with clang, and uses clang when compiling the .c generated from the .cob.


[btiffin@cobol]$ scan-build cobc -v -x hello.cob
scan-build: 'clang' executable not found in '/usr/lib64/clang-analyzer/scan-build/bin'.
scan-build: Using 'clang' from path: /usr/bin/clang
preprocessing hello.cob into /tmp/cob18158_0.cob
translating /tmp/cob18158_0.cob into /tmp/cob18158_0.c
clang -pipe -c -I/usr/local/include -Wno-unused -fsigned-char -Wno-pointer-sign -o /tmp/cob18158_0.o /tmp/cob18158_0.c
clang -pipe -Wl,--export-dynamic -o hello /tmp/cob18158_0.o -L/usr/local/lib -lcob -lm -lgmp -lncurses -ldb
scan-build: Removing directory '/tmp/scan-build-2012-05-23-2' because it contains no reports.
[btiffin@cobol]$ ./hello
Hello
[btiffin@cobol]$ ls -la hello
-rwxrwxr-x. 1 btiffin btiffin 9630 May 23 12:37 hello

Sweet and a woohoo.

Cheers,
Brian

Leave a Reply

Your email address will not be published. Required fields are marked *