Mac de COBOL 入門編
入り用でお勉強、そもそもCOBOLを知らない人。
先ずは環境構築から。
$ tar xzvf open-cobol-1.0.tar.gz $ cd open-cobol-1.0 $ ./configure --prefix /usr ... checking for getopt.h... yes checking gmp.h usability... no checking gmp.h presence... no checking for gmp.h... no configure: error: gmp.h is required
gmp.hが無いとおこられた…
http://gmplib.org/#DOWNLOAD からソースを落としてきて以下を実施。
$ tar xzvf wget gmp-4.2.4.tar.gz $ cd gmp-4.2.4 $ ./configure checking build system type... pentiumm-apple-darwin9.5.0 checking host system type... pentiumm-apple-darwin9.5.0 checking for a BSD-compatible install... /usr/bin/install -c ... config.status: linking ./mpn/generic/addsub_n.c to mpn/addsub_n.c config.status: linking ./mpn/x86/p6/mmx/gmp-mparam.h to gmp-mparam.h $ make ... creating libgmp.la (cd .libs && rm -f libgmp.la && ln -s ../libgmp.la libgmp.la) $ sudo make install
OK、再度OpenCOBOLへ。
$ ./configure --prefix /usr ... checking for dbopen in -ldb... no configure: error: libdb is required
こんどは libdb!
BerkeleyDBに同梱されているモノらしいので、BerkeleyDBを入れることに。
http://www.oracle.com/technology/software/products/berkeley-db/index.html からソースを落としてインストール。
$ tar xzvf db-4.7.25.tar.gz $ cd db-4.7.25/build_unix/ $ ../dist/configure ... config.status: creating db.h config.status: creating db_config.h $ make ... creating db_verify /bin/sh ./libtool --mode=execute true db_verify $ make install $ sudo ln -s /usr/local/BerkeleyDB.4.7/lib/libdb.a /usr/lib/libdb.a $ sudo ln -s /usr/local/BerkeleyDB.4.7/lib/libdb.dylib /usr/lib/libdb.dylib $ sudo ln -s /usr/local/BerkeleyDB.4.7/lib/libdb-4.7.a /usr/lib/libdb-4.7.a $ sudo ln -s /usr/local/BerkeleyDB.4.7/lib/libdb-4.7.la /usr/lib/libdb-4.7.la $ sudo ln -s /usr/local/BerkeleyDB.4.7/lib/libdb-4.7.dylib /usr/lib/libdb-4.7.dylib
そういえば BerkeleyDBはOracle 傘下になったんだっけ…
なんか目的を見失いそう… OpenCOBOL 今度こそ。
$ ./configure --prefix=/usr ... Use fcntl for file locking: yes Use ncurses/pdcurses/curses for screen I/O: yes $ make ... Making all in cobol85 make[3]: Nothing to be done for `all'. make[3]: Nothing to be done for `all-am'. make[2]: Nothing to be done for `all-am'. $ sudo make install ... test -z "/usr/include" || /bin/sh ./mkinstalldirs "/usr/include" /usr/bin/install -c -m 644 'libcob.h' '/usr/include/libcob.h' $ which cobc /usr/bin/cobc
無事入ったっぽい。環境構築に時間かけすぎorz
Hello world だけやっとこ。以下2つの書き方ができる様子。先頭のスペースを取ってコンパイルできなかった初心者が通りますよ、と。
- hello.cob (1)
* Sample COBOL program IDENTIFICATION DIVISION. PROGRAM-ID. hello. PROCEDURE DIVISION. DISPLAY "Hello World!". STOP RUN.
- hello.cob (2)
000100* Sample COBOL program 000200 IDENTIFICATION DIVISION. 000300 PROGRAM-ID. hello. 000400 PROCEDURE DIVISION. 000500 DISPLAY "Hello World!". 000600 STOP RUN.
実行形式でコンパイル
$ cobc -x hello.cob $ ls hello hello.cob $ ./hello Hello World!
各種命令はおいおい学ぼう2008。あぁ、脱線が多い…